#define MAIN_CLK 48000000
#define CARRIER_CLK 38000
#define DEMI_PERIODE_US 13
#define PERIODE_AFF_MS 10
/* Brochage afficheur 7 segments :
** Cathodes :
** ___
** | RE0 |
** RE1 | | RA1
** | ___ |
** | RA5 |
** RA3 | | RA2
** | ___ |
** RA4
**
** Anodes:
** _ _
** |_| |_|
** |_| |_|
** RE2 RA0
*/
short displayed = 12;
short toogle = 0;
short intervalle = 0;
short running = 0;
int inc = 0;
int old_pushed_button = 0;
void IrCycles (int nbCycles) {
int i = 0;
for (i=0; i<nbCycles; i++) {
latd.f1 = 1;
Delay_us(DEMI_PERIODE_US);
latd.f1 = 0;
Delay_us(DEMI_PERIODE_US);
}
}
void WaitCycles (int nbCycles) {
int i = 0;
latd.f1 = 0;
for (i=0; i<nbCycles; i++) {
Delay_us(DEMI_PERIODE_US);
Delay_us(DEMI_PERIODE_US);
}
}
void TakePhoto (void) {
latd.f2 = 1;
IrCycles(76);
WaitCycles(1064);
IrCycles(15);
WaitCycles(60);
IrCycles(15);
WaitCycles(136);
IrCycles(15);
Delay_us(63200);
IrCycles(76);
WaitCycles(1064);
IrCycles(15);
WaitCycles(60);
IrCycles(15);
WaitCycles(136);
IrCycles(15);
latd.f2 = 0;
}
void DisplayNumber (char number) {
number = number%16;
switch (number) {
case 0:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 1;
late.f0 = 0;
late.f1 = 0;
break;
case 1:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 1;
lata.f4 = 1;
lata.f5 = 1;
late.f0 = 1;
late.f1 = 1;
break;
case 2:
lata.f1 = 0;
lata.f2 = 1;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 1;
break;
case 3:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 1;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 1;
break;
case 4:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 1;
lata.f4 = 1;
lata.f5 = 0;
late.f0 = 1;
late.f1 = 0;
break;
case 5:
lata.f1 = 1;
lata.f2 = 0;
lata.f3 = 1;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
case 6:
lata.f1 = 1;
lata.f2 = 0;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
case 7:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 1;
lata.f4 = 1;
lata.f5 = 1;
late.f0 = 0;
late.f1 = 1;
break;
case 8:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
case 9:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 1;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
case 0xa:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 0;
lata.f4 = 1;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
case 0xb:
lata.f1 = 1;
lata.f2 = 0;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 1;
late.f1 = 0;
break;
case 0xc:
lata.f1 = 1;
lata.f2 = 1;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 1;
late.f0 = 0;
late.f1 = 0;
break;
case 0xd:
lata.f1 = 0;
lata.f2 = 0;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 1;
late.f1 = 1;
break;
case 0xe:
lata.f1 = 1;
lata.f2 = 1;
lata.f3 = 0;
lata.f4 = 0;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
case 0xf:
lata.f1 = 1;
lata.f2 = 1;
lata.f3 = 0;
lata.f4 = 1;
lata.f5 = 0;
late.f0 = 0;
late.f1 = 0;
break;
}
}
void interrupt (void) {
if (INT0IF_bit) {
if (!PORTB.f0) {
if (intervalle != 0) inc = 0;
else inc = 1;
}
INT0IF_bit = 0;
}
if (TMR0IF_bit) {
if (displayed >=0) {
if (toogle) {
late.f2 = 1; //dizaine
lata.f0 = 0; //unite
DisplayNumber((displayed/10)%10);
}
else {
late.f2 = 0; //dizaine
lata.f0 = 1; //unite
DisplayNumber((displayed)%10);
}
}
else {
late.f2 = 0; //dizaine
lata.f0 = 0; //unite
}
toogle = !toogle;
TMR0IF_bit = 0;
}
}
void main() {
int i = 0;
int j = 0;
int cligno = 0;
trisd.f2 = 0;
trisd.f1 = 0;
trisa = 0;
trise = 0;
RBPU_bit = 0;
latd.f2 = 0;
INTEDG0_bit = 0; //falling edge
INT0IE_bit = 1;
TMR0IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
T08BIT_bit = 0;
T0CS_bit = 0;
PSA_bit = 1;
TMR0H = 0;
TMR0L = 0;
TMR0ON_bit = 1;
intervalle = 0;
i = -0;
j = 0;
inc = 0;
cligno = 0;
old_pushed_button = 0;
while (1) {
if (!running) {
if (intervalle > 0) displayed = intervalle;
else displayed = -1;
}
if (!portb.f0) {
j = 0;
if (inc == 1) {
if ((intervalle < 10) && (i%50 == 0) && (i>0)) intervalle++;
else if ((intervalle >= 10) && (intervalle < 99) && (i%25 == 0) && (i>0)) intervalle++;
}
else if ((i%50 == 0) && (i>0)) intervalle = 0;
i++;
}
else {
if ((i<50)&&(i>0)&& (old_pushed_button)) {
if (intervalle == 0) TakePhoto();
else running = !running;
}
i = -0;
if (running) {
if ((j/100<intervalle)) {
if (j%50 == 0) cligno = !cligno;
if (cligno) displayed = intervalle - j/100;
else displayed = -1;
j++;
}
else {
j = 0;
TakePhoto();
}
}
}
old_pushed_button = !portb.f0;
Delay_ms(10);
}
}