Initial commit

This commit is contained in:
adri 2017-12-12 10:47:31 +01:00
commit 85f8740e7c
16 changed files with 1037 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
*.vssscc
$tf*/

1
.tfignore Normal file
View File

@ -0,0 +1 @@
\.git

Binary file not shown.

BIN
.vs/horloge/v14/.atsuo Normal file

Binary file not shown.

22
horloge.atsln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Atmel Studio Solution File, Format Version 11.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "horloge", "horloge\horloge.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AVR = Debug|AVR
Release|AVR = Release|AVR
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

31
horloge/global.h Normal file
View File

@ -0,0 +1,31 @@
/*
* global.h
*
* Created: 28-11-17 13:53:21
* Author: Adrien
*/
#ifndef GLOBAL_H_
#define GLOBAL_H_
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define __BP_PLUS__ PINB0
#define __BP_MOIN__ PINB1
#define __BP_CONF__ PINB3
#define __BP_START__ PINB2
#define __TMP_BP_MAX__ 1000 //Acc?l?ration Min
#define __TMP_BP_MIN__ 50 //Acc?leration MAx
#define __TMP_BP_NLOOP_DEC__ 2 //Acc?l?ration apr?s x incr?mentation/d?cr?mentation
#define __TMP_BP_SETUP__ 500 //tmp pour rentrer dans le setup
typedef enum { NONE = 0, LCONF = 1, RCONF = 2} setup_t;
typedef enum {NORMALMODE = 0, CHRONO = 1, MINUTERIE = 2, REVEIL = 3} mode_t;
extern uint8_t appuisBPflag;
#endif /* GLOBAL_H_ */

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.2.0</CVersion>
<DefaultRepoPath>G:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include\avr\iom328p.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>UMk4QUzkkuShabuoYtNl/Q==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iom328p.h</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>ZJ6gYgbh1LauuUkZtQozzA==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.cpp</Name>
<SelectString>Main file (.cpp)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>gcc/dev/atmega328p</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
</Files>
<PackName>ATmega_DFP</PackName>
<PackPath>G:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.132/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.2.132</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATmega328P</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string>
</RteComponents>
<Status>Resolved</Status>
<VersionMode>Fixed</VersionMode>
<IsComponentInAtProject>true</IsComponentInAtProject>
</ProjectComponent>
</ProjectComponents>
</Store>

193
horloge/horloge.cppproj Normal file
View File

@ -0,0 +1,193 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<avrdevice>ATmega328P</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
<Language>CPP</Language>
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
<OutputFileExtension>.elf</OutputFileExtension>
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
<AssemblyName>horloge</AssemblyName>
<Name>horloge</Name>
<RootNamespace>horloge</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
<ProgFlashFromRam>true</ProgFlashFromRam>
<RamSnippetAddress>0x20000000</RamSnippetAddress>
<UncachedRange />
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue>exception_table</OverrideVtorValue>
<BootSegment>2</BootSegment>
<eraseonlaunchrule>0</eraseonlaunchrule>
<AsfFrameworkConfig>
<framework-data xmlns="">
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.1" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
<avrtool>com.atmel.avrdbg.tool.simulator</avrtool>
<avrtoolserialnumber />
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
<com_atmel_avrdbg_tool_simulator>
<ToolOptions xmlns="">
<InterfaceProperties>
</InterfaceProperties>
</ToolOptions>
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
<ToolNumber xmlns="">
</ToolNumber>
<ToolName xmlns="">Simulator</ToolName>
</com_atmel_avrdbg_tool_simulator>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include</Value>
</ListValues>
</avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcccpp.compiler.symbols.DefSymbols>
<avrgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include</Value>
</ListValues>
</avrgcccpp.compiler.directories.IncludePaths>
<avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
<avrgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include</Value>
</ListValues>
</avrgcccpp.assembler.general.IncludePaths>
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="global.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="horlogeLepot.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="horlogeLepot.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="main.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="max7219.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="max7219.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="util.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="util.h">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>

133
horloge/horlogeLepot.cpp Normal file
View File

@ -0,0 +1,133 @@
/*
* horlogeLepot.c
*
* Created: 28-11-17 13:18:33
* Author: Adrien
*/
#include "max7219.h"
#include "util.h"
#include "horlogeLepot.h"
#include "global.h"
#pragma region horloge
horloge::horloge(max7219 *max)
{
this->max = max;
t = millis();
ar[0] = ar[1] = ar[2] = ar[3] = 0;
heures=0;
minutes=0;
HHMM=0;
decalageMinutes=0;
decalageHeures=0; //Pour "synchronis?" sur la fonction millis
}
void horloge::afficherHeur()
{
t = millis();
unsigned long decalageMilis = HH_MMtoHHMM(decalageHeures, decalageMinutes);
decalageMilis = HHMMToMillis(decalageMilis);
millisToHH_MM_Decalage(&heures, &minutes, decalageMilis);
HHMM = HH_MMtoHHMM(heures, minutes);//on fusionne pour n'avoir qu'un chiffre. 11h30 devien 1130
intTo4DigitArray(HHMM, ar, 4);//Decompose chaque digit
if(((t%1000)>500)) //Clignotement des ":"
ar[2] |= _BV(7);
else
ar[2] &= ~(_BV(7));
max->sendDigitFromArray(ar,4);
max->on();
}
void horloge::configMinute()
{
t=millis();
unsigned long decalageMilis = HH_MMtoHHMM(decalageHeures, decalageMinutes);
decalageMilis = HHMMToMillis(decalageMilis);
millisToHH_MM_Decalage(&heures, &minutes, decalageMilis);
HHMM = HH_MMtoHHMM(heures, minutes);//on fusionne pour n'avoir qu'un chiffre. 11h30 devien 1130
intTo4DigitArray(HHMM, ar, 4);//Decompose chaque digit
if(((t%1000)>500) && PINB&_BV(__BP_MOIN__) && PINB&_BV(__BP_PLUS__) && PINB&_BV(__BP_START__) && PINB&_BV(__BP_CONF__)) //Clignotement des ":" et des min (arret du clignotement si on apuie sur un bp)
{
ar[2] |= _BV(7);
ar[0] |= 0x0F;
ar[1] |= 0x0F;
}
else
{
ar[2] &= ~(_BV(7));
}
max->sendDigitFromArray(ar,4);
if(!(PINB&_BV(__BP_PLUS__)) && !appuisBPflag)
{
_delay_ms(10);
++decalageMinutes %= 60;
appuisBPflag = 1;
}
if(!(PINB&_BV(__BP_MOIN__)) && !appuisBPflag)
{
_delay_ms(10);
--decalageMinutes = (decalageMinutes>59)?59:decalageMinutes;
appuisBPflag = 1;
}
}
void horloge::configHeure()
{
t = millis();
unsigned long decalageMilis = HH_MMtoHHMM(decalageHeures, decalageMinutes);
decalageMilis = HHMMToMillis(decalageMilis);
millisToHH_MM_Decalage(&heures, &minutes, decalageMilis);
HHMM = HH_MMtoHHMM(heures, minutes);//on fusionne pour n'avoir qu'un chiffre. 11h30 devien 1130
intTo4DigitArray(HHMM, ar, 4);//Decompose chaque digit
if(((t%1000)>500) && PINB&_BV(__BP_MOIN__) && PINB&_BV(__BP_PLUS__) && PINB&_BV(__BP_START__) && PINB&_BV(__BP_CONF__)) //Clignotement des ":" et des min (arret du clignotement si on apuie sur un bp)
{
ar[2] |= _BV(7);
ar[2] |= 0x0F;
ar[3] |= 0x0F;
}
else
{
ar[2] &= ~(_BV(7));
}
max->sendDigitFromArray(ar,4);
if(!(PINB&_BV(__BP_PLUS__)) && !appuisBPflag)
{
_delay_ms(10);
++decalageHeures %= 24;
appuisBPflag = 1;
}
if(!(PINB&_BV(__BP_MOIN__)) && !appuisBPflag)
{
_delay_ms(10);
--decalageHeures = (decalageHeures>23)?23:decalageHeures;
appuisBPflag = 1;
}
}
void afficherHeur()
{
}
void configMinute()
{
}
void configHeure()
{
}
#pragma endregion horloge
#pragma region minuterie
#pragma endregion minuterie
#pragma region compteur
#pragma endregion compteur
#pragma region reveil
#pragma endregion reveil

35
horloge/horlogeLepot.h Normal file
View File

@ -0,0 +1,35 @@
/*
* horlogeLepot.h
*
* Created: 28-11-17 13:18:01
* Author: Adrien
*/
#ifndef HORLOGELEPOT_H_
#define HORLOGELEPOT_H_
#ifndef __MAX7219_H__
#include "max7219.h"
#endif
class horloge
{
private:
max7219 *max;
unsigned long t;
uint8_t ar[4];
uint8_t heures, minutes;
int HHMM;
uint8_t decalageMinutes, decalageHeures; //Pour "synchronis?" sur la fonction millis
public:
horloge(max7219 *max);
void afficherHeur();
void configMinute();
void configHeure();
};
#endif /* HORLOGELEPOT_H_ */

