main.c
资源名称:QFI4ddQe.rar [点击查看]
上传用户:tzjinxin1
上传日期:2022-08-08
资源大小:272k
文件大小:2k
源码类别:
嵌入式/单片机编程
开发平台:
Visual C++
- /*
- www.mcu123.net/bbs
- 学习论坛
- 本例程ucOS-II 版本为2.51
- 注:
- 此例程运行于内RAM > 1024 Byte的51内核的单片机即可。
- 比 如 : SST89E564RD ,STC89C516RD 等
- S */
- #include "includes.h"
- #include "serial.h"
- sbit LED1=P1^5;
- sbit LED2=P1^6;
- unsigned char xdata strbuf[8];
- OS_STK TaskStartStk1[MaxStkSize],TaskStartStk2[MaxStkSize],TaskStartStk3[MaxStkSize];
- void Task1(void *nouse) reentrant;
- void Task2(void *nouse) reentrant;
- void Task3(void *nouse) reentrant;
- void DecTochar(unsigned int n,unsigned char *buf)
- { unsigned char i;
- unsigned char buffer[8];
- for(i=0;i<5;i++)
- {
- buffer[i]=n%10+0x30;
- n=n/10;
- if(n==0)break;
- }
- for(;i>0;i--)*buf++=buffer[i];
- *buf++=buffer[i];
- *buf='r';
- buf++;
- *buf='n';
- }
- void main(void)
- {
- OSInit();
- InitHardware();
- OSTaskCreate(Task1, (void *)0, &TaskStartStk1[0],2);
- OSTaskCreate(Task2, (void *)0, &TaskStartStk2[0],3);
- OSTaskCreate(Task3, (void *)0, &TaskStartStk3[0],4);
- OSStart();
- }
- void Task1(void *nouse) reentrant
- {
- unsigned char const Str0[]="Welcome to MCU123.COM rn";
- unsigned char const Str1[]="Task1 is running! LED1=ON rn";
- unsigned char const Strv[]="uCosII_Ver";
- nouse=nouse;
- SendStr(Str0, sizeof(Str0));
- DecTochar(OSVersion(),strbuf);
- SendStr(Strv,sizeof(Strv));
- SendStr(strbuf, sizeof(strbuf));
- for(;;)
- {
- LED1 = 0;
- SendStr(Str1, sizeof(Str1));
- OSTimeDly(OS_TICKS_PER_SEC*2);
- }
- }
- void Task2(void *nouse) reentrant
- { unsigned char const Str2[]="Task2 is running! LED2=ON rn";
- nouse=nouse;
- for(;;)
- {
- LED2 = 0;
- SendStr(Str2, sizeof(Str2));
- OSTimeDly(OS_TICKS_PER_SEC*2);
- }
- }
- void Task3(void *nouse) reentrant
- { unsigned char const Str3[]="Task3 is running! LED1=OFF LED2=OFF rn";
- nouse=nouse;
- for(;;)
- {
- LED1 = 1;
- LED2 = 1;
- SendStr(Str3, sizeof(Str3));
- OSTimeDly(OS_TICKS_PER_SEC);
- }
- }