我在练习数码管循环显示时,奇数次循环没有问题如第一张图,偶数次循环都会出现第二张图的问题,反复看了代码感觉没有问题,还想请教各位我这里是出现了什么问题,谢谢
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code tabledu[]={0x06,0x5b,0x4f,0x66,0x6d,0x7d}; //,0x07,0x6f,0x77,0x7c,0x58,0x5e,0x7b,0x71};
uchar code tablewe[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; //,0xbf,0x7f};
sbit wela=P2^7;
sbit dula=P2^6;
uint a,num1,num2;
void init();
void main()
{
init();
while(1)
{
if(a==20)
{
num1++;
num2--;
if(num1>5)
{
num1=0;
num2=5;
}
P0=tablewe[num1];
wela=1;
wela=0;
P0=tabledu[num2];
dula=1;
dula=0;
a=0;
}
}
}
void init()
{
TMOD=0x11;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET1=1;
TR1=1;
num1=0;
num2=5;
wela=1;
P0=tablewe[num1];
wela=0;
dula=1;
P0=tabledu[num2];
dula=0;
}
void timer1() interrupt 3
{
a++;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
}
|