⑴ proteus鍵盤輸入實現四位數碼管顯示的c語言代碼怎麼寫
#include<reg52.h>
#defineucharunsignedchar
#defineuintunsignedint
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};//0-f-最後一個空
ucharj=1;
sbitp37=P3^7;
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voiddisplay(ucharshu)
{
P1=table[shu];
delay(5);
}
ucharkeyscan()
{
uchartemp,num;
P2=0xfe;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case0xee:num=1;break;
case0xde:num=2;break;
case0xbe:num=3;break;
default:break;
}
while(temp!=0xf0)//**********鬆手檢測鬆手後顯示
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
P2=0xfd;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case0xed:num=4;break;
case0xdd:num=5;break;
case0xbd:num=6;break;
}
while(temp!=0xf0)
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
P2=0xfb;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case0xeb:num=7;break;
case0xdb:num=8;break;
case0xbb:num=9;break;
}
while(temp!=0xf0)
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
P2=0xf7;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case0xe7:num=16;break;
case0xd7:num=0;break;
case0xb7:num=16;break;
}
while(temp!=0xf0)
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
//if(j==1)num=16;
returnnum;
}
voidmain()
{
p37=1;
while(1)
{
display(keyscan());
//display(7);
}
}
我寫的簡單鍵盤程序並有數碼管顯示模擬結果如圖所示你可以按照圖示實驗有什麼問題可以共同討論