想动态扫描显示87654321,但是运行后,在学习板上却显示87654329,大家瞧瞧是怎么回事。
/*数码管动态扫描显示87654321*/
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar n1,n2,t;
uchar code tabledu[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tablewe[]={
0,0x01,0x02,0x03,0x04,
0x05,0x06,0x07};
void init();
void main()
{
init(); //初始化
while(1)
{
if(t==1)
{
t=0;
n1--;
if(n1==1)
n1=9;
P2=tabledu[n1]; //送段选
P1=tablewe[n2]; //送位选
n2++;
if(n2==8)
n2=0;
}
}
}
/*初始化子程序*/
void init()
{
n1=9;
TMOD=0x01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;
ET0=1;
TR0=1;
}
/* 定时器中断子程序 */
void timer0() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
t++;
}
} |