proteus仿真51单片机做计时器,第三位为何无法显示?

用proteus仿真,第三位死活显示不了,一帧一帧看偶尔能看到第三位出现个1。不知道各位有没有遇到过类似的问题,请教下,多谢啦。

#include<reg52.h>
#include<intrins.h>
#include<math.h>
#define uchar unsigned char
uchar code dis_code[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code wei_code[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
sbit wela = P2^7;
sbit dula = P2^6;
uchar counter;
void delay(uchar time)#延时函数
{
uchar x,y;
for(x=time;x>0;x--)
for(y=120;y>0;y--);
}
void cleaner()#消残影函数
{
P1 = 0x00;
wela = 1;
wela = 0;
}
void single_display(uchar num,uchar wei)#显示函数
{
cleaner();
P1 = dis_code[num];
dula = 1;
dula = 0;
P1 = 0xff;
delay(1);
P1 = wei_code[wei];
wela = 1;
wela = 0;
delay(1);
}
void o2t(uchar num,uchar wei)
{
if(num<10)single_display(num,wei);#分别一位还是两位
else {single_display(num/10,wei+1);cleaner();single_display(num%10,wei);}
}
void main()
{
int shi = 0, feng = 0, miao = 0,num = 0;
EA = 1;#计时器初始化
ET1 = 1;
TMOD = 0x10;
TH1 = (65535 - 5000)/256;
TL1 = (65535 - 5000)%256;
TR1 = 1;
while(1)
{
if(counter == 2)
{
counter = 0;
miao++;
o2t(miao,1);
if(miao >= 60){miao-=60;feng++;o2t(feng,3);}#计数超过60则送三位显示
cleaner();
}
}
}
void time1() interrupt 3 using 1
{
TH1 = (65535 - 5000)/256;
TL1 = (65535 - 5000)%256;
counter++;
}

原理图
b6e5904deed753a74a783fcabb585ef0_b.jpg

阅读 3.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