|
目的 數(shù)碼管顯示000-999,1/10s 變一次 按下鍵盤s6數(shù)碼管停住
單獨(dú)執(zhí)行鍵盤掃描程序ok
單獨(dú)執(zhí)行數(shù)碼管顯示ok
加一起就出錯(cuò)
程序如下
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar ge,shi,bai,aa,num,num1;
uint temp;
sbit wela=P2^7;
sbit dula=P2^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uchar,uchar,uchar);
void delay(uint);
void init();
uchar keyscan();
void main()
{
init();
while(1)
{
display(bai,shi,ge);
num1=keyscan();
if(num1==1);
{
TR0=0;
};
};
}
uchar keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
};
};
};
return num;
}
void display(uchar bai,uchar shi,uchar ge )
{
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[bai];
dula=0;
delay(1);
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[shi];
dula=0;
delay(1);
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[ge];
dula=0;
delay(1);
}
void timer0 () interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==2)
{
aa=0;
temp++;
if(temp==999)
{
temp=0;
};
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
};
}
void delay (uint z)//延時(shí)程序1ms
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=250;y>0;y--)
{
};
};
}
void init()
{
num=0;
aa=0;
temp=0;
wela=1;
P0=0x00;
wela=0;
dula=1;
P0=0x00;
dula=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
|
|