📄 keyboard_test.c
字号:
/*********************************************************************************************
* File name: keyboard.c
* Author: Embest
* Descript: keyboard source code.
* History:
* H.T.Zhang, Programming modify, September 14, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "def.h"
#include "lcd.h"
//#include "iic_keybd.h"
#include "demo.h"
extern void lcd_disp_ascii8x16(UINT16T, UINT16T, UINT8T, UINT8T *);
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
int f_nKeyPress;
extern UINT8T f_ucChar;
/*------------------------------------------------------------------------------------------*/
/* function declare */
/*------------------------------------------------------------------------------------------*/
void keyboard_test(void);
void keyboard_init(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)
{
int i;
i = 0;
f_ucChar = 0;
f_nKeyPress = 0;
while(f_ucChar != 2 )
{
while(!f_nKeyPress);
f_nKeyPress = 0;
iic_read_keybd(0x70, 0x1, &f_ucChar);
f_ucChar = key_set(f_ucChar);
if(i > 6) i = 0;
lcd_clr_rect(100,60+20*i,205,60+20*(i+1),BLUE);
switch(f_ucChar)
{
case 0:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 0");
break;
case 1:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 1");
break;
// case 2:
// lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 2");
// break;
case 3:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 3");
break;
case 4:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 4");
break;
case 5:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 5");
break;
case 6:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 6");
break;
case 7:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 7");
break;
case 8:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 8");
break;
case 9:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key 9");
break;
case 10:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key A");
break;
case 11:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key B");
break;
case 12:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key C");
break;
case 13:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key D");
break;
case 14:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key E");
break;
case 0xF:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key F");
break;
case '+':
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key +");
break;
case '-':
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key -");
break;
case '*':
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key *");
break;
case 0xFF:
lcd_disp_ascii8x16(100,60+20*i ,WHITE,"press key Fun");
break;
default:
break;
}
i++;
}
}
/*********************************************************************************************
* 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 + -