📄 main.c
字号:
#include"..\ucos-ii\includes.h" /* uC/OS interface */
#include "..\inc\drv.h"
#include "..\ucos-ii\add\osaddition.h"
#include "..\inc\OSFile.h"
#include "..\inc\drv\Ustring.h"
#include "..\inc\resource.h"
#include "..\inc\SetTimeArea.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 Led_Flash_Stack[STACKSIZE]= {0, }; //LED闪烁任务堆栈
void Led_Flash_Task(void *Id); //LED闪烁任务
#define Led_Flash_Prio 60
/**************已经定义的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_Task
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
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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
U8 onKey(int nkey, int fnkey);
OS_STK Rtc_Disp_Stack[STACKSIZE]={0, }; //Rtc_Disp_Task堆栈
void Rtc_Disp_Task(void *Id); //Rtc_Disp_Task
#define Rtc_Disp_Task_Prio 14
OS_EVENT *Rtc_Updata_Sem;//时钟更新控制权
U32 mainstatus;
PListCtrl pMainListCtrl;
PTextCtrl pStatusTextCtrl;
PTextCtrl ptimeTextCtrl,pdateTextCtrl;
PTextCtrl pRiliTextCtrl;
PTextCtrl pYinliTextCtrl;
#define ID_TimeZone_TextCtrl1 50
extern U16* MainFn[];
extern U16* MainTip[];
extern U16* MainWe[];
extern U16* MainYin[];
extern U16* MainChe[];
extern U16* MainCity[];
void onListselChange(U32 ctrlID, int ListSel)
{
}
void Main_Task(void *Id ) //Main_Test_Task
{
POSMSG pMsg=0;
structRECT rect;
ClearScreen();
Rtc_Updata_Sem=OSSemCreate(1);
OSTaskCreate(Rtc_Disp_Task, (void *)0, (OS_STK *)&Rtc_Disp_Stack[STACKSIZE-1], Rtc_Disp_Task_Prio); //5
mainstatus=MAIN_MENU;
SetRect(&rect, 0,160,80,219); //创建控制菜单
pMainListCtrl=CreateListCtrl(ID_MainListBox, &rect, 50,FONTSIZE_SMALL,CTRL_STYLE_DBFRAME,NULL);
ReLoadListCtrl(pMainListCtrl,&MainFn[0],MAIN_FUNCTION_NUM);
SetWndCtrlFocus(NULL, ID_MainListBox);
SetRect(&rect, 60,0,320,160); //创建日历显示文本框
pRiliTextCtrl=CreateTextCtrl(ID_MainStatus, &rect, FONTSIZE_SMALL,CTRL_STYLE_DBFRAME,NULL,NULL);
SetRect(&rect, 0,0,59,159); //创建阴历显示文本框
pYinliTextCtrl=CreateTextCtrl(ID_MainStatus, &rect, FONTSIZE_SMALL,CTRL_STYLE_DBFRAME,NULL,NULL);
SetRect(&rect, 0,220,189,239); // 创建状态文本框
pStatusTextCtrl=CreateTextCtrl(ID_MainStatus, &rect, FONTSIZE_SMALL,CTRL_STYLE_DBFRAME,NULL,NULL);
SetTextCtrlText(pStatusTextCtrl, MainTip[0],FALSE);
SetRect(&rect, 190,220,255,239); //创建日期时间显示文本框
pdateTextCtrl=CreateTextCtrl(ID_MainTimeStatus, &rect, FONTSIZE_SMALL,CTRL_STYLE_DBFRAME,NULL,NULL);
SetRect(&rect, 255,220,319,239); //创建日期时间显示文本框
ptimeTextCtrl=CreateTextCtrl(ID_MainTimeStatus, &rect, FONTSIZE_SMALL,CTRL_STYLE_DBFRAME,NULL,NULL);
TimeZoneShow();
TimeYinShow();
ReDrawOSCtrl();
//消息循环
for(;;){
POS_Ctrl pCtrl;
pMsg=WaitMessage(0);
if(pMsg->pOSCtrl){
if(pMsg->pOSCtrl->CtrlMsgCallBk)
(*pMsg->pOSCtrl->CtrlMsgCallBk)(pMsg);
}
else{
switch(pMsg->Message){
case OSM_LISTCTRL_SELCHANGE:
onListselChange(pMsg->WParam,pMsg->LParam);
break;
case OSM_KEY:
if(onKey(pMsg->WParam,pMsg->LParam) )
break;
default:
OSOnSysMessage(pMsg);
break;
}
}
DeleteMessage(pMsg);
}
}
U8 OnKeyUp()
{
switch(mainstatus){
case MAIN_SETTIME:
SetTimeUp();
return TRUE;
case MAIN_CHECKTIME:
CheckTimeUp();
return TRUE;
}
return FALSE;
}
U8 OnKeyDown()
{
switch(mainstatus){
case MAIN_SETTIME:
SetTimeDown();
return TRUE;
case MAIN_CHECKTIME:
CheckTimeDown();
return TRUE;
}
return FALSE;
}
void OnSetTime()
{
CreateSetTimeArea(TRUE);
SetTimeSetFocus();
SetTextCtrlText(pStatusTextCtrl, MainTip[1],FALSE);
/*ListCtrlReMoveAll(pMainListCtrl);
ReLoadListCtrl(pMainListCtrl,&MainFn[0],MAIN_FUNCTION_NUM);*/
mainstatus=MAIN_SETTIME;
ReDrawOSCtrl();
}
void OnCheckTime()
{
CreateCheckTimeArea(TRUE);
CheckTimeSetFocus();
SetTextCtrlText(pStatusTextCtrl, MainTip[2],FALSE);
/*CheckTimeOK();*/
/*exchange();*/
/*ListCtrlReMoveAll(pMainListCtrl);
ReLoadListCtrl(pMainListCtrl,&MainFn[0],MAIN_FUNCTION_NUM);*/
mainstatus=MAIN_CHECKTIME;
ReDrawOSCtrl();
}
void OnTimeZone()
{
CreateTimeZoneArea(TRUE);
SetTextCtrlText(pStatusTextCtrl, MainTip[3],FALSE);
ListCtrlReMoveAll(pMainListCtrl);
ReLoadListCtrl(pMainListCtrl,&MainCity[0],TIMEZONE_FUNCTION_NUM);
mainstatus=MAIN_TIMEZONE;
ReDrawOSCtrl();
}
void OnBeijing()
{
Beijing(TRUE);
mainstatus=TIMEZONE_BEIJING;
}
void OnHongkong()
{
Beijing(TRUE);
mainstatus=TIMEZONE_HONGKONG;
}
void OnTaibei()
{
Beijing(TRUE);
mainstatus=TIMEZONE_TAIBEI;
}
void OnZhongtudao()
{
TimeZoneSetFocus();
TimeZoneOK();
mainstatus=TIMEZONE_ZHONGTUDAO;
}
void OnXiaweiyi()
{
Beijing(TRUE);
mainstatus=TIMEZONE_XIAWEIYI;
}
void OnAlasijia()
{
Beijing(TRUE);
mainstatus=TIMEZONE_ALASIJIA;
}
void OnLuoshanji()
{
Beijing(TRUE);
mainstatus=TIMEZONE_LUOSHANJI;
}
void OnJiujinshan()
{
Beijing(TRUE);
mainstatus=TIMEZONE_JIUJINSHAN;
}
void OnZhijiage()
{
Beijing(TRUE);
mainstatus=TIMEZONE_ZHIJIAGE;
}
void OnNiuyue()
{
Beijing(TRUE);
mainstatus=TIMEZONE_NIUYUE;
}
void OnHuashengdun()
{
Beijing(TRUE);
mainstatus=TIMEZONE_HUASHENGDUN;
}
void OnShengdiyage()
{
Beijing(TRUE);
mainstatus=TIMEZONE_SHENGDIYAGE;
}
void OnBaxiliya()
{
Beijing(TRUE);
mainstatus=TIMEZONE_BAXILIYA;
}
void OnGelinglan()
{
Beijing(TRUE);
mainstatus=TIMEZONE_GELINLAN;
}
void OnFodejiao()
{
Beijing(TRUE);
mainstatus=TIMEZONE_FODEJIAO;
}
void OnDubolin()
{
Beijing(TRUE);
mainstatus=TIMEZONE_DUBOLIN;
}
void OnAidingbao()
{
Beijing(TRUE);
mainstatus=TIMEZONE_AIDINGBAO;
}
void OnLundun()
{
Beijing(TRUE);
mainstatus=TIMEZONE_LUNDUN ;
}
void OnLisiben()
{
Beijing(TRUE);
mainstatus=TIMEZONE_LISIBEN ;
}
void OnBogeda()
{
Beijing(TRUE);
mainstatus=TIMEZONE_BOGEDA ;
}
void OnBali()
{
Beijing(TRUE);
mainstatus=TIMEZONE_BALI ;
}
void OnLuoma()
{
Beijing(TRUE);
mainstatus=TIMEZONE_LUOMA ;
}
void OnBolin()
{
Beijing(TRUE);
mainstatus=TIMEZONE_BOLIN ;
}
void OnMadeli()
{
Beijing(TRUE);
mainstatus=TIMEZONE_MADELI;
}
void OnHuasha()
{
Beijing(TRUE);
mainstatus=TIMEZONE_HUASHA;
}
void OnYadian()
{
Beijing(TRUE);
mainstatus=TIMEZONE_YADIAN;
}
void OnKailuo()
{
Beijing(TRUE);
mainstatus=TIMEZONE_KAILUO;
}
void OnYelusaleng()
{
Beijing(TRUE);
mainstatus=TIMEZONE_YELUSALENG;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -