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

📄 main.c

📁 在proteus仿真arm处理器
💻 C
📖 第 1 页 / 共 5 页
字号:
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  TaskKeyBoard(void *pdata)
{   
	uint8 keycode;
	pdata=pdata;
	//TargetInit();
	Keyboard_Initialize();
	for(;;)
	{	
		keycode = Keyboard_Scan();
		KeyDecode(keycode);	
		if(Flag_AppRunning == 1)				//若有标志表示功能函数运行,则
			(*mainmenu[MenuSelect].Function)();	//运行功能函数
		OSTimeDly(OS_TICKS_PER_SEC/40);			//任务切换,交出cpu使用权
    }	
}
/*********************************************************************************************************
** 函数名称: TaskLed3
** 功能描述: LED闪烁任务,显示操作系统的运行状况
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  TaskLED3(void *pdata)
{  
	uint32 j;
	pdata=pdata;
	//TargetInit();
	LedInit();
	for(;;)
	{
	  for(j=0;j<=2;j++)
	  {
	    LED3_ON();
	    OSTimeDlyHMSM(0,0,0,50);
	    LED3_OFF();
	    OSTimeDlyHMSM(0,0,0,50);
	  }
	}                                  
}  
/*********************************************************************************************************
** 函数名称: TaskPowerDown
** 功能描述: 空闲任务,处理器时钟停止,但是外设保持工作状态,任何中断都会唤醒处理器
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void  TaskPowerDown(void *pdata)
{   
	pdata=pdata;
	//TargetInit();
	//PCONP = 0x0202;                       //除定时器,RTC之外其他外设都关闭,可以需要的时候再打开
	for(;;)
	{
	 	PCON = 0x01;						//关闭处理器时钟,外设仍然工作 ARM IDLE mode
	 	OSTimeDly(OS_TICKS_PER_SEC/50);		//任务切换,交出cpu使用权
	 	//OSTimeDly(OS_TICKS_PER_SEC/10);		//任务切换,交出cpu使用权
        //因为TaskPowerDown优先级高,所以切换延时越短,CPU使用率越高.
        //实际使用过程中,保持平衡,因为此任务是让ARM进入IDLE mode,降低功耗.
	}                                 
}
/*
*********************************************************************************************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This allows you to perform other
*              operations during a context switch.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the 
*                 task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
/*OSTaskSwHook*/
void OSTaskSwHook (void)
{
	INT16U           time;
    TASK_USER_DATA  *puser;
    time  = PC_ElapsedStop();                       /* 本任务完成                                         */
    PC_ElapsedStart();                              /* 开始下一个任务                                     */
    puser = OSTCBCur->OSTCBExtPtr;                  /* 指向刚刚使用过的任务                               */
    if (puser != (TASK_USER_DATA *)0) {
        //puser->TaskCtr++;                           /* 增加任务计数器                                     */
        /*puser->TaskCtr++和OSTCBCur->OSTCBCtxSwCtr的方法,TaskStart任务计数相差2次                       */
        /*原因在于__OSStartHighRdy中调用OSTaskSwHook,多出来的两次在于OSSTATINIT中切换的2次。             */
        /*而OSTCBCtxSwCtr只在OS_Sched()和OSIntExit()中增加                                                */
        puser->TaskCtr = OSTCBCur->OSTCBCtxSwCtr;   /* 增加任务计数器,uC/OS-II 2.62新特性                 */
        puser->TaskExecTime     = time;             /* 更新任务执行时间                                   */
        puser->TaskTotExecTime += time;             /* 更新任务总执行时间                                 */
    }  
}

/*********************************************************************************************************
*                                           STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task.  This allows your 
*              application to add functionality to the statistics task.
*
* Arguments  : none
*********************************************************************************************************
*/
/*OSTaskStatHook*/
void OSTaskStatHook (void)
{
	char	str[40];
	uint8	i;
    INT32U  total_exec_time;
    uint8   pct;
    total_exec_time = 0L;                                   /* Totalize TOT. EXEC. TIME for each task */
    for (i = 0; i < 5; i++) {
        total_exec_time += TaskUserData[i].TaskTotExecTime;
        if(F_flag==0x40){									/* 当功能7执行时才显示                    */
 	         sprintf(str, "%0d    ",TaskUserData[i].TaskExecTime);		//任务执行时间	
	         GUI_PutString(70,30+i*10,str);
	         sprintf(str, "%d",TaskUserData[i].TaskCtr);				//任务总切换次数	
	         GUI_PutString(110,30+i*10,str);
	         sprintf(str, "%d",TaskUserData[i].TaskTotExecTime);		//任务总执行时间	
	         GUI_PutString(155,30+i*10,str);       
        }
    }
    if (total_exec_time > 0) {
        for (i = 0; i < 5; i++) {                        	/* Derive percentage of each task         */
            pct = 100 * TaskUserData[i].TaskTotExecTime / total_exec_time;
            if(F_flag==0x40)								/* 当功能7执行时才显示                    */
            {
				sprintf(str, "%3d%%",pct);		
				GUI_PutString(205,30+i*10,str);
            }
        }
    }
    if (total_exec_time > 10000000L) {                      /* Reset total time counters at 10000000L */
        for (i = 0; i < 5; i++) {
            TaskUserData[i].TaskTotExecTime = 0L;
            TaskUserData[i].TaskCtr = 0L;
        }
    }
}
/**********************************************************************************************************
***********************************************************************************************************                           
*********************************************************************************************************** 
***********************************************************************************************************/
/*********************************************************************************************************
** 函数名称: LedInit
** 功能描述: Led口的输入输出定义
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无 
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void LedInit(void)
{
#if LED1 < 16
	PINSEL0 &= ~(3 << (2 * LED1));
#else
	PINSEL1 &= ~(3 << (2 * (LED1 - 16)));
#endif

#if LED2 < 16
	PINSEL0 &= ~(3 << (2 * LED2));
#else
	PINSEL1 &= ~(3 << (2 * (LED2 - 16)));
#endif

#if LED3 < 16
	PINSEL0 &= ~(3 << (2 * LED3));
#else
	PINSEL1 &= ~(3 << (2 * (LED3 - 16)));
#endif
	IO0DIR |= (1<<LED1)|(1<<LED2)|(1<<LED3);	//GPIO As Output
	LED1_ON();
	LED2_OFF();
	LED3_ON();
}
/*********************************************************************************************************
** 函数名称: KeyInit
** 功能描述: 键盘输入输出定义
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void KeyInit(void)
{
	uint32	pinselbak;
	pinselbak = PINSEL2;				//根据文档,PINSEL2操作使用读-修改-写的方式。
	pinselbak |= 0x00000000;			//PINSEL2.3 = 0时,P1.16~P1.25用于GPIO
	PINSEL2 = pinselbak;
	IO1DIR |= (KEY1|KEY2|KEY3|KEY4);	//KEY1-4输出
	IO1DIR &= ~(KEYA|KEYB|KEYC|KEYD);	//KEYA-D输入
	IO1SET = KEY1|KEY2|KEY3|KEY4;		//初始化,KEY1-4输出高电平
} 
/*********************************************************************************************************
** 函数名称: Display_Init
** 功能描述: 初始化界面显示
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/	
void	Display_Init(void)
{
	uint8	i,x,y;
	char str[40];
	extern uint8 *title0[];	// 汉字资源(参见resource.c)extern uint8 *help_all[][4];//Help文字资源
	x = 0;
	y = 0;
	for(i=0;i<5;i++)
	{	//显示"嵌入式系统"
		GUI_PutHZ(x+18*i, y, (uint8 *)title0[i],16, 16);
	}
	sprintf(str, "#Tasks:");				//任务总个数,包括IDLE和STAT任务	
	GUI_PutString(96,0,str);				
	sprintf(str, "#CPU Usage:");			//CPU使用率	
	GUI_PutString(159,0,str);				
	sprintf(str, "#Task switch/sec:");		//任务每秒切换次数		
	GUI_PutString(96,9,str);	
	GUI_Rectangle(0,17,239,127,1);			//画边界框 
	sprintf(str, "uC/OS-II V%1d.%02d", OSVersion() / 100, OSVersion() % 100); //显示uC/OS-II版本号
	GUI_PutString(5,119,str);  
}
/*********************************************************************************************************
** 函数名称: RTC_SetTime
** 功能描述: 初始化系统时间
** 输 入: 无 
** 输 出: 无       
** 全局变量: 调用全局变量today和now
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void	RTC_SetTime(void)
{  
	today.da_year = 2007;
	today.da_mon = 12;
	today.da_day = 29;
	today.da_dow = 1;
	now.ti_hour = 12;
	now.ti_min = 11;
	now.ti_sec = 00;
	setdate(&today);
	settime(&now); 
}

⌨️ 快捷键说明

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