📄 keyboard.c
字号:
/*********************************************************************************************
* File: keyboard.c
* Author: embest
* Desc: keyboard source code
* History:
*********************************************************************************************/
/*--- include files ---*/
#include "44b.h"
#include "44blib.h"
#include "includes.h"
#include "keyboard.h"
/*--- global variables ---*/
/* keyboard control address */
//#define keyboard_base (*(volatile unsigned char *)(0x06000000))
volatile unsigned char *keyboard_base = (unsigned char *) 0x06000000;
/*--- function declare ---*/
void init_keyboard();
void KeyboardInt(void);
//void Eint4567Isr(void);
/*--- function code ---*/
/*********************************************************************************************
* name: init_keyboard
* func: init keyboard interrupt
* para: none
* ret: none
* modify:
* comment:
********************************************************************************************/
void init_keyboard()
{
/* enable interrupt */
rINTMOD = 0x0;
rINTCON = 0x1;
/* set EINT1 interrupt handler */
rINTMSK =~(BIT_GLOBAL|BIT_EINT1);
pISR_EINT1 = (int)KeyboardInt;
// pISR_EINT4567 = (int)Eint4567Isr;
/* PORT G */
rPCONG = 0xffff; // EINT7~0
rPUPG = 0x0; // pull up enable
rEXTINT = rEXTINT|0x20; // EINT1 falling edge mode
rI_ISPC = BIT_EINT1; // clear pending bit
rEXTINTPND = 0xf; // clear EXTINTPND reg
}
/*********************************************************************************************
* name: Test_Keyboard
* func: test keyboard
* para: none
* ret: none
* modify:
* comment:
********************************************************************************************/
void Test_Keyboard()
{
// init keyboard
init_keyboard();
Uart_Printf("\nPlease press one key on keyboard and look at LED ...");
Uart_Printf("\nplease watch growth the qihuanyun self......:");
// close keyboard
// close_keyboard();
}
/*********************************************************************************************
* name: KeyboardInt
* func: keyboard interrupt handler function
* para: none
* ret: none
* modify:
* comment:
********************************************************************************************/
void KeyboardInt(void)
{
int value;
rI_ISPC = BIT_EINT1; // clear pending bit
rEXTINTPND = 0xf; // clear EXTINTPND reg
value = key_read();
if(value > -1)
Digit_Led_Symbol(value);
rI_ISPC = BIT_EINT1; // clear pending bit
rINTCON = 0x1;
}
/*********************************************************************************************
* name: key_read
* func: read key value
* para: none
* ret: key value, -1 -- error
* modify:
* comment:
********************************************************************************************/
inline int key_read()
{
int value;
char temp;
/* read line 1 */
temp = *(&keyboard_base+0xfd);
/* not 0xF mean key down */
if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)
{
if( (temp&0x1) == 0 )
value = 3;
else if( (temp&0x2) == 0 )
value = 2;
else if( (temp&0x4) == 0 )
value = 1;
else if( (temp&0x8) == 0 )
value = 0;
return value;
}
/* read line 2 */
temp = *(&keyboard_base+0xfb);
/* not 0xF mean key down */
if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)
{
if( (temp&0x1) == 0 )
value = 7;
else if( (temp&0x2) == 0 )
value = 6;
else if( (temp&0x4) == 0 )
value = 5;
else if( (temp&0x8) == 0 )
value = 4;
return value;
}
/* read line 3 */
temp = *(&keyboard_base+0xf7);
/* not 0xF mean key down */
if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)
{
if( (temp&0x1) == 0 )
value = 0xb;
else if( (temp&0x2) == 0 )
value = 0xa;
else if( (temp&0x4) == 0 )
value = 9;
else if( (temp&0x8) == 0 )
value = 8;
return value;
}
/* read line 4 */
temp = *(&keyboard_base+0xef);
/* not 0xF mean key down */
if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)
{
if( (temp&0x1) == 0 )
value = 0xf;
else if( (temp&0x2) == 0 )
value = 0xe;
else if( (temp&0x4) == 0 )
value = 0xd;
else if( (temp&0x8) == 0 )
value = 0xc;
return value;
}
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -