//timercount ext_6-2
#include
#include
#include
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include
unsigned char TEXT[2][16];
unsigned char hour = 0;
unsigned char min = 0;
unsigned char sec = 0;
unsigned char n = 0;
bit flag = 0;
bit flag_1 = 0;
unsigned char key;
void Display_switch(void)
{
key = PIND & 0x03;
switch(key){
case 0b00000010:
delay_ms(150);
if(flag_1 == 0)
{
flag_1 = 1;
}
else
{
flag_1 = 0;
}
break;
case 0b00000001:
sec = 0;
min = 0;
hour = 0;
n = 0;
if(flag_1 == 1)
flag = 0;
break;
default: break;
}
}
--------------------------------------------
:handshake
void Display_count(void)
{
if(sec >= 100){
sec = 0;
min++;
if(min >= 60){
min = 0;
hour++;
if(hour >=60){
hour = 0;
n++;
if(n > 12){
n = 0;
}
}
}
}
}
void Display_LCD(void)
{
lcd_clear();
sprintf(TEXT[0],"%2d :%2d", n, hour);
lcd_gotoxy(0,0);
lcd_puts(TEXT[0]);
sprintf(TEXT[1],":%2d :%2d", min,sec);
lcd_gotoxy(0,1);
lcd_puts(TEXT[1]);
}
void main()
{
DDRC = 0xff;
PORTC =0xff;
DDRD = 0x00;
TCCR1A = 0x00;
TCCR1B = 0x0D;
OCR1A = 156;
TIMSK = 0x10;
SREG = 0x80;
lcd_init(16);
#asm("sei")
while(1)
{
Display_switch();
Display_count();
if(flag == 1){
flag = 0;
Display_LCD();
}
};
}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
if(flag_1 == 1){
sec++;
}
flag = 1;
}
:handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake