first commit
This commit is contained in:
138
lib/DCF77 - Copie.cpp
Normal file
138
lib/DCF77 - Copie.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* DCF77.cpp
|
||||
*
|
||||
* Created: 19/12/2013 14:06:30
|
||||
* Author: Adrien
|
||||
*/
|
||||
#include "DCF77.h"
|
||||
#include "timer.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
volatile uint8_t dcf77_bits_capture[6]; //Tableau comportent les bits d<>coder (6 * 8bits)
|
||||
volatile unsigned long int time_low = 0;
|
||||
volatile unsigned long int time_high = 0;
|
||||
volatile bool dcf77_flag_start = 0; // Drapeau qui permet de savoir si on peut commenc<6E> la capture
|
||||
volatile bool dcf77_flag_decode = 0; // " " " " " " " " " le d<>codage
|
||||
volatile int dcf77_bit_count = 0; // Compte le nombre de bit d<>ja encod<6F>
|
||||
void dcf77::start_capture()
|
||||
{
|
||||
timer1_init();
|
||||
dcf77_flag_start = 0;
|
||||
DDRD |= 1<<PIND2;
|
||||
EICRA |= 1<<ISC00; //Interuption a chaque changement d'<27>tat de INT0
|
||||
EIMSK |= 1<<INT0; //Activation de l'interuption INT0
|
||||
sei();
|
||||
}
|
||||
void dcf77::stop_capture()
|
||||
{
|
||||
EIMSK &= ~(1<<INT0);
|
||||
dcf77_flag_start = 0;
|
||||
dcf77_flag_decode = 0;
|
||||
dcf77_bit_count = 0;
|
||||
}
|
||||
bool dcf77::decode()
|
||||
{
|
||||
int decodage_bit_n = 0;//Variable pour voir ou est le decodage des bits
|
||||
int place_bit = 0;//Pour savoir ou est plac<61> le bit
|
||||
for (int z = 0 ; z <= 6 ; z++) //Passage au crible des tableau
|
||||
{
|
||||
int place_bit = 0;//Pour savoir ou est plac<61> le bit
|
||||
for(int y= 8 ; y >= 0 ; y--)
|
||||
{
|
||||
if(z == 0 && !(dcf77_bits_capture[0] >> 8)) //Bit 00 TOUJOURS <20> 0
|
||||
{
|
||||
if(decodage_bit_n <= 19) // Bit 00 <20> 19 ne nous interesse pas
|
||||
{}
|
||||
else if(decodage_bit_n <= 28) //Partie minutes
|
||||
{
|
||||
if((dcf77_bits_capture[z]>>y) && decodage_bit_n == 20) //Bit 20 TOUJOURS <20> 1
|
||||
{}
|
||||
else
|
||||
return false;
|
||||
if (decodage_bit_n > 20 && decodage_bit_n <= 28)//Arriv<69> a la partie minute
|
||||
{
|
||||
if(decodage_bit_n == 21)
|
||||
place_bit = 0;
|
||||
if(decodage_bit_n != 28)
|
||||
{
|
||||
Minute |= ((dcf77_bits_capture[z]>>y) & 0x01) << place_bit;
|
||||
place_bit++;
|
||||
}
|
||||
else if((Minute&0x1) && !((dcf77_bits_capture[z]>>y)&0x01) || !(Minute&0x1) && ((dcf77_bits_capture[z]>>y)&0x01))
|
||||
{}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
decodage_bit_n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
if(PORTD&(1<<PIND2))//Si c'est au niveau haut
|
||||
{
|
||||
time_high = millis(); //D<>marage du comptage du temps haut
|
||||
time_low = millis() - time_low; //Calcul du Temps bas
|
||||
if(dcf77_flag_start && dcf77_bit_count <= 59) //D<>marage de la d<>modulation si toute les condition sont OK
|
||||
{
|
||||
dcf77_flag_decode = 0; //Anonce que le decodage ne peut pas <20>tre <20>fectu<74>
|
||||
int bit;
|
||||
if(time_low <= 100 && time_low != 0) //Si le temp bas est <= 100ms le bit est <20> 0
|
||||
bit = 0;
|
||||
else if(time_low <= 200 && time_low != 0) //Si le temp bas est <= 200ms le bit est <20> 1
|
||||
bit = 1;
|
||||
else //ereur
|
||||
{
|
||||
dcf77_flag_start = 0;
|
||||
return;
|
||||
}
|
||||
if(dcf77_bit_count < 8)
|
||||
{
|
||||
dcf77_bits_capture[0] = (dcf77_bits_capture[0]<<1) | bit;
|
||||
}
|
||||
else if (dcf77_bit_count < 16)
|
||||
{
|
||||
dcf77_bits_capture[1] = (dcf77_bits_capture[1]<<1) | bit;
|
||||
}
|
||||
else if (dcf77_bit_count < 24)
|
||||
{
|
||||
dcf77_bits_capture[2] = (dcf77_bits_capture[2]<<1) | bit;
|
||||
}
|
||||
else if (dcf77_bit_count < 32)
|
||||
{
|
||||
dcf77_bits_capture[3] = (dcf77_bits_capture[3]<<1) | bit;
|
||||
}
|
||||
else if (dcf77_bit_count < 40)
|
||||
{
|
||||
dcf77_bits_capture[4] = (dcf77_bits_capture[4]<<1) | bit;
|
||||
}
|
||||
else if (dcf77_bit_count < 48)
|
||||
{
|
||||
dcf77_bits_capture[5] = (dcf77_bits_capture[5]<<1) | bit;
|
||||
}
|
||||
else if (dcf77_bit_count < 56)
|
||||
{
|
||||
dcf77_bits_capture[6] = (dcf77_bits_capture[6]<<1) | bit;
|
||||
}
|
||||
dcf77_bit_count++;
|
||||
}
|
||||
else if(dcf77_bit_count > 59)//Apr<70>s le d<>codage 60e bit
|
||||
{
|
||||
dcf77_flag_start = 0; //Remise a zero du drapeau de d<>marage
|
||||
dcf77_flag_decode = 1; //Mise a un du drapeau decode
|
||||
dcf77_bit_count = 0; //Mise <20> zero le nombre de bit decod<6F>
|
||||
}
|
||||
}
|
||||
else //Passage au niveau bas
|
||||
{
|
||||
time_high = millis() - time_high; //Calcul du temps Haut
|
||||
time_low = millis(); //D<>marage du comptage du temps bas
|
||||
if(time_high > 800) //Si le Temps bas est > <20> 800, d<>but de la transmition
|
||||
dcf77_flag_start = 1;
|
||||
}
|
||||
}
|
||||
39
lib/DCF77 - Copie.h
Normal file
39
lib/DCF77 - Copie.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* DCF77.h
|
||||
*
|
||||
* Created: 22/12/2013 15:47:27
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DCF77_H_
|
||||
#define DCF77_H_
|
||||
|
||||
#include <stdint.h>
|
||||
class dcf77
|
||||
{
|
||||
private:
|
||||
uint8_t dcf77_bits[6];
|
||||
uint8_t Minute = 0x00;
|
||||
uint8_t Heur = 0x00;
|
||||
uint8_t Daymonth = 0x00;
|
||||
uint8_t Dayweek = 0x00;
|
||||
uint8_t Month = 0x00;
|
||||
uint8_t Year = 0x00;
|
||||
bool dcf77_flag_send_decode;
|
||||
bool decode();
|
||||
public:
|
||||
void start_capture();
|
||||
void stop_capture();
|
||||
bool ready();
|
||||
uint8_t minutes();
|
||||
uint8_t heure();
|
||||
uint8_t day_month();
|
||||
uint8_t day_week();
|
||||
uint8_t month();
|
||||
uint8_t year();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* DCF77_H_ */
|
||||
211
lib/DCF77.cpp
Normal file
211
lib/DCF77.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* DCF77.cpp
|
||||
*
|
||||
* Created: 19/12/2013 14:06:30
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
#include "DCF77.h"
|
||||
#include "timer.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/atomic.h>
|
||||
#include <util/delay.h>
|
||||
#include "LCD.h"
|
||||
|
||||
#define LCD_DEBUG false
|
||||
#define time_low_dcf77_min_0 80
|
||||
#define time_low_dcf77_max_0 120
|
||||
#define time_low_dcf77_min_1 180
|
||||
#define time_low_dcf77_max_1 220
|
||||
#define time_no_modulation 1000
|
||||
#define en_attente_de_signal 0
|
||||
#define decodage_en_cours 1
|
||||
#define decodage_effectuer 2
|
||||
#define decodage_erreur 3
|
||||
#define temps_haut_min 500
|
||||
#define temps_bas_min 20
|
||||
|
||||
|
||||
dcf77 atc_;
|
||||
//#if LCD_DEBUG
|
||||
LCD lcd1;
|
||||
//#endif
|
||||
|
||||
void dcf77::start_capture()
|
||||
{
|
||||
DDRB |= 1<<PINB5;
|
||||
timer1_init();
|
||||
dcf77_flag_start = 0;
|
||||
DDRD &= ~(1<<PIND2); //PIND2 en entr<74>e
|
||||
EICRA = 1<<ISC00; //Interuption a chaque changement d'<27>tat de INT0
|
||||
EIMSK |= 1<<INT0; //Activation de l'interuption INT0
|
||||
sei(); //Activation des interuption en g<>n<EFBFBD>rale
|
||||
}
|
||||
void dcf77::stop_capture()
|
||||
{
|
||||
EIMSK &= ~(1<<INT0); //D<>sactive l'interuption
|
||||
dcf77_flag_start = 0;
|
||||
dcf77_bit_count = 0;
|
||||
cli();
|
||||
}
|
||||
void dcf77::hi()
|
||||
{
|
||||
|
||||
time_check = millis() - time_low_dcf77;
|
||||
if( time_check >= temps_bas_min || time_low_dcf77 == 0)
|
||||
{
|
||||
PORTB |= 1<<PINB5; //Led de Debug <20> 1
|
||||
parasite_flag = false;
|
||||
time_high_dcf77 = millis(); //D<>marage du comptage du temps haut
|
||||
time_low_dcf77 = millis() - time_low_dcf77; //Calcul du Temps bas
|
||||
if(dcf77_flag_start && dcf77_bit_count <= 58) //D<>marage de la d<>modulation si toute les condition sont OK
|
||||
{
|
||||
dcf77_status = decodage_en_cours; //En cours de d<>codage
|
||||
int bit;
|
||||
if(time_low_dcf77 >= time_low_dcf77_min_0 && time_low_dcf77 <= time_low_dcf77_max_0) //Si le temp bas est <= 100ms le bit est <20> 0
|
||||
bit = 0;
|
||||
else if(time_low_dcf77 >= time_low_dcf77_min_1 && time_low_dcf77 <= time_low_dcf77_max_1) //Si le temp bas est <= 200ms le bit est <20> 1
|
||||
bit = 1;
|
||||
else //ereur
|
||||
{
|
||||
//dcf77_bit_count = 0;
|
||||
//dcf77_flag_start = 0;
|
||||
//return;
|
||||
}
|
||||
if(dcf77::decode(bit))
|
||||
{
|
||||
dcf77_bit_count = 0;
|
||||
dcf77_flag_start = 0;
|
||||
//return;
|
||||
}
|
||||
dcf77_bit_count++;
|
||||
}
|
||||
else if(dcf77_bit_count > 58)//Apr<70>s le d<>codage 60e bit
|
||||
{
|
||||
//atc_.stop_capture(); //Ar<41>t de la capture
|
||||
dcf77_flag_start = 0; //Remise a zero du drapeau de d<>marage
|
||||
dcf77_bit_count = 0; //Mise <20> zero le nombre de bit decod<6F>
|
||||
dcf77_status = decodage_effectuer;
|
||||
}
|
||||
else
|
||||
{
|
||||
// lcd1.set_cursor(5, 1);
|
||||
// lcd1.print_text("Wt S.F.");
|
||||
}
|
||||
}
|
||||
else
|
||||
parasite_flag = true;
|
||||
}
|
||||
void dcf77::lo()
|
||||
{
|
||||
|
||||
time_check = millis() - time_high_dcf77;
|
||||
if( time_check >= temps_haut_min || time_high_dcf77 == 0)
|
||||
{
|
||||
PORTB &= ~(1<<PINB5);//Led de debug <20> 0
|
||||
parasite_flag = false;
|
||||
time_high_dcf77 = millis() - time_high_dcf77; //Calcul du temps Haut
|
||||
time_low_dcf77 = millis(); //D<>marage du comptage du temps bas
|
||||
if(time_high_dcf77 > time_no_modulation | dcf77_flag_start) //Si le Temps bas est > <20> 800, d<>but de la transmition
|
||||
{
|
||||
dcf77_flag_start = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dcf77_status = en_attente_de_signal;
|
||||
}
|
||||
}
|
||||
else
|
||||
parasite_flag = true;
|
||||
}
|
||||
bool dcf77::decode(uint8_t bit)
|
||||
{
|
||||
bool flag_no_error = true;
|
||||
if(bit_dcode_n == 0 && !bit) //Bit 00 Toujours <20> 0 si le contraire erreur
|
||||
flag_no_error = false;
|
||||
else if(bit_dcode_n >= 1 && bit_dcode_n <= 19); //Bits 01 <20> 19 ne nous interesse pas
|
||||
else if (bit_dcode_n == 20 && !bit) //Bit 20 Toujours <20> 1
|
||||
flag_no_error = false;
|
||||
else if (bit_dcode_n >= 21 && bit_dcode_n <= 27) //Bit 21 <20> 27 = Minute
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Minute |= 1 << (bit_dcode_n-21);
|
||||
else
|
||||
dcf77_Minute &= ~(1 << (bit_dcode_n-21));
|
||||
}
|
||||
else if(bit_dcode_n == 28 && (dcf77_Minute&0x01) && !bit || bit_dcode_n == 28 && !(dcf77_Minute&0x01) && bit) //Bit de parit<69> des minutes
|
||||
flag_no_error = false;
|
||||
else if(bit_dcode_n >= 29 && bit_dcode_n <= 34) //Bit 29 <20> 34 = Heure
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Heur |= 1 << (bit_dcode_n-29);
|
||||
else
|
||||
dcf77_Heur &= ~(1 << (bit_dcode_n-29));
|
||||
}
|
||||
else if(bit_dcode_n == 35 && (dcf77_Heur&0x01) && !bit || bit_dcode_n == 35 && !(dcf77_Heur&0x01) && bit) //Bit de parit<69> des Heure
|
||||
flag_no_error = false;
|
||||
else if(bit_dcode_n >= 36 && bit_dcode_n <= 41) //Bit 36 <20> 41 = Jours du moi
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Daymonth |= 1 << (bit_dcode_n-36);
|
||||
else
|
||||
dcf77_Daymonth &= ~(1 << (bit_dcode_n-36));
|
||||
}
|
||||
else if(bit_dcode_n >= 42 && bit_dcode_n <= 44); //Bit 42 <20> 44 = Jours de la semaine, ne nous interesse pas
|
||||
else if(bit_dcode_n >= 45 && bit_dcode_n <= 49) //Bit 45 <20> 49 = Mois
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Month |= 1 << (bit_dcode_n-45);
|
||||
else
|
||||
dcf77_Month &= ~(1 << (bit_dcode_n-45));
|
||||
}
|
||||
else if(bit_dcode_n>= 50 && bit_dcode_n <= 57) //Bit 50 <20> 57 = Ann<6E>e
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Year |= 1 << (bit_dcode_n-50);
|
||||
else
|
||||
dcf77_Year &= ~(1 << (bit_dcode_n-50));
|
||||
}
|
||||
else if(bit_dcode_n == 58 && (dcf77_Month&0x01) && !bit || bit_dcode_n && !(dcf77_Month&0x01) && bit);//Parity
|
||||
bit_dcode_n++;
|
||||
return flag_no_error;
|
||||
}
|
||||
int dcf77::status()
|
||||
{
|
||||
return dcf77_status;
|
||||
}
|
||||
uint8_t dcf77::minutes()
|
||||
{
|
||||
return dcf77_Minute;
|
||||
}
|
||||
uint8_t dcf77::heure()
|
||||
{
|
||||
return dcf77_Heur;
|
||||
}
|
||||
uint8_t dcf77::month()
|
||||
{
|
||||
return dcf77_Month;
|
||||
}
|
||||
uint8_t dcf77::day_month()
|
||||
{
|
||||
return dcf77_Daymonth;
|
||||
}
|
||||
uint8_t dcf77::year()
|
||||
{
|
||||
return dcf77_Year;
|
||||
}
|
||||
ISR(INT0_vect)//Vecteur d'interuption INT0
|
||||
{
|
||||
ATOMIC_BLOCK(ATOMIC_FORCEON)
|
||||
{
|
||||
if(((PIND&(1<<PIND2))>>PIND2))//Si c'est au niveau haut
|
||||
{
|
||||
atc_.hi();
|
||||
}
|
||||
else //Passage au niveau bas
|
||||
{
|
||||
atc_.lo();
|
||||
}
|
||||
}
|
||||
}
|
||||
211
lib/DCF77.cpp~
Normal file
211
lib/DCF77.cpp~
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* DCF77.cpp
|
||||
*
|
||||
* Created: 19/12/2013 14:06:30
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
#include "DCF77.h"
|
||||
#include "timer.h"
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/atomic.h>
|
||||
#include <util/delay.h>
|
||||
#include "LCD.h"
|
||||
|
||||
#define LCD_DEBUG false
|
||||
#define time_low_dcf77_min_0 80
|
||||
#define time_low_dcf77_max_0 120
|
||||
#define time_low_dcf77_min_1 180
|
||||
#define time_low_dcf77_max_1 220
|
||||
#define time_no_modulation 1000
|
||||
#define en_attente_de_signal 0
|
||||
#define decodage_en_cours 1
|
||||
#define decodage_effectuer 2
|
||||
#define decodage_erreur 3
|
||||
#define temps_haut_min 500
|
||||
#define temps_bas_min 20
|
||||
|
||||
|
||||
dcf77 atc_;
|
||||
//#if LCD_DEBUG
|
||||
LCD lcd1;
|
||||
//#endif
|
||||
|
||||
void dcf77::start_capture()
|
||||
{
|
||||
DDRB |= 1<<PINB5;
|
||||
timer1_init();
|
||||
dcf77_flag_start = 0;
|
||||
DDRD &= ~(1<<PIND2); //PIND2 en entr<74>e
|
||||
EICRA = 1<<ISC00; //Interuption a chaque changement d'<27>tat de INT0
|
||||
EIMSK |= 1<<INT0; //Activation de l'interuption INT0
|
||||
sei(); //Activation des interuption en g<>n<EFBFBD>rale
|
||||
}
|
||||
void dcf77::stop_capture()
|
||||
{
|
||||
EIMSK &= ~(1<<INT0); //D<>sactive l'interuption
|
||||
dcf77_flag_start = 0;
|
||||
dcf77_bit_count = 0;
|
||||
cli();
|
||||
}
|
||||
void dcf77::hi()
|
||||
{
|
||||
|
||||
time_check = millis() - time_low_dcf77;
|
||||
if( time_check >= temps_bas_min || time_low_dcf77 == 0)
|
||||
{
|
||||
PORTB |= 1<<PINB5; //Led de Debug <20> 1
|
||||
parasite_flag = false;
|
||||
time_high_dcf77 = millis(); //D<>marage du comptage du temps haut
|
||||
time_low_dcf77 = millis() - time_low_dcf77; //Calcul du Temps bas
|
||||
if(dcf77_flag_start && dcf77_bit_count <= 58) //D<>marage de la d<>modulation si toute les condition sont OK
|
||||
{
|
||||
dcf77_status = decodage_en_cours; //En cours de d<>codage
|
||||
int bit;
|
||||
if(time_low_dcf77 >= time_low_dcf77_min_0 && time_low_dcf77 <= time_low_dcf77_max_0) //Si le temp bas est <= 100ms le bit est <20> 0
|
||||
bit = 0;
|
||||
else if(time_low_dcf77 >= time_low_dcf77_min_1 && time_low_dcf77 <= time_low_dcf77_max_1) //Si le temp bas est <= 200ms le bit est <20> 1
|
||||
bit = 1;
|
||||
else //ereur
|
||||
{
|
||||
//dcf77_bit_count = 0;
|
||||
//dcf77_flag_start = 0;
|
||||
//return;
|
||||
}
|
||||
if(dcf77::decode(bit))
|
||||
{
|
||||
dcf77_bit_count = 0;
|
||||
dcf77_flag_start = 0;
|
||||
//return;
|
||||
}
|
||||
dcf77_bit_count++;
|
||||
}
|
||||
else if(dcf77_bit_count > 58)//Apr<70>s le d<>codage 60e bit
|
||||
{
|
||||
//atc_.stop_capture(); //Ar<41>t de la capture
|
||||
dcf77_flag_start = 0; //Remise a zero du drapeau de d<>marage
|
||||
dcf77_bit_count = 0; //Mise <20> zero le nombre de bit decod<6F>
|
||||
dcf77_status = decodage_effectuer;
|
||||
}
|
||||
else
|
||||
{
|
||||
// lcd1.set_cursor(5, 1);
|
||||
// lcd1.print_text("Wt S.F.");
|
||||
}
|
||||
}
|
||||
else
|
||||
parasite_flag = true;
|
||||
}
|
||||
void dcf77::lo()
|
||||
{
|
||||
|
||||
time_check = millis() - time_high_dcf77;
|
||||
if( time_check >= temps_haut_min || time_high_dcf77 == 0)
|
||||
{
|
||||
PORTB &= ~(1<<PINB5);//Led de debug <20> 0
|
||||
parasite_flag = false;
|
||||
time_high_dcf77 = millis() - time_high_dcf77; //Calcul du temps Haut
|
||||
time_low_dcf77 = millis(); //D<>marage du comptage du temps bas
|
||||
if(time_high_dcf77 > time_no_modulation | dcf77_flag_start) //Si le Temps bas est > <20> 800, d<>but de la transmition
|
||||
{
|
||||
dcf77_flag_start = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dcf77_status = en_attente_de_signal;
|
||||
}
|
||||
}
|
||||
else
|
||||
parasite_flag = true;
|
||||
}
|
||||
bool dcf77::decode(uint8_t bit)
|
||||
{
|
||||
bool flag_no_error = true;
|
||||
if(bit_dcode_n == 0 && !bit) //Bit 00 Toujours <20> 0 si le contraire erreur
|
||||
flag_no_error = false;
|
||||
else if(bit_dcode_n >= 1 && bit_dcode_n <= 19); //Bits 01 <20> 19 ne nous interesse pas
|
||||
else if (bit_dcode_n == 20 && !bit) //Bit 20 Toujours <20> 1
|
||||
flag_no_error = false;
|
||||
else if (bit_dcode_n >= 21 && bit_dcode_n <= 27) //Bit 21 <20> 27 = Minute
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Minute |= 1 << (bit_dcode_n-21);
|
||||
else
|
||||
dcf77_Minute &= ~(1 << (bit_dcode_n-21));
|
||||
}
|
||||
else if(bit_dcode_n == 28 && (dcf77_Minute&0x01) && !bit || bit_dcode_n == 28 && !(dcf77_Minute&0x01) && bit) //Bit de parit<69> des minutes
|
||||
flag_no_error = false;
|
||||
else if(bit_dcode_n >= 29 && bit_dcode_n <= 34) //Bit 29 <20> 34 = Heure
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Heur |= 1 << (bit_dcode_n-29);
|
||||
else
|
||||
dcf77_Heur &= ~(1 << (bit_dcode_n-29));
|
||||
}
|
||||
else if(bit_dcode_n == 35 && (dcf77_Heur&0x01) && !bit || bit_dcode_n == 35 && !(dcf77_Heur&0x01) && bit) //Bit de parit<69> des Heure
|
||||
flag_no_error = false;
|
||||
else if(bit_dcode_n >= 36 && bit_dcode_n <= 41) //Bit 36 <20> 41 = Jours du moi
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Daymonth |= 1 << (bit_dcode_n-36);
|
||||
else
|
||||
dcf77_Daymonth &= ~(1 << (bit_dcode_n-36));
|
||||
}
|
||||
else if(bit_dcode_n >= 42 && bit_dcode_n <= 44); //Bit 42 <20> 44 = Jours de la semaine, ne nous interesse pas
|
||||
else if(bit_dcode_n >= 45 && bit_dcode_n <= 49) //Bit 45 <20> 49 = Mois
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Month |= 1 << (bit_dcode_n-45);
|
||||
else
|
||||
dcf77_Month &= ~(1 << (bit_dcode_n-45));
|
||||
}
|
||||
else if(bit_dcode_n>= 50 && bit_dcode_n <= 57) //Bit 50 <20> 57 = Ann<6E>e
|
||||
{
|
||||
if(bit)
|
||||
dcf77_Year |= 1 << (bit_dcode_n-50);
|
||||
else
|
||||
dcf77_Year &= ~(1 << (bit_dcode_n-50));
|
||||
}
|
||||
else if(bit_dcode_n == 58 && (dcf77_Month&0x01) && !bit || bit_dcode_n && !(dcf77_Month&0x01) && bit);//Parity
|
||||
bit_dcode_n++;
|
||||
return flag_no_error;
|
||||
}
|
||||
int dcf77::status()
|
||||
{
|
||||
return dcf77_status;
|
||||
}
|
||||
uint8_t dcf77::minutes()
|
||||
{
|
||||
return dcf77_Minute;
|
||||
}
|
||||
uint8_t dcf77::heure()
|
||||
{
|
||||
return dcf77_Heur;
|
||||
}
|
||||
uint8_t dcf77::month()
|
||||
{
|
||||
return dcf77_Month;
|
||||
}
|
||||
uint8_t dcf77::day_month()
|
||||
{
|
||||
return dcf77_Daymonth;
|
||||
}
|
||||
uint8_t dcf77::year()
|
||||
{
|
||||
return dcf77_Year;
|
||||
}
|
||||
ISR(INT0_vect)//Vecteur d'interuption INT0
|
||||
{
|
||||
ATOMIC_BLOCK(ATOMIC_FORCEON)
|
||||
{
|
||||
if(((PIND&(1<<PIND2))>>PIND2))//Si c'est au niveau haut
|
||||
{
|
||||
atc_.hi();
|
||||
}
|
||||
else //Passage au niveau bas
|
||||
{
|
||||
atc_.lo();
|
||||
}
|
||||
}
|
||||
}
|
||||
52
lib/DCF77.h
Normal file
52
lib/DCF77.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* DCF77.h
|
||||
*
|
||||
* Created: 22/12/2013 15:47:27
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DCF77_H_
|
||||
#define DCF77_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class dcf77
|
||||
{
|
||||
private:
|
||||
//uint8_t dcf77_bits[6];
|
||||
//bool dcf77_flag_send_decode;
|
||||
unsigned long int time_low_dcf77 = 0;
|
||||
unsigned long int time_high_dcf77 = 0;
|
||||
bool dcf77_flag_start = 0; // Drapeau qui permet de savoir si on peut commenc<6E> la capture
|
||||
//bool dcf77_flag_end_decode = 0; // " " " " " " le d<>codage est termin<69>
|
||||
int dcf77_bit_count = 0; // Compte le nombre de bit d<>ja encod<6F>
|
||||
uint8_t dcf77_Minute = 0x00;
|
||||
uint8_t dcf77_Heur = 0x00;
|
||||
uint8_t dcf77_Daymonth = 0x00;
|
||||
uint8_t dcf77_Dayweek = 0x00;
|
||||
uint8_t dcf77_Month = 0x00;
|
||||
uint8_t dcf77_Year = 0x00;
|
||||
int dcf77_status = 0;
|
||||
int bit_dcode_n = 0;
|
||||
bool parasite_flag = false;
|
||||
unsigned int time_check = 0;
|
||||
|
||||
public:
|
||||
void start_capture();
|
||||
void stop_capture();
|
||||
void lo();
|
||||
void hi();
|
||||
uint8_t minutes();
|
||||
uint8_t heure();
|
||||
uint8_t day_month();
|
||||
uint8_t day_week();
|
||||
uint8_t month();
|
||||
uint8_t year();
|
||||
bool decode(uint8_t bit);
|
||||
int status();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* DCF77_H_ */
|
||||
190
lib/DS1307.cpp
Normal file
190
lib/DS1307.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* ds1307.cpp
|
||||
*
|
||||
* Created: 19/12/2013 14:06:21
|
||||
* Author: Adrien
|
||||
*
|
||||
* Note : Apr<70>s r<>flection, l'utilisation d'une class est inutile ...
|
||||
*
|
||||
*/
|
||||
|
||||
#define F_CPU 16000000UL
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "DS1307.h"
|
||||
|
||||
#define adresse_DS1307 0xD0 //Adresse I2C du DS1307
|
||||
|
||||
#define LED_RED 1<<PINB3 /*Ici direct en Hex*/
|
||||
#define LED_GREEN 1<<PINB4 /*Ici direct en Hex*/
|
||||
#define LED_BLUE 1<<PINB5 /*Ici direct en Hex*/
|
||||
|
||||
ds1307::ds1307()
|
||||
{
|
||||
iic_error = false;
|
||||
}
|
||||
|
||||
void ds1307::write(int adresse_m, uint8_t data)
|
||||
{
|
||||
//SCK Config <20> 80Khz (MAX DS1307 = 100Khz)
|
||||
TWBR = 0x5C; //Bit rate division <20> 92
|
||||
TWSR &= ~((1<<TWPS1)|(1<<TWPS0)) ; // Prescale <20> 1
|
||||
|
||||
//I2C Init
|
||||
TWCR = (1<<TWEN); //Active l'I2C
|
||||
TWCR = (1<<TWEN)|(1<<TWSTA)|(1<<TWINT); //Envoi la condiont de d<>marage
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//DS1307 adresse write
|
||||
TWDR = adresse_DS1307; //Inscrit l'adresse, Mode write
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi l'adresse
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Adresse memoir send
|
||||
TWDR = adresse_m; //Inscrit l'adresse m<>moire
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi l'adresse
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Data send
|
||||
TWDR = data; //Inscrit les donn<6E>e
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi les donn<6E>e
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Stop condition
|
||||
TWCR = (1<<TWEN)|(1<<TWINT)|(1<<TWSTO);
|
||||
while((TWCR&(1<<TWSTO)))
|
||||
{
|
||||
|
||||
}
|
||||
TWCR &= (~(1<<TWEN));
|
||||
}
|
||||
uint8_t ds1307::read(uint8_t adresse_m)
|
||||
{
|
||||
TWBR = 0x5C; //Bit rate division <20> 92
|
||||
TWSR &= ~((1<<TWPS1)|(1<<TWPS0)); // Prescale <20> 1
|
||||
|
||||
//I2C Init
|
||||
TWCR = (1<<TWEN); //Active l'I2C
|
||||
TWCR = (1<<TWEN)|(1<<TWSTA)|(1<<TWINT); //Envoi la condiont de d<>marage
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
//DS1307 adresse write
|
||||
TWDR = adresse_DS1307; //Inscrit l'adresse, Mode write
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi l'adresse
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//DS1307 adresse mem
|
||||
TWDR = adresse_m; //Inscrit l'adresse m<>moir
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi l'adresse
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Restart condition
|
||||
TWCR = (1<<TWEN)|(1<<TWSTA)|(1<<TWINT); //Envoi la condiont de d<>marage
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//DS1307 adresse + read
|
||||
TWDR = adresse_DS1307|0x01; //Inscrit l'adresse + Mode read
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi l'adresse
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Receive
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Demande de r<>ception
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de la r<>ception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t data = TWDR;
|
||||
|
||||
//Stop condition
|
||||
TWCR = (1<<TWEN)|(1<<TWINT)|(1<<TWSTO);
|
||||
while((TWCR&(1<<TWSTO)))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TWCR&=(~(1<<TWEN));
|
||||
return data;
|
||||
}
|
||||
uint8_t ds1307::r_seconde()
|
||||
{
|
||||
return ds1307::read(0x00);
|
||||
}
|
||||
uint8_t ds1307::r_minute()
|
||||
{
|
||||
return ds1307::read(0x01);
|
||||
}
|
||||
uint8_t ds1307::r_heur()
|
||||
{
|
||||
return ds1307::read(0x02);
|
||||
}
|
||||
uint8_t ds1307::r_jour()
|
||||
{
|
||||
return ds1307::read(0x04);
|
||||
}
|
||||
uint8_t ds1307::r_moi()
|
||||
{
|
||||
return ds1307::read(0x05);
|
||||
}
|
||||
uint8_t ds1307::r_year()
|
||||
{
|
||||
return ds1307::read(0x06);
|
||||
}
|
||||
void ds1307::w_seconde(uint8_t data)
|
||||
{
|
||||
ds1307::write(0x00, data);
|
||||
}
|
||||
void ds1307::w_minute(uint8_t data)
|
||||
{
|
||||
ds1307::write(0x01, data);
|
||||
}
|
||||
void ds1307::w_heur(uint8_t data, uint8_t pm)
|
||||
{
|
||||
if(pm)
|
||||
data |= (1<<6);
|
||||
else
|
||||
data &= ~(1<<6);
|
||||
ds1307::write(0x02, data);
|
||||
}
|
||||
void ds1307::w_date(uint8_t data)
|
||||
{
|
||||
ds1307::write(0x04, data);
|
||||
}
|
||||
void ds1307::w_moi(uint8_t data)
|
||||
{
|
||||
ds1307::write(0x05, data);
|
||||
}
|
||||
void ds1307::w_year(uint8_t data)
|
||||
{
|
||||
ds1307::write(0x06, data);
|
||||
}
|
||||
37
lib/DS1307.h
Normal file
37
lib/DS1307.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* DS1307.h
|
||||
*
|
||||
* Created: 22/12/2013 15:28:08
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DS1307_H_
|
||||
#define DS1307_H_
|
||||
#include <stdint.h>
|
||||
class ds1307
|
||||
{
|
||||
private:
|
||||
uint8_t curent_couleur;
|
||||
bool iic_error;
|
||||
public:
|
||||
ds1307();
|
||||
void write(int adresse_m, uint8_t data);
|
||||
uint8_t read(uint8_t adresse_m);
|
||||
uint8_t r_seconde();
|
||||
uint8_t r_minute();
|
||||
uint8_t r_heur();
|
||||
uint8_t r_jour();
|
||||
uint8_t r_moi();
|
||||
uint8_t r_year();
|
||||
void w_seconde(uint8_t data);
|
||||
void w_minute(uint8_t data);
|
||||
void w_heur(uint8_t data, uint8_t pm);
|
||||
void w_date(uint8_t data);
|
||||
void w_moi(uint8_t data);
|
||||
void w_year(uint8_t data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* DS1307_H_ */
|
||||
170
lib/LCD.cpp
Normal file
170
lib/LCD.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* LCD.cpp
|
||||
*
|
||||
* Created: 27/12/2013 13:32:02
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
/************************************************************************************************************
|
||||
* Cette librairie permet de control<6F> un <20>crans LCD a traver un PCF8574 avec comme adresse 0x40 *
|
||||
* *
|
||||
* ############################## *
|
||||
* #----------------------------# *
|
||||
* #| Configuration des pins |# *
|
||||
* #|~~~~~~~~~~~~~~~~~~~~~~~~~~|# *
|
||||
* #| PCF8574 | LCD |# *
|
||||
* #|~~~~~~~~~~~~~~|~~~~~~~~~~~|# *
|
||||
* #| 0 | D4 |# *
|
||||
* #| 1 | D5 |# *
|
||||
* #| 2 | D6 |# *
|
||||
* #| 3 | D7 |# *
|
||||
* #| 4 | NC |# *
|
||||
* #| 5 | E |# *
|
||||
* #| 6 | RS |# *
|
||||
* #| 7 | RW |# *
|
||||
* #----------------------------# *
|
||||
* ############################## *
|
||||
* *
|
||||
* *
|
||||
* @@ <09><> <20><> ####### *
|
||||
* @@@@ <20><> <20><> ## ##### *
|
||||
* @@ @@ <20><> <09><> ## #### *
|
||||
* @@ @@ <20><> <20><> ## ## *
|
||||
* @@ @@ <09><> <20><> ## ## *
|
||||
* @@~&&&&&&~@@ <20><> <20><> ## #### *
|
||||
* @@ @@ <20><><EFBFBD><EFBFBD> ## ##### *
|
||||
* @@ @@ <20><> ####### *
|
||||
* *
|
||||
************************************************************************************************************
|
||||
*/
|
||||
|
||||
#define adresse_DS1307 0x40
|
||||
#define F_CPU 16000000UL
|
||||
|
||||
#define RS 0x01<<6
|
||||
#define RW 0x01<<7
|
||||
#define E 0x01<<5
|
||||
#define D4 0x01<<0
|
||||
#define D5 0x01<<1
|
||||
#define D6 0x01<<2
|
||||
#define D7 0x01<<3
|
||||
#define D0 0x01<<0
|
||||
#define D1 0x01<<1
|
||||
#define D2 0x01<<2
|
||||
#define D3 0x01<<3
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <avr/delay.h>
|
||||
#include <avr/io.h>
|
||||
#include "LCD.h"
|
||||
|
||||
|
||||
|
||||
uint8_t PCF8574::send(uint8_t data, uint8_t read)
|
||||
{
|
||||
uint8_t read_data;
|
||||
//SCK Config (27.77Khz)
|
||||
TWBR = 0x0A; //Bit rate division <20> 10
|
||||
TWSR = (TWSR & ~((1<<TWPS0) & (1<<TWPS1))); //TWPS <20> 0
|
||||
|
||||
//I2C Init
|
||||
TWCR = (1<<TWEN); //Active l'I2C
|
||||
TWCR = (1<<TWEN)|(1<<TWSTA)|(1<<TWINT); //Envoi la condiont de d<>marage
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
;
|
||||
|
||||
//DS1307 adresse write
|
||||
TWDR = adresse_DS1307|read ; //Inscrit l'adresse, Mode
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi l'adresse
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
;
|
||||
|
||||
|
||||
//Data send
|
||||
if(!read) //Si <20>criture
|
||||
TWDR = data; //Inscrit les donn<6E>e
|
||||
TWCR = (1<<TWEN)|(1<<TWINT); //Envoi les donn<6E>e
|
||||
while(!(TWCR&(1<<TWINT))) //Attente de l'envoi
|
||||
;
|
||||
if(read) //Si lecture
|
||||
read_data = TWDR;
|
||||
|
||||
//Stop condition
|
||||
TWCR = (1<<TWEN)|(1<<TWINT)|(1<<TWSTO);
|
||||
while((TWCR&(1<<TWSTO)))
|
||||
;
|
||||
|
||||
_delay_ms(1);
|
||||
TWCR &= (~(1<<TWEN));
|
||||
if(read)
|
||||
return read_data;
|
||||
}
|
||||
bool LCD::check_busy_flag()
|
||||
{
|
||||
PCF8574::send(RW, 0);
|
||||
uint8_t bf = PCF8574::send(RW, 1)&D7;
|
||||
//_delay_ms(10000);
|
||||
if((bf&(D7)>>3))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
void LCD::send(uint8_t data, bool debut_instuction)
|
||||
{
|
||||
while(check_busy_flag() && debut_instuction) //V<>rifie qu'il n'y a pas une opp<70>tation en cours
|
||||
{}
|
||||
PCF8574::send(0x00, 0); //Met les pins <20>0
|
||||
PCF8574::send(data, 0); //Ecris les donn<6E>es
|
||||
data |= (E);
|
||||
//_delay_ms(1000);
|
||||
PCF8574::send(data, 0); //Confirme les donn<6E>es
|
||||
_delay_us(1); //Attente que la confiramation soit bien re<72>ue
|
||||
data &= ~(E);
|
||||
PCF8574::send(data, 0);
|
||||
_delay_us(1);
|
||||
}
|
||||
void LCD::display_init()
|
||||
{
|
||||
send(0x03, true); //Mode 4bit
|
||||
|
||||
send(0x08, false); //Mode 2ligne
|
||||
|
||||
send(0x00, true);send(0x01, false); //Clear display
|
||||
send(0x00, true);send(0x02, false); //Return home
|
||||
send(0x00, true);send((D2|D1), false); //Incr<63>mentation de la RAM et d<>placement du curseur vers la droite
|
||||
send(0x00, true);send((D3|D2), false); //Allume l'afficheur sans curseur
|
||||
|
||||
}
|
||||
void LCD::send_leter(uint8_t lettre)
|
||||
{
|
||||
uint8_t data = (RS)|(lettre>>4); //Inscrit les 4 dernier bit dans la RAM
|
||||
send(data, true);
|
||||
data = (RS)|(lettre&0b00001111); //Inscrit les 4 premier bit dans la RAM
|
||||
send(data, false);
|
||||
}
|
||||
void LCD::clear()
|
||||
{
|
||||
send(0x00, true); send(D0, false); //Clear Display
|
||||
send(0x00, true);send(0x02, false); //Return home
|
||||
}
|
||||
void LCD::set_cursor(int x, int y)
|
||||
{
|
||||
uint8_t data;
|
||||
if(y == 1)
|
||||
data = 0x00 + x;
|
||||
else if(y == 2)
|
||||
data = 0x40 + x;
|
||||
send((data>>4)|0x08, true);_delay_us(5);send(data&0x0F, false);
|
||||
}
|
||||
void LCD::print_text(char *txt)
|
||||
{
|
||||
for(int a = 0 ; a < strlen(txt) ; a++)
|
||||
send_leter(txt[a]);
|
||||
}
|
||||
void LCD::print_number(int num)
|
||||
{
|
||||
char c[64];
|
||||
sprintf(c, "%d", num);
|
||||
print_text(c);
|
||||
}
|
||||
37
lib/LCD.h
Normal file
37
lib/LCD.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* LCD.h
|
||||
*
|
||||
* Created: 27/12/2013 13:32:19
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LCD_H_
|
||||
#define LCD_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
class PCF8574
|
||||
{
|
||||
public:
|
||||
static uint8_t send(uint8_t data, uint8_t read);
|
||||
};
|
||||
class LCD
|
||||
{
|
||||
private:
|
||||
bool check_busy_flag();
|
||||
public:
|
||||
void setup(int rs_pin, int rw_pin, int e_pin, int d4_pin, int d5_pin, int d6_pin, int d7_pin);
|
||||
void send(uint8_t data, bool BF);
|
||||
void display_init();
|
||||
void send_leter(uint8_t lettre);
|
||||
void print_text(char *txt);
|
||||
void print_number(int num);
|
||||
void clear();
|
||||
void set_cursor(int x, int y);
|
||||
};
|
||||
|
||||
|
||||
#endif /* LCD_H_ */
|
||||
37
lib/UART.cpp
Normal file
37
lib/UART.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* UART.cpp
|
||||
*
|
||||
* Created: 31/05/2014 23:16:31
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "UART.h"
|
||||
#define F_CPU 16000000UL
|
||||
#define BAUD 9600
|
||||
#define MYUBRR (((F_CPU / (BAUD * 16UL))) - 1)
|
||||
|
||||
void USART_ini()
|
||||
{
|
||||
UBRR0H = (unsigned char)(MYUBRR>>8);
|
||||
UBRR0L = (unsigned char)MYUBRR;
|
||||
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
|
||||
UCSR0C = ((1<<UCSZ00)|(1<<UCSZ01));
|
||||
}
|
||||
void USART_Transmit( unsigned char data )
|
||||
{
|
||||
/* Wait for empty transmit buffer */
|
||||
while ( !( UCSR0A & (1<<UDRE0)) )
|
||||
;
|
||||
/* Put data into buffer, sends the data */
|
||||
UDR0 = data;
|
||||
}
|
||||
unsigned char USART_Receive( void )
|
||||
{
|
||||
/* Wait for data to be received */
|
||||
if((UCSR0A & (1<<RXC0)))
|
||||
return UDR0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
18
lib/UART.h
Normal file
18
lib/UART.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* UART.h
|
||||
*
|
||||
* Created: 31/05/2014 23:16:48
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef UART_H_
|
||||
#define UART_H_
|
||||
|
||||
|
||||
void USART_ini();
|
||||
void USART_Transmit( unsigned char data );
|
||||
unsigned char USART_Receive( void );
|
||||
|
||||
|
||||
#endif /* UART_H_ */
|
||||
186
lib/hc74595.cpp
Normal file
186
lib/hc74595.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* _74595.cpp
|
||||
*
|
||||
* Created: 19/12/2013 14:06:10
|
||||
* Author: Adrien
|
||||
*/
|
||||
#define F_CPU 16000000UL
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "hc74595.h"
|
||||
|
||||
hc74595::hc74595(int data, int clk, int stcp,volatile uint8_t *port_uc/*, volatile uint8_t *ddr_uc*/)
|
||||
{
|
||||
pin_DATA = data;
|
||||
pin_CLK = clk;
|
||||
pin_STCP = stcp;
|
||||
port = port_uc;
|
||||
ddr = --port_uc;
|
||||
*ddr |= (0x01 << data | 0x01 << clk | 0x01 << stcp);
|
||||
}
|
||||
void hc74595::send(uint8_t data, bool inverted) //Envoi des donn<6E>e au Shift Register
|
||||
{
|
||||
|
||||
for(int a = 0; a < 8 ; a++)
|
||||
{
|
||||
if(!inverted)
|
||||
{
|
||||
*port &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x01 << a)) //Regarde la valeur de chaque bit
|
||||
*port |= 0x01 << pin_DATA;
|
||||
else
|
||||
*port &= ~(0x01 << pin_DATA);
|
||||
*port|= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
else
|
||||
{
|
||||
*port &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x80 >> a)) //Regarde la valeur de chaque bit
|
||||
*port |= 0x01 << pin_DATA;
|
||||
else
|
||||
*port &= ~(0x01 << pin_DATA);
|
||||
*port |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
}
|
||||
}
|
||||
void hc74595::confirm() //Envoi le signal du storage register
|
||||
{
|
||||
*port |= 0x01 << pin_STCP;
|
||||
_delay_us(1);
|
||||
*port &= ~(0x01 << pin_STCP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
* _74595.cpp
|
||||
*
|
||||
* Created: 19/12/2013 14:06:10
|
||||
* Author: Adrien
|
||||
*
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "hc74595.h"
|
||||
|
||||
void hc74595::setup(int data, int clk, int stcp, char port_uc)
|
||||
{
|
||||
pin_DATA = data;
|
||||
pin_CLK = clk;
|
||||
pin_STCP = stcp;
|
||||
port = port_uc;
|
||||
switch (port) //Configure les pin n<>sessaire en sortie
|
||||
{
|
||||
case 'B' :
|
||||
DDRB |= (0x01 << data | 0x01 << clk | 0x01 << stcp);
|
||||
break;
|
||||
case 'C' :
|
||||
DDRC |= (0x01 << data | 0x01 << clk | 0x01 << stcp);
|
||||
break;
|
||||
case 'D' :
|
||||
DDRD |= (0x01 << data | 0x01 << clk | 0x01 << stcp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void hc74595::hc74595(int data, int clk, int stcp, uint8_t *port_uc)
|
||||
{
|
||||
pin_DATA = data;
|
||||
pin_CLK = clk;
|
||||
pin_STCP = stcp;
|
||||
*port = port_uc;
|
||||
*port |= (0x01 << data | 0x01 << clk | 0x01 << stcp);
|
||||
}
|
||||
void hc74595::send(uint8_t data, bool inverted) //Envoi des donn<6E>e au Shift Register
|
||||
{
|
||||
switch (port)
|
||||
{
|
||||
case 'B' :
|
||||
for(int a = 0; a < 8 ; a++)
|
||||
{
|
||||
if(!inverted)
|
||||
{
|
||||
PORTB &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x01 << a)) //Regarde la valeur de chaque bit
|
||||
PORTB |= 0x01 << pin_DATA;
|
||||
else
|
||||
PORTB &= ~(0x01 << pin_DATA);
|
||||
PORTB |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x80 >> a)) //Regarde la valeur de chaque bit
|
||||
PORTB |= 0x01 << pin_DATA;
|
||||
else
|
||||
PORTB &= ~(0x01 << pin_DATA);
|
||||
PORTB |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'C' :
|
||||
for(int a = 0; a < 8 ; a++)
|
||||
{
|
||||
if(!inverted)
|
||||
{
|
||||
PORTC &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x01 << a)) //Regarde la valeur de chaque bit
|
||||
PORTC |= 0x01 << pin_DATA;
|
||||
else
|
||||
PORTC &= ~(0x01 << pin_DATA);
|
||||
PORTC |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTC &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x80 >> a)) //Regarde la valeur de chaque bit
|
||||
PORTC |= 0x01 << pin_DATA;
|
||||
else
|
||||
PORTC &= ~(0x01 << pin_DATA);
|
||||
PORTC |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'D' :
|
||||
for(int a = 0; a < 8 ; a++)
|
||||
{
|
||||
if(!inverted)
|
||||
{
|
||||
PORTD &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x01 << a)) //Regarde la valeur de chaque bit
|
||||
PORTD |= 0x01 << pin_DATA;
|
||||
else
|
||||
PORTD &= ~(0x01 << pin_DATA);
|
||||
PORTD |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTD &= ~(0x01 << pin_CLK); //Met l'orloge <20> 0
|
||||
if(data & (0x80 >> a)) //Regarde la valeur de chaque bit
|
||||
PORTD |= 0x01 << pin_DATA;
|
||||
else
|
||||
PORTD &= ~(0x01 << pin_DATA);
|
||||
PORTD |= 0x01 << pin_CLK; //Met l'orloge <20> 1
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
void hc74595::confirm() //Envoi le signal du storage register
|
||||
{
|
||||
switch(port)
|
||||
{
|
||||
case 'B' :
|
||||
PORTB |= 0x01 << pin_STCP;
|
||||
PORTB &= ~(0x01 << pin_STCP);
|
||||
break;
|
||||
case 'C' :
|
||||
PORTC |= 0x01 << pin_STCP;
|
||||
PORTC &= ~(0x01 << pin_STCP);
|
||||
break;
|
||||
case 'D' :
|
||||
PORTD |= 0x01 << pin_STCP;
|
||||
PORTD &= ~(0x01 << pin_STCP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
27
lib/hc74595.h
Normal file
27
lib/hc74595.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* _74hc595.h
|
||||
*
|
||||
* Created: 22/12/2013 15:19:47
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HC74595_H_
|
||||
#define HC74595_H_
|
||||
|
||||
#include <stdint.h>
|
||||
class hc74595
|
||||
{
|
||||
private:
|
||||
int pin_DATA;
|
||||
int pin_CLK;
|
||||
int pin_STCP;
|
||||
volatile uint8_t *port;
|
||||
volatile uint8_t *ddr;
|
||||
public:
|
||||
hc74595(int data, int clk, int stcp, volatile uint8_t *port_uc);
|
||||
void send(uint8_t data, bool inverted);
|
||||
void confirm();
|
||||
};
|
||||
|
||||
#endif /* 74HC595_H_ */
|
||||
104
lib/timer.cpp
Normal file
104
lib/timer.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#define F_CPU 16000000UL // 16 MHz
|
||||
|
||||
// Calculate the value needed for
|
||||
// the CTC match value in OCR1A.
|
||||
#define CTC_MATCH_OVERFLOW ((F_CPU / 1000) / 8)
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/atomic.h>
|
||||
volatile unsigned long timer1_millis;
|
||||
void timer1_init()
|
||||
{
|
||||
// clear to compar (CTC) mode, Clock/8
|
||||
TCCR1B |= (1 << WGM12) | (1 << CS11);
|
||||
|
||||
|
||||
OCR1AH = (CTC_MATCH_OVERFLOW >> 8);
|
||||
OCR1AL = CTC_MATCH_OVERFLOW;
|
||||
|
||||
// Activation du mode comparaison
|
||||
TIMSK1 |= (1 << OCIE1A);
|
||||
|
||||
sei();
|
||||
|
||||
}
|
||||
void interup_1hz_init()//DS1307
|
||||
{
|
||||
EICRA |= 1<<ISC11 | 1<< ISC10; //Configuration pour activer INT1 sur un front montant
|
||||
EIMSK |= 1<<INT1; // Activation de l'interuption INT1
|
||||
sei();
|
||||
}
|
||||
unsigned long millis ()
|
||||
{
|
||||
unsigned long millis_return;
|
||||
|
||||
// Ensure this cannot be disrupted
|
||||
ATOMIC_BLOCK(ATOMIC_FORCEON) {
|
||||
millis_return = timer1_millis;
|
||||
}
|
||||
|
||||
return millis_return;
|
||||
}
|
||||
ISR (TIMER1_COMPA_vect)
|
||||
{
|
||||
timer1_millis++;
|
||||
}
|
||||
|
||||
/*
|
||||
* timer.cpp
|
||||
*
|
||||
* Created: 21/12/2013 15:45:30
|
||||
* Author: Adrien
|
||||
*
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "timer.h"
|
||||
volatile unsigned long us = 0;
|
||||
volatile unsigned long us_s = 0;
|
||||
volatile unsigned long int s = 0;
|
||||
#define calibration 1;
|
||||
void timer1_init()
|
||||
{
|
||||
TCCR1A = 0x00; //D<>sactive les comparateur + Mode normal
|
||||
TCCR1B = 0x00;//Mise a zero de toutes les valeurs
|
||||
us = 0;
|
||||
s = 0;
|
||||
TCNT1 = 0x0000;
|
||||
/*
|
||||
Horloge <20> 16Mhz
|
||||
1 p<>riode = 62.5ns
|
||||
clk/8 = 0.5<EFBFBD>s d<>bordement <20> 32768 <20>s
|
||||
clk/64 = 4<>s d<>bordement <20> 262144 <20>s
|
||||
clk/256 = 16<31>s d<>bordement <20> 1 048 576<37>s
|
||||
clk/1024 = 64<36>s d<>bordement <20> 4 194 304<30>s
|
||||
Le prescale sera <20> 8
|
||||
*
|
||||
TCCR1B |= (1<<CS12) | (0<<CS11) | (1<<CS10); //Prescale <20> 8
|
||||
TIMSK1 = 1<<TOIE1; // Initialisation de l'interuption de d<>bordement
|
||||
sei();
|
||||
}
|
||||
void interup_1hz_init()
|
||||
{
|
||||
EICRA |= 1<<ISC11 | 1<< ISC10; //Configuration pour activer INT1 sur un front montant
|
||||
EIMSK |= 1<<INT1; // Activation de l'interuption INT1
|
||||
sei();
|
||||
}
|
||||
unsigned long int millis()
|
||||
{
|
||||
return (TCNT1/64)/100;
|
||||
}
|
||||
unsigned long int secondes()
|
||||
{
|
||||
return s;
|
||||
}
|
||||
ISR(TIMER1_OVF_vect)
|
||||
{
|
||||
// us += 32768; //Lors du d<>bordement le timer est <20>gale <20> (2^16)*0.5 ms
|
||||
TCNT1 = 0;
|
||||
}
|
||||
ISR(INT1_vect)
|
||||
{
|
||||
s++;
|
||||
}*/
|
||||
106
lib/timer.cpp~
Normal file
106
lib/timer.cpp~
Normal file
@@ -0,0 +1,106 @@
|
||||
#define F_CPU 16000000UL // 16 MHz
|
||||
|
||||
// Calculate the value needed for
|
||||
// the CTC match value in OCR1A.
|
||||
#define CTC_MATCH_OVERFLOW ((F_CPU / 1000) / 8)
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/atomic.h>
|
||||
volatile unsigned long timer1_millis;
|
||||
void timer1_init()
|
||||
{
|
||||
// CTC mode, Clock/8
|
||||
TCCR1B |= (1 << WGM12) | (1 << CS11);
|
||||
|
||||
// Load the high byte, then the low byte
|
||||
// into the output compare
|
||||
OCR1AH = (CTC_MATCH_OVERFLOW >> 8);
|
||||
OCR1AL = CTC_MATCH_OVERFLOW;
|
||||
|
||||
// Enable the compare match interrupt
|
||||
TIMSK1 |= (1 << OCIE1A);
|
||||
|
||||
// Now enable global interrupts
|
||||
sei();
|
||||
|
||||
}
|
||||
void interup_1hz_init()
|
||||
{
|
||||
EICRA |= 1<<ISC11 | 1<< ISC10; //Configuration pour activer INT1 sur un front montant
|
||||
EIMSK |= 1<<INT1; // Activation de l'interuption INT1
|
||||
sei();
|
||||
}
|
||||
unsigned long millis ()
|
||||
{
|
||||
unsigned long millis_return;
|
||||
|
||||
// Ensure this cannot be disrupted
|
||||
ATOMIC_BLOCK(ATOMIC_FORCEON) {
|
||||
millis_return = timer1_millis;
|
||||
}
|
||||
|
||||
return millis_return;
|
||||
}
|
||||
ISR (TIMER1_COMPA_vect)
|
||||
{
|
||||
timer1_millis++;
|
||||
}
|
||||
|
||||
/*
|
||||
* timer.cpp
|
||||
*
|
||||
* Created: 21/12/2013 15:45:30
|
||||
* Author: Adrien
|
||||
*
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "timer.h"
|
||||
volatile unsigned long us = 0;
|
||||
volatile unsigned long us_s = 0;
|
||||
volatile unsigned long int s = 0;
|
||||
#define calibration 1;
|
||||
void timer1_init()
|
||||
{
|
||||
TCCR1A = 0x00; //D<>sactive les comparateur + Mode normal
|
||||
TCCR1B = 0x00;//Mise a zero de toutes les valeurs
|
||||
us = 0;
|
||||
s = 0;
|
||||
TCNT1 = 0x0000;
|
||||
/*
|
||||
Horloge <20> 16Mhz
|
||||
1 p<>riode = 62.5ns
|
||||
clk/8 = 0.5<EFBFBD>s d<>bordement <20> 32768 <20>s
|
||||
clk/64 = 4<>s d<>bordement <20> 262144 <20>s
|
||||
clk/256 = 16<31>s d<>bordement <20> 1 048 576<37>s
|
||||
clk/1024 = 64<36>s d<>bordement <20> 4 194 304<30>s
|
||||
Le prescale sera <20> 8
|
||||
*
|
||||
TCCR1B |= (1<<CS12) | (0<<CS11) | (1<<CS10); //Prescale <20> 8
|
||||
TIMSK1 = 1<<TOIE1; // Initialisation de l'interuption de d<>bordement
|
||||
sei();
|
||||
}
|
||||
void interup_1hz_init()
|
||||
{
|
||||
EICRA |= 1<<ISC11 | 1<< ISC10; //Configuration pour activer INT1 sur un front montant
|
||||
EIMSK |= 1<<INT1; // Activation de l'interuption INT1
|
||||
sei();
|
||||
}
|
||||
unsigned long int millis()
|
||||
{
|
||||
return (TCNT1/64)/100;
|
||||
}
|
||||
unsigned long int secondes()
|
||||
{
|
||||
return s;
|
||||
}
|
||||
ISR(TIMER1_OVF_vect)
|
||||
{
|
||||
// us += 32768; //Lors du d<>bordement le timer est <20>gale <20> (2^16)*0.5 ms
|
||||
TCNT1 = 0;
|
||||
}
|
||||
ISR(INT1_vect)
|
||||
{
|
||||
s++;
|
||||
}*/
|
||||
17
lib/timer.h
Normal file
17
lib/timer.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* timer.cpp
|
||||
*
|
||||
* Created: 21/12/2013 15:45:27
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INTERUPTION_H_
|
||||
#define INTERUPTION_H_
|
||||
|
||||
void timer1_init();
|
||||
void interup_1hz_init();
|
||||
unsigned long int millis();
|
||||
unsigned long int secondes();
|
||||
|
||||
#endif
|
||||
17
lib/timer.h~
Normal file
17
lib/timer.h~
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* timer.cpp
|
||||
*
|
||||
* Created: 21/12/2013 15:45:27
|
||||
* Author: Adrien
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INTERUPTION_H_
|
||||
#define INTERUPTION_H_
|
||||
|
||||
void timer1_init();
|
||||
void interup_1hz_init();
|
||||
unsigned long int millis();
|
||||
unsigned long int secondes();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user