本帖最后由 jinglixixi 于 2020-11-27 20:46 编辑
前面介绍了双色OLED屏的显示,那OKdo E1开发板是否能驱动彩色OLED屏呢? 答案是肯定的,其显示效果见图1~图3所示。 图1
图2
图3
有别于I2C接口的双色屏,彩色屏所采用的接口是SPI,故要比双色屏占用更多的I/O口。 那使用哪些引脚呢? 这里OLED屏与MCU的连接关系为: SCLK--P0.7 DIN --P1.0 RST --P0.15 DC --P1.5 CS --P1.8 BLK --P0.0 定义相关引脚输出高低电平的语句为: #defineOLED_SCLK_Clr() GPIO_PinWrite(GPIO, 0u,7u, 0) //CLK #defineOLED_SCLK_Set() GPIO_PinWrite(GPIO, 0u,7u, 1)
#defineOLED_SDIN_Clr() GPIO_PinWrite(GPIO, 1u,0u, 0) //DIN #defineOLED_SDIN_Set() GPIO_PinWrite(GPIO, 1u,0u, 1)
#defineOLED_RST_Clr() GPIO_PinWrite(GPIO, 0u,15u, 0) //RES #defineOLED_RST_Set() GPIO_PinWrite(GPIO, 0u,15u, 1)
#defineOLED_DC_Clr() GPIO_PinWrite(GPIO, 1u,5u, 0) //DC #defineOLED_DC_Set() GPIO_PinWrite(GPIO, 1u,5u, 1)
#defineOLED_CS_Clr() GPIO_PinWrite(GPIO, 1u,8u, 0) //CS #defineOLED_CS_Set() GPIO_PinWrite(GPIO, 1u,8u, 1)
#defineOLED_BLK_Clr() GPIO_PinWrite(GPIO, 0u,0u, 0) //BLK #defineOLED_BLK_Set() GPIO_PinWrite(GPIO, 0u,0u, 1) 配置引脚为输出功能的函数为: - void app_oled_init(void)
- {
- gpio_pin_config_t gpioPinConfig;
- gpioPinConfig.pinDirection = kGPIO_DigitalOutput;
- gpioPinConfig.outputLogic = 1u;
- GPIO_PinInit (GPIO, 0u, 7u, &gpioPinConfig);
- GPIO_PinInit (GPIO, 1u, 0u, &gpioPinConfig);
- GPIO_PinInit (GPIO, 0u, 15u, &gpioPinConfig);
- GPIO_PinInit (GPIO, 1u, 5u, &gpioPinConfig);
- GPIO_PinInit (GPIO, 0u, 0u, &gpioPinConfig);
- GPIO_PinInit (GPIO, 1u, 8u, &gpioPinConfig);
- OLED_BLK_Set();
- }
复制代码
实现图片显示的函数为: - void LCD_ShowPicturea(u16 x1,u16 y1,u16 x2,u16 y2)
- {
- int i;
- LCD_Address_Set(x1,y1,x2,y2);
- for(i=0;i<12800;i++)
- {
- LCD_WR_DATA8(gImage_moled[i*2]);
- LCD_WR_DATA8(gImage_moled[i*2+1]);
- }
- }
复制代码
实现图示效果的主程序为: - int main(void)
- {
- uint8_t num,vol=10;
- uint16_t i,j,k;
- volatile uint8_t s_KeyValue = 0;
- POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
- BOARD_BootClockFROHF96M();
- CLOCK_EnableClock(kCLOCK_Iocon);
- IOCON->PIO[1][24] = (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN );
- IOCON->PIO[0][27] = (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN );
- CLOCK_DisableClock(kCLOCK_Iocon);
- usart_config_t s_UARTConfig;
- CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);
- USART_GetDefaultConfig(&s_UARTConfig);
- s_UARTConfig.baudRate_Bps = 9600;
- s_UARTConfig.enableTx = true;
- s_UARTConfig.enableRx = false;
- USART_Init(USART2, &s_UARTConfig, 12000000);
- USART_WriteBlocking(USART2, cmd, 10);
- SystemCoreClockUpdate();
- if (SysTick_Config(SystemCoreClock / 1000U))
- {
- while (1)
- {
- }
- }
- key_init();
- app_oled_init();
- Lcd_Init();
- LCD_Clear(BLACK);
- BACK_COLOR=BLACK;
- LCD_ShowChinese(28,0,0,32,YELLOW);
- LCD_ShowChinese(60,0,1,32,YELLOW);
- LCD_ShowChinese(92,0,2,32,YELLOW);
- LCD_ShowChinese(20,40,0,16,YELLOW);
- LCD_ShowChinese(36,40,1,16,YELLOW);
- LCD_ShowChinese(52,40,2,16,YELLOW);
- LCD_ShowChinese(68,40,3,16,YELLOW);
- LCD_ShowChinese(84,40,4,16,YELLOW);
- LCD_ShowChinese(100,40,5,16,YELLOW);
- LCD_ShowChinese(116,40,6,16,YELLOW);
- LCD_ShowString(0,60," 0.96 TFT SPI",YELLOW);
- while(key_read()!= KEY3_NUM);
- LCD_Clear(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(key_read()!= KEY3_NUM);
- LCD_ShowPicturea(0,0,159,79);
- while(1);
- }
复制代码
|