📄 app_keyboard.c
字号:
#include <includes.h>
extern OS_EVENT *AppKbdQ;
extern OS_EVENT *AppKeyQ;
extern CPU_INT08U Key_Flag;
extern CPU_INT08U DisableMainMenu;
extern OS_EVENT *DispUpdadteSem;
extern void DispRefresh (void);
// Declaration for Keypad Hands-On Exercise 2
extern void Green_LED_On_Off(void);
/*
*********************************************************************************************************
* Display_Key()
*
* Description : Display in the VFD the Key that has been pressed.
*
* Argument(s) : Key
*
* Return(s) : none
*
*********************************************************************************************************
*/
void Display_Key(CPU_INT08U rKeyValue)
{
DispClrLine(3);
switch (rKeyValue)
{
case KEY_F1:
DispStr(3,0,"F1");
break;
case KEY_F2:
DispStr(3,0,"F2");
break;
case KEY_F3:
DispStr(3,0,"F3");
break;
case KEY_F4:
DispStr(3,0,"F4");
break;
case KEY_PLUS:
DispStr(3,0,"+");
break;
case KEY_MINUS:
DispStr(3,0,"-");
break;
case KEY_ARW_UP:
DispStr(3,0,"Arrow Up");
if(Brightness_Global <8) Brightness_Global++;
DispBrightness(Brightness_Global);
break;
case KEY_ARW_DN:
DispStr(3,0,"Arrow Down");
if(Brightness_Global > 1) Brightness_Global--;
DispBrightness(Brightness_Global);
break;
case KEY_ARW_LT:
DispStr(3,0,"Arrow Left");
break;
case KEY_ARW_RT:
DispStr(3,0,"Arrow Right");
break;
case KEY_OK:
DispStr(3,0,"OK");
break;
case KEY_MENU:
DispStr(3,0,"MENU");
break;
case KEY_SEND:
DispStr(3,0,"SEND");
break;
case KEY_CLEAR:
DispStr(3,0,"CLEAR");
break;
case KEY_END:
DispStr(3,0,"END - ON/OFF");
break;
case KEY_1:
DispStr(3,0,"1");
break;
case KEY_2:
DispStr(3,0,"2");
break;
case KEY_3:
DispStr(3,0,"3");
break;
case KEY_4:
DispStr(3,0,"4");
break;
case KEY_5:
DispStr(3,0,"5");
break;
case KEY_6:
DispStr(3,0,"6");
break;
case KEY_7:
DispStr(3,0,"7");
break;
case KEY_8:
DispStr(3,0,"8");
break;
case KEY_9:
DispStr(3,0,"9");
break;
case KEY_0:
DispStr(3,0,"0");
break;
case KEY_ASTERISK:
DispStr(3,0,"*");
break;
case KEY_POUND:
DispStr(3,0,"#");
break;
default:
// DispStr(3,0,"Decoding Error");
break;
}
}
/*
*********************************************************************************************************
* KeypadCheck()
*
* Description : Checks is there has been a key pressed. If this is the case, the Decoder is called
*
* Argument(s) : none
*
* Return(s) : Key decoded.
*
*********************************************************************************************************
*/
CPU_INT08U KeypadCheck ( void )
{
CPU_INT08U lKeypadValue = 0;
if(Key_Flag == 1) // External Interrupt 2 set Key_Flag when the 1st interrupt occured (key pressed)
{
I2C_Read_Counter = 0;
I2C_Write_Counter = 0;
Row_Counter = 0;
Row_Found = 0;
Row_Value = 0;
Column_Value = 0;
Keypad_Data_Read = Keypad_Read(); // Read Input Register
if ((Keypad_Data_Read | P1_KPAD_COLUMN_MASK) != 0xFF) // Keypad decoded if input Register different from 0xFF
{
lKeypadValue = Keypad_Decoder(); // Perform the Keypad Scanning / Decoding routine
}
Key_Flag = 0;
OSTimeDlyHMSM(0, 0, 0, 250); // Add a delay to be sure the pressed key has been released
VICIntEnable = (1 << VIC_EINT2); // Enable External Interrupt 2 once Scanning/Decoding performed
}
return lKeypadValue;
}
/*
*********************************************************************************************************
* AppTaskKbd()
*
* Description : Monitor the state of the push buttons and passes messages to AppTaskStart()
*
* Argument(s) : p_arg Argument passed to 'AppTaskKbd()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
void AppTaskKbd (void *p_arg)
{
CPU_BOOLEAN b1; /* State of Push Button #1 */
CPU_BOOLEAN b1_prev;
CPU_BOOLEAN b2; /* State of Push Button #2 */
CPU_BOOLEAN b2_prev;
CPU_BOOLEAN b3; /* State of Push Button #3 */
CPU_BOOLEAN b3_prev;
CPU_BOOLEAN b4; /* State of Push Button #4 */
CPU_BOOLEAN b4_prev;
CPU_INT08U lKey;
CPU_INT08U err;
(void)p_arg;
b1_prev = DEF_FALSE;
b2_prev = DEF_FALSE;
b3_prev = DEF_FALSE;
b4_prev = DEF_FALSE;
while (DEF_TRUE) {
b1 = PB_GetStatus(1);
b2 = PB_GetStatus(2);
b3 = PB_GetStatus(3);
b4 = PB_GetStatus(4);
if ((b1 == DEF_TRUE) && (b1_prev == DEF_FALSE)) {
OSQPost(AppKbdQ, (void *)1);
}
if ((b2 == DEF_TRUE) && (b2_prev == DEF_FALSE)) {
OSQPost(AppKbdQ, (void *)2);
}
if ((b3 == DEF_TRUE) && (b3_prev == DEF_FALSE)) {
OSQPost(AppKbdQ, (void *)3);
}
if ((b4 == DEF_TRUE) && (b4_prev == DEF_FALSE)) {
OSQPost(AppKbdQ, (void *)4);
}
b1_prev = b1;
b2_prev = b2;
b3_prev = b3;
b4_prev = b4;
lKey = KeypadCheck();
if (lKey)
{
if(lKey == KEY_MENU){
OSSemPend(DispUpdadteSem, 0, &err); /* Obtain exclusive access to the display */
if(DisableMainMenu == 0){
OSQFlush(AppKeyQ);
DisableMainMenu = 1;
}else{
DisableMainMenu = 0;
DispRefresh();
DispClrLine(3);
}
OSSemPost(DispUpdadteSem); /*Semaphore Post*/
}
else{
if(DisableMainMenu == 0){
Display_Key(lKey);
}
}
OSQPost(AppKeyQ, (void *)lKey);
}
OSTimeDly(OS_TICKS_PER_SEC / 100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -