📄 kb.lst
字号:
11 =1 0x1a, 'z',
12 =1 0x1b, 's',
13 =1 0x1c, 'a',
14 =1 0x1d, 'w',
15 =1 0x1e, '2',
16 =1 0x21, 'c',
17 =1 0x22, 'x',
18 =1 0x23, 'd',
19 =1 0x24, 'e',
20 =1 0x25, '4',
21 =1 0x26, '3',
22 =1 0x29, ' ',
23 =1 0x2a, 'v',
24 =1 0x2b, 'f',
25 =1 0x2c, 't',
26 =1 0x2d, 'r',
27 =1 0x2e, '5',
28 =1 0x31, 'n',
29 =1 0x32, 'b',
30 =1 0x33, 'h',
31 =1 0x34, 'g',
32 =1 0x35, 'y',
33 =1 0x36, '6',
34 =1 0x39, ',',
35 =1 0x3a, 'm',
36 =1 0x3b, 'j',
37 =1 0x3c, 'u',
38 =1 0x3d, '7',
39 =1 0x3e, '8',
40 =1 0x41, ',',
41 =1 0x42, 'k',
42 =1 0x43, 'i',
43 =1 0x44, 'o',
44 =1 0x45, '0',
45 =1 0x46, '9',
46 =1 0x49, '.',
C51 COMPILER V6.12 KB 03/03/2007 18:29:42 PAGE 6
47 =1 0x4a, '-',
48 =1 0x4b, 'l',
49 =1 0x4c, 'o',
50 =1 0x4d, 'p',
51 =1 0x4e, '+',
52 =1 0x52, 'e',
53 =1 0x54, 'a',
54 =1 0x55, '\\',
55 =1 0x5a, 13,
56 =1 0x5b, '_',
57 =1 0x5d, '\'',
58 =1 0x61, '<',
59 =1 0x66, 8,
60 =1 0x69, '1',
61 =1 0x6b, '4',
62 =1 0x6c, '7',
63 =1 0x70, '0',
64 =1 0x71, ',',
65 =1 0x72, '2',
66 =1 0x73, '5',
67 =1 0x74, '6',
68 =1 0x75, '8',
69 =1 0x79, '+',
70 =1 0x7a, '3',
71 =1 0x7b, '-',
72 =1 0x7c, '*',
73 =1 0x7d, '9',
74 =1 0, 0
75 =1 };
76 =1
77 =1
78 =1 // Shifted characters
79 =1 code unsigned char shifted[][2] = {
80 =1 0x0d, 9,
81 =1 0x0e, 10, //'§',
82 =1 0x15, 'Q',
83 =1 0x16, '!',
84 =1 0x1a, 'Z',
85 =1 0x1b, 'S',
86 =1 0x1c, 'A',
87 =1 0x1d, 'W',
88 =1 0x1e, '"',
89 =1 0x21, 'C',
90 =1 0x22, 'X',
91 =1 0x23, 'D',
92 =1 0x24, 'E',
93 =1 0x25, 11, //'¤',
94 =1 0x26, '#',
95 =1 0x29, ' ',
96 =1 0x2a, 'V',
97 =1 0x2b, 'F',
98 =1 0x2c, 'T',
99 =1 0x2d, 'R',
100 =1 0x2e, '%',
101 =1 0x31, 'N',
102 =1 0x32, 'B',
103 =1 0x33, 'H',
104 =1 0x34, 'G',
105 =1 0x35, 'Y',
106 =1 0x36, '&',
107 =1 0x39, 'L',
108 =1 0x3a, 'M',
C51 COMPILER V6.12 KB 03/03/2007 18:29:42 PAGE 7
109 =1 0x3b, 'J',
110 =1 0x3c, 'U',
111 =1 0x3d, '/',
112 =1 0x3e, '(',
113 =1 0x41, ';',
114 =1 0x42, 'K',
115 =1 0x43, 'I',
116 =1 0x44, 'O',
117 =1 0x45, '=',
118 =1 0x46, ')',
119 =1 0x49, ':',
120 =1 0x4a, '_',
121 =1 0x4b, 'L',
122 =1 0x4c, 'O',
123 =1 0x4d, 'P',
124 =1 0x4e, '?',
125 =1 0x52, 'E',
126 =1 0x54, 'A',
127 =1 0x55, '`',
128 =1 0x5a, 13,
129 =1 0x5b, '^',
130 =1 0x5d, '*',
131 =1 0x61, '>',
132 =1 0x66, 8,
133 =1 0x69, '1',
134 =1 0x6b, '4',
135 =1 0x6c, '7',
136 =1 0x70, '0',
137 =1 0x71, ',',
138 =1 0x72, '2',
139 =1 0x73, '5',
140 =1 0x74, '6',
141 =1 0x75, '8',
142 =1 0x79, '+',
143 =1 0x7a, '3',
144 =1 0x7b, '-',
145 =1 0x7c, '*',
146 =1 0x7d, '9',
147 =1 0, 0
148 =1 };
149 =1
150 =1 #endif // __SCANCODES_H__
6
7
8 #define BUFF_SIZE 32
9
10 unsigned char edge, bitcount; // 0 = neg. 1 = pos.
11 unsigned char kb_buffer[BUFF_SIZE];
12 unsigned char *inpt, *outpt;
13 unsigned char buffcnt;
14
15 extern void clr(void);
16
17 void init_kb(void)
18 {
19 1 inpt = kb_buffer; // Initialize buffer
20 1 outpt = kb_buffer;
21 1 buffcnt = 0;
22 1
23 1 // INT0 interrupt on falling edge
24 1
25 1 edge = 0; // 0 = falling edge 1 = rising edge
C51 COMPILER V6.12 KB 03/03/2007 18:29:42 PAGE 8
26 1 bitcount = 11;
27 1 }
28
29
30 void INT0_interrupt(void) interrupt 0 using 2
31 {
32 1 static unsigned char cdata; // Holds the received scan code
33 1
34 1 if (!edge) // Routine entered at falling edge
35 1 {
36 2 if(bitcount < 11 && bitcount > 2) // Bit 3 to 10 is data. Parity bit,
37 2 { // start and stop bits are ignored.
38 3 cdata = (cdata >> 1);
39 3 if(PIND)
40 3 cdata = cdata | 0x80; // Store a '1'
41 3 }
42 2
43 2 /*MCUCR = 3; */ // Set interrupt on rising edge
44 2 edge = 1;
45 2
46 2 }
47 1 if (edge) { // Routine entered at rising edge
48 2 /*MCUCR = 2; */ // Set interrupt on falling edge
49 2 edge = 0;
50 2
51 2 if(--bitcount == 0) // All bits received
52 2 {
53 3 decode(cdata);
54 3 bitcount = 11;
55 3 }
56 2 }
57 1 }
58
59
60 void decode(unsigned char sc)
61 {
62 1 static unsigned char is_up = 0, shift = 0, mode = 0;
63 1 unsigned char i;
64 1
65 1 if (!is_up) // Last data received was the up-key identifier
66 1 {
67 2 switch (sc)
68 2 {
69 3 case 0xF0 : // The up-key identifier
70 3 is_up = 1;
71 3 break;
72 3 case 0x12 : // Left SHIFT
73 3 shift = 1;
74 3 break;
75 3 case 0x59 : // Right SHIFT
76 3 shift = 1;
77 3 break;
78 3 case 0x05 : // F1
79 3 if(mode == 0)
80 3 mode = 1; // Enter scan code mode
81 3 if(mode == 2)
82 3 mode = 3; // Leave scan code mode
83 3 break;
84 3 default:
85 3 if(mode == 0 || mode == 3) // If ASCII mode
86 3 {
87 4 if(!shift) // If shift not pressed,
C51 COMPILER V6.12 KB 03/03/2007 18:29:42 PAGE 9
88 4 { // do a table look-up
89 5 for(i = 0; unshifted[i][0]!=sc && unshifted[i][0]; i++);
90 5 if (unshifted[i][0] == sc) {
91 6 put_kbbuff(unshifted[i][1]);
92 6 }
93 5 } else { // If shift pressed
94 5 for(i = 0; shifted[i][0]!=sc && shifted[i][0]; i++);
95 5 if (shifted[i][0] == sc) {
96 6 put_kbbuff(shifted[i][1]);
97 6 }
98 5 }
99 4 } else{ // Scan code mode
100 4 print_hexbyte(sc); // Print scan code
101 4 put_kbbuff(' ');
102 4 put_kbbuff(' ');
103 4 }
104 3 break;
105 3 }
106 2 } else {
107 2 is_up = 0; // Two 0xF0 in a row not allowed
108 2 switch (sc)
109 2 {
110 3 case 0x12 : // Left SHIFT
111 3 shift = 0;
112 3 break;
113 3 case 0x59 : // Right SHIFT
114 3 shift = 0;
115 3 break;
116 3 case 0x05 : // F1
117 3 if(mode == 1)
118 3 mode = 2;
119 3 if(mode == 3)
120 3 mode = 0;
121 3 break;
122 3 case 0x06 : // F2
123 3 clr();
124 3 break;
125 3 }
126 2 }
127 1 }
128
129
130 void put_kbbuff(unsigned char c)
131 {
132 1 if (buffcnt < BUFF_SIZE) // If buffer not full
133 1 {
134 2 *inpt = c; // Put character into buffer
135 2 inpt++; // Increment pointer
136 2
137 2 buffcnt++;
138 2
139 2 if (inpt >= kb_buffer + BUFF_SIZE) // Pointer wrapping
140 2 inpt = kb_buffer;
141 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -