#include<iom16v.h>
#include<macros.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint i;
void delay(uint z)
{
uint a,b;
for(a=z;a>0;a--)
for(b=110;b>0;b--);
}
void init()
{
DDRC=0xff;
PORTC=0;
DDRD=0xff;
PORTD=0;
}
void time1_init()
{
TCCR1A=0;
TCCR1B=0x04;//设置256分频
TCNT1H=0x85;
TCNT1L=0xed;//设置定时器初值
TIMSK|=BIT(2);//开中断使能
SREG|=BIT(7);
}
void display()
{
PORTD=0xfe;
PORTC=table[i/10];
PORTD=0xfd;
PORTC=table[i%10];
}
void main()
{
init();
time1_init();
while(1)
{
display();
}
}
#pragma interrupt_handler time1_isr:9
void time1_isr()
{
TCNT1H=0x85;
TCNT1L=0xed;//设置定时器初值
i++;
if(i==60)
i=1;
}
[