📄 test_key.c
字号:
//====================================================================================
//File name: Test_Key.c
//Function: Key test
//Update: V1.0 by wangtao <wangtao@sunnorth.com.cn>
//====================================================================================
#include "SystemHeader.h"
#define KEY_CNT 3 // Number of keys
#define KEY_X 220 // The coordinates of the top-left corner of key icon
#define KEY_Y 200
#define KEY_H 20 // Length of key
#define KEY_S 10 // Space of every two keys
short Test_Key(void)
{
short x, y;
short Ret = 0;
int i;
unsigned int KeyCode;
*P_GPIO_CLK_CONF = C_GPIO_CLK_EN | C_GPIO_RST_DIS;
*P_IOB_GPIO_SETUP |= 0x38380000; // Pull down IOB5, IOB4, and IOB3 for input
*P_IOB_GPIO_SETUP &= ~0x00003800;
*P_IOB_GPIO_SETUP |= 0x00000700; // Output via IOB2, IOB1, and IOB0; initialized to be low level
*P_IOB_GPIO_SETUP &= ~0x00000007;
TFT_SetBGColor(0x0001);
TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
TFT_SetBGColor(COLOR_WHITE);
TFT_SetWindow(40, 40, 279, 169);
TFT_SetColor(COLOR_RED);
TFT_Rectangle(0, 0, 239, 129, PAINT_HOLLOW);
TFT_SetColor(COLOR_BLUE);
TFT_SetTextPos(30, 30);
TFT_Print("Test the three keys on the board\n");
TFT_SetTextPos(30, 60);
TFT_Print("Click any position on the screen to return");
TFT_SetBGColor(COLOR_BLACK);
TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
x = KEY_X;
y = KEY_Y;
TFT_SetColor(COLOR_CYAN);
for(i=0; i<KEY_CNT; i++)
{
TFT_Rectangle(x, y, x+KEY_H-1, y+KEY_H-1, PAINT_HOLLOW);
x += KEY_H+KEY_S;
}
x = KEY_X+2;
y = KEY_Y+2;
TFT_SetColor(COLOR_MAGENTA);
for(i=0; i<KEY_CNT; i++)
{
TFT_Rectangle(x, y, x+KEY_H-5, y+KEY_H-5, PAINT_SOLID);
x += KEY_H+KEY_S;
}
x = KEY_X + KEY_H/2;
y = KEY_Y + KEY_H/2;
TFT_SetColor(COLOR_WHITE);
for(i=0; i<KEY_CNT; i++)
{
TFT_Circle(x, y, KEY_H/2-4, PAINT_SOLID);
x += KEY_H+KEY_S;
}
KeyCode = 0x0000;
while(1)
{
if((*P_IOB_GPIO_INPUT&0x3800) != KeyCode)
{
KeyCode = *P_IOB_GPIO_INPUT&0x3800;
*P_IOB_GPIO_SETUP &= ~0x0007;
*P_IOB_GPIO_SETUP |= KeyCode>>11;
for(i=0; i<KEY_CNT; i++)
{
if(KeyCode & (0x0800<<i))
{
x = KEY_X+(KEY_H+KEY_S)*i+2;
y = KEY_Y+2;
TFT_SetColor(COLOR_GREEN);
TFT_Rectangle(x, y, x+KEY_H-5, y+KEY_H-5, PAINT_SOLID);
TFT_SetColor(COLOR_YELLOW);
x = KEY_X+(KEY_H+KEY_S)*i+KEY_H/2;
y = KEY_Y + KEY_H/2;
TFT_Circle(x, y, KEY_H/2-4, PAINT_SOLID);
Ret |= (0x01<<i);
}
else
{
x = KEY_X+(KEY_H+KEY_S)*i+2;
y = KEY_Y+2;
TFT_SetColor(COLOR_MAGENTA);
TFT_Rectangle(x, y, x+KEY_H-5, y+KEY_H-5, PAINT_SOLID);
TFT_SetColor(COLOR_WHITE);
x = KEY_X+(KEY_H+KEY_S)*i+KEY_H/2;
y = KEY_Y + KEY_H/2;
TFT_Circle(x, y, KEY_H/2-4, PAINT_SOLID);
}
}
}
Touch_Get(&x, &y);
if(x!=-1)
{
for(i=0; i<1000000; i++);
break;
}
}
TFT_SetBGColor(0x0001);
TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
if(Ret == 0x07)
Ret = 1;
else
Ret = 0;
return Ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -