⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboard.c

📁 无线通信的
💻 C
字号:
/*********************************************************************************************
* File:	8led.c
* Author:	embest	
* Desc:	8-segment digit LED control functions
* History:	
*********************************************************************************************/
#include "44b.h"
#include "44blib.h"
#include "def.h"
#include "iic.h"

/*------------------------------------------------------------------------------------------*/
/*	 								global variables					 				    */
/*------------------------------------------------------------------------------------------*/
int f_nKeyPress;

/*------------------------------------------------------------------------------------------*/
/*	 								function declare						 				    */
/*------------------------------------------------------------------------------------------*/
void keyboard_test(void);
void keyboard_int(void);
UINT8T key_set(UINT8T ucChar);

/*********************************************************************************************
* name:		keyboard_test
* func:		test 8led
* para:		none
* ret:		none
* modify:
* comment:		
********************************************************************************************/
void keyboard_test(void)
{
	int i, j, k;
	UINT8T ucChar, t;
	
	iic_init();
	
	// initiaze the 8led-function first of ZLG7290 (more to see ZLG7290.pdf)
	// precent the invalid sign generated while keyboard-function
	for(i=0; i<8; i++)
		iic_write(0x70, 0x10+i, 0xFE);

	// set EINT2 interrupt handler
    pISR_EINT2 = (int)keyboard_int;

	for(;;)
	{
	    f_nKeyPress = 0;
		rINTMSK = rINTMSK & (~(BIT_GLOBAL|BIT_EINT2));		// enable EINT2 int
		while(f_nKeyPress == 0);
		iic_read(0x70, 0x1, &ucChar);
		ucChar = key_set(ucChar);			// key map for EduKitII

		if(ucChar<16)
			uart_printf(" press key %3d\r",ucChar);
		else if(ucChar<255)
			uart_printf(" press key %3c\r",ucChar);
				
		if(ucChar==0xFF) 
			uart_printf(" press key FUN\r");
	}
    
    while(1);
}

/*********************************************************************************************
* 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 = 0xFE;
	}
	return ucChar;
}

/*********************************************************************************************
* name:		keyboard_int
* func:		keyboard interrupt handler
* para:		none
* ret:		none
* modify:
* comment:		
********************************************************************************************/
void keyboard_int(void)
{
	UINT8T ucChar;

    f_nKeyPress = 1;
    rI_ISPC = BIT_EINT2;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -