#include <STC15Fxxxx.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code duan[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0
};
unsigned char code wei[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
};
uchar num,temp;
sbit SDA1=P4^0;
sbit SCL1=P4^3;
sbit SCL2=P5^4;
uchar keyscan();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void Whc_in(unsigned char Data)
{
unsigned char i;
for(i=0;i<8;i++)
{
SCL1=0;
SDA1=Data&0x80;
Data<<=1;
SCL1=1;
}
}
void Whc_out(void)
{
SCL2=0;
_nop_();
SCL2=1;
}
void Disp(unsigned char m,unsigned char n)
{
Whc_in(wei[n]);
Whc_in(duan[m]);
Whc_out();
delay(10);
}
void main()
{
while(1)
{
Disp(keyscan(),0);
}
}
uchar keyscan()
{
P0=0xfe;
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P0;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp!=0xf0)
{
temp=P0;
temp=temp&0xf0;
}
}
}
P0=0xfd;
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P0;
switch(temp)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
while(temp!=0xf0)
{
temp=P0;
temp=temp&0xf0;
}
}
}
P0=0xfb;
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P0;
switch(temp)
{
case 0xeb:num=9;
break;
case 0xdb:num=10;
break;
case 0xbb:num=11;
break;
case 0x7b:num=12;
break;
}
while(temp!=0xf0)
{
temp=P0;
temp=temp&0xf0;
}
}
}
P0=0xf7;
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P0;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P0;
switch(temp)
{
case 0xe7:num=13;
break;
case 0xd7:num=14;
break;
case 0xb7:num=15;
break;
case 0x77:num=16;
break;
}
while(temp!=0xf0)
{
temp=P0;
temp=temp&0xf0;
}
}
}
return num;
}
|