基本情況
芯片: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ō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();
}
|