📄 main.c
字号:
#include"..\ucos-ii\includes.h" /* uC/OS interface */
#include "..\ucos-ii\add\osaddition.h"
#include "..\inc\drv.h"
#include <string.h>
#include "..\inc\template.h"
#include"..\inc\experiment.h"
///******************任务定义***************///
OS_STK Main_Stack[STACKSIZE*8]={0, }; //Main_Test_Task堆栈
void Main_Task(void *Id); //Main_Test_Task
#define Main_Task_Prio 12
OS_STK Tag_Glint_Stack[STACKSIZE*8]={0,};
void Tag_Glint_Task(void*Id); //光标闪烁任务
#define Tag_Glint_Prio 61
/**************已经定义的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);
///////////////光标闪烁任务在每个棋盘格闪烁的起始点///////////////////
structPOINT Row1_Col1={ROW1_COL1_STARTx,ROW1_COL1_STARTy};
structPOINT Row1_Col2={ROW1_COL2_STARTx,ROW1_COL2_STARTy};
structPOINT Row1_Col3={ROW1_COL3_STARTx,ROW1_COL3_STARTy};
structPOINT Row2_Col1={ROW2_COL1_STARTx,ROW2_COL1_STARTy};
structPOINT Row2_Col2={ROW2_COL2_STARTx,ROW2_COL2_STARTy};
structPOINT Row2_Col3={ROW2_COL3_STARTx,ROW2_COL3_STARTy};
structPOINT Row3_Col1={ROW3_COL1_STARTx,ROW3_COL1_STARTy};
structPOINT Row3_Col2={ROW3_COL2_STARTx,ROW3_COL2_STARTy};
structPOINT Row3_Col3={ROW3_COL3_STARTx,ROW3_COL3_STARTy};
structPOINT* Tag_Glint_StartPoints[9]={&Row1_Col1,&Row1_Col2,&Row1_Col3,&Row2_Col1,
&Row2_Col2,&Row2_Col3,&Row3_Col1,
&Row3_Col2,&Row3_Col3}; //{Row1_Col1,Row1_Col2,Row1_Col3,Row2_Col1,Row2_Col2,Row2_Col3,Row3_Col1,Row3_Col2,Row3_Col3};
//以下为九个棋格的矩形位置
structRECT Rect1,Rect2,Rect3,Rect4,Rect5,Rect6,Rect7,Rect8,Rect9;
structRECT* pRect1,*pRect2,*pRect3,*pRect4,*pRect5,*pRect6,*pRect7,*pRect8,*pRect9;
U8 Tag_Glint_Position=4; //这是个全局变量,指示的是光标当前在哪个棋盘格闪烁
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(Tag_Glint_Task,(void*)0,(OS_STK*)&Tag_Glint_Stack[STACKSIZE*8-1],Tag_Glint_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
{
structPOINT Touch_Position,*pTouch_Position;
POSMSG pMsg=0;
pRect1=&Rect1;
pRect2=&Rect2;
pRect3=&Rect3;
pRect4=&Rect4;
pRect5=&Rect5;
pRect6=&Rect6;
pRect7=&Rect7;
pRect8=&Rect8;
pRect9=&Rect9;
Rect1.top=0;
Rect1.left=0;
Rect1.bottom=80;
Rect1.right=80;
Rect2.top=0;
Rect2.left=80;
Rect2.bottom=80;
Rect2.right=160;
Rect3.top=0;
Rect3.left=160;
Rect3.bottom=80;
Rect3.right=240;
Rect4.top=80;
Rect4.left=0;
Rect4.bottom=160;
Rect4.right=80;
Rect5.top=80;
Rect5.left=80;;
Rect5.bottom=160;
Rect5.right=160;
Rect6.top=80;
Rect6.left=160;
Rect6.bottom=160;
Rect6.right=240;
Rect7.top=160;
Rect7.left=0;
Rect7.bottom=240;
Rect7.right=80;
Rect8.top=160;
Rect8.left=80;
Rect8.bottom=240;
Rect8.right=160;
Rect9.top=160;
Rect9.left=160;
Rect9.bottom=240;
Rect9.right=240;
//structPOINT Touch_Position,*pTouch_Position;
pTouch_Position=&Touch_Position;
//POSMSG pMsg=0;
ClearScreen();
InitInterface();
//消息循环
for(;;){
pMsg=WaitMessage(0); //等待消息
switch(pMsg->Message){
case OSM_KEY:
onKey(pMsg->WParam,pMsg->LParam);
break;
case OSM_TOUCH_SCREEN:
Touch_Position.x=pMsg->WParam&0xffff;
Touch_Position.y=pMsg->WParam>>16;
if(IsInRect2(pRect1,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=0;
DrawChess();
}
else if(IsInRect2(pRect2,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=1;
DrawChess();
}
else if(IsInRect2(pRect3,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=2;
DrawChess();
}
else if(IsInRect2(pRect4,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=3;
DrawChess();
}
else if(IsInRect2(pRect5,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=4;
DrawChess();
}
else if(IsInRect2(pRect6,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=5;
DrawChess();
}
else if(IsInRect2(pRect7,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=6;
DrawChess();
}
else if(IsInRect2(pRect8,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=7;
DrawChess();
}
else if(IsInRect2(pRect9,pTouch_Position)){
ClearOldTag();
Tag_Glint_Position=8;
DrawChess();
}
break;
default:
OSOnSysMessage(pMsg);
break;
}
DeleteMessage(pMsg);//删除消息,释放资源
OSTimeDly(200);
}
}
void Tag_Glint_Task(void * Id){
PDC pdc=CreateDC();
U8 ColorJudge=0;
U8 Position;
for(;;){
if(ColorJudge==1){
SetPenColor(pdc,RGB(0,0,0));
ColorJudge=0;
}
else{
SetPenColor(pdc,RGB(255,255,255));
ColorJudge=1;
}
Position=Tag_Glint_Position;
MoveTo(pdc,Tag_Glint_StartPoints[Position]->x,Tag_Glint_StartPoints[Position]->y);
LineTo(pdc,Tag_Glint_StartPoints[Position]->x+60,Tag_Glint_StartPoints[Position]->y);
MoveTo(pdc,Tag_Glint_StartPoints[Position]->x,Tag_Glint_StartPoints[Position]->y+1);
LineTo(pdc,Tag_Glint_StartPoints[Position]->x+60,Tag_Glint_StartPoints[Position]->y+1);
MoveTo(pdc,Tag_Glint_StartPoints[Position]->x,Tag_Glint_StartPoints[Position]->y+2);
LineTo(pdc,Tag_Glint_StartPoints[Position]->x+60,Tag_Glint_StartPoints[Position]->y+2);
Delay(1000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -