|
- #include <reg52.h>
- unsigned char code table[]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77};
- unsigned char a[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
- unsigned char KeyH;
- unsigned char KeyL;
- unsigned char Key;
- unsigned char d4;
- void delay(unsigned int x);
- void display1(unsigned char d4);
- #define shuma P0
- sbit LED_0=P1^0;
- sbit LED_1=P1^1;
- sbit LED_2=P1^2;
- sbit LED_3=P1^3;
- #define KL_0 P2&=0xf0
- #define KL_F P2|=0x0f
- #define KH_0 P2&=0x0f
- #define KH_F P2|=0xf0
- void main()
- {
- unsigned char t;
- unsigned char i;
- unsigned char res;
- d4=0;
- while(1)
- {
- display1(d4);
- KL_0;
- t=P2&0xf0;
- if(t!=0xf0)
- {
- KeyH=t&0xf0;
- P2=0xff;
- delay(100);
- P2&=0x0f;
- t=P2&0x0f;
- if(t!=0x0f)
- {
- KeyL=t;
- Key=KeyH|KeyL;
- for(i=0;i<16;i++)
- {
- if(table[i]==Key)
- res=i;
- }
- d4=res;
- }
- }
- P2=0xff;
- }
- }
- void delay(unsigned int x)
- {
- unsigned int i;
- for(i=0;i<x;i++);
- }
- void display1(unsigned char d4)
- {
- shuma=a[d4];
- LED_3=0;
- delay(100);
- LED_3=1;
- }
復(fù)制代碼
|
|