#include #include #include #include #include #include byte sec=0, min=0, hour=0; byte min_str[2]={48,48}, hour_str[2]={48,48}, clock_str[5]={48,48,33,48,48}, sec_str[2]={0,0}; byte start=0; // Timer 2 output compare interrupt service routine interrupt [TIM2_COMP] void timer2_comp_isr(void) { sec++; } void main(void) { PORTA=0x00; DDRA=0x00; PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0x00; PORTD=0x00; DDRD=0x80; TCCR0=0x00; TCNT0=0x00; OCR0=0x00; TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; ASSR=0x08; TCCR2=0x2F; TCNT2=0x00; OCR2=0x1E; MCUCR=0x00; MCUCSR=0x00; TIMSK=0x80; ACSR=0x80; SFIOR=0x00; #asm("sei") LcdInit(); LcdStr(1, 1, 1, clock_str); while (1) { if (PINA&0x40) { if (min == 60) min = 0; else min++; itoa(min, min_str); if (min < 10) { clock_str[3] = 48; clock_str[4] = min_str[0]; LcdStr(1, 1, 1, clock_str); } else { clock_str[3] = min_str[0]; clock_str[4] = min_str[1]; LcdStr(1, 1, 1, clock_str); } } if (PINA&0x80) { if (hour == 24) hour = 0; else hour++; itoa(hour, hour_str); if (hour < 10) { clock_str[0] = 48; clock_str[1] = hour_str[0]; LcdStr(1, 1, 1, clock_str); } else { clock_str[0] = hour_str[0]; clock_str[1] = hour_str[1]; LcdStr(1, 1, 1, clock_str); } } if (PINA&0x20) sec=0; itoa(sec, sec_str); LcdStr(30, 1, 1, sec_str); if (sec == 60) { min++; sec = 0; if (min == 60) { min = 0; if (hour == 23) hour = 0; else hour++; itoa(min, min_str); itoa(hour, hour_str); clock_str[3] = 48; clock_str[4] = min_str[0]; if (hour < 10) { clock_str[0] = 48; clock_str[1] = hour_str[0]; LcdStr(1, 1, 1, clock_str); } else { clock_str[0] = hour_str[0]; clock_str[1] = hour_str[1]; LcdStr(1, 1, 1, clock_str); } } else { itoa(min, min_str); if (min < 10) { clock_str[3] = 48; clock_str[4] = min_str[0]; LcdStr(1, 1, 1, clock_str); } else { clock_str[3] = min_str[0]; clock_str[4] = min_str[1]; LcdStr(1, 1, 1, clock_str); } } } }; }