请大佬们帮我看看下面这程序那里出了问题。
程序想要实现的是用定时器中断方式实现数码管动态显示。实现六个数码管显示0~999999,从000000开始没隔1s数码管+1。中断是1ms,每中断一次刷新一次数码管。可是我把程序烧进开发板所实现的现象是每进入一次中断数码管数据就会加1,并不是1s加1。查了好久弄不明白是什么原因。
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dule=P2^6;
sbit wele=P2^7;
uchar code wetable[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //数码管位选
uchar code dutable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00}; //段选
uchar ledbuff[6]={0x00,0x00,0x00,0x00,0x00,0x00}; //暂存
uchar flag1s=0; //1s标志
uchar i=0;
uint cnt=0;
unsigned long sec=0;
void main()
{
dule=0;
wele=0;
TH0=0xfc;
TL0=0x67;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(cnt==1000)
{
cnt=0;
flag1s=1;
}
if(flag1s==1)
{
flag1s=0;
sec++;
ledbuff[0]=dutable[sec%10];
ledbuff[1]=dutable[sec/10%10];
ledbuff[2]=dutable[sec/100%10];
ledbuff[3]=dutable[sec/1000%10];
ledbuff[4]=dutable[sec/10000%10];
ledbuff[5]=dutable[sec/100000%10];
}
}
}
void timer0() interrupt 1
{
TH0=0xfc;
TL0=0x67;
switch(i)
{
case 0:i++;P0=ledbuff[0];dule=1;dule=0;_nop_();P0=wetable[7];wele=1;wele=0;break;
case 1:i++;P0=ledbuff[1];dule=1;dule=0;_nop_();P0=wetable[6];wele=1;wele=0;break;
case 2:i++;P0=ledbuff[2];dule=1;dule=0;_nop_();P0=wetable[5];wele=1;wele=0;break;
case 3:i++;P0=ledbuff[3];dule=1;dule=0;_nop_();P0=wetable[4];wele=1;wele=0;break;
case 4:i++;P0=ledbuff[4];dule=1;dule=0;_nop_();P0=wetable[3];wele=1;wele=0;break;
case 5:i=0;P0=ledbuff[5];dule=1;dule=0;_nop_();P0=wetable[2];wele=1;wele=0;break;
default:break;
}
cnt++;
}
|