View File

@ -0,0 +1,44 @@
/*
* horloge.cpp
*
* Created: 17-10-17 20:53:10
* Author : Adrien
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include "util.h"
#include "max7219.h"
#define __plus__ 1
#define __moins__ 2
#define __start__ 3
#define __conf__ 4
#define __MAX_DIN__ 5
#define __MAX_LOAD__ 6
#define __MAX_CLK__ 7
int main(void)
{
/* Replace with your application code */
max7219 max(__MAX_DIN__, __MAX_LOAD__, __MAX_LOAD__, 4);
max.sendRAWdata(1,max7219::D1);
uint8_t heures = 0, minutes = 0, secondes = 0;
while (1)
{
max.sendRAWdata(1,max7219::D1);
max.sendRAWdata(1,max7219::D2);
max.setIntensity(50);
}
}
isr(__INT__)
{
}

145
horloge/main.cpp Normal file
View File

@ -0,0 +1,145 @@
/*
* horloge.cpp
*
* Created: 17-10-17 20:53:10
* Author : Adrien
*|----------------------------
*| LCONF | RCONF |
*|____________________________
*| D4 | D3 | D2 | D1 |
*|----------------------------
*| ### ### ### ### |
*| # # # # o # # # # |
*| ### ### ### ### |
*| # # # # o # # # # |
*| ### o ### o ### o ### o|
*|----------------------------
*| o = dot ; pour activer mettre <EFBFBD> 1 le bit 7 digit|_BV(7)
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include "util.h"
//#include "max7219.h"
#include "horlogeLepot.h"
#include "global.h"
uint8_t appuisBPflag = 0;
int main(void)
{
max7219 max(2,3,4, 4);
horloge horloge0(&max);
/* Replace with your application qcode */
DDRB &= ~(_BV(__BP_PLUS__)|_BV(__BP_MOIN__)|_BV(__BP_CONF__)|_BV(__BP_START__));
PORTB |= _BV(__BP_PLUS__)|_BV(__BP_MOIN__)|_BV(__BP_CONF__)|_BV(__BP_START__); //PULL-UP
mode_t mode = NORMALMODE;
setup_t setup = NONE;
setupMilis();
unsigned int tempoBP = __TMP_BP_MAX__;
unsigned int tempoBPi = 0;
unsigned long millisBPStart = 0;
_delay_ms(50);
unsigned long t = millis();
while (1)
{
t = millis();
#pragma region GestionTempoBP
if((millis()-millisBPStart) > tempoBP && appuisBPflag)
{
millisBPStart = millis();
appuisBPflag = 0;
tempoBPi++;
if(tempoBP>__TMP_BP_MIN__ && tempoBPi == __TMP_BP_NLOOP_DEC__)
{
tempoBP *=0.75;
tempoBPi = 0;
}
}
if(PINB&_BV(__BP_MOIN__) && PINB&_BV(__BP_PLUS__) && PINB&_BV(__BP_START__) && PINB&_BV(__BP_CONF__) ) //Reset des var lors du relachement
{
appuisBPflag = 0;
tempoBPi = 0;
tempoBP = __TMP_BP_MAX__;
}
#pragma endregion GestionTempoBP
#pragma region GestionConfig
if(!(PINB&_BV(__BP_CONF__))) //Getsion config
{
_delay_ms(10);//Anti rebon soft
unsigned int tapuis = millis();
while(!(PINB&_BV(__BP_CONF__)))
{
//Routine a exe si besoin
}
if(millis()-tapuis < __TMP_BP_SETUP__ && !setup)
{
switch(mode)
{
case NORMALMODE:
mode = CHRONO;
break;
case CHRONO:
mode = MINUTERIE;
break;
case MINUTERIE:
mode = REVEIL;
break;
case REVEIL:
mode = NORMALMODE;
break;
}
}
else
{
switch(setup)
{
case NONE:
setup = RCONF;
break;
case RCONF:
setup = LCONF;
break;
case LCONF:
setup = NONE;
break;
}
}
}
#pragma endregion GestionConfig
if(!setup)
{
switch(mode)
{
default:
horloge0.afficherHeur();
break;
}
}
else
{
switch (setup)
{
case RCONF:
horloge0.configMinute();
break;
case LCONF:
horloge0.configHeure();
break;
}
}
}
}

