標(biāo)題: 求助12832 OLED移植代碼,屏幕不亮 [打印本頁]

作者: lmh123456    時間: 2025-4-7 17:25
標(biāo)題: 求助12832 OLED移植代碼,屏幕不亮
基本情況
芯片:stm32f401ccu6
屏幕:12832OLED
引腳:SCLPB3  SDAPA8上拉電阻都是10k
IO口模擬I2C
在103板子上屏幕顯示正常
401代碼
int main(void)
{        
        int t;
                delay_init();                     //延時函數(shù)初始化         
                NVIC_Configuration();          //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級         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);//關(guān)閉顯示
        
        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);//設(shè)置對比度
        OLED_WR_Byte(0xff,OLED_CMD);

        OLED_WR_Byte(0xa1,OLED_CMD);//段重定向設(shè)置

        OLED_WR_Byte(0xa6,OLED_CMD);//
        
        OLED_WR_Byte(0xa8,OLED_CMD);//設(shè)置驅(qū)動路數(shù)
        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
注釋跟代碼無關(guān),是移植的時候沒改
作者: 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.torrancerestoration.com/bbs/) Powered by Discuz! X3.1