1 #include <reg52.h> 2 #define uint unsigned int 3 #define uchar unsigned char 4 uchar keynum=0; 5 uchar duan[]={0xc0,~0x06,~0x5b,~0x4f,~0x66,~0x6d,~0x7d,~0x07,~0x7f,~0x6f,~0x77,~0x7c,~0x39,~0x5e,~0x79,~0x71}; 6 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 7 void delay() 8 { 9 int i=200; 10 while(i--); 11 } 12 void key44scan(void) 13 { 14 uchar t; 15 P2=0xfe; 16 t=P2; 17 t=t&0xf0; 18 if(t!=0xf0) 19 { 20 delay(); 21 t=P2; 22 t=t&0xf0; 23 if(t!=0xf0) 24 { 25 t=P2; 26 switch(t) 27 { 28 case 0xee:keynum=0;break; 29 case 0xde:keynum=4;break; 30 case 0xbe:keynum=7;break; 31 case 0x7e:keynum=12;break; 32 } 33 P3=duan[keynum]; 34 while(t!=0xf0) 35 { 36 t=P2; 37 t=t&0xf0; 38 } 39 } 40 } 41 /* *************************************************************************************** */ 42 P2=0xfd; 43 t=P2; 44 t=t&0xf0; 45 if(t!=0xf0) 46 { 47 delay(); 48 t=P2; 49 t=t&0xf0; 50 if(t!=0xf0) 51 { 52 t=P2; 53 switch(t) 54 { 55 case 0xed:keynum=1;break; 56 case 0xdd:keynum=5;break; 57 case 0xbd:keynum=9;break; 58 case 0x7d:keynum=13;break; 59 } 60 P3=duan[keynum]; 61 while(t!=0xf0) 62 { 63 t=P2; 64 t=t&0xf0; 65 } 66 } 67 } 68 /* *************************************************************************************** */ 69 P2=0xfb; 70 t=P2; 71 t=t&0xf0; 72 if(t!=0xf0) 73 { 74 delay(); 75 t=P2; 76 t=t&0xf0; 77 if(t!=0xf0) 78 { 79 t=P2; 80 switch(t) 81 { 82 case 0xeb:keynum=2;break; 83 case 0xdb:keynum=6;break; 84 case 0xbb:keynum=10;break; 85 case 0x7b:keynum=14;break;
86 }
87 P3=duan[keynum]; 88 while(t!=0xf0) 89 { 90 t=P2; 91 t=t&0xf0; 92 } 93 } 94 } 95 /* *************************************************************************************** */ 96 97 P2=0xf7; 98 t=P2; 99 t=t&0xf0; 100 if(t!=0xf0) 101 { 102 delay(); 103 t=P2; 104 t=t&0xf0; 105 if(t!=0xf0) 106 { 107 t=P2; 108 switch(t) 109 { 110 case 0xe7:keynum=3;break; 111 case 0xd7:keynum=7;break; 112 case 0xb7:keynum=11;break; 113 case 0x77:keynum=15;break; 114 } 115 P3=duan[keynum]; 116 while(t!=0xf0) 117 { 118 t=P2; 119 t=t&0xf0; 120 } 121 } 122 } 123 } 124 /* *************************************************************************************** */ 125 126 main() 127 { 128 129 while(1) 130 { 131 key44scan(); 132 } 133 } 134 135
136 137 138 139 140 141 142 143 144 145 146