1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# include "reg51.h" unsigned char code tab[] = { 0x00, 0x7e, 0xff, 0xc3, 0xc3, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x43, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x63, 0xc7, 0xcf, 0xdb, 0xf3, 0x63, 0x00, 0x00, 0x42, 0xdb, 0xdb, 0xdb, 0xff, 0x66, 0x00, 0x00, 0x3e, 0x46, 0xff, 0xff, 0x06, 0x06, 0x00, }; unsigned char row[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; unsigned char num = 0, flag = 0; sbit key0 = P1^0;
void key() { if (flag == 0 && key0 == 0) { flag = 1; } if (flag == 1 && key0 == 1) { num++; flag = 0; } if (num == 5) { num = 0; } }
void matrix() { unsigned int i = 0;
for (i=8*num; i<8*(num+1); i++) { P3 = ~row[i-8*num]; P2 = tab[i]; } }
void main() { while(1) { matrix(); key(); } }
|