天行健,君子以自强不息
分类: LINUX
2009-07-10 10:40:26
#include
#include
#define LED7 XBYTE[0x9f00]
#define LED6 XBYTE[0x9f01]
#define LED5 XBYTE[0x9f02]
#define LED4 XBYTE[0x9f03]
#define LED3 XBYTE[0x9f04]
#define LED2 XBYTE[0x9f05]
#define LED1 XBYTE[0x9f06]
#define LED0 XBYTE[0x9f07]
sbit p27=P2^7;
sbit p26=P2^6;
sbit p25=P2^5;
sbit d0=P0^0;
sbit d1=P0^1;
sbit d2=P0^2;
sbit d3=P0^3;
sbit d4=P0^4;
sbit d5=P0^5;
sbit d6=P0^6;
sbit d7=P0^7;
#define uint unsigned int
#define uchar unsigned char
uint t[]= //数码显示表(89c52)
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x40
};
void init()
{
LED7=0;
LED6=0;
LED5=0;
LED4=0;
LED3=0;
LED2=0;
LED1=0;
LED0=0;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void keyscan()
{
p27=1;
p26=0;
p25=1;
/////////////////////////////key1
if(d0==0)
{
delay(5);
if(d0==0)
LED7=t[1];
delay(500);
if(d0==1)
LED7=0;
}
///////////////////////////////key2
if(d1==0)
{
delay(5);
if(d1==0)
LED6=t[2];
delay(500);
if(d1==1)
LED6=0;
}
/////////////////////////////key3
if(d2==0)
{
delay(5);
if(d2==0)
LED5=t[3];
delay(500);
if(d2==1)
LED5=0;
}
////////////////////////////////key4
if(d3==0)
{
delay(5);
if(d3==0)
LED4=t[4];
delay(500);
if(d3==1)
LED4=0;
}
///////////////////////////////key5
if(d4==0)
{
delay(5);
if(d4==0)
LED3=t[5];
delay(500);
if(d4==1)
LED3=0;
}
///////////////////////////////key6
if(d5==0)
{
delay(5);
if(d5==0)
LED2=t[6];
delay(500);
if(d5==1)
LED2=0;
}
//////////////////////////key7
if(d6==0)
{
delay(5);
if(d6==0)
LED1=t[7];
delay(500);
if(d6==1)
LED1=0;
}
///////////////////////////key8
if(d7==0)
{
delay(5);
if(d7==0)
LED0=t[8];
delay(500);
if(d7==1)
LED0=0;
}
}
void main()
{
while(1)
{
init();
keyscan();
}
}