中级会员
- 积分
- 370
- 金钱
- 370
- 注册时间
- 2017-8-3
- 在线时间
- 38 小时
|
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "malloc.h"
#include "tpad.h"
#include "beep.h"
#include "touch.h"
#include "includes.h"
#define START_TASK_PRIO 10
#define START_STK_SIZE 128
OS_STK START_TASK_STK[START_STK_SIZE];
void start_task(void *pdata);
#define MAIN_TASK_PRIO 9
#define MAIN_STK_SIZE 128
OS_STK MAIN_TASK_STK[MAIN_STK_SIZE];
void main_task(void *pdata);
#define LED_TASK_PRIO 8
#define LED_STK_SIZE 128
OS_STK LED_TASK_STK[LED_STK_SIZE];
void led_task(void *pdata);
#define KEY_TASK_PRIO 7
#define KEY_STK_SIZE 128
OS_STK KEY_TASK_STK[KEY_STK_SIZE];
void key_task(void* pdata);
void ucos_load_main_ui(void )
{
LCD_Clear (WHITE );
POINT_COLOR = RED;
LCD_ShowString(10,10,200,16,16,"author: xiexuewei");
LCD_ShowString (10,30,200,16,16,"ucosii test");
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
LCD_ShowString(150,10,200,16,16,"CPU: %");
LCD_ShowString(150,30,200,16,16,"MEM: %");
delay_ms (300);
}
OS_TMR* tmr1;
OS_TMR* tmr2;
OS_TMR* tmr3;
int main()
{
NVIC_PriorityGroupConfig (NVIC_PriorityGroup_2);
delay_init (168);
uart_init (115200);
LCD_Init ();
LED_Init ();
BEEP_Init ();
KEY_Init ();
TPAD_Init (8);
my_mem_init(SRAMIN);
ucos_load_main_ui ();
OSInit ();
OSTaskCreate (start_task , (void*)0, (OS_STK *)&START_TASK_STK[START_STK_SIZE-1], START_TASK_PRIO);
OSStart ();
}
void start_task(void* pdata)
{
OS_CPU_SR cpu_sr=0;
u8 err;
pdata = pdata;
OSStatInit ();
OS_ENTER_CRITICAL();
OSTaskCreate (led_task , (void*)0, (OS_STK *)&LED_TASK_STK [LED_STK_SIZE-1], LED_TASK_PRIO );
OSTaskCreate (main_task , (void*)0, (OS_STK *)&MAIN_TASK_STK [MAIN_STK_SIZE-1], MAIN_TASK_PRIO);
OSTaskCreate (key_task , (void*)0 , (OS_STK*)&KEY_TASK_STK[KEY_STK_SIZE-1],KEY_TASK_PRIO);
OSTaskSuspend (START_TASK_PRIO );
OS_EXIT_CRITICAL ();
}
void led_task(void* pdata)
{
u8 t;
while(1)
{
t++;
delay_ms(10);
if(t==8)
LED0=1;
if(t==100)
{
t=0;
LED0=0;
}
}
}
void tmr1_callback(OS_TMR *ptmr, void* p_arg)
{
static u16 cpuusage=0;
static u8 tcnt=0;
POINT_COLOR=BLUE ;
if(tcnt == 5)
{
LCD_ShowxNum(182,10,cpuusage/5,3,16,0);
cpuusage=0;
tcnt = 0;
}
cpuusage +=OSCPUUsage;
tcnt++;
LCD_ShowxNum (182,30,my_mem_perused(SRAMIN),3,16,0);
}
void tmr2_callback(OS_TMR* ptmr,void* p_arg)
{
static u8 sta=0;
switch(sta)
{
case 0:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,RED);
break;
case 1:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,GREEN);
break;
case 2:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,BLUE);
break;
case 3:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,MAGENTA);
break;
case 4:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,GBLUE);
break;
case 5:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,YELLOW);
break;
case 6:
LCD_Fill (131,211,lcddev.width-1,lcddev.height -1,BRRED);
break;
}
sta++;
if(sta>6)
sta=0;
}
void tmr3_callback(OS_TMR* ptmr,void* p_arg)
{
}
void main_task(void* pdata)
{
u32 key=0;
u8 err;
u8 tmr2sta=1;
u8 tmr3sta=0;
u8 flagsclrt=0;
tmr1 = OSTmrCreate(10,10,OS_TMR_OPT_PERIODIC,(OS_TMR_CALLBACK)tmr1_callback,0,"tmr1",&err);
tmr2 = OSTmrCreate (10,10,OS_TMR_OPT_PERIODIC ,(OS_TMR_CALLBACK)tmr2_callback,0,"tmr2",&err);
tmr3 = OSTmrCreate(10,10,OS_TMR_OPT_PERIODIC ,(OS_TMR_CALLBACK)tmr3_callback,0,"tmr3",&err);
OSTmrStart (tmr1,&err);
OSTmrStart (tmr2,&err);
while(1)
{
delay_ms(10);
}
}
void key_task(void* pdata)
{
while(1)
{
delay_ms(100);
}
}
|
|