新手入门
- 积分
- 13
- 金钱
- 13
- 注册时间
- 2020-5-21
- 在线时间
- 1 小时
|
楼主 |
发表于 2020-5-26 17:44:23
|
显示全部楼层
main.c 代码如下:- #include "sys.h"
- #include "led.h"
- #include <rtthread.h>
- static struct rt_thread led0_thread;//线程控制块
- static struct rt_thread led1_thread;//线程控制块
- ALIGN(RT_ALIGN_SIZE)
- static rt_uint8_t rt_led0_thread_stack[1024];//线程栈
- static rt_uint8_t rt_led1_thread_stack[1024];//线程栈
- //线程 LED0
- static void led0_thread_entry(void* parameter)
- {
- while(1)
- {
- LED0=0;
- rt_thread_delay(RT_TICK_PER_SECOND/5); //延时
-
- LED0=1;
- rt_thread_delay(RT_TICK_PER_SECOND/5); //延时
- }
- }
- //线程 LED1
- static void led1_thread_entry(void* parameter)
- {
- while(1)
- {
- LED1=0;
- rt_thread_delay(RT_TICK_PER_SECOND/2); //延时
-
- LED1=1;
- rt_thread_delay(RT_TICK_PER_SECOND/2); //延时
- }
- }
- int main(void)
- {
- LED_Init(); //初始化 LED
-
- // 创建静态线程
- rt_thread_init(&led0_thread,
- "led0",
- led0_thread_entry,
- RT_NULL,
- &rt_led0_thread_stack[0],
- sizeof(rt_led0_thread_stack),
- 3,
- 20);
- rt_thread_startup(&led0_thread);
-
- rt_thread_init(&led1_thread,
- "led1",
- led1_thread_entry,
- RT_NULL,
- &rt_led1_thread_stack[0],
- sizeof(rt_led1_thread_stack),
- 3,
- 20);
- rt_thread_startup(&led1_thread);
- }
复制代码 |
|