📄 my_task_keypad.c
字号:
#include <tk/tkernel.h> //T-KERNEL系统调用,基本的数据类型
#include <tm/tmonitor.h> //TMONITOR相关调用
#include <tk/sysdef.h> //系统结构的数据类型
#include <libstr.h> //提供str的一些操作函数
#include <stdio.h>
#include "keyscan.h" //导入所用设备的头文件
#include "display.h" //导入所用设备的头文件
#define Read 0x01
void Keypad_Task(INT stacd ,VP exinf);//
EXPORT ER disp_init(void);//LCD display init
EXPORT void location(void );
ID keypad_tskid=-1;
B g_buff[128]; //串口输出调试信息
ID g_scrdd; //LCD设备ID
LCD_DRAW test_disp; //与LCD设备有关的结构体 详见display.h
UB x=0;
UB y=0;
EXPORT void main(void )
{
ID tsk_id=0;
ER er=0;
T_CTSK ctsk;
#if TRG_DEBUG
tm_putstring("application main started\n");
#endif
er=screen_drv(0,NULL);
if(er<0)
{
return ;
}
er=keyscan_drv(0,NULL);
if (er<0)
{
return ;
}
er=disp_init();
if (er<0)
{
return ;
}
memset(&ctsk,0,sizeof(T_CTSK));
ctsk.tskatr = TA_HLNG | TA_RNG0; //任务属性
ctsk.task = (FP)Keypad_Task; //任务函数名
ctsk.itskpri = 2; //任务优先级
ctsk.stksz = 1024 * 2; //用户堆栈设置
ctsk.sstksz = 1024 * 2; //系统堆栈设置
ctsk.exinf=0; //参数 不传入参数设置为0
er = tk_cre_tsk((T_CTSK*)&ctsk); //建立LedScan任务
if (er < 0)
{
return;
}
keypad_tskid = er;
er=tk_sta_tsk(keypad_tskid,0);
if (er<0)
{
return ;
}
tk_slp_tsk(TMO_FEVR);
#if TRG_DEBUG
tm_putstring((UB *)"\n*** main task ended ***\n"); //串口输出调试信息(实验中没有使用串口和电脑相连接)
#endif
return ;
}
void Keypad_Task(INT stacd ,VP exinf)
{
ER ercd;
ER g_keydd;
UB keyscandev[] = {"keyscan\0"};
INT sz;
UB key_code;
//tm_putstring((B *)"start Keyscan_task \n");
ercd = tk_opn_dev(keyscandev, TD_UPDATE);
if (ercd < 0)
{
sprintf((B *)g_buff, "key tk_opn_dev() error [%#x]\n", ercd);
tm_putstring(g_buff);
goto EXIT_KEYINIT;
}
g_keydd = ercd;
while (1)
{
ercd = tk_srea_dev(g_keydd, DN_KEYCODE, (VP)&key_code, sizeof(UB), &sz);
if (ercd < E_OK)
{
sprintf((B *)g_buff, "tk_srea_dev() error [%#x]\n", ercd);
tm_putstring(g_buff);
break;
}
switch (key_code & 0xF0) /*键盘解码程序(详见模板工程tkdev_EOSTK /src/main/hew_sh7145/statemachine/statemachine.c)*/
{
case 0x70:
{
switch (key_code & 0x0F)
{
case 0x07:
{
#if TRG_DEBUG
tm_putstring((B *)"1\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "1");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
}
case 0x0B:
#if TRG_DEBUG
tm_putstring((B *)"4\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "4");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0D:
#if TRG_DEBUG
tm_putstring((B *)"7\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "7");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0E:
#if TRG_DEBUG
tm_putstring((B *)"A\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "A");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
default:
break;
}
break;
}
case 0xB0:
{
switch (key_code & 0x0F)
{
case 0x07:
#if TRG_DEBUG
tm_putstring((B *)"2\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "2");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0B:
#if TRG_DEBUG
// tm_putstring((B *)"5\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "5");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0D:
#if TRG_DEBUG
// tm_putstring((B *)"8\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "8");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0E:
#if TRG_DEBUG
tm_putstring((B *)"0\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "0");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
default:
break;
}
break;
}
case 0xD0:
{
switch (key_code & 0x0F)
{
case 0x07:
#if TRG_DEBUG
tm_putstring((B *)"3\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "3");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0B:
#if TRG_DEBUG
tm_putstring((B *)"6\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "6");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0D:
#if TRG_DEBUG
tm_putstring((B *)"9\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "9");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0E:
#if TRG_DEBUG
tm_putstring((B *)"B\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "B");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
default:
break;
}
break;
}
case 0xE0:
{
switch (key_code & 0x0F)
{
case 0x07:
#if TRG_DEBUG
tm_putstring((B *)"F\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "F");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0B:
#if TRG_DEBUG
tm_putstring((B *)"E\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "E");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0D:
#if TRG_DEBUG
tm_putstring((B *)"D\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "D");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
case 0x0E:
#if TRG_DEBUG
tm_putstring((B *)"C\n");
#endif
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x=x;
test_disp.y=y;
test_disp.text_len = 1;
sprintf((B *)test_disp.text, "C");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
location();
break;
default:
break;
}
break;
}
default:
break;
}
tk_dly_tsk(35); /*need for SW debounce*/
}
EXIT_KEYINIT:
if (g_keydd > 0)
{
tk_cls_dev(g_keydd, 0);
g_keydd = -1;
}
tm_putstring((B *)"end test_Keyscan \n");
tk_exd_tsk();
}
EXPORT ER disp_init(void)
{
ER ercd;
UB scrdev[] = {"SCREEN\0"};
INT sz;
g_scrdd = -1;
ercd = tk_opn_dev(scrdev, TD_UPDATE); //系统函数 任务打开
if (ercd < 0)
{
sprintf((B *)g_buff, "tk_opn_dev() error [%#x]\n", ercd);
tm_putstring(g_buff);
goto EXIT_SCRINIT;
}
g_scrdd = ercd;
ercd = tk_swri_dev(g_scrdd, DN_LCDCLEAR, (VP)NULL, 0, &sz); //写设备 清空屏幕
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x = 0;
test_disp.y = 0;
test_disp.text_len = 11;
sprintf((B *)test_disp.text, "LuoXingYuan");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp, //写设备 把test_disp.text的内容写到LCD上
sizeof(LCD_DRAW), &sz);
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x = 0;
test_disp.y = 1;
test_disp.text_len = 14;
sprintf((B *)test_disp.text, "Keypad Program");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x = 0;
test_disp.y = 2;
test_disp.text_len = 20;
sprintf((B *)test_disp.text, "Written By LXY");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
memset(&test_disp, 0, sizeof(LCD_DRAW));
test_disp.x = 0;
test_disp.y = 3;
test_disp.text_len = 12;
sprintf((B *)test_disp.text, "2008-10-7-AM");
ercd = tk_swri_dev(g_scrdd, DN_LCDDRAW, (VP)&test_disp,
sizeof(LCD_DRAW), &sz);
tk_dly_tsk(100);
EXIT_SCRINIT:
return ercd;
}
EXPORT void location(void)
{
x++;
if(x>19)
{
x=0;
y++;
if (y>3)y=0;
}
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -