代码如下:
#define LED_PIN GET_PIN(A, 7) ALIGN(RT_ALIGN_SIZE) static rt_uint8_t led_stack[512]; static struct rt_thread led_thread; void rt_hw_led_init(void) { rt_pin_mode(LED_PIN,PIN_MODE_OUTPUT); } static void led1_thread_entry(void *parameter) { unsigned int count = 0; rt_hw_led_init(); while(1){ rt_kprintf("led on, count : %d\r\n", count); count++; rt_pin_write(LED_PIN, 0); rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */ /* led1 off */ rt_kprintf("led off\r\n"); rt_pin_write(LED_PIN, 1); rt_thread_delay(RT_TICK_PER_SECOND / 2); } } int led1_sample_init(void) { rt_err_t result; result = rt_thread_init(&led_thread, "led",led1_thread_entry, RT_NULL, (rt_uint8_t *)&led_stack[0], sizeof(led_stack), 20, 5); if(result == RT_EOK) { rt_thread_startup(&led_thread); } return 0; } MSH_CMD_EXPORT(led1_sample_init, led sample);
打开串口终端
运行程序如下: