📄 keyboard_test.c
字号:
/*********************************************************************************************
* File name: keyboard.c
* Author: Embest
* Descript: keyboard source code.
* History:
* Y.J.Guo, Programming start, April 4, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "iic_keybd.h"
/*------------------------------------------------------------------------------------------*/
/* function declare */
/*------------------------------------------------------------------------------------------*/
void keyboard_test(void);
void keyboard_int(void);// __attribute__ ((interrupt ("IRQ")));
UINT8T key_set(UINT8T ucChar);
extern void isrEINT1(void);
static char f_nKeyPress=0;
/*********************************************************************************************
* name: keyboard_init
* func: keyboard initialize
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void keyboard_init(void)
{
int i;
// initiaze the 8led-function first of ZLG7290 (more to see ZLG7290.pdf)
// precent the invalid sign generated while keyboard-function
iic_init_8led();
for(i=0; i<8; i++)
{
iic_write_8led(0x70, 0x10+i, 0xFF); // write data to DpRam0~DpRam7(Register of ZLG7290)
delay(5);
}
iic_init_keybd(); // enable IIC and EINT1 int
// set EINT1 interrupt handler
pISR_EINT1 = (int)isrEINT1;//keyboard_int;
}
/*********************************************************************************************
* name: keyboard_test
* func: test keyboard
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void keyboard_test(void)
{
UINT8T ucChar;
UINT8T szBuf[40];
uart_printf("\n Keyboard Test Example\n");
uart_printf(" Press any key to exit...\n");
keyboard_init();
g_nKeyPress=0xFE;
while(1)
{
f_nKeyPress = 0;
while(f_nKeyPress==0)
{
if(uart_getkey()) // Press any key from UART0 to exit
return;
else if(ucChar==7) // or press 5x4 Key-7 to exit
return;
else if(g_nKeyPress!=0xFE) // or SB1202/SB1203 to exit
return;
}
iic_read_keybd(0x70, 0x1, &ucChar); // get data from ZLG7290
if(ucChar != 0)
{
ucChar = key_set(ucChar); // key map for EduKitII
if(ucChar<16)
sprintf(&szBuf, " press key %d",ucChar);
else if(ucChar<255)
sprintf(&szBuf, " press key %c",ucChar);
if(ucChar==0xFF)
sprintf(&szBuf, " press key FUN");
#ifdef BOARDTEST
print_lcd(200,170,0x1c,&szBuf);
#endif
uart_printf(szBuf);
uart_printf("\n");
}
}
uart_printf(" end.\n");
}
/*********************************************************************************************
* name: key_set
* func: keyboard setting
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
UINT8T key_set(UINT8T ucChar)
{
switch(ucChar)
{
case 1:
case 2:
case 3:
case 4:
case 5:
ucChar-=1; break;
case 9:
case 10:
case 11:
case 12:
case 13:
ucChar-=4; break;
case 17:
case 18:
case 19:
case 20:
case 21:
ucChar-=7; break;
case 25: ucChar = 0xF; break;
case 26: ucChar = '+'; break;
case 27: ucChar = '-'; break;
case 28: ucChar = '*'; break;
case 29: ucChar = 0xFF; break;
default: ucChar = 0;
}
return ucChar;
}
/*********************************************************************************************
* name: keyboard_int
* func: keyboard interrupt handler
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void keyboard_int(void)
{
UINT8T ucChar;
ClearPending(BIT_EINT1);
f_nKeyPress = 1;
#ifdef BOARDTEST
g_nKeyPress = 0xFE;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -