标题:
求助12832 OLED移植代码,屏幕不亮
[打印本页]
作者:
lmh123456
时间:
2025-4-7 17:25
标题:
求助12832 OLED移植代码,屏幕不亮
基本情况
芯片:stm32f401ccu6
屏幕:12832OLED
引脚:SCLPB3 SDAPA8上拉电阻都是10k
IO口模拟I2C
在103板子上屏幕显示正常
401代码
int main(void)
{
int t;
delay_init(); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级 LED_Init(); //LED端口初始化
OLED_Init();
while(1){
OLED_Clear();
OLED_ShowString(0,0,"OLED TEST",16);
// OLED_ShowString(0,2,"Hello World!",16);
delay_ms(2000);
OLED_Clear();
OLED_ShowNum(0,0,1234,4,16);
delay_ms(2000);
}
}
OLED初始化
void OLED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure={0};
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //PD3,PD6推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//速度50MHz
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOD3,6
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //PD3,PD6推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//速度50MHz
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化GPIOD3,6
OLED_SCLK_Set();
OLED_SDIN_Set();
Delay_1ms(100);//上电延时
delay_ms(500);
OLED_WR_Byte(0xAE,OLED_CMD);//关闭显示
OLED_WR_Byte(0x40,OLED_CMD);//---set low column address
OLED_WR_Byte(0xB0,OLED_CMD);//---set high column address
OLED_WR_Byte(0xC8,OLED_CMD);//-not offset
OLED_WR_Byte(0x81,OLED_CMD);//设置对比度
OLED_WR_Byte(0xff,OLED_CMD);
OLED_WR_Byte(0xa1,OLED_CMD);//段重定向设置
OLED_WR_Byte(0xa6,OLED_CMD);//
OLED_WR_Byte(0xa8,OLED_CMD);//设置驱动路数
OLED_WR_Byte(0x1f,OLED_CMD);
OLED_WR_Byte(0xd3,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xd5,OLED_CMD);
OLED_WR_Byte(0xf0,OLED_CMD);
OLED_WR_Byte(0xd9,OLED_CMD);
OLED_WR_Byte(0x22,OLED_CMD);
OLED_WR_Byte(0xda,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0xdb,OLED_CMD);
OLED_WR_Byte(0x49,OLED_CMD);
OLED_WR_Byte(0x8d,OLED_CMD);
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xaf,OLED_CMD);
OLED_Clear();
}
作者:
lmh123456
时间:
2025-4-7 17:29
功能代码都是103移植的,401需要跟sht30共用,main中暂时没包含,电压是够的
作者:
lmh123456
时间:
2025-4-7 17:44
注释跟代码无关,是移植的时候没改
作者:
ucmic
时间:
2025-4-9 11:06
这个灯我记得有两种速率的,另一种是1000ns左右
作者:
lmh123456
时间:
2025-4-9 17:36
我错误原因是delay.h里面没包含#include "stm32f4xx.h",但是delay.h包含sys.h,sys.h里面包含#include "stm32f4xx.h",但是在delay.h加上这个头文件之后就好了。还是自己粗心的问题
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1