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

📄 user_app.c

📁 实现ucos任务调度时保存LCD上的显示信息
💻 C
字号:
#include "includes.h"

OS_STK xdata mystack1[USER_STACK_SIZE],mystack2[USER_STACK_SIZE],mystack3[USER_STACK_SIZE];


void init_port(void);
void init_clk(void);
void lcdtask(void) ;
void mytask2(void) ;
void mytask3(void) ;
extern void init_timer0(void);


void main(void)
{
	PCA0MD = 0x00;				
	init_clk();
	//PORT2_Init();
	init_port();
	init_uart0();	
	//ADC0_Init();
	init_timer0();
	DF_init();
	LCD_init();
	OSInit();

	OSTaskCreate(lcdtask,0,&mystack1[0],7);
	OSTaskCreate(mytask2,0,&mystack2[0],8);
	OSTaskCreate(mytask3,0,&mystack3[0],9);

	uart_put_str("Hello UCOS-II!\n");

	OSStart();
}

void init_port(void)
{
	unsigned char i = 255;

	P0MDIN = 0xFF;				/* non-analog input									*/
	P0MDOUT = 0x10;				/* TX0 push-pull output, RX0 open drain output 		*/
	P1MDIN = 0xFF;
	P1MDOUT = 0x02;
	P1 = 0x02;					/* enable max3223									*/
	
	XBR0 = 0x01;				/* enable uart0									 	*/
	XBR1 = 0x40;				/* enable cross, enable draw-up resistor			*/

	while(i--);					/* some delay for system stablity					*/
}

void init_clk(void)
{
	unsigned char i;
	
	OSCICN = 0x83;				/* enable internal high frequency oscillator 		*/
	while(!(OSCICN & 0x40));    /* wait internal high frequency oscillator ready 	*/
	
	OSCLCN = 0x00;				/* shutdown internal low frequency oscillator 		*/
	OSCXCN = 0x00;				/* shutdown external oscillator						*/
	
	CLKMUL = 0x80;				/* enable multiplier use internal oscillator 		*/ 
	for(i = 255; i > 0;i --);	/* delay 5us minimum								*/
	CLKMUL |= 0xC0;				/* initial multiplier								*/
	while(!(CLKMUL & 0x20));	/* wait multiplier ready							*/
	
	CLKSEL = 0x03;				/* usb and sysclk both use multiplier output, 48MHz	*/
}


void lcdtask(void) 
{
	TR0 =1;
	EA	=1;

	while(1)
	{
	 	uart_put_str("task111 is running ... \n");
		OSTimeDly(50);
	}
}
void mytask2(void) 
{
	while(1)
	{
		uart_put_str("task222 is running ... \n");
		OSTimeDly(130);
	}
}

void mytask3(void) 
{
	while(1)
	{
		uart_put_str("task333 is running ... \n");
		OSTimeDly(100);
	}
}


⌨️ 快捷键说明

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