#include
#define uchar unsigned char
#define uint unsigned int
uchar b,bai,shi,ge;
uchar const table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x76,0x79,0x38,0x00};
sbit dula=P2^6;
sbit wela=P2^7;
uchar keycan(void);
void delay(uint z);
void display(uchar bai,uchar shi,uchar ge);
void main()
{
uchar key;
P0=0x00;
while(1)
{
key=keycan();
switch(key)
{
case 0xee: b=1*1; break;
case 0xde: b=2*2; break;
case 0xbe: b=3*3; break;
case 0x7e: b=4*4; break;
case 0xed: b=5*5; break;
case 0xdd: b=6*6; break;
case 0xbd: b=7*7; break;
case 0x7d: b=8*8; break;
case 0xeb: b=9*9; break;
case 0xdb: b=10*10; break;
case 0xbb: b=11*11; break;
case 0x7b: b=12*12; break;
case 0xe7: b=13*13; break;
case 0xd7: b=14*14; break;
case 0xb7: b=15*15; break;
case 0x77: b=16*16; break;
}
bai=b/100;
shi=b%100/10;
ge=b%10;
display(bai,shi,ge);
}
}
uchar keycan()
{
uchar cord_h,cord_l;
P3=0x0f;
cord_h=P3&0x0f;
if(cord_h!=0x0f)
{
delay(100);
cord_h=P3&0x0f;
if(cord_h!=0x0f)
{
P3=cord_h|0xf0;
cord_l=P3&0xf0;
return(cord_h+cord_l);
}
}return (0xff);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
我认为是你的void display(uchar bai,uchar shi,uchar ge)这里有错误,上面是我的程序,只是改了一点, 我的好用, 你的显示程序外围我不知道,
u百度地图
再写不出再来找我吧
能不能把reg52.h这个头文件发出来看一下