在实现LCD5110屏显示之后,本打算完成I2C接口的OLED屏显示,无奈经多次测试似乎在GD32F450上无法实现,故只得进行SPI接口的2.2寸TFT彩色屏测试。 为了便于连线,TFT屏与GD32F450开发板的连接是通过Arduino接口,相应的连接关系如下: CS -- PE2 REST -- PE5 DC -- PE6 SDI -- PE4 SCK -- PD0 LED+ -- PD1 GND可直接从Arduino接口取用,而稍有遗憾的是3.3V 电源则要从其位置引用。 在相应引脚设置为输出模式的情况下,其输出高低电平的语句定义如下: - #define LCD_CS_High() gpio_bit_set(GPIOE, GPIO_PIN_2);
- #define LCD_CS_Low() gpio_bit_reset(GPIOE, GPIO_PIN_2);
-
- #define LCD_REST_High() gpio_bit_set(GPIOE, GPIO_PIN_5);
- #define LCD_REST_Low() gpio_bit_reset(GPIOE, GPIO_PIN_5);
-
- #define LCD_DC_High() gpio_bit_set(GPIOE, GPIO_PIN_6);
- #define LCD_DC_Low() gpio_bit_reset(GPIOE, GPIO_PIN_6);
-
- #define LCD_SDI_High() gpio_bit_set(GPIOE, GPIO_PIN_4);
- #define LCD_SDI_Low() gpio_bit_reset(GPIOE, GPIO_PIN_4);
-
- #define LCD_SCK_High() gpio_bit_set(GPIOD, GPIO_PIN_0);
- #define LCD_SCK_Low() gpio_bit_reset(GPIOD, GPIO_PIN_0);
-
- #define LCD_LED_High() gpio_bit_set(GPIOD, GPIO_PIN_1);
- #define LCD_LED_Low() gpio_bit_reset(GPIOD, GPIO_PIN_1);
复制代码在其它函数基本不变的情况下,即可实现TFT屏的显示驱动。 为实现图像的显示,可将图像数据存放到数组中以供读取,实现的显示效果如图所示。 对应的引脚配置函数为: - void SPI_CONFIG()
- {
- rcu_periph_clock_enable(RCU_GPIOE);
- gpio_mode_set (GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_2| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_4);
- gpio_output_options_set(GPIOE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_2| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_4);
- rcu_periph_clock_enable(RCU_GPIOD);
- gpio_mode_set (GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_0| GPIO_PIN_1);
- gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_0| GPIO_PIN_1);
- GPIO_BOP(GPIOD) = GPIO_PIN_1;
- rcu_periph_clock_enable(RCU_GPIOB);
- gpio_mode_set (GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_14);
- gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_14);
- }
复制代码 初始化函数为: - void Lcd_Init(void)
- {
- LCD_REST_Low();
- delay_1ms(20);
- LCD_REST_High();
- delay_1ms(20);
- LCD_CS_Low();
- LCD_WR_REG(0xCB);
- LCD_WR_DATA8(0x39);
- LCD_WR_DATA8(0x2C);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x34);
- LCD_WR_DATA8(0x02);
- LCD_WR_REG(0xCF);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0XC1);
- LCD_WR_DATA8(0X30);
- LCD_WR_REG(0xE8);
- LCD_WR_DATA8(0x85);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x78);
- LCD_WR_REG(0xEA);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x00);
- LCD_WR_REG(0xED);
- LCD_WR_DATA8(0x64);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0X12);
- LCD_WR_DATA8(0X81);
- LCD_WR_REG(0xF7);
- LCD_WR_DATA8(0x20);
- LCD_WR_REG(0xC0);
- LCD_WR_DATA8(0x23);
- LCD_WR_REG(0xC1);
- LCD_WR_DATA8(0x10);
- LCD_WR_REG(0xC5);
- LCD_WR_DATA8(0x3e);
- LCD_WR_DATA8(0x28);
- LCD_WR_REG(0xC7);
- LCD_WR_DATA8(0x86);
- LCD_WR_REG(0x36);
- LCD_WR_DATA8(0x48);
- LCD_WR_REG(0x3A);
- LCD_WR_DATA8(0x55);
- LCD_WR_REG(0xB1);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x18);
- LCD_WR_REG(0xB6);
- LCD_WR_DATA8(0x08);
- LCD_WR_DATA8(0x82);
- LCD_WR_DATA8(0x27);
- LCD_WR_REG(0xF2);
- LCD_WR_DATA8(0x00);
- LCD_WR_REG(0x26);
- LCD_WR_DATA8(0x01);
- LCD_WR_REG(0xE0);
- LCD_WR_DATA8(0x0F);
- LCD_WR_DATA8(0x31);
- LCD_WR_DATA8(0x2B);
- LCD_WR_DATA8(0x0C);
- LCD_WR_DATA8(0x0E);
- LCD_WR_DATA8(0x08);
- LCD_WR_DATA8(0x4E);
- LCD_WR_DATA8(0xF1);
- LCD_WR_DATA8(0x37);
- LCD_WR_DATA8(0x07);
- LCD_WR_DATA8(0x10);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0x0E);
- LCD_WR_DATA8(0x09);
- LCD_WR_DATA8(0x00);
- LCD_WR_REG(0XE1);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x0E);
- LCD_WR_DATA8(0x14);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0x11);
- LCD_WR_DATA8(0x07);
- LCD_WR_DATA8(0x31);
- LCD_WR_DATA8(0xC1);
- LCD_WR_DATA8(0x48);
- LCD_WR_DATA8(0x08);
- LCD_WR_DATA8(0x0F);
- LCD_WR_DATA8(0x0C);
- LCD_WR_DATA8(0x31);
- LCD_WR_DATA8(0x36);
- LCD_WR_DATA8(0x0F);
- LCD_WR_REG(0x11);
- delay_1ms(120);
- LCD_WR_REG(0x29);
- LCD_WR_REG(0x2c);
- }
复制代码图像显示函数为: - void show_pic(const unsigned char *p)
- {
- int i,j;
- unsigned char picH,picL;
- Address_set(0,0,LCD_W-1,LCD_H-1);
- for(i=0;i<240;i++)
- {
- for(j=0;j<320;j++)
- {
- picH=*p++;
- picL=*p++;
- LCD_WR_DATA8(picH);
- LCD_WR_DATA8(picL);
- }
- }
- }
复制代码主函数为: - int main(void)
- {
- systick_config();
- SPI_CONFIG();
- Lcd_Init();
- show_pic(gImage_123);
- while (1);
- }
复制代码 |