📄 main.c
字号:
#include"..\ucos-ii\includes.h" /* uC/OS interface */#include "..\ucos-ii\add\osaddition.h"#include "..\inc\drv.h"#include <string.h>unsigned char MykeyBoard_KeyMap[]={1,4,7,10,2,5,8,0,3,6,9,11,12,13,14,15};//10-退格,11-*/.,12-↑,13-↓,14-确定,15-取消U16 MyGetScanKey();U32 MyGetKey();void onKey(int nkey, int fnkey);///******************任务定义***************///OS_STK Main_Stack[STACKSIZE*8]={0, }; //Main_Test_Task堆栈void Main_Task(void *Id); //Main_Test_Task#define Main_Task_Prio 12OS_STK Led_Flash_Stack[STACKSIZE]= {0, }; //LED闪烁任务堆栈void Led_Flash_Task(void *Id); //LED闪烁任务#define Led_Flash_Prio 60OS_STK My_Key_Scan_Stack[STACKSIZE]={0, }; //Key_Test_Task堆栈void My_Key_Scan_Task(void *Id); //键盘扫描任务#define MyKey_Scan_Task_Prio 58/**************已经定义的OS任务*************#define Touch_Screen_Task_Prio 9#define Main_Task_Prio 12#define Key_Scan_Task_Prio 58#define Lcd_Fresh_prio 59#define Led_Flash_Prio 60***************************************////////////*****************事件定义*****************///OS_EVENT *Nand_Rw_Sem; //Nand_Flash读写控制权旗语//and you can use it as folloeing:// Nand_Rw_Sem=OSSemCreate(1); //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件//// OSSemPend(Nand_Rw_Sem,0,&err);// OSSemPost(Nand_Rw_Sem);OS_EVENT *Uart_Rw_Sem; //Uart读写控制权旗语//and you can use it as folloeing:// Uart_Rw_Sem=OSSemCreate(1); //创建Uart读写控制权旗语,初值为1满足互斥条件//// OSSemPend(Uart_Rw_Sem,0,&err);// OSSemPost(Uart_Rw_Sem);//////////////////////////////////////////////////////////void Led_Flash_Task(void *Id)//指示RTOS处于正常工作中{ unsigned char led_state; Uart_Printf(0,"\n10"); for (;;) { Led_Display(led_state); led_state=~led_state; OSTimeDly(250); }}//Led_Flash_Taskvoid My_Key_Scan_Task(void *Id)//指示RTOS处于正常工作中{ U32 key; u32 tempkey=0; POSMSG pmsg; Uart_Printf("begin key task \n"); for (;;){ key=MyGetKey(); key&=0x000f; if(key>9){ Uart_SendByte(0,0x31); tempkey=key-10; Uart_SendByte(0,tempkey|=0x0030); } else Uart_SendByte(0,key|0x0030); Uart_Printf(","); pmsg=OSCreateMessage(NULL, OSM_KEY,key,key); if(pmsg) SendMessage(pmsg); }}void initOSGUI() //初始化操作系统的图形界面{ initOSMessage(); initOSList(); initOSDC(); initOSCtrl(); initOSFile();}/////////////////////////////////////////////////////// Main function. //////////////////////////////////////////////////////int Main(int argc, char **argv){ ARMTargetInit(); // do target (uHAL based ARM system) initialisation // OSInit(); // needed by uC/OS-II // uHALr_ResetMMU(); LCD_Init(); //初始化LCD模块 LCD_printf("LCD initialization is OK\n"); LCD_printf("320 x 240 Text Mode\n"); LoadFont(); LoadConfigSys(); // create the tasks in uC/OS and assign increasing // // priorities to them so that Task3 at the end of // // the pipeline has the highest priority. // LCD_printf("Create task on uCOS-II...\n"); OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[STACKSIZE*8-1], Main_Task_Prio);// 1 OSTaskCreate(Led_Flash_Task, (void *)0, (OS_STK *)&Led_Flash_Stack[STACKSIZE-1], Led_Flash_Prio );// 10 OSTaskCreate(My_Key_Scan_Task, (void *)0, (OS_STK *)&My_Key_Scan_Stack[STACKSIZE-1], MyKey_Scan_Task_Prio ); OSAddTask_Init(); LCD_printf("Starting uCOS-II...\n"); LCD_printf("Entering graph mode...\n"); LCD_ChangeMode(DspGraMode); initOSGUI(); InitRtc(); Nand_Rw_Sem=OSSemCreate(1); //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件// ARMTargetStart(); //Start the (uHAL based ARM system) system running // OSStart(); // start the game // // never reached // return 0;}//main//////////////////////////////////////////////////////////////////////////////////////////////////////////////////void Main_Task(void *Id) //Main_Test_Task{ POSMSG pMsg=0; LCD_ChangeMode(DspTxtMode); LCD_Cls(); for(;;){ pMsg=WaitMessage(0); //等待消息 switch(pMsg->Message){ case OSM_KEY: onKey(pMsg->WParam,pMsg->LParam); break; Delay(200); } DeleteMessage(pMsg);//删除消息,释放资源 }}U16 MyGetScanKey(){ U16 key; U32 i,temp; for(i=1;i<0x10;i<<=1){ rPDATE|=0xf0; rPDATE&=~(i<<4); key<<=4; OSTimeDly(1); temp=rPDATC; key|=(temp&0xf); } return key;}U32 MyGetKey(){ int i; U16 key,tempkey=1; static U16 oldkey=0xffff; static U8 keystatus=0; U8 keycnt=0; while(1){ key=0xffff; while(1){ key=MyGetScanKey(); if(key!=0xffff) break; OSTimeDly(20); oldkey=0xffff; } OSTimeDly(50); if(key!=MyGetScanKey()) continue; if(oldkey!=key){ keystatus=0; } if(keystatus==0){ //第一次按下此键 keycnt=0; keystatus=1; } else if(keystatus==1){ //第二次重复此键 keycnt++; if(keycnt==20) keystatus=2; else continue; } oldkey=key; break; } for(i=0;i<16;i++){ //查找按键,不包括功能键 if((key&tempkey)==0) break; tempkey<<=1; } return MykeyBoard_KeyMap[i];}void onKey(int nkey, int fnkey){ char temp[3]; if(nkey>9){ temp[0]=0x31; temp[1]=(nkey-10)|0x30; temp[2]=0; } else { temp[0]=nkey+0x30; temp[1]=0; } LCD_printf(temp); LCD_printf("\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -