求大神帮忙看下这个定时1s的程序为什么不能执行啊?先谢谢了
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
#pragma interrupt_handler time1_isr:9
const SEG_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};//共阴极数码管码表
uchar i;
uchar table[2];
void delay()
{
uchar a;
for(a=300;a>0;a--);
}
/*显示函数*/
void display()
{
/*显示十位*/
PORTC =SEG_CODE[table[0]];
PORTD &=~BIT(0);
delay();
PORTD |=BIT(0);
/*显示个位*/
PORTC =SEG_CODE[table[1]];
PORTD &=~BIT(1);
delay();
PORTD |=BIT(1);
}
/*端口初始化*/
void ini()
{
DDRC=0XFF;
PORTC=0XFF;
DDRD=0XFF;
PORTD=0XFF;
}
/*8MHZ晶振,定时器初始化*/
void time1_init()
{
TCCR1B |=0X04;//256分频率
TCNT1H=0x85;
TCNT1L=0xed;
TIMSK |=BIT(2);
SREG |=BIT(2);
}
void main()
{
ini();
time1_init();
while(1)
{
table[0]=i%10;
table[1]=i/10;
display();
}
}
void time1_isr()
{
flag=1;
TCNT1H=0x85;
TCNT1L=0xed;
i++;
if(i==60)
{
i=0;
}
}
|