125
horloge/max7219.cpp Normal file
View File

@ -0,0 +1,125 @@
/*
* max7219.cpp
*
* Created: 17-10-17 21:26:30
* Author: Adrien
*/
#define F_CPU 16000000UL
#include "max7219.h"
#include "util.h"
#include <assert.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/cpufunc.h>
max7219::max7219(uint8_t din, uint8_t load, uint8_t clk, uint8_t nOfDigit)
{
this->din = pinArduinoToPINXX(din);
this->load = pinArduinoToPINXX(load);
this->clk = pinArduinoToPINXX(clk);
this->nOfDigit = nOfDigit;
pinDin = pinToPINX(din);
pinLoad = pinToPINX(load);
pinClk = pinToPINX(clk);
ddrDin = pinDin+1; ddrLoad=pinLoad+1;ddrClk=pinClk+1;
portDin = pinDin+2; portLoad=pinLoad+2;portClk=pinClk+2;
*ddrDin |= _BV(pinArduinoToPINXX(din));
*ddrLoad |= _BV(pinArduinoToPINXX(load));
*ddrClk |= _BV(pinArduinoToPINXX(clk));
setLoadTo(1);
setClkTo(0);
setDataTo(0);
_delay_ms(50);
sendRAWdata(nOfDigit, SCANLIMIT);
sendRAWdata((0xff),DECODEMODE);
on();
}
void max7219::sendRAWdata(volatile uint8_t data, volatile address ad)
{
int i = 0;
setClkTo(0);
setLoadTo(0);
_NOP();
_NOP();
for (i=0; i<8 ; i++)
{
setDataTo(ad&(0b10000000>>i));
_NOP();
_NOP();
setClkTo(1);
_delay_us(1);
setClkTo(0);
_NOP();
_NOP();
}
for (i=0; i<8 ; i++)
{
setClkTo(0);
setDataTo(data&(0b10000000>>i));
_NOP();
_NOP();
setClkTo(1);
_delay_us(1);
setClkTo(0);
_NOP();
_NOP();
}
setLoadTo(1);
_delay_us(1);
}
void max7219::on()
{
sendRAWdata(0x01, SHUTDOWN);
}
void max7219::off()
{
sendRAWdata(0x00, SHUTDOWN);
}
void max7219::sendDigitFromArray(uint8_t *array, uint8_t s)
{
sendRAWdata(0xFF, DECODEMODE);
for (int i=0;i<s;i++)
{
sendRAWdata(array[i],(address)(D1+i));
}
}
void max7219::setIntensity(const uint8_t i)
{
sendRAWdata(i, INTENSITY);
}
void max7219::setClkTo(uint8_t v)
{
if(v)
{
*portClk |= _BV(clk);
}
else
{
*portClk &= ~(_BV(clk));
}
}
void max7219::setLoadTo(uint8_t v)
{
if(v)
{
*portLoad |= _BV(load);
}
else
{
*portLoad &= ~(_BV(load));
}
}
void max7219::setDataTo(uint8_t v)
{
if(v)
{
*portDin |= _BV(din);
}
else
{
*portDin &= ~(_BV(din));
}
}

47
horloge/max7219.h Normal file
View File

@ -0,0 +1,47 @@
/*
* max7219.h
*
* Created: 17-10-17 21:26:30
* Author: Adrien
*/
#ifndef __MAX7219_H__
#define __MAX7219_H__
#include <stdint.h>
class max7219
{
//variables
public:
typedef enum{NOP=0x00,D1=0x01,D2=0x02,D3,D4,D5,D6,D7,D8,DECODEMODE,INTENSITY=0x0A,SCANLIMIT,SHUTDOWN,TEST=0x0F} address;
protected:
private:
uint8_t nOfDigit;
uint8_t din,load,clk;
uint8_t decodeMode;
volatile uint8_t *pinDin, *portDin, *ddrDin;
volatile uint8_t *pinLoad, *portLoad, *ddrLoad;
volatile uint8_t *pinClk, *portClk, *ddrClk;
//functions
public:
max7219(uint8_t din, uint8_t load, uint8_t clk, uint8_t nOfDigit);
void sendRAWdata(uint8_t data, address ad);
void on();
void off();
void sendDigitFromArray(uint8_t *array, uint8_t s);
void setIntensity(uint8_t i);
protected:
private:
void setClkTo(uint8_t v);
void setLoadTo(uint8_t v);
void setDataTo(uint8_t v);
}; //max7219
#endif //__MAX7219_H__

