/*失败*/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
sbit KEY_IN_1 = P2^4;
sbit KEY_IN_2 = P2^5;
sbit KEY_IN_3 = P2^6;
sbit KEY_IN_4 = P2^7;
sbit KEY_OUT_1 = P2^3;
sbit KEY_OUT_2 = P2^2;
sbit KEY_OUT_3 = P2^1;
sbit KEY_OUT_4 = P2^0;
unsigned char code LedChar[] =
{
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E,
0
};
uchar num, temp;void delay(uint z)
{
uint x,y;
for(x=z; x>0; x--)
for(y=110; y>0; y--);
}
void main()
{
ENLED = 0;
ADDR3 = 1;
ADDR2 = 0;
ADDR1 = 0;
ADDR0 = 0;
while(1)
{
P2 = 0xf7;
temp = P2;
temp = temp & 0xf0;
while(temp != 0xf0);
{
delay(5);
temp = P2;
temp = temp & 0xf0;
while(temp != 0xf0)
{
temp = P2;
switch(temp)
{
case 0xe7: num=1;
break;
case 0xd7: num=2;
break;
case 0xb7: num=3;
break;
case 0x77: num=4;
break;
}
P0 = LedChar[num-1];
}
}
P2 = 0xfb;
temp = P2;
temp = temp & 0xf0;
while(temp != 0xf0);
{
delay(5);
temp = P2;
temp = temp & 0xf0;
while(temp != 0xf0)
{
temp = P2;
switch(temp)
{
case 0xeb: num=1;
break;
case 0xdb: num=2;
break;
case 0xbb: num=3;
break;
case 0x7b: num=4;
break;
}
P0 = LedChar[num-1];
}
}
}
}
|