#include "stm32f1xx_hal.h"
#include "oled_ssd1306.h"
#define OLED_I2C_ADDR 0x3C
void OLED_Init(void);
void OLED_Clear(void);
void OLED_DisplayText(const char *text, uint8_t x, uint8_t y);
int main(void)
{
HAL_Init();
SystemClock_Config();
/* 初始化I2C */
I2C1_Init();
OLED_Init(); // 初始化OLED
while (1)
{
OLED_Clear(); // 清屏
OLED_DisplayText("Hello, OLED!", 10, 10); // 显示文本
}
}
void OLED_Init(void)
{
// 初始化OLED
OLED_InitTypeDef OLED_InitStructure;
OLED_InitStructure.Address = OLED_I2C_ADDR;
OLED_Init(&OLED_InitStructure);
OLED_Clear();
OLED_DisplayOn();
}
void OLED_Clear(void)
{
// 清除OLED屏幕
OLED_FillScreen(OLED_COLOR_BLACK);
}
void OLED_DisplayText(const char *text, uint8_t x, uint8_t y)
{
// 显示文本
OLED_SetCursor(x, y);
OLED_WriteString(text, OLED_FONT_11X18, OLED_COLOR_WHITE);
} |