RT1052开发板实现SPI接口的OLED屏显示

原创 2022-06-18 16:09:00 rt1052 OLED屏 SPI接口OLED屏
 

这里再介绍一下在飞凌RT1052开发板上使用键盘端口(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);

配置各引脚为输出端口的函数为:

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屏的初始化函数为:

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屏显示效果

 

实现图示效果的主程序为:

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);

}

相关产品 >

  • 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开发板

    飞凌提供的i.MXRT105x系列单片机,iMXRT1052单片机基于NXP Cortex-M7 i.MX RT1052跨界处理器设计,底板+核心板分离结构,开发更简单,imxrt1052核心板仅售68元,欢迎致电400-699-6866咨询。推荐iMXRT单片机,性价比高。 了解详情
    OK1052-C开发板

推荐阅读 换一批 换一批