|
我刚学定时器,想让数码管 自动计时,但是。。数码管的个位能正常显示,但十位不显示,求助!!!!!!!!
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
code char tab[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint i ,j ,count;
sbit tr1 = P0^5; //个位
sbit tr2 = P0^4; //十位
void delay() //延时
{
int a,b;
for(a=0;a<20;a++)
for(b=0;b<30;b++);;
}
void init() //定时初始化
{
TMOD=0x01;
TH0= (65536 - 50000) / 255;
TL0= (65536 - 50000) % 255;
EA=1;
ET0=1;
TR0=1;
}
void func() //执行
{
tr1 = 0;
tr2 = 1;
P1 = tab[i];
delay();
tr1 = 1;
tr2 = 0;
P1 = tab[j];
delay();
}
timer0()interrupt 1 using 1 //定时器中断
{
TH0= (65536 - 50000) / 255;
TL0= (65536 - 50000) % 255;
if(count == 20)
{
count = 0;
i++;
if(i==10)
{
i = 0; j++;
if(j == 6) j = 0;
}
}
else
count++;
}
main()
{
P1 = 0x00;
init(); //计时初始化
while(1)
{
func();
}
}
|
|