⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于S3C44B0X开发的一个校园导航系统
💻 C
字号:
#include"..\ucos-ii\includes.h"               /* uC/OS interface */
#include "..\ucos-ii\add\osaddition.h"
#include "..\inc\drv.h"
#include "..\inc\drv\tchscr.h"
#include "..\INC\DRV\DISPLAY.h"
#include "..\SRC\ShortestPath.h"
#include "..\SRC\TaskWnd.h"
#include "..\SRC\Initial.h"
#include "..\SRC\define.h"
#include "..\SRC\global.h"
#include "..\SRC\define.h"
#include "..\SRC\Key.h"
#include <string.h>
#include<math.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任务*************
tcp监控任务		11
以太网物理层监控任务	8
触摸屏任务		9
键盘任务		10
lcd刷新任务		59
系统任务		1
*****************************************************/

///*****************事件定义*****************///
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);
//////////////////////////////////////////////////////////

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// Define some global variable
//used for store thr time string
U16 g_strTime[10];

// The variable to indicate the current window
int g_iWndLevel = 0;

// The device context 
PDC pdc;

// Store all of the points 
structPOINT PlacePointArray[15];

// Eight rectangles used in keyboard choosing finding path
// function to indicate which point is selected
structRECT PointRect[8];

// Char used for displaying the distance in find path
// function
char chDistance[]  = "Distance:";
U16  UchDistance[20];

// Two listctrls used for finding path by listbox 
PListCtrl pStartPosListCtrl;
PListCtrl pEndPosListCtrl;

// Listctrl for watch introduction function
PListCtrl pIntrodListCtrl;

// Store the choosed two points in finding path function
int LB_Result[2];

// Store the strings contained in list box
char PosName[8][25]   = { " Gate",          " NO.8 Building", " Playground",   
	                      " South Gate",    " Minzhu Lake",   " Hospital",     
	                      " FengYu Square", " Clock Tower"};

// Store the bitmap name used for watching introduction 
char IntroName[8][25] = { "gate.bmp",     "building.bmp",   "ground.bmp",   
	                      "sgate.bmp",    "lake.bmp",       "hospital.bmp",  
	                      "fengyu.bmp",   "tower.bmp"};


void initOSGUI()	//初始化操作系统的图形界面
{
	initOSMessage();
	initOSList();
	initOSDC();
	initOSCtrl();
	initOSFile();
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//Main function.         
int Main(int argc, char **argv)
{
	ARMTargetInit(); //开发板初始化
	OSInit(); //操作系统初始化      
	uHALr_ResetMMU();//复位MMU
	LCD_Init();             //初始化LCD模块
	LCD_printf("LCD initialization is OK\n");//向液晶屏输出数据
	LCD_printf("320 x 240  Text Mode\n");
	initOSGUI();//初始化图形界面
	LoadFont();//调Unicode字库
	LoadConfigSys();//使用config.sys文件配置系统设置
	LCD_printf("Create task on uCOS-II...\n");
	OSTaskCreate(Main_Task,  (void *)0,  (OS_STK *)&Main_Stack[STACKSIZE*8-1], 
	              Main_Task_Prio);// 创建系统任务
	OSAddTask_Init();//创建系统附加任务
	LCD_printf("Starting uCOS-II...\n");
	LCD_printf("Entering graph mode...\n");
	LCD_ChangeMode(DspGraMode);//变LCD显示模式为文本模式
	InitRtc();//初始化系统时钟
	Nand_Rw_Sem=OSSemCreate(1);   //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件//
	OSStart();//操作系统任务调度开始
	//不会执行到这里
	return 0;
}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
OS_EVENT *Rtc_Updata_Sem;//时钟更新控制权
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

void Main_Task(void *Id)             //Main_Test_Task
{
	// Initialize the global variable
	// Initialize those place point position 
	PlacePointArray[0].x = 49;
	PlacePointArray[0].y = 56;

	PlacePointArray[1].x = 111;
	PlacePointArray[1].y = 81;

	PlacePointArray[2].x = 210;
	PlacePointArray[2].y = 142;

	PlacePointArray[3].x = 188;
	PlacePointArray[3].y = 163;

	PlacePointArray[4].x = 249;
	PlacePointArray[4].y = 142;
 
	PlacePointArray[5].x = 275;
	PlacePointArray[5].y = 70;
 
	PlacePointArray[6].x = 249;
	PlacePointArray[6].y = 70;
 
	PlacePointArray[7].x = 169;
	PlacePointArray[7].y = 56;

	PlacePointArray[8].x = 73;
	PlacePointArray[8].y = 81;
	
	PlacePointArray[9].x = 144;
	PlacePointArray[9].y = 81;
	
	PlacePointArray[10].x = 136;
	PlacePointArray[10].y = 106;
	
	PlacePointArray[11].x = 79;
	PlacePointArray[11].y = 56;
	
	PlacePointArray[12].x = 188;
	PlacePointArray[12].y = 70;
	
	PlacePointArray[13].x = 208;
	PlacePointArray[13].y = 120;
	
	PlacePointArray[14].x = 198;
	PlacePointArray[14].y = 142;
	
	// Initialize those eight point rect 
	SetRect(&PointRect[0],43, 51, 53, 61);
	SetRect(&PointRect[1],105,70, 115,80);
	SetRect(&PointRect[2],205,131,215,141);
	SetRect(&PointRect[3],181,164,191,174);
	SetRect(&PointRect[4],236,132,246,142);
	SetRect(&PointRect[5],270,71, 280,81);
	SetRect(&PointRect[6],231,58, 241,68);
	SetRect(&PointRect[7],164,46, 174,56);

	//Define the time update task
	Rtc_Updata_Sem=OSSemCreate(1);
	OSTaskCreate( Rtc_Disp_Task,(void *)0,(OS_STK *)&Rtc_Disp_Stack[STACKSIZE-1], 
	              Rtc_Disp_Task_Prio);	//5//创建时钟任务

	// Convert the char used for display "distance"
	strChar2Unicode(UchDistance,chDistance);
	pdc = CreateDC();
	
	//Enter the program window 
	EnterWnd();

	// Main function
	while(1)
	{
		switch(g_iWndLevel)
		{
		case 0:
			// Choose function window
			ChooseWnd();
			break;
		case 1:
			// Watch introduction by list box window
			IntroLBxWnd();
			break;
		case 2:
			// Finding path by listbox window
			FindPathLBxWnd();
			break;
		case 3:
			// Finding path by using keyboard to 
			// input the point window
			FindPathKbdWnd();
			break;
		case 4:
			// Watch map window
			WatchMapWnd();
			break;
		case 5:
			// Help system window
			HelpWnd();
			break;
		}		
	}
	DestoryDC(pdc);
}

////////////////////////////////////////////////////////////////
//Time update task
void Rtc_Disp_Task(void *Id) 
{	
	INT8U err;	
	for(;;){
		if(Rtc_IsTimeChange(RTC_SECOND_CHANGE)){//不需要更新显示
			OSSemPend(Rtc_Updata_Sem, 0,&err);//等待信号量
			Rtc_Format("%H:%I:%S",g_strTime);//格式化时间
			OSSemPost(Rtc_Updata_Sem);//发送信号量
		}
		OSTimeDly(250);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -