为什么下载到实验板上前三个数码管全部都亮?看不清跑表走的数字?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit key=P3^4;
void delay(uchar x);
void display(uchar aa,uchar bb,uchar cc);
void inint();
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71, 0x76,0x79,0x38,0x3f,0};
uchar num,bai,shi,ge;
void delay(uchar x) //延时子函数
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar aa,uchar bb,uchar cc ) //显示子函数
{
dula=1; //显示百位
P0=table[aa];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
dula=1; //显示十位
P0=table[bb];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
dula=1; //显示各位
P0=table[cc];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
}
void inint() //定时器初始化
{
TMOD=0X01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
}
void main()
{
inint();
while(1)
{
display(bai,shi,ge);
if(key==0)
{
delay(10);
if(key==0)
{
TR0=0;
while(!key);
display(bai,shi,ge);
TR0=1;
}
}
}
}
void T0_
time() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
num++;
bai=num/100;
shi=num%100/10;
ge=num%10;
}
一周热门 更多>