#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#pragma interrupt_handler miao:9
uchar num;
const uchar table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void init();
void delay(uint z);
void displsy();
void init_timer();
void miao();
void main()
{
init();
init_timer();
while(1)
{
display();
}
}
void miao()
{
num++;
if(num==60)
num=0;
TCNT1H=0X85;
TCNT1L=0XED;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
DDRA|=0X1C;
DDRB|=0XFF;
PORTA&=~BIT(2);
PORTB=0XFF;
PORTA|=BIT(2);
PORTA&=~BIT(2);//关LED
}
void display()
{
uchar num1,num2;
num1=num/10;
num2=num%10;
PORTA&=~BIT(3);
PORTB=table[num1];
PORTA|=BIT(3);
PORTA&=~BIT(3);
PORTA&=~BIT(4);
PORTB=0XFE;
PORTA|=BIT(4);
PORTA&=~BIT(4);
delay(5);
PORTA&=~BIT(3);
PORTB=table[num2];
PORTA|=BIT(3);
PORTA&=~BIT(3);
PORTA&=~BIT(4);
PORTB=0XFD;
PORTA|=BIT(4);
PORTA&=~BIT(4);
delay(5);
}
void init_timer()
{
TCCR1B=0X04;
TCNT1H=0X85;
TCNT1L=0XED;
TIMSK|=BIT(2);
SREG|=BIT(7);
}