本帖最后由 jinglixixi 于 2018-11-10 10:12 编辑
这里再介绍一下在飞凌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
复制代码
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);
- }
复制代码
|