#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit fmq=P3^6;
uchar code seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
void delayms(uint i)
{
uchar j;
while(i--)
for(j=0;j<125;j++);
}
void delay500us(){
uchar j;
for(j=0;j<57;j++){;}
}
void display(uchar i,uchar j){
P2=0x40;
P0=seg[i];
delayms(1);
P2=0x80;
P0=seg[j];
delayms(1);
}
void main(){
uchar scan1,scan2,keycode,num,i,j;
i=j=10;
while(1){
P1=0xf0;
scan1=P1;
if(scan1!=0xf0){
delayms(20);
scan1=P1;
if(scan1!=0xf0){
for(i=0;i<100;i++){
fmq=0;
delay500us();
fmq=1;
delay500us();
}
fmq=1;
delayms(100);
P1=0x0f;
scan2=P1;
keycode=scan1|scan2;
}
switch(keycode){
case 0xee: num=0;break;
case 0xde: num=1;break;
case 0xbe: num=2;break;
case 0x7e: num=3;break;
case 0xed: num=4;break;
case 0xdd: num=5;break;
case 0xbd: num=6;break;
case 0x7d: num=7;break;
case 0xeb: num=8;break;
case 0xdb: num=9;break;
case 0xbb: num=10;break;
case 0x7b: num=11;break;
case 0xe7: num=12;break;
case 0xd7: num=13;break;
case 0xb7: num=14;break;
case 0x77: num=15;break;
}
i=num/10;
j=num%10;
}
display(i,j);
}
}
|