www.pudn.com > mutiADdisplay.rar > Main.c, change:2006-03-27,size:12453b


#include"..\ucos-ii\includes.h"               /* uC/OS interface */ 
#include "..\ucos-ii\add\osaddition.h" 
#include "..\inc\drv.h" 
#include <string.h> 
#include"..\inc\drv\ad.h" 
 
#define ID_ChannelTextCtrl 101 
#define ID_ValueTextCtrl 102 
#define Draw_Wnd_ID 104 
PTextCtrl pChannelTextCtrl,pValueTextCtrl; 
float result_AD0,result_AD1,result_AD2,result_AD3; 
int WarnningData[4]={33,33,33,33}; 
int edit[2]={0,0}; 
 
///******************任务定义***************/// 
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 Display_Task_Stack[STACKSIZE*8]={0, };   //Main_Test_Task堆栈 
void Display_Task(void *Id);             //Main_Test_Task 
#define Display_Task_Prio     20 
 
OS_STK AD0_Task_Stack[STACKSIZE*8]={0, };   //Main_Test_Task堆栈 
void AD0_Task(void *Id);             //Main_Test_Task 
#define AD0_Task_Prio     21 
 
OS_STK AD1_Task_Stack[STACKSIZE*8]={0, };   //Main_Test_Task堆栈 
void AD1_Task(void *Id);             //Main_Test_Task 
#define AD1_Task_Prio     22 
 
OS_STK AD2_Task_Stack[STACKSIZE*8]={0, };   //Main_Test_Task堆栈 
void AD2_Task(void *Id);             //Main_Test_Task 
#define AD2_Task_Prio     23 
 
OS_STK AD3_Task_Stack[STACKSIZE*8]={0, };   //Main_Test_Task堆栈 
void AD3_Task(void *Id);             //Main_Test_Task 
#define AD3_Task_Prio     24 
 
/**************已经定义的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); 
////////////////////////////////////////////////////////// 
 
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);// 创建系统任务 
	OSTaskCreate(Display_Task,(void *)0,  (OS_STK *)&Display_Task_Stack[STACKSIZE-1],  Display_Task_Prio);// 20 
	OSTaskCreate(AD0_Task,(void *)0,  (OS_STK *)&AD0_Task_Stack[STACKSIZE-1],  AD0_Task_Prio); 
	OSTaskCreate(AD1_Task,(void *)0,  (OS_STK *)&AD1_Task_Stack[STACKSIZE-1],  AD1_Task_Prio); 
	OSTaskCreate(AD2_Task,(void *)0,  (OS_STK *)&AD2_Task_Stack[STACKSIZE-1],  AD2_Task_Prio); 
	OSTaskCreate(AD3_Task,(void *)0,  (OS_STK *)&AD3_Task_Stack[STACKSIZE-1],  AD3_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; 
} 
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
//void init_ADdevice() 
//{ 
	//rADCPSR=20; 
	//rADCCON=ADCCON_SLEEP; 
//} 
 
U8 onKey(int nkey, int fnkey) 
{ 
	static BOOLEAN input=FALSE; 
	static int EditNumber=1; 
	if(EditNumber==1) 
	{ 
		switch(nkey) 
		{	 
		case 14://OK 
			if(!input) 
			{ 
				SetWndCtrlFocus(NULL, ID_ChannelTextCtrl); 
				pChannelTextCtrl->text[0]=0;  //清空文本框 
				SetTextCtrlEdit(pChannelTextCtrl, TRUE); 
				DrawTextCtrl(pChannelTextCtrl); 
				input=TRUE; 
				edit[0]=1; 
			} 
			else 
			{ 
				SetTextCtrlEdit(pChannelTextCtrl, FALSE); 
				DrawTextCtrl(pChannelTextCtrl); 
				input=FALSE; 
				edit[0]=0; 
				EditNumber=2; 
			} 
			return TRUE; 
		case 16://Cancel 
			SetTextCtrlEdit(pChannelTextCtrl, FALSE); 
			input=FALSE; 
			edit[0]=0; 
			EditNumber=2; 
			return TRUE; 
		} 
		 
	} 
	else if(EditNumber==2) 
	{ 
		switch(nkey) 
		{	 
		case 14://OK 
			if(!input) 
			{ 
				SetWndCtrlFocus(NULL, ID_ValueTextCtrl); 
				pValueTextCtrl->text[0]=0;  //清空文本框 
				SetTextCtrlEdit(pValueTextCtrl, TRUE); 
				DrawTextCtrl(pValueTextCtrl); 
				input=TRUE; 
				edit[1]=1; 
			} 
			else 
			{ 
				SetTextCtrlEdit(pValueTextCtrl, FALSE); 
				DrawTextCtrl(pValueTextCtrl); 
				input=FALSE; 
				edit[1]=0; 
				EditNumber=1; 
				WarnningData[ Unicode2Int(pChannelTextCtrl->text)]=Unicode2Int(pValueTextCtrl->text); 
			} 
			return TRUE; 
		case 17://Cancel 
			SetTextCtrlEdit(pValueTextCtrl, FALSE); 
			DrawTextCtrl(pValueTextCtrl); 
			input=FALSE; 
			edit[1]=0; 
			EditNumber=1; 
			return TRUE; 
		} 
	} 
	return FALSE; 
} 
 
void Main_Task(void *Id)             //Main_Test_Task 
{ 
	POSMSG pMsg; 
	init_ADdevice(20,ADCCON_SLEEP); 
	for(;;) 
	{ 
		POS_Ctrl pCtrl; 
		pMsg=WaitMessage(0); 
		if(pMsg->pOSCtrl) 
		{ 
			if(pMsg->pOSCtrl->CtrlMsgCallBk) 
				(*pMsg->pOSCtrl->CtrlMsgCallBk)(pMsg); 
		} 
		else 
		{ 
			switch(pMsg->Message) 
			{ 
			case OSM_KEY: 
				pCtrl=GetCtrlfromID(NULL, GetWndCtrlFocus(NULL)); 
				if(pCtrl->CtrlType==CTRLTYPE_WINDOW) 
				{ 
					if((((PWnd)pCtrl)->style&WND_STYLE_MODE)==WND_STYLE_MODE) 
					{ 
						//焦点是有模式窗口,消息直接传递过去 
						OSOnSysMessage(pMsg); 
						break; 
					} 
				} 
				if(onKey(pMsg->WParam,pMsg->LParam) ) 
					break; 
			default: 
				OSOnSysMessage(pMsg); 
				break; 
			} 
		} 
		DeleteMessage(pMsg); 
		OSTimeDly(200); 
	} 
} 
 
void Display_Task(void * Id)            //Main_Test_Task 
{ 
	PDC pdc; 
	structRECT ChannelTextCtrl_Rect,ValueTextCtrl_Rect,Draw_Wnd_Rect; 
	char Channel_Caption_8[10]="Channel:"; 
	char Value_Caption_8[10]="Value:"; 
	char Draw_Wnd_Caption_8[]="Draw Window"; 
	char vol_8[]="Vol"; 
	char chn_8[]="Chn"; 
	char chn0_8[]="0"; 
	char chn1_8[]="1"; 
	char chn2_8[]="2"; 
	char chn3_8[]="3"; 
	char vol_10_8[]="10"; 
	char vol_20_8[]="20"; 
	char  vol_30_8[]="30"; 
	u16 Channel_Caption_16[10]; 
	u16 Value_Caption_16[10]; 
	U16 Draw_Wnd_Caption_16[20]; 
	u16 vol_16[5]; 
	u16 chn_16[5]; 
	u16 chn0_16[2]; 
	u16 chn1_16[2]; 
	u16 chn2_16[2]; 
	u16 chn3_16[2]; 
	u16 vol_10_16[3]; 
	u16 vol_20_16[3]; 
	u16 vol_30_16[3]; 
	Wnd Draw_Wnd; 
	PWnd pDraw_Wnd; 
	int warnning[4]={1,1,1,1}; 
	BOOLEAN IsEdit=0; 
	 
	 
	 
	pdc=CreateDC(); 
	pDraw_Wnd=&Draw_Wnd; 
	strChar2Unicode(Draw_Wnd_Caption_16, Draw_Wnd_Caption_8); 
	strChar2Unicode(Channel_Caption_16, Channel_Caption_8); 
	strChar2Unicode(Value_Caption_16, Value_Caption_8); 
	strChar2Unicode(chn_16, chn_8); 
	strChar2Unicode(vol_16, vol_8); 
	strChar2Unicode(chn0_16, chn0_8); 
	strChar2Unicode(chn1_16, chn1_8); 
	strChar2Unicode(chn2_16, chn2_8); 
	strChar2Unicode(chn3_16, chn3_8); 
	strChar2Unicode(vol_10_16,vol_10_8); 
	strChar2Unicode(vol_20_16,vol_20_8); 
	strChar2Unicode(vol_30_16,vol_30_8); 
	SetRect(&ChannelTextCtrl_Rect, 10,50,55,75); 
	SetRect(&ValueTextCtrl_Rect, 10,125,55,150); 
	SetRect(&Draw_Wnd_Rect, 74, 9, 301, 216); 
	pChannelTextCtrl=CreateTextCtrl(ID_ChannelTextCtrl, &ChannelTextCtrl_Rect, FONTSIZE_MIDDLE, CTRL_STYLE_FRAME, NULL,NULL); 
	pValueTextCtrl=CreateTextCtrl(ID_ValueTextCtrl, &ValueTextCtrl_Rect, FONTSIZE_MIDDLE, CTRL_STYLE_FRAME, NULL,NULL); 
	pDraw_Wnd=CreateWindow(Draw_Wnd_ID, &Draw_Wnd_Rect, FONTSIZE_SMALL,WND_STYLE_MODELESS, Draw_Wnd_Caption_16, NULL); 
	ClearScreen(); 
	TextOut(pdc, 55, 10, vol_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 290, 215, chn_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 116, 215, chn0_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 166, 215, chn1_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 216, 215, chn2_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 266, 215, chn3_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 60, (int)(205-1*200/3.3), vol_10_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 60, (int)(205-2*200/3.3), vol_20_16, TRUE, FONTSIZE_SMALL); 
	TextOut(pdc, 60, (int)(205-3*200/3.3), vol_30_16, TRUE, FONTSIZE_SMALL); 
	DrawTextCtrl(pChannelTextCtrl); 
	DrawTextCtrl(pValueTextCtrl); 
	 
	for(;;) 
	{ 
		TextOut(pdc, 10, 35, Channel_Caption_16, TRUE, FONTSIZE_SMALL); 
		TextOut(pdc, 10, 110, Value_Caption_16, TRUE, FONTSIZE_SMALL); 
		if(edit[0]==1) 
		{ 
			if(IsEdit==1) 
			{ 
				FillRect(pdc, 10, 35, 60, 45, GRAPH_MODE_NORMAL, COLOR_WHITE); 
				IsEdit=0; 
			} 
			else 
			{ 
				IsEdit=1; 
			} 
		} 
		if(edit[1]==1) 
		{ 
			if(IsEdit==1) 
			{ 
				FillRect(pdc, 10, 110, 60, 120, GRAPH_MODE_NORMAL, COLOR_WHITE); 
				IsEdit=0; 
			} 
			else 
			{ 
				IsEdit=1; 
			} 
		} 
		DrawWindow(pDraw_Wnd); 
		MoveTo(pdc, 75, 15); 
		LineTo(pdc, 80,10); 
		LineTo(pdc, 85, 15); 
		MoveTo(pdc,80 , 10); 
		LineTo(pdc, 80, 210); 
		LineTo(pdc, 300, 210); 
		MoveTo(pdc, 295, 205); 
		LineTo(pdc, 300, 210); 
		LineTo(pdc, 295, 215); 
		MoveTo(pdc, 80, (int)(210-1*200/3.3)); 
		LineTo(pdc, 300, (int)(210-1*200/3.3)); 
		MoveTo(pdc, 80, (int)(210-2*200/3.3)); 
		LineTo(pdc, 300, (int)(210-2*200/3.3)); 
		MoveTo(pdc, 80, (int)(210-3*200/3.3)); 
		LineTo(pdc, 300, (int)(210-3*200/3.3)); 
		if(result_AD0<=WarnningData[0]) 
		{ 
			FillRect(pdc, 110, (int)(210-result_AD0*20/3.3), 130, 210,GRAPH_MODE_NORMAL, COLOR_BLACK); 
		} 
		else 
		{ 
			if(warnning[0]==1) 
			{ 
				FillRect(pdc, 110, (int)(210-result_AD0*20/3.3), 130, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
				warnning[0]=0; 
			} 
			else 
			{ 
				warnning[0]=1; 
				FillRect(pdc, 110, (int)(210-WarnningData[0]*20/3.3), 130, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
			} 
		} 
		if(result_AD1<=WarnningData[1]) 
		{ 
			FillRect(pdc, 160, (int)(210-result_AD1*20/3.3), 180, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
		} 
		else 
		{ 
			if(warnning[1]==1) 
			{ 
				FillRect(pdc, 160, (int)(210-result_AD1*20/3.3), 180, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
				warnning[1]=0; 
			} 
			else 
			{ 
				warnning[1]=1; 
				FillRect(pdc, 160, (int)(210-WarnningData[1]*20/3.3), 180, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
			} 
		} 
		if(result_AD2<=WarnningData[2]) 
		{ 
			FillRect(pdc, 210, (int)(210-result_AD2*20/3.3), 230, 210,GRAPH_MODE_NORMAL, COLOR_BLACK); 
		} 
		else 
		{ 
			if(warnning[2]==1) 
			{ 
				FillRect(pdc, 210, (int)(210-result_AD2*20/3.3), 230, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
				warnning[2]=0; 
			} 
			else 
			{ 
				warnning[2]=1; 
				FillRect(pdc, 210, (int)(210-WarnningData[2]*20/3.3), 230, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
			} 
		} 
		if(result_AD3<=WarnningData[3]) 
		{ 
			FillRect(pdc, 260, (int)(210-result_AD3*20/3.3), 280, 210,GRAPH_MODE_NORMAL, COLOR_BLACK); 
		} 
		else 
		{ 
			if(warnning[3]==1) 
			{ 
				FillRect(pdc, 260, (int)(210-result_AD3*20/3.3), 280, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
				warnning[3]=0; 
			} 
			else 
			{ 
				warnning[3]=1; 
				FillRect(pdc, 260, (int)(210-WarnningData[3]*20/3.3), 280, 210, GRAPH_MODE_NORMAL,COLOR_BLACK); 
			} 
		} 
		OSTimeDly(500); 
	} 
} 
 
void AD0_Task(void * Id)            //Main_Test_Task 
{ 
	for(;;) 
	{ 
		result_AD0=GetADresult(0)*33/1024; 
		//Uart_Printf("result_AD0=%d\n",result_AD0); 
		OSTimeDly(100); 
	} 
} 
 
void AD1_Task(void * Id)            //Main_Test_Task 
{ 
	for(;;) 
	{ 
		result_AD1=GetADresult(1)*33/1024; 
		//Uart_Printf("result_AD1=%d\n",result_AD1); 
		OSTimeDly(100); 
	} 
} 
 
void AD2_Task(void * Id)            //Main_Test_Task 
{ 
	for(;;) 
	{ 
		result_AD2=GetADresult(2)*33/1024; 
		//Uart_Printf("result_AD2=%d\n",result_AD2); 
		OSTimeDly(100); 
	} 
} 
 
void AD3_Task(void * Id)            //Main_Test_Task 
{ 
	for(;;) 
	{ 
		result_AD3=GetADresult(3)*33/1024; 
		//Uart_Printf("result_AD3=%d\n",result_AD3); 
		OSTimeDly(100); 
	} 
}