?? 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\drv\ad.h"
#include "motorctrl.h"
#pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
#define MOTOR_SEVER_FRE 1000 //20kHz
#define MOTOR_CONT (MCLK/2/2/MOTOR_SEVER_FRE)
#define MOTOR_MID (MOTOR_CONT/2)
#define ADCCON_FLAG 0x40
#define ADCCON_SLEEP 0x20
#define ADCCON_ADIN0 (0x0<<2)
#define ADCCON_ADIN1 (0x1<<2)
#define ADCCON_ADIN2 (0x2<<2)
#define ADCCON_ADIN3 (0x3<<2)
#define ADCCON_ADIN4 (0x4<<2)
#define ADCCON_ADIN5 (0x5<<2)
#define ADCCON_ADIN6 (0x6<<2)
#define ADCCON_ADIN7 (0x7<<2)
#define ADCCON_READ_START 0x2
#define ADCCON_ENABLE_START 0x1
#define ID_ChannelTextCtrl 101
#define ID_ValueTextCtrl 102
#define Draw_Wnd_ID 104
#define Line_Button_ID 105
#define Circle_Button_ID 106
#define Curve_Button_ID 107
PTextCtrl pChannelTextCtrl,pValueTextCtrl;
float result_AD0,result_AD1,result_AD2,result_AD3;
int WarnningData[1]={5000};
int edit;
int j=0;
int ADData;
int ADData1;
int a=0;
int b=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 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);
//////////////////////////////////////////////////////////
int GetADresult(int channel)
{
rADCCON=(channel<<2)|ADCCON_ENABLE_START;
Delay(10);
while(!(rADCCON&ADCCON_FLAG));//轉換結束
return rADCDAT;//返回采樣值
}
void initOSGUI() //初始化操作系統的圖形界面
{
initOSMessage();
initOSList();
initOSDC();
initOSCtrl();
initOSFile();
}
/////////////////////////////////////////////////////
// Main function. //
////////////////////////////////////////////////////
int main(void)
{
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(AD3_Task,(void *)0, (OS_STK *)&AD3_Task_Stack[STACKSIZE-1], AD3_Task_Prio);
OSTaskCreate(Display_Task,(void *)0, (OS_STK *)&Display_Task_Stack[STACKSIZE-1], Display_Task_Prio);// 20
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_ValueTextCtrl);
pValueTextCtrl->text[0]=0; //清空文本框
SetTextCtrlEdit(pValueTextCtrl, TRUE);
DrawTextCtrl(pValueTextCtrl);
input=TRUE;
edit=1;
}
else
{
SetTextCtrlEdit(pValueTextCtrl, FALSE);
DrawTextCtrl(pValueTextCtrl);
input=FALSE;
edit=0;
EditNumber=1;
WarnningData[ Unicode2Int(pChannelTextCtrl->text)]=Unicode2Int(pValueTextCtrl->text);
ADData=WarnningData[ Unicode2Int(pChannelTextCtrl->text)];
}
return TRUE;
case 17://Cancel
SetTextCtrlEdit(pValueTextCtrl, FALSE);
DrawTextCtrl(pValueTextCtrl);
input=FALSE;
edit=0;
EditNumber=1;
return TRUE;
}
}
return FALSE;
}
void Main_Task(void *Id) //Main_Test_Task
{
init_ADdevice(20,ADCCON_SLEEP);
for(;;)
{
POSMSG pMsg;
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
{
POSMSG pMsg1;
int warnning[1]={1};
BOOLEAN IsEdit=0;
PDC pdc;
structPOINT Touch_Position,*pTouch_Position;
ButtonCtrl Line_Button,Circle_Button,Curve_Button;
PButtonCtrl pLine_Button,pCircle_Button,pCurve_Button;
structRECT Line_Button_RECT,Circle_Button_RECT,Curve_Button_RECT;
structRECT *pLine_Button_RECT,*pCircle_Button_RECT,*pCurve_Button_RECT;
structRECT ChannelTextCtrl_Rect,ValueTextCtrl_Rect;
char Line_Button_Caption_8[]="up";
char Circle_Button_Caption_8[]="down";
char Curve_Button_Caption_8[]="stop";
char Value_Caption_8[10]="speed:";
U16 Line_Button_Caption_16[20];
U16 Circle_Button_Caption_16[20];
U16 Curve_Button_Caption_16[20];
u16 Value_Caption_16[10];
pTouch_Position=&Touch_Position;
pLine_Button=&Line_Button;
pCircle_Button=&Circle_Button;
pCurve_Button=&Curve_Button;
pLine_Button_RECT=&Line_Button_RECT;
pCircle_Button_RECT=&Circle_Button_RECT;
pCurve_Button_RECT=&Curve_Button_RECT;
strChar2Unicode(Line_Button_Caption_16, Line_Button_Caption_8);
strChar2Unicode(Circle_Button_Caption_16, Circle_Button_Caption_8);
strChar2Unicode(Curve_Button_Caption_16, Curve_Button_Caption_8);
Line_Button_RECT.bottom=70;
Line_Button_RECT.left=110;
Line_Button_RECT.right=160;
Line_Button_RECT.top=30;
Circle_Button_RECT.bottom=120;
Circle_Button_RECT.left=110;
Circle_Button_RECT.right=160;
Circle_Button_RECT.top=80;
Curve_Button_RECT.bottom=170;
Curve_Button_RECT.left=110;
Curve_Button_RECT.right=160;
Curve_Button_RECT.top=130;
pLine_Button=CreateButton(Line_Button_ID, pLine_Button_RECT, FONTSIZE_SMALL, CTRL_STYLE_3DDOWNFRAME, Line_Button_Caption_16, NULL);
pCircle_Button=CreateButton(Circle_Button_ID, pCircle_Button_RECT, FONTSIZE_SMALL, CTRL_STYLE_3DDOWNFRAME, Circle_Button_Caption_16, NULL);
pCurve_Button=CreateButton(Curve_Button_ID, pCurve_Button_RECT, FONTSIZE_SMALL, CTRL_STYLE_3DDOWNFRAME, Curve_Button_Caption_16, NULL);
pdc=CreateDC();
strChar2Unicode(Value_Caption_16, Value_Caption_8);
SetRect(&ValueTextCtrl_Rect, 10,125,55,150);
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);
ClearScreen();
DrawTextCtrl(pChannelTextCtrl);
DrawTextCtrl(pValueTextCtrl);
DrawButton(pLine_Button);
DrawButton(pCircle_Button);
DrawButton(pCurve_Button);
for(;;)
{
TextOut(pdc, 10, 110, Value_Caption_16, TRUE, FONTSIZE_SMALL);
Uart_Printf("ADData=%d\n",ADData);
pMsg1=WaitMessage(0);
switch(pMsg1->Message)
{
case OSM_TOUCH_SCREEN:
Touch_Position.x=pMsg1->WParam&0xffff;
Touch_Position.y=pMsg1->WParam>>16;
if(IsInRect2(pLine_Button_RECT, pTouch_Position))
{
a++;
Uart_Printf("a=%d\n",a);
}
else if(IsInRect2(pCircle_Button_RECT, pTouch_Position))
{
b++;
Uart_Printf("b=%d\n",b);
}
else if(IsInRect2(pCurve_Button_RECT, pTouch_Position))
{
j++;
Uart_Printf("j=%d\n",j);
}
DeleteMessage(pMsg1);
OSTimeDly(500);
}
}
}
void AD3_Task(void *Id)
{
POSMSG pMsg2;
for(;;)
{
pMsg2=WaitMessage(0);
init_MotorPort();
ADData1=GetADresult(1);
Delay(10);
SetPWM((ADData-512)*MOTOR_CONT/1024);
Delay(10);
Uart_Printf("ADData1=%d\n",ADData1);
DeleteMessage(pMsg2);
OSTimeDly(100);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -