屏幕使用0.96寸OLED屏幕,PIN61连接到I2C0_SCL,PIN62连接到I2C_SDA
温湿度传感器使用DHT11,DATA线连接到PIN_59,并添加上拉电阻
oled屏幕驱动程序由 TL-LED 提供(帖子附件下载),原帖地址【AG32VH407开发板】硬件i2c方式驱动oled显示屏 - 国产芯片交流 - 电子工程世界-论坛
温湿度传感器部分源码
- #include "board.h"
- #include "gpio.h"
- #include "timer/mtimer.h"
- #include "dh11/dh11.h"
- #include "oled/oled.h"
-
- char Humidity[2];
- char Temperature[2];
-
- void DH11_set_heigh(void)
- {
- GPIO_SetValue(DH11_GPIO, DH11_GPIO_BITS, 1);
- }
-
- void DH11_set_low(void)
- {
- GPIO_SetValue(DH11_GPIO, DH11_GPIO_BITS, 0);
- }
-
- uint8_t DH11_get_value(void)
- {
- GPIO_GetValue(DH11_GPIO, DH11_GPIO_BITS);
- }
-
-
- void DHT11_start()
- {
- DH11_set_heigh;
- mstimer_delay_us(2);
- DH11_set_low;
- mstimer_delay_ms(25);
- DH11_set_heigh;
- mstimer_delay_us(30);
- }
-
-
- unsigned char DHT11_rec_byte()
- {
- unsigned char i, dat = 0;
- for (i = 0; i < 8; i++)
- {
- while (DH11_get_value == 0)
- ;
-
- while (DH11_get_value() == 1)
- ;
-
- mstimer_delay_us(60);
- dat <<= 1;
- if (DH11_get_value() == 1)
- dat += 1;
-
- while (DH11_get_value == 0)
- ;
- }
- return dat;
- }
主程序
- int main(void)
- {
- // This will init clock and uart on the board
- board_init();
-
- // The default isr table is plic_isr. The default entries in the table are peripheral name based like CAN0_isr() or
- // GPIO0_isr(), and can be re-assigned.
- plic_isr[BUT_GPIO_IRQ] = Button_isr;
- // Any interrupt priority needs to be greater than MIN_IRQ_PRIORITY to be effective
- INT_SetIRQThreshold(MIN_IRQ_PRIORITY);
- // Enable interrupt from BUT_GPIO
- INT_EnableIRQ(BUT_GPIO_IRQ, PLIC_MAX_PRIORITY);
-
- init_mtimer(1);
- init_oled();
- oled_Temperature_init();
- mstimer_delay_ms(100);
-
- while (true)
- {
- /* code */
- DHT11_receive();
-
- mstimer_delay_ms(1000);
- }
- }
-
运行示例
|