RT1052開發(fā)板實現(xiàn)SPI接口的OLED屏顯示

原創(chuàng) 2022-06-18 16:09:00 rt1052 OLED屏 SPI接口OLED屏
 

這里再介紹一下在飛凌RT1052開發(fā)板上使用鍵盤端口(KPP)來驅動SPI接口OLED屏的用法。

OLED屏與RT1052的連接關系如下:

CS  --P1.24
DC  --P1.26
RST --P1.28
DIN --P1.27  D1
SCLK--P1.25  D0

使個引腳輸出高低電平的定義如下:

#define OLED_CS_Clr()       GPIO_PinWrite(GPIO1, (24U), 0U);

#define OLED_CS_Set()       GPIO_PinWrite(GPIO1, (24U), 1U);

#define OLED_DC_Clr()       GPIO_PinWrite(GPIO1, (26U), 0U);

#define OLED_DC_Set()       GPIO_PinWrite(GPIO1, (26U), 1U);

#define OLED_RST_Clr()      GPIO_PinWrite(GPIO1, (28U), 0U);

#define OLED_RST_Set()      GPIO_PinWrite(GPIO1, (28U), 1U);

#define OLED_SDIN_Clr()     GPIO_PinWrite(GPIO1, (27U), 0U);

#define OLED_SDIN_Set()    GPIO_PinWrite(GPIO1, (27U), 1U);

#define OLED_SCLK_Clr()     GPIO_PinWrite(GPIO1, (25U), 0U);

#define OLED_SCLK_Set()     GPIO_PinWrite(GPIO1, (25U), 1U);

配置各引腳為輸出端口的函數(shù)為:

void LCD_GPIO_Cogfig(void)

{

    gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};

    GPIO_PinInit(GPIO1, (25U), &led_config);

    GPIO_PinInit(GPIO1, (27U), &led_config);

    GPIO_PinInit(GPIO1, (24U), &led_config);

    GPIO_PinInit(GPIO1, (26U), &led_config);

    GPIO_PinInit(GPIO1, (28U), &led_config);

    GPIO_PinInit(GPIO1, (30U), &led_config);

    GPIO_PinInit(GPIO1, (31U), &led_config);

}

 

該OLED屏的初始化函數(shù)為:

void OLED_Init(void)

{

    LCD_GPIO_Cogfig();

    OLED_RST_Set();

    delay_ms(100);

    OLED_RST_Clr();

    delay_ms(100);

    OLED_RST_Set();

    OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel

    OLED_WR_Byte(0x00,OLED_CMD);//---set low column address

    OLED_WR_Byte(0x10,OLED_CMD);//---set high column address

    OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM    OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register

    OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness

    OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping

    OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction

    OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display

    OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)

    OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty

    OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset

    OLED_WR_Byte(0x00,OLED_CMD);//-not offset

    OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency

    OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec

    OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period

    OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock

    OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration

    OLED_WR_Byte(0x12,OLED_CMD);

    OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh

    OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level

    OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)

    OLED_WR_Byte(0x02,OLED_CMD);//

    OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable

    OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable

    OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)

    OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)

    OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel

    OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/

    OLED_Clear();

    OLED_Set_Pos(0,0);

}


SPI 接口OLED屏顯示效果

 

實現(xiàn)圖示效果的主程序為:

int main(void)

{

    uint16_t i=0;

    gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};

    BOARD_ConfigMPU();

    BOARD_InitPins();

    BOARD_BootClockRUN();

    BOARD_InitDebugConsole();

    GPIO_PinInit(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, &led_config);

    delay();

    OLED_Init();

    OLED_Clear();

    OLED_ShowString(8,0,"OK1052-C");

    OLED_ShowString(8,2,"OLED TEST");

    OLED_ShowString(8,4,"JINGLIXIXI"); 

    OLED_ShowString(8,6,"2018/11/8");

    while(1);

}

相關產(chǎn)品 >

  • FET1052-C核心板

    iMXRT核心板采用NXP iMXRT1050系列的i.MX RT1052跨界處理器設計,兼容MCU與MPU各自領域特點。iMXRT1052主頻高達600MHz是單片機界的性能怪獸。iMXRT1052作為一款跨界核心板,采用 Cortex-M7架構微控制器,主頻卻高達600MHz,高密度的512KB TCM SRAM和16MB的高速SDRAM,超快的實時響應,超低的功耗,超強處理性能賦予了RT1052視頻編解碼能力。


    了解詳情
    FET1052-C核心板
  • OK1052-C開發(fā)板

    飛凌提供的i.MXRT105x系列單片機,iMXRT1052單片機基于NXP Cortex-M7 i.MX RT1052跨界處理器設計,底板+核心板分離結構,開發(fā)更簡單,imxrt1052核心板僅售68元,歡迎致電400-699-6866咨詢。推薦iMXRT單片機,性價比高。 了解詳情
    OK1052-C開發(fā)板

推薦閱讀 換一批 換一批