一、AHT20温湿度采集
1.I2C
解释什么是“软件I2C”和“硬件I2C”? (阅读野火配套教材的第23章“I2C–读写EEPROM”原理章节)
I2C总线是由Philips公司开发的一种简单、双向二线制同步串行总线。它只需要两根线即可在连接于总线上的器件之间传送信息。主器件用于启动总线传送数据,并产生时钟以开放传送的器件,此时任何被寻址的器件均被认为是从器件.在总线上主和从、发和收的关系不是恒定的,而取决于此时数据传送方向。如果主机要发送数据给从器件,则主机首先寻址从器件,然后主动发送数据至从器件,最后由主机终止数据传送;如果主机要接收从器件的数据,首先由主器件寻址从器件.然后主机接收从器件发送的数据,最后由主机终止接收过程。在这种情况下.主机负责产生定时时钟和终止数据传送。 软件I2C: 软件I2C一般是使用GPIO管脚,用软件控制SCL,SDA线输出高低电平,模拟I2C协议的时序。 硬件I2C: 硬件I2C对应芯片上的I2C外设,有相应I2C驱动电路,其所使用的I2C管脚也是专用的,因而效率要远高于软件模拟的I2C;一般也较为稳定,但是程序较为繁琐。
2.温湿度采集
代码
奥松官网下载AHT20芯片代码:奥松官网 修改main函数
#include "led.h"
#include "usart.h"
#include "temhum.h"
int main(void)
{
u32 CT_data[2]={0};
volatile float hum=0,tem=0;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
LED_Init();
temphum_init();
while(1)
{
AHT20_Read_CTdata(CT_data);
hum = CT_data[0]*100*10/1024/1024;
tem = CT_data[1]*200*10/1024/1024-500;
printf("湿度:%.1f%%\r\n",(hum/10));
printf("温度:%.1f度\r\n",(tem/10));
printf("\r\n");
LED=0;
delay_ms(1000);
LED=1;
delay_ms(1000);
}
}
效果
二、OLED显示
1.显示学号姓名
姓名点阵:使用工具转换
0x00,0x00,0x01,0xFE,0x00,0x20,0xFC,0x40,0x11,0xFC,0x11,0x04,0x11,0x24,0x11,0x24,
0x11,0x24,0x11,0x24,0x11,0x24,0x1D,0x44,0xE0,0x50,0x40,0x88,0x01,0x04,0x02,0x02,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0xE0,0x08,0x20,0x08,0x20,0x08,0x20,0x0A,0x20,0x09,0x20,0x08,0xA0,
0x08,0xA0,0x08,0x20,0x10,0x20,0x10,0x22,0x20,0x22,0x20,0x22,0x40,0x1E,0x80,0x00,
显示代码:
void TEST_MainPage(void)
{
GUI_ShowCHinese(28,20,16,"项一凡",1);
GUI_ShowString(4,48,"631907060524",16,1);
delay_ms(1500);
delay_ms(1500);
}
main函数:
int main(void)
{
delay_init();
OLED_Init();
OLED_Clear(0);
while(1)
{
TEST_MainPage();
}
}
效果:
2.诗句显示
流程基本与上面一致 字阵:
"扶",0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0xFD,0xFC,0x10,0x20,0x10,0x20,0x14,0x20,
0x1B,0xFE,0x30,0x20,0xD0,0x50,0x10,0x50,0x10,0x88,0x10,0x88,0x51,0x04,0x22,0x02,
"摇",0x10,0x08,0x10,0x3C,0x13,0xC0,0x10,0x04,0xFA,0x44,0x11,0x28,0x11,0xFC,0x1A,0x20,
0x30,0x20,0xD3,0xFE,0x10,0x20,0x11,0x24,0x11,0x24,0x11,0x24,0x51,0xFC,0x20,0x04,
"直",0x01,0x00,0x01,0x00,0x7F,0xFC,0x01,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,
0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x10,0x10,0xFF,0xFE,0x00,0x00,
"上",0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x03,0xF8,0x02,0x00,
0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0xFF,0xFE,0x00,0x00,
"九",0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x7F,0xE0,0x04,0x20,0x04,0x20,0x04,0x20,
0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x22,0x10,0x22,0x20,0x22,0x40,0x1E,0x80,0x00,
"万",0x00,0x00,0x00,0x00,0xFF,0xFE,0x04,0x00,0x04,0x00,0x04,0x00,0x07,0xF0,0x04,0x10,
0x04,0x10,0x08,0x10,0x08,0x10,0x10,0x10,0x10,0x10,0x20,0x10,0x40,0xA0,0x80,0x40,
"里",0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x3F,0xF8,
0x01,0x00,0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,
滚动显示:
OLED_WR_Byte(0x2E,OLED_CMD);
OLED_WR_Byte(0x27,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0x07,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xFF,OLED_CMD);
GUI_ShowCHinese(10,0,16,"扶摇直上九万里",1);
OLED_WR_Byte(0x2F,OLED_CMD);
效果:
三、总结
OLED,即有机发光二极管(Organic Light-Emitting Diode),又称为有机电激光显示(Organic Electroluminesence Display, OELD)。OLED由于同时具备自发光,不需背光源、对比度高、厚度薄、视角广、反应速度快、可用于挠曲性面板、使用温度范围广、构造及制程较简单等优异之特性,被认为是下一代的平面显示器新兴应用技术。 OLED显示技术具有自发光的特性,采用非常薄的有机材料涂层和玻璃基板,当有电流通过时,这些有机材料就会发光,而且OLED显示屏幕可视角度大,并且能够节省电能,从2003年开始这种显示设备在MP3播放器上得到了应用。 LCD都需要背光,而OLED不需要,因为它是自发光的。这样同样的显示,OLED效果要来得好一些。以目前的技术,OLED的尺寸还难以大型化,但是分辨率确可以做到很高。
四、参考
STM32F103基于spi实现OLED显示
|