下面的程序为何唯独不能显示出2,6,10,14数字,其它数字正常显示?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit smg1=P2^4;
sbit smg2=P2^5;
sbit smg3=P2^6;
sbit rst=P3^6;
sbit en=P1^6;
uchar table[3];
unsigned char code smg_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x10};
unsigned char code smg_we[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78};
uint k;
uchar temp;
uint shu;
void keyscan();
void display();
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
while(1)
{
keyscan();
display();
}
}
void display()
{
uchar i;
// shu=k*k;
table[2]=k/100;
table[1]=k/10%10;
table[0]=k%10;
rst=0;
en=1;
for(i=0;i<3;i++)
{
P1=smg_du[table[ i]];
P2=smg_we[ i];
delayms(1);
}
en=0;
}
void keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:k=0;break;
case 0xde:k=1;break;
case 0xbe:k=2;break;
case 0x7e:k=3;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:k=4;break;
case 0xdd:k=5;break;
case 0xbd:k=6;break;
case 0x7d:k=7;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:k=8;break;
case 0xdb:k=9;break;
case 0xbb:k=10;break;
case 0x7b:k=11;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delayms(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:k=12;break;
case 0xd7:k=13;break;
case 0xb7:k=14;break;
case 0x77:k=15;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
|