commit 85f8740e7ce11851ceabe4c149e2ee4bb9606346 Author: adri Date: Tue Dec 12 10:47:31 2017 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..176c449 --- /dev/null +++ b/.gitignore @@ -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*/ \ No newline at end of file diff --git a/.tfignore b/.tfignore new file mode 100644 index 0000000..e37a9f1 --- /dev/null +++ b/.tfignore @@ -0,0 +1 @@ +\.git \ No newline at end of file diff --git a/.vs/horloge/v14/-DESKTOP-M2KTSKL.atsuo b/.vs/horloge/v14/-DESKTOP-M2KTSKL.atsuo new file mode 100644 index 0000000..a33a7ed Binary files /dev/null and b/.vs/horloge/v14/-DESKTOP-M2KTSKL.atsuo differ diff --git a/.vs/horloge/v14/.atsuo b/.vs/horloge/v14/.atsuo new file mode 100644 index 0000000..3b4dcf0 Binary files /dev/null and b/.vs/horloge/v14/.atsuo differ diff --git a/horloge.atsln b/horloge.atsln new file mode 100644 index 0000000..6972969 --- /dev/null +++ b/horloge.atsln @@ -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 diff --git a/horloge/global.h b/horloge/global.h new file mode 100644 index 0000000..09d9770 --- /dev/null +++ b/horloge/global.h @@ -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 +#include + + +#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_ */ \ No newline at end of file diff --git a/horloge/horloge.componentinfo.xml b/horloge/horloge.componentinfo.xml new file mode 100644 index 0000000..8a755c6 --- /dev/null +++ b/horloge/horloge.componentinfo.xml @@ -0,0 +1,86 @@ + + + + + + + Device + Startup + + + Atmel + 1.2.0 + G:/Program Files (x86)\Atmel\Studio\7.0\Packs + + + + + G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include + + include + C + + + include + + + + + G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\include\avr\iom328p.h + + header + C + UMk4QUzkkuShabuoYtNl/Q== + + include/avr/iom328p.h + + + + + G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\templates\main.c + template + source + C Exe + GD1k8YYhulqRs6FD1B2Hog== + + templates/main.c + Main file (.c) + + + + G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\templates\main.cpp + template + source + C Exe + ZJ6gYgbh1LauuUkZtQozzA== + + templates/main.cpp + Main file (.cpp) + + + + G:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p + + libraryPrefix + GCC + + + gcc/dev/atmega328p + + + + + ATmega_DFP + G:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.132/Atmel.ATmega_DFP.pdsc + 1.2.132 + true + ATmega328P + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/horloge/horloge.cppproj b/horloge/horloge.cppproj new file mode 100644 index 0000000..002c600 --- /dev/null +++ b/horloge/horloge.cppproj @@ -0,0 +1,193 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.CPP + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATmega328P + none + Executable + CPP + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + horloge + horloge + horloge + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + + + + + + + + + + + + + com.atmel.avrdbg.tool.simulator + + 0x1E950F + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + + + + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p" + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include + + + Optimize for size (-Os) + True + True + True + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include + + + + + + + + + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p" + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include + + + Optimize (-O1) + True + True + Default (-g2) + True + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include + + + Optimize (-O1) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.2.132\include + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/horloge/horlogeLepot.cpp b/horloge/horlogeLepot.cpp new file mode 100644 index 0000000..cd435c4 --- /dev/null +++ b/horloge/horlogeLepot.cpp @@ -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 \ No newline at end of file diff --git a/horloge/horlogeLepot.h b/horloge/horlogeLepot.h new file mode 100644 index 0000000..39aaab6 --- /dev/null +++ b/horloge/horlogeLepot.h @@ -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_ */ \ No newline at end of file diff --git a/horloge/main-DESKTOP-M2KTSKL.cpp b/horloge/main-DESKTOP-M2KTSKL.cpp new file mode 100644 index 0000000..803d747 --- /dev/null +++ b/horloge/main-DESKTOP-M2KTSKL.cpp @@ -0,0 +1,44 @@ +/* + * horloge.cpp + * + * Created: 17-10-17 20:53:10 + * Author : Adrien + */ + +#define F_CPU 16000000UL + +#include +#include + +#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__) +{ + +} diff --git a/horloge/main.cpp b/horloge/main.cpp new file mode 100644 index 0000000..148d823 --- /dev/null +++ b/horloge/main.cpp @@ -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 � 1 le bit 7 digit|_BV(7) + */ + +#define F_CPU 16000000UL + + +#include +#include + +#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; + } + } + } +} diff --git a/horloge/max7219.cpp b/horloge/max7219.cpp new file mode 100644 index 0000000..166dbaf --- /dev/null +++ b/horloge/max7219.cpp @@ -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 +#include +#include +#include + +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 + +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__ diff --git a/horloge/util.cpp b/horloge/util.cpp new file mode 100644 index 0000000..b1ae593 --- /dev/null +++ b/horloge/util.cpp @@ -0,0 +1,120 @@ +/* + * util.cpp + * + * Created: 17-10-17 21:21:20 + * Author: Adrien + */ +#include +#include + +#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 +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_ */ \ No newline at end of file