120
horloge/util.cpp Normal file
View File

@ -0,0 +1,120 @@
/*
* util.cpp
*
* Created: 17-10-17 21:21:20
* Author: Adrien
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "util.h"
#include "global.h"
unsigned long tmpMillis = 0UL;
uint8_t uint8ToBCD(uint8_t val)
{
return (val%10)|((val/10)<<4);
}
void intTo4DigitArray(unsigned int d, uint8_t * array, uint8_t arrayMax)
{
int i;
for(i = 0; d && i<arrayMax ; i++)
{
array[i] = d%10;
d/=10;
}
for(;i<arrayMax;i++)
array[i] = 0;
}
volatile uint8_t *pinToPINX(uint8_t pin)
{
if(pin<=7)
return &PIND;
else if(pin<=13)
return &PINB;
else
return &PINC;
}
uint8_t pinArduinoToPINXX(uint8_t pin)
{
if(pin <= 13)
return pin%8;
else
return pin-13;
}
void setupMilis()
{
TCCR0A = 0x00;
TCCR0B = _BV(CS11)|_BV(CS10); //Divide 16Mhz by 64
TIMSK0 = _BV(OCIE1A);
OCR0A = 250;
//Compare at 250, every ms
sei();
}
unsigned long millis()
{
return tmpMillis;
}
unsigned int millisToHHMM()
{
unsigned long seconde = millis()/1000;
unsigned long minute = seconde/60;
unsigned long heure = minute/60;
minute %= 60;
heure %= 24;
return (heure*100)+minute;
}
void millisToHH_MM(uint8_t * HH, uint8_t *MM)
{
unsigned long seconde = millis()/1000;
unsigned long minute = seconde/60;
unsigned long heure = minute/60;
minute %= 60;
heure %= 24;
*MM = (uint8_t)minute;
*HH = (uint8_t)(heure);
}
void millisToHH_MM_Decalage(uint8_t * HH, uint8_t *MM, unsigned long decalage)
{
unsigned long seconde = (millis()+decalage)/1000;
unsigned long minute = seconde/60;
unsigned long heure = minute/60;
minute %= 60;
heure %= 24;
*MM = (uint8_t)minute;
*HH = (uint8_t)(heure);
}
unsigned long HHMMToMillis(unsigned int HHMM)
{
unsigned long minute = (HHMM%100)+((HHMM/100)*60);
unsigned long ms = minute*60*1000;
return ms;
}
unsigned int HH_MMtoHHMM(uint8_t HH, uint8_t MM)
{
return (unsigned int)(HH*100)+MM;
}
void HHMMtoHH_MM(uint8_t HHMM, uint8_t * HH, uint8_t *MM)
{
*HH = HHMM/100;
*MM = HHMM%100;
}
uint8_t VerifappuisBP()
{
return !(PINB&_BV(__BP_MOIN__) && PINB&_BV(__BP_PLUS__) && PINB&_BV(__BP_START__) && PINB&_BV(__BP_CONF__));
}
ISR(TIMER0_COMPA_vect)
{
++tmpMillis;
TCNT0 = 0;
}

26
horloge/util.h Normal file
View File

@ -0,0 +1,26 @@
/*
* util.h
*
* Created: 17-10-17 20:59:25
* Author: Adrien
*/
#ifndef UTIL_H_
#define UTIL_H_
#include <stdint.h>
typedef enum {A0=14, A1, A2, A3, A4, A5} AnalogPin;
uint8_t uint8ToBCD(uint8_t val);
volatile uint8_t *pinToPINX(uint8_t pin);
uint8_t pinArduinoToPINXX(uint8_t pin);
void setupMilis();
unsigned long millis();
void intTo4DigitArray(unsigned int d, uint8_t * array, uint8_t arrayMax);
unsigned int millisToHHMM();
void millisToHH_MM(uint8_t * HH, uint8_t *MM);
void millisToHH_MM_Decalage(uint8_t * HH, uint8_t *MM, unsigned long decalage);
unsigned long HHMMToMillis(unsigned int HHMM);
unsigned int HH_MMtoHHMM(uint8_t HH, uint8_t MM);
void HHMMtoHH_MM(uint8_t HHMM, uint8_t * HH, uint8_t *MM);
uint8_t VerifappuisBP();
#endif /* UTIL_H_ */