接下来是处理Caps Lock,Num_Lock,Scroll Lock这3个特殊的东东了,之所以特殊是因为在键盘的右上角有3栈灯对应着这3个键,原理书上说得很清楚,这里懒得废话了,都是些关于硬件的东东,有关硬件嘛,就是往端口中读写一些数据罢了。
在keyboard.c中添加这几个static函数:
- static void KB_Wait()
- {
- u8 kb_stat;
- do
- {
- kb_stat = In_Byte(0x64);
- }while(kb_stat & 0x2);
- }
- static void KB_Ack()
- {
- u8 kb_read;
- do
- {
- kb_read = In_Byte(0x60);
- }while(kb_read != 0xfa);
- }
- static void Set_Leds()
- {
- KB_Wait();
- Out_Byte(0x60,0xed);
- KB_Ack();
- KB_Wait();
- Out_Byte(0x60,(Caps_Lock << 2) | (Num_Lock << 1) | Scroll_Lock);
- KB_Ack();
- }
并添加3个static变量来表示这3个键的状态:
- static int Caps_Lock;
- static int Num_Lock;
- static int Scroll_Lock;
接着在Init_Keyboard函数中初始化一下灯的状态(第5行):
- void Init_Keyboard()
- {
- kb_input_buffer.count = 0;
- kb_input_buffer.p_head = kb_input_buffer.p_tail = kb_input_buffer.buffer;
- Set_Leds();
- Put_IRQ_Handler(1,Keyboard_Handler);
- Enable_IRQ(1);
- }
还得在Keyboard_Read函数中添加对这3个键的响应的:
- case CAPS_LOCK:
- if(make)
- {
- Caps_Lock = !Caps_Lock;
- Set_Leds();
- }
- break;
- case NUM_LOCK:
- if(make)
- {
- Num_Lock = !Num_Lock;
- Set_Leds();
- }
- break;
- case SCROLL_LOCK:
- if(make)
- {
- Scroll_Lock = !Scroll_Lock;
- Set_Leds();
- }
- break;
到此结束,make,运行。启动后3个灯都是灭的,因为3个状态值都为0,如图所示:
3个灯都亮的时候: