#include<reg52.h>
#define uchar unsigned char //o궨òå
#define uint unsigned int //o궨òå
sbit P27=P2^7;
unsigned char code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xBF};
//12ÑôêyÂë1ü0¡¤F±àÂë 0xBF 1011 1111 "-"
void delay1ms(uint i)
{
uchar j;
while(i--)
{
for(j=0;j<115;j++); //1msÎa»ù×¼μÄÑó3ùoˉêy
}
}
void display(unsigned char i)
{
P27=0; //Ñ¡í¨×îóò¶ËμÄêyÂëÏÔê¾
P0=table[i]; //ÏÔê¾i2Îêy′«à′μÄ×ÖDíÂë
}
void main(void)
{
unsigned char temp;
display(16); //3õê¼ÏÔê¾"-"
while(1)
{
P1=0xff; //ÏèÏòP1¿úD′1£»¶Ë¿ú¶á3ö×′ì¬
P1=0xf0;
temp=P1;
if(temp!=0xf0)
{
delay1ms(15); //Ïû¶¶
if(temp!=0xf0)
{
P1=0xfe;
temp=P1;
switch(temp)
{
case(0xee):display(0);break; //Ö÷òåcase()oóÃæóÃμÄêÇðoÅ£¬2»òa′íD′3é·ÖoÅ
case(0xde):display(1);break;
case(0xbe):display(2);break;
case(0x7e):display(3);break;
}
P1=0xfd;
temp=P1;
switch(temp)
{
case(0xed):display(4);break;
case(0xdd):display(5);break;
case(0xbd):display(6);break;
case(0x7d):display(7);break;
}
P1=0xfb;
temp=P1;
switch(temp)
{
case(0xeb):display(8);break;
case(0xdb):display(9);break;
case(0xbb):display(10);break;
case(0x7b):display(11);break;
}
P1=0xf7;
temp=P1;
switch(temp)
{
case(0xe7):display(12);break;
case(0xd7):display(13);break;
case(0xb7):display(14);break;
case(0x77):display(15);break;
}
}
}
}
}
|