#include<avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define uchar unsigned char
uchar Table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar Data[4]={0,0,0,0};
uchar Time[2]={0,0};
uchar CNT=0;
void Display(uchar *p)
{
uchar i,sel=0x01;
for(i=0;i<4;i++)
{
PORTC=sel;
PORTA=Table[p[i]];
_delay_ms(2);
sel=sel<<1;
}
}
void Process(uchar *p1,uchar *p2)
{
p2[0]=p1[0]/10;
p2[1]=p1[0]%10;
p2[2]=p1[1]/10;
p2[3]=p1[1]%10;
}
void Init_IO(void)
{
DDRA=0xff;
PORTA=0xff;
DDRC=0xff;
PORTC=0xff;
}
void main(void)
{
Init_IO();
_delay_ms(10);
TCCR0=0x04;
TCNT0=0x06;
TIMSK=0x01;
sei();
while(1)
{
Process(Time,Data);
Display(Data);
}
}
ISR(TIMER0_OVF_vect)
{
CNT++;
if(CNT==125)
{
CNT=0;
Time[1]++;
if(Time[1]==60)
{
Time[1]=0;
Time[0]++;
}
if(Time[0]==60)
Time[0]=0;
}
}