STM32F103VC+DS18B20温度+hc-sr04超声波测距+I2C OLED显示
Posted perseverance52
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32F103VC+DS18B20温度+hc-sr04超声波测距+I2C OLED显示相关的知识,希望对你有一定的参考价值。
STM32F103VC+DS18B20温度+hc-sr04超声波测距+I2C OLED显示
- 📌相关篇《STM32F103VE基于STM32CubeMX 配置I2C驱动0.96/1.3 OLED显示》
- 📺实物演示:
⛳屏幕类型说明
- 🍁驱动0.96寸屏幕和1.3寸屏幕有
2
处需要调整:
- OLED初始化函数:
//初始化SSD1306
void OLED_Init(void)
HZ=GB16_NUM();
IIC_GPIO_Config();
Write_IIC_Command(0xAE); //--display off
Write_IIC_Command(0x02);//-设置低位列地址set low column address 注意:0.96屏幕从0x00开始写数据,1.3寸屏幕从0x02开始写数据
Write_IIC_Command(0x10); //---set high column address
Write_IIC_Command(0x40); //--set start line address
Write_IIC_Command(0xB0); //--set page address
Write_IIC_Command(0x81); // contract control
Write_IIC_Command(0xFF); //--128
Write_IIC_Command(0xA1); //set segment remap
Write_IIC_Command(0xA6); //--normal / reverse
Write_IIC_Command(0xA8); //--set multiplex ratio(1 to 64)
Write_IIC_Command(0x3F); //--1/32 duty
Write_IIC_Command(0xC8); //Com scan direction
Write_IIC_Command(0xD3); //-set display offset
Write_IIC_Command(0x00); //
Write_IIC_Command(0xD5); //set osc division
Write_IIC_Command(0x80); //
Write_IIC_Command(0xD8); //set area color mode off
Write_IIC_Command(0x05); //
Write_IIC_Command(0xD9); //Set Pre-Charge Period
Write_IIC_Command(0xF1); //
Write_IIC_Command(0xDA); //set com pin configuartion
Write_IIC_Command(0x12); //
Write_IIC_Command(0xDB); //set Vcomh
Write_IIC_Command(0x30); //
Write_IIC_Command(0x8D); //set charge pump enable
Write_IIC_Command(0x14); //
Write_IIC_Command(0xAF); //--turn on oled panel
- 清屏函数:
//OLED全屏填充
void OLED_Fill(u8 fill_Data)
u8 m,n;
for(m=0;m<8;m++)
Write_IIC_Command(0xb0+m); //page0-page1
Write_IIC_Command(0x02);//low column start address1.3寸屏幕发送地址是从0x02开始的,0.96屏幕是从0x00地址开始的特别注意个地方!!!
Write_IIC_Command(0x10); //high column start address
for(n=0;n<130;n++)
Write_IIC_Data(fill_Data);
📝接口定义说明
VCC--3.3V/5V
GND--GND
SCL--PB8
SDA--PB9
18B20接线定义:
VCC--3.3V/5V
GND--GND
DQ--PA5
HC-SR04超声波接线定义:
VCC--3.3V/5V(最好选择是5V供电)
GND--GND
Trig--PB7
Echo--PB6
📚程序源码
链接:https://pan.baidu.com/s/1IwL8D7NlIZTClr7pgAlf7g
提取码:mbaf
以上是关于STM32F103VC+DS18B20温度+hc-sr04超声波测距+I2C OLED显示的主要内容,如果未能解决你的问题,请参考以下文章
ArduinoSTM32 利用DS18B20读取温度 on STM32F103C8
STM32入门开发: 编写DS18B20温度传感器驱动(读取环境温度支持级联)