精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

【RA2L1開發(fā)實(shí)踐】- 溫濕度檢測平臺(tái)

冬至子 ? 來源:xiaodaidaii ? 作者:xiaodaidaii ? 2023-10-10 15:06 ? 次閱讀

主要驅(qū)動(dòng)代碼

dht11.c

/*

  • Copyright (c) 2006-2021, RT-Thread Development Team
  • SPDX-License-Identifier: Apache-2.0
  • Change Logs:
  • Date Author Notes
  • 2023-03-15 XiaoDai the first version
    /
    #ifndef SRC_DHT11_C_
    #define SRC_DHT11_C_
    #include "dht11.h"
    #include
    #include "hal_data.h"
    #include
    #define DBG_TAG "sensor.asair.dhtxx"
    #ifdef PKG_USING_DHTXX_DEBUG
    #define DBG_LVL DBG_LOG
    #else
    #define DBG_LVL DBG_ERROR
    #endif
    #include
    /
    timing /
    #define DHT1x_BEGIN_TIME 20 /
    ms /
    #define DHT2x_BEGIN_TIME 1 /
    ms /
    #define DHTxx_PULL_TIME 30 /
    us /
    #define DHTxx_REPLY_TIME 100 /
    us /
    #define MEASURE_TIME 40 /
    us /
    RT_WEAK void rt_hw_us_delay(rt_uint32_t us)
    {
    rt_uint32_t delta;
    us = us * (SysTick->LOAD / (1000000 / RT_TICK_PER_SECOND));
    delta = SysTick->VAL;
    while (delta - SysTick->VAL < us) continue;
    }
    /
    *
  • This function will split a number into two part according to times.
  • @param num the number will be split
  • @param integer the integer part
  • @param decimal the decimal part
  • @param times how many times of the real number (you should use 10 in this case)
  • @return 0 if num is positive, 1 if num is negative
    */
    int split_int(const int num, int *integer, int *decimal, const rt_uint32_t times)
    {
    int flag = 0;
    if (num < 0) flag = 1;
    int anum = num<0 ? -num : num;
    integer = anum / times;
    decimal = anum % times;
    return flag;
    }
    /
  • This function will convert temperature in degree Celsius to Kelvin.
  • @param c the temperature indicated by degree Celsius
  • @return the result
    /
    float convert_c2k(float c)
    {
    return c + 273.15;
    }
    /
    *
  • This function will convert temperature in degree Celsius to Fahrenheit.
  • @param c the temperature indicated by degree Celsius
  • @return the result
    /
    float convert_c2f(float c)
    {
    return c * 1.8 + 32;
    }
    /
    *
  • This function will convert temperature in degree Fahrenheit to Celsius.
  • @param f the temperature indicated by degree Fahrenheit
  • @return the result
    /
    float convert_f2c(float f)
    {
    return (f - 32) * 0.55555;
    }
    /
    *
  • This function will read a bit from sensor.
  • @param pin the pin of Dout
  • @return the bit value
    /
    static uint8_t dht_read_bit(const rt_base_t pin)
    {
    uint8_t retry = 0;
    while(rt_pin_read(pin) && retry < DHTxx_REPLY_TIME)
    {
    retry++;
    rt_hw_us_delay(1);
    }
    retry = 0;
    while(!rt_pin_read(pin) && retry < DHTxx_REPLY_TIME)
    {
    retry++;
    rt_hw_us_delay(1);
    }
    rt_hw_us_delay(MEASURE_TIME);
    return rt_pin_read(pin);
    }
    /
    *
  • This function will read a byte from sensor.
  • @param pin the pin of Dout
  • @return the byte
    */
    static uint8_t dht_read_byte(const rt_base_t pin)
    {
    uint8_t i, byte = 0;
    for(i=0; i<8; i++)
    {
    byte <<= 1;
    byte |= dht_read_bit(pin);
    }
    return byte;
    }
    /**
  • This function will read and update data array.
  • @param dev the device to be operated
  • @return RT_TRUE if read successfully, otherwise return RT_FALSE.
    /
    rt_bool_t dht_read(dht_device_t dev)
    {
    RT_ASSERT(dev);
    uint8_t i, retry = 0, sum = 0;
    #ifdef PKG_USING_DHTXX_INTERRUPT_DISABLE
    rt_base_t level;
    #endif
    /
    Reset data buffer /
    rt_memset(dev->data, 0, DHT_DATA_SIZE);
    /
    MCU request sampling /
    rt_pin_mode(dev->pin, PIN_MODE_OUTPUT);
    rt_pin_write(dev->pin, PIN_LOW);
    if (dev->type == DHT11) {
    rt_thread_mdelay(DHT1x_BEGIN_TIME); /
    Tbe /
    } else {
    rt_thread_mdelay(DHT2x_BEGIN_TIME);
    }
    #ifdef PKG_USING_DHTXX_INTERRUPT_DISABLE
    level = rt_hw_interrupt_disable();
    #endif
    rt_pin_mode(dev->pin, PIN_MODE_INPUT_PULLUP);
    rt_hw_us_delay(DHTxx_PULL_TIME); /
    Tgo /
    /
    Waiting for sensor reply /
    while (rt_pin_read(dev->pin) && retry < DHTxx_REPLY_TIME)
    {
    retry++;
    rt_hw_us_delay(1); /
    Trel /
    }
    if(retry >= DHTxx_REPLY_TIME) return RT_FALSE;
    retry = 0;
    while (!rt_pin_read(dev->pin) && retry < DHTxx_REPLY_TIME)
    {
    retry++;
    rt_hw_us_delay(1); /
    Treh /
    };
    if(retry >= DHTxx_REPLY_TIME) return RT_FALSE;
    /
    Read data /
    for(i=0; i {
    dev->data[i] = dht_read_byte(dev->pin);
    }
    #ifdef PKG_USING_DHTXX_INTERRUPT_DISABLE
    rt_hw_interrupt_enable(level);
    #endif
    /
    Checksum */
    for(i=0; i {
    sum += dev->data[i];
    }
    if(sum != dev->data[4]) return RT_FALSE;
    return RT_TRUE;
    }
    /**
  • This function will get the humidity from dhtxx sensor.
  • @param dev the device to be operated
  • @return the humidity value
    /
    rt_int32_t dht_get_humidity(dht_device_t const dev)
    {
    RT_ASSERT(dev);
    rt_int32_t humi = 0;
    switch(dev->type)
    {
    case DHT11:
    humi = dev->data[0] * 10 + dev->data[1];
    break;
    default:
    break;
    }
    return humi;
    }
    /
    *
  • This function will get the temperature from dhtxx sensor.
  • @param dev the device to be operated
  • @return the temperature value
    /
    rt_int32_t dht_get_temperature(dht_device_t const dev)
    {
    RT_ASSERT(dev);
    rt_int32_t temp = 0;
    switch(dev->type)
    {
    case DHT11:
    temp = dev->data[2] * 10 + (dev->data[3] & 0x7f);
    if(dev->data[3] & 0x80) {
    temp = -temp;
    }
    break;
    default:
    break;
    }
    return temp;
    }
    /
    *
  • This function will init dhtxx sensor device.
  • @param dev the device to init
  • @param pin the pin of Dout
  • @return the device handler
    */
    rt_err_t dht_init(struct dht_device dev, const rt_base_t pin)
    {
    if(dev == NULL)
    return -RT_ERROR;
    dev->type = DHT_TYPE;
    dev->pin = pin;
    rt_memset(dev->data, 0, DHT_DATA_SIZE);
    rt_pin_mode(dev->pin, PIN_MODE_INPUT_PULLUP);
    return RT_EOK;
    }
    // 1、初始化類型
    dht_device_t dht_create(const rt_base_t pin)
    {
    dht_device_t dev;
    dev = rt_calloc(1, sizeof(struct dht_device));
    if (dev == RT_NULL)
    {
    LOG_E("Can't allocate memory for dhtxx device");
    return RT_NULL;
    }
    dev->type = DHT_TYPE;
    dev->pin = pin;
    rt_memset(dev->data, 0, DHT_DATA_SIZE);
    rt_pin_mode(dev->pin, PIN_MODE_INPUT_PULLUP);
    return dev;
    }
    void dht_delete(dht_device_t dev)
    {
    if (dev)
    rt_free(dev);
    }
    #endif /
    SRC_DHT11_C_ /
    /
  • Copyright (c) 2006-2021, RT-Thread Development Team
  • SPDX-License-Identifier: Apache-2.0
  • Change Logs:
  • Date Author Notes
  • 2023-03-15 XiaoDai the first version
    */
    #ifndef SRC_DHT11_H_
    #define SRC_DHT11_H_
    dht11.h

#include
#include
#include
#include
#include
#define DHTLIB_VERSION "0.9.0"
#define DHT_DATA_SIZE 5
/* sensor model type */
#define DHT11 0
#define DHT_TYPE DHT11
struct dht_device
{
rt_base_t pin;
rt_uint8_t type;
rt_uint8_t data[DHT_DATA_SIZE];
rt_mutex_t lock;
};
typedef struct dht_device *dht_device_t;
dht_device_t dht_create(const rt_base_t pin);
void dht_delete(dht_device_t dev);
rt_err_t dht_init(struct dht_device *dev, const rt_base_t pin);
rt_bool_t dht_read(dht_device_t dev);
rt_int32_t dht_get_humidity(dht_device_t dev);
rt_int32_t dht_get_temperature(dht_device_t dev);
float convert_c2k(float c);//將攝氏溫度轉(zhuǎn)為開氏溫度
float convert_c2f(float c);//將攝氏溫度轉(zhuǎn)為華氏溫度
float convert_f2c(float f);//將華氏溫度轉(zhuǎn)為攝氏溫度
rt_int32_t split_int(const rt_int32_t num, rt_int32_t *integer,
rt_int32_t *decimal, const rt_uint32_t times);
rt_err_t rt_hw_dht_init(const char *name, struct rt_sensor_config cfg);
#endif /
SRC_DHT11_H_ */
0.96oled代碼
void lcd_thread_handler(void *parameter)
{
LCD_Init();
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
lcd_show();
rt_thread_mdelay(1000);
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
while(1)
{
lcd_show_pic1();
rt_thread_mdelay(500);
}
}
if(key_num ==1)
{
// u8g2_ClearBuffer(&u8g2);
u8g2_DrawStr(&u8g2, 1, 40, "LED2 is on");
u8g2_SendBuffer(&u8g2);
}
else {
// u8g2_ClearBuffer(&u8g2);
u8g2_DrawStr(&u8g2, 1, 40, "LED2 is off");
u8g2_SendBuffer(&u8g2);
}
hal_entry.c

/*

Copyright (c) 2006-2021, RT-Thread Development Team

SPDX-License-Identifier: Apache-2.0

Change Logs:
Date Author Notes
2021-10-10 Sherman first version
/
#include
#include "hal_data.h"
#include
#define LED1_PIN "P502" /
Onboard LED1 pins /
#define LED2_PIN "P501" /
Onboard LED2 pins */
#define USER_INPUT "P004"
rt_uint32_t pin ;
int key_num ;
void hal_entry(void)
{
rt_kprintf("nHello RT-Thread!n");
while (1)
{
if( pin == 1)
{
rt_kprintf("nUSER_INPUT push !n");
rt_pin_write(LED2,PIN_HIGH);
}
rt_thread_mdelay(500);
}
}
void irq_callback_test(void args)
{
static int out ,out2 ;
rt_kprintf("n IRQ03 triggered n");
rt_uint32_t led1_pin = rt_pin_get(LED1_PIN);
rt_uint32_t led2_pin = rt_pin_get(LED2_PIN);
out = rt_pin_read(led1_pin)?PIN_LOW:PIN_HIGH;
out2 = rt_pin_read(led2_pin)?PIN_LOW:PIN_HIGH;
rt_pin_write(led1_pin,out);
rt_pin_write(led2_pin,out2);
key_num++;
if( pin == 0 && key_num ==2)
{
rt_kprintf("n LED2 is on !n");
rt_pin_write(LED2,PIN_HIGH);
}
else {
rt_kprintf("n LED2 is off !n");
rt_pin_write(LED2,PIN_LOW);
}
if(key_num ==2 )
key_num =0;
}
void push_btn(void)
{
/
init */
rt_uint32_t pin = rt_pin_get(USER_INPUT);
rt_kprintf("n pin number : 0x%04X n", pin);
rt_err_t err = rt_pin_attach_irq(pin, PIN_IRQ_MODE_RISING, irq_callback_test, RT_NULL);
if (RT_EOK != err)
{
rt_kprintf("n attach irq failed. n");
}
err = rt_pin_irq_enable(pin, PIN_IRQ_ENABLE);
if (RT_EOK != err)
{
rt_kprintf("n enable irq failed. n");
}
}
MSH_CMD_EXPORT(push_btn, push_btn);

偶然之中在源代碼中發(fā)現(xiàn)官方已經(jīng)幫我們定義好了有些引腳,所以就沒必要重復(fù)定義了

1.jpg

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • LCD屏
    +關(guān)注

    關(guān)注

    0

    文章

    122

    瀏覽量

    15398
  • SRC
    SRC
    +關(guān)注

    關(guān)注

    0

    文章

    60

    瀏覽量

    17961
  • DHT11
    +關(guān)注

    關(guān)注

    19

    文章

    277

    瀏覽量

    57544
  • CMD命令
    +關(guān)注

    關(guān)注

    0

    文章

    28

    瀏覽量

    8299
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1272

    瀏覽量

    39921
收藏 人收藏

    評論

    相關(guān)推薦

    RA2L1開發(fā)實(shí)踐】-觸摸按鍵控制舵機(jī)

    RA2L1評估開發(fā)板盡量不要只用BIN文件下載,容易鎖死芯片。
    的頭像 發(fā)表于 10-10 15:14 ?1839次閱讀
    【<b class='flag-5'>RA2L1</b><b class='flag-5'>開發(fā)</b><b class='flag-5'>實(shí)踐</b>】-觸摸按鍵控制舵機(jī)

    使用RT-Thread和CPK-RA2L1采集DHT11溫濕度

    本篇文章主要介紹使用RT-Thread Studio 和瑞薩 CPK-RA2L1評估板,使用大佬的輪子采集溫濕度
    的頭像 發(fā)表于 10-11 11:34 ?1567次閱讀
    使用RT-Thread和CPK-<b class='flag-5'>RA2L1</b>采集DHT11<b class='flag-5'>溫濕度</b>

    基于RA2L1開發(fā)板的初識(shí)點(diǎn)燈

    。  3.開發(fā)板框圖  4.學(xué)習(xí)記錄(點(diǎn)燈+串口打?。 ?.1 硬件連線  4.2 原理圖  4.3 環(huán)境安裝  這里是根據(jù)《瑞薩RA2L1開發(fā)實(shí)踐指南》-零、
    發(fā)表于 04-03 16:55

    利用LabVIEW軟件開發(fā)平臺(tái)實(shí)現(xiàn)溫濕度檢測系統(tǒng)的設(shè)計(jì)

    本文基于Labview軟件設(shè)計(jì)可以采集3路溫度和2濕度信號的溫濕度檢測系統(tǒng),具有溫濕度數(shù)據(jù)顯示、波形顯示、
    的頭像 發(fā)表于 06-26 08:02 ?6363次閱讀
    利用LabVIEW軟件<b class='flag-5'>開發(fā)</b><b class='flag-5'>平臺(tái)</b>實(shí)現(xiàn)<b class='flag-5'>溫濕度</b><b class='flag-5'>檢測</b>系統(tǒng)的設(shè)計(jì)

    RA2L1硬件用戶手冊(中英)

    RA2L1硬件用戶手冊(中英)
    發(fā)表于 11-07 19:49 ?6次下載
    <b class='flag-5'>RA2L1</b>硬件用戶手冊(中英)

    RA2L1開發(fā)板資料

    RA2L1開發(fā)板資料
    發(fā)表于 11-07 19:50 ?18次下載
    <b class='flag-5'>RA2L1</b><b class='flag-5'>開發(fā)</b>板資料

    基于RA2L1的串口及J-Link的燒寫說明

    本節(jié)介紹使用串口工具對RA2L1進(jìn)行程序的燒寫。采用CPK-RA2L1開發(fā)板,硬件如下圖所示。
    的頭像 發(fā)表于 11-25 13:55 ?1694次閱讀

    RA2L1 組用戶手冊:硬件

    RA2L1 組用戶手冊:硬件
    發(fā)表于 01-09 19:06 ?5次下載
    <b class='flag-5'>RA2L1</b> 組用戶手冊:硬件

    RA2L1 組數(shù)據(jù)表

    RA2L1 組數(shù)據(jù)表
    發(fā)表于 01-09 19:06 ?0次下載
    <b class='flag-5'>RA2L1</b> 組數(shù)據(jù)表

    瑞薩e2studio----RA2L1通過傳感器檢測溫濕度

    ?本篇文章主要介紹如何使用芯片型號R7FA2L1AB2DFL的開發(fā)板外接溫濕度傳感器進(jìn)行溫濕度檢測,并通過串口顯示
    的頭像 發(fā)表于 01-04 14:38 ?1505次閱讀
    瑞薩e<b class='flag-5'>2studio----RA2L1</b>通過傳感器<b class='flag-5'>檢測溫濕度</b>

    RA2L1 組用戶手冊:硬件

    RA2L1 組用戶手冊:硬件
    發(fā)表于 06-30 18:50 ?1次下載
    <b class='flag-5'>RA2L1</b> 組用戶手冊:硬件

    RA2L1 組數(shù)據(jù)表

    RA2L1 組數(shù)據(jù)表
    發(fā)表于 06-30 18:50 ?0次下載
    <b class='flag-5'>RA2L1</b> 組數(shù)據(jù)表

    RTT RA2L1 HS3003采集溫濕度之一

    選擇基于開發(fā)板->CPK-RA2L1 填入項(xiàng)目名稱,點(diǎn)擊完成,就創(chuàng)建好了工程。
    的頭像 發(fā)表于 10-12 11:02 ?584次閱讀
    RTT <b class='flag-5'>RA2L1</b> HS3003采集<b class='flag-5'>溫濕度</b>之一

    基于RA2L1實(shí)現(xiàn)串口DTC數(shù)據(jù)接收

    基于RA2L1實(shí)現(xiàn)串口DTC數(shù)據(jù)接收
    的頭像 發(fā)表于 10-10 09:34 ?490次閱讀
    基于<b class='flag-5'>RA2L1</b>實(shí)現(xiàn)串口DTC數(shù)據(jù)接收

    瑞薩RA2L1系列CAN通信應(yīng)用

    瑞薩RA2L1系列CAN通信應(yīng)用
    的頭像 發(fā)表于 06-26 08:06 ?560次閱讀
    瑞薩<b class='flag-5'>RA2L1</b>系列CAN通信應(yīng)用