Files

copied
Last update 4 years 8 months
Files
KitchenTimer.c
KitchenTimer.h
Timer.DSN
Timer.pcb
Timer.sch
KitchenTimer.h
#ifndef KITCHTIMER_H #define KITCHTIMER_H #include <avr/io.h> #include <avr/interrupt.h> #include <avr/eeprom.h> //TimerCounter0 #define T0 0x9E #define C0 0x05 //TimerCounter1 #define TCH 0x67 #define TCL 0x6A #define CK1 0x04 // #define SEG1 0 #define SEG2 1 #define SEG3 2 #define SEG4 3 // PortC #define SOUND 0 // enum Events{ TURN,// START,// STOP// }; /* -------------- ----------------*/ uint8_t Seconds = 60; uint8_t Minutes = 60;// , 60 uint8_t digH = 0; uint8_t digL = 0; enum Events Flags = TURN; uint8_t Count = 0xC0 ;// uint8_t i = 0;// Countdown uint8_t Digit[10] EEMEM = {0xC0 , 0xF9 , 0xA4 , 0xB0 , 0x99 , 0x92 , 0x82 , 0xF8 , 0x00 , 0x90}; // - 0 - - 1- - 2 - - 3 - - 4 - - 5 - - 6 - - 7 - - 8 - - 9 - uint8_t Countdown[6] EEMEM = {0xFE , 0xBE , 0xB6 , 0xB7 , 0xF7 , 0xFF}; /*---------------- -----------------*/ /* DisplayTime - */ void DisplayTime(){ uint8_t adrL, adrH; uint8_t tmp = Minutes; if(tmp >= 10){ adrL = tmp%10; adrH = (tmp - adrL)/10; } else { adrH = 0; adrL = tmp; } digH = eeprom_read_byte(&Digit[adrH]); digL = eeprom_read_byte(&Digit[adrL]); } /* Alarm - */ void Alarm(){ if(PORTC & (1 << SOUND)) PORTC = ~(1 << SOUND); else PORTC = (1 << SOUND); } /* EventsInd - */ void EventsInd(){// if(Flags == TURN){ GIFR = 0x40; GICR = (1 << INT1)|(1 << INT0); } if(Flags == START)GICR = (0 << INT1)|(0 << INT0);// if(Flags == STOP){// GIFR = 0xC0; GICR = (1 << INT1)|(0<< INT0); } } /*------------------------- --------------------------*/ /* INT0 - 5 */ ISR(INT0_vect){ Minutes+=5; if(Minutes > 90) Minutes = 5; DisplayTime(); } /* INT1 - / */ ISR(INT1_vect){ if(Flags != STOP){ Flags = START; TCCR1B = CK1; TCCR1A = 0x00; TCNT1H = TCH; TCNT1L = TCL; TIMSK |= (1 << TOIE1); } else { TIMSK = (0 << TOIE1)|(1 << TOIE0);// PORTC = ~(1 << SOUND);// Seconds = 60; Minutes = 60; DisplayTime(); Flags = TURN; } } /* TimerCounter1 - , */ ISR(TIMER1_OVF_vect){ TCNT1H = TCH; TCNT1L = TCL; if(Flags == START){ Count = eeprom_read_byte(&Countdown[i]); i++; if(i == 6) i = 0; --Seconds; if(Seconds == 0){ --Minutes; DisplayTime(); Seconds = 60; } if(Minutes == 0){ Flags = STOP;// Alarm(); Count = 0xC0; i = 0; } } else { Alarm();} } /* TimerCounter0 - */ ISR(TIMER0_OVF_vect){ TCNT0 = T0; uint8_t tmp = PORTB; switch (tmp) { case 0x01 : PORTB = (1 << SEG2); PORTA = digH; break; case 0x02 : PORTB = (1 << SEG3); PORTA = Count; break; case 0x04: PORTB = (1 << SEG4); PORTA = Count; break; case 0x08 : PORTB = (1 << SEG1); PORTA = digL; break; default: PORTB = (1 << SEG1); PORTA = digL; break; } } #endif /*KITCHTIMER_H*/
Report a bug