本帖最后由 jinglixixi 于 2021-3-10 12:38 编辑
彩色OLED屏相较于TFT屏,其显示屏的尺寸虽小却也同TFT屏一样具有了丰富的色彩表现力,该显示屏的接口为SPI方式,其与MCU的连接关系为: CS ---PB13
RES---PB11
DC ---PB12
SDA---PB9
SCK---PB8
BLK---PB14
配置相关引脚为输出功能的函数为:
void app_oled_init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_8|GPIO_Pins_9|GPIO_Pins_11|GPIO_Pins_12|GPIO_Pins_13|GPIO_Pins_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
OLED_BLK_Set();
}
OLED屏的初始化函数为:
void Lcd_Init(void)
{
app_oled_init();
OLED_RST_Clr();
Delay_ms(200);
OLED_RST_Set();
Delay_ms(200);
LCD_WR_REG(0x11);
Delay_ms(100);
LCD_WR_REG(0x21);
LCD_WR_REG(0xB1);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB3);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB4);
LCD_WR_DATA8(0x03);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x62);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x04);
LCD_WR_REG(0xC1);
LCD_WR_DATA8(0xC0);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x8D);
LCD_WR_DATA8(0x6A);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x8D);
LCD_WR_DATA8(0xEE);
LCD_WR_REG(0xC5); /*VCOM*/
LCD_WR_DATA8(0x0E);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x12);
LCD_WR_DATA8(0x27);
LCD_WR_DATA8(0x37);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x06);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x26);
LCD_WR_DATA8(0x36);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0x36);
LCD_WR_DATA8(0x78);
LCD_WR_REG(0x29);
}
实现显示效果的主程序为:
int main(void)
{
uint16_t i;
AT32_Board_Init();
app_oled_init();
Lcd_Init();
LCD_Clear(BLACK);
BACK_COLOR=BLACK;
LCD_ShowString(10,0,"LCD_W:",RED);
LCD_ShowNum(70,0,LCD_W,3,RED);
LCD_ShowString(10,20,"LCD_H:",RED);
LCD_ShowNum(70,20,LCD_H,2,RED);
for(i=0;i<4;i++)
{
LCD_ShowPicture(i*40,40,39+i*40,79);
}
while(1);
}
运行的显示效果如图所示:
|