#include <reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint K=0;
uchar code tabel[][8]= {0x81,0xFD,0xFD,0x81,0xFD,0xFD,0x81,0xFF,
0x81,0xBF,0xBF,0x81,0xFD,0xFD,0x81,0xFF,0x81,0xF7,0xF7,0xF7,0xD7,0xC7,0xE7,0xFF};
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
void KEY()
{
P3=0Xf0;
if(P3!=0xf0)
{
delay(20);
if(P3!=0xf0)
{
switch(P3)
{
case 0xe0: K=0; break;
case 0xd0: K=1; break;
case 0xb0: K=2; break;
case 0x70: K=3; break;
}
P3=0x0f;
switch(P3)
{
case 0x0e: K=K; break;
case 0x0d: K=K+4; break;
case 0x0b: K=K+8; break;
case 0x07: K=K+12; break;
}
while(P3!=0X0f);
}
}
P3=0xff;
if(P3!=0xff)
{
delay(20);
if(P3!=0xff)
{
switch(P3)
{
case 0xfe: K=16; break;
case 0xfd: K=17; break;
case 0xfb: K=18; break;
case 0xf7: K=19; break;
}
while(P3!=0xff);
}
}
}
sbit DIO=P3^4;
sbit S_CLK=P3^5;
sbit R_CLK=P3^6;
void Send_Byte(uchar dat)
{
uchar i;
S_CLK=0;
R_CLK=0;
for(i=0;i<8;i++)
{
if(dat & 0x01)
DIO=1;
else
DIO=0;
S_CLK=1;
dat >>= 1;
S_CLK=0;
}
}
void Out_Byte()
{
uchar ROM,j;
ROM=0X80;
for(j=0;j<8;j++)
{
Send_Byte(tabel[K][j]);
Send_Byte(ROM);
R_CLK=1;
ROM=_cror_(ROM,1);
}
}
void main()
{
while(1)
{
void KEY();
P3=0X00;
void Out_Byte();
delay(100);
}
}
|