生于忧患,死于安乐。时间过的真快,去年在实习的时候,我觉得我还是挺认真的,那时候岗位不对口,一心想着做嵌入式,自学了不少。现在如愿做了嵌入式,却很少做总结了。也没有当初做嵌入式的那种热血了。还是不能堕落呀。接下来进入正题。
先写一个demo,创建两个线程,一个线程获取并发送按键响应,另一个线程实现led灯的切换。主要代码如下:
#include <rtthread.h>
#include <board.h>
#include <rtdevice.h>
#define LED1 GET_PIN(C, 0)
#define LED3 GET_PIN(E,0)
#define KEY3 GET_PIN(B,14)
static rt_thread_t led1_thread =RT_NULL;
static rt_thread_t led3_thread =RT_NULL;
static rt_uint8_t count;
static rt_uint8_t count1;
static void led1_thread_entry(void *parmeter)
{
for(count =0;;count ++) {
rt_pin_write(LED1, PIN_HIGH);
rt_kprintf("led_on,count: %d\r\n",count);
rt_thread_mdelay(500);
rt_pin_write(LED1, PIN_LOW);
rt_kprintf("led off\r\n");
rt_thread_mdelay(500);
}
}
static void led3_thread_entry(void *parmeter)
{
while (1){
if( rt_pin_read(KEY3)==0){
// LED3=~LED3;