7脚oled的野火霸道F103的接法和c代码
时间: 2024-03-25 12:38:48 浏览: 18
以下是野火霸道 F103 硬件连接 7 脚 OLED 屏幕的接法:
| OLED | F103 |
|------|------|
| GND | GND |
| VCC | 3.3V |
| SCL | PB10 |
| SDA | PB11 |
注意:7 脚 OLED 屏幕通常需要接另一个电位器来调整对比度,接法为 VCC、GND 和 VO(对比度调整)三个引脚。
以下是在野火霸道 F103 上使用 7 脚 OLED 屏幕的 C 代码:
```c
#include <stdio.h>
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "i2c.h"
#include "oled.h"
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 设置NVIC中断分组2: 2位抢占优先级,2位响应优先级
delay_init(72); // 初始化延时函数
USART1_Init(115200); // 初始化USART1,波特率为115200
I2C_Soft_Init(); // 初始化软件I2C
OLED_Init(); // 初始化OLED屏幕
OLED_Clear(); // 清空OLED屏幕
while(1)
{
OLED_ShowString(0, 0, "Hello, World!");
OLED_ShowString(0, 2, "This is OLED test.");
OLED_ShowString(0, 4, "Welcome to use it!");
delay_ms(500);
OLED_Clear();
delay_ms(500);
}
}
```
该程序使用了野火提供的 OLED 屏幕库,通过软件 I2C 通信方式控制 OLED 屏幕显示内容。程序中通过 `OLED_Init()` 函数初始化 OLED 屏幕,并通过 `OLED_ShowString()` 函数在屏幕上显示字符串。循环中不断显示 "Hello, World!"、"This is OLED test."、"Welcome to use it!" 的信息,每个信息间隔 0.5 秒,同时通过 `OLED_Clear()` 函数清空屏幕。