1.3”TFT LCD (240 x 3RGB x 240 )驱动配置

这篇博客详细介绍了如何使用SPI总线与1.3英寸240x240 TFT LCD进行通信,包括初始化GPIO、模拟SPI操作、显示配置命令和颜色设置。代码中展示了从唤醒屏幕到设置像素的完整过程,有助于理解LCD驱动原理。
摘要由CSDN通过智能技术生成

用SPI总线通讯

1、模拟spi:

static void LCD_GPIO_Init(void)
{
    nrf_gpio_cfg_output(LCD_CS_PIN);
    nrf_gpio_pin_set(LCD_CS_PIN);

    nrf_gpio_cfg_output(LCD_RESET_PIN);
    nrf_gpio_cfg_output(LCD_DC_PIN);
    nrf_gpio_cfg_output(LCD_SCLK_PIN);
    nrf_gpio_cfg_output(LCD_SDI_PIN);

    nrf_gpio_cfg_output(LCD_VCC_PIN);
    nrf_gpio_pin_clear(LCD_VCC_PIN);
}

static void enable_cs_pin(void)
{
    nrf_gpio_pin_clear(LCD_CS_PIN);
}

static void disable_cs_pin(void)
{
    nrf_gpio_pin_set(LCD_CS_PIN);
}


void lcd_240x240_reset(void)
{
    /* 
    //---------------------Reset sequence----------// 
    LCD_RESET=1; //
    nrf_delay_ms(1); //Delay 1ms 
    LCD_RESET=0; 
    nrf_delay_ms(10); //Delay 10ms 
    LCD_RESET=1; 
    nrf_delay_ms(120); //Delay 120ms 
    //--------------------------------------------------------------------//
    */
    nrf_gpio_pin_set(LCD_VCC_PIN);
    nrf_delay_ms(10);
    nrf_gpio_pin_set(LCD_RESET_PIN);
    nrf_delay_ms(1);
    nrf_gpio_pin_clear(LCD_RESET_PIN);
    nrf_delay_ms(10);
    nrf_gpio_pin_set(LCD_RESET_PIN);
    nrf_delay_ms(120);

}

void LCD240x240_WriteCMD( unsigned char data)
{
    /*四线SPI接口屏的操作*/
    unsigned char i,MB=0;
    nrf_gpio_pin_clear(LCD_DC_PIN);/*低,0:代表CMD,芯片规格书规定*/
    enable_cs_pin();  //CS low
    MB=data;
    for(i=0; i<8; i++)   /*模拟SPI协义*/
    {
        //nrf_gpio_pin_set(LCD_SCLK_PIN);//注意芯片规格书时序图,先准备数据,再拉时钟线
        if(MB&0x80)
            nrf_gpio_pin_set(LCD_SDI_PIN);
        else
            nrf_gpio_pin_clear(LCD_SDI_PIN);
        nrf_gpio_pin_set(LCD_SCLK_PIN);
        nrf_gpio_pin_clear(LCD_SCLK_PIN);
        MB<<=1;
    }
    disable_cs_pin();  //CS high

}

void LCD240x240_WriteDAT(unsigned char data)
{
       /*四线SPI接口屏的操作*/
    unsigned char i,MB=0;
    nrf_gpio_pin_set(LCD_DC_PIN);/*高,1,代表数据,芯片规格书规定*/
    enable_cs_pin();  //CS low
    MB=data;
    for(i=0; i<8; i++)
    {
        //nrf_gpio_pin_set(LCD_SCLK_PIN);//注意芯片规格书时序图,先准备数据,再拉时钟线
        if(MB&0x80)
            nrf_gpio_pin_set(LCD_SDI_PIN);
        else
            nrf_gpio_pin_clear(LCD_SDI_PIN);
        nrf_gpio_pin_set(LCD_SCLK_PIN);
        nrf_gpio_pin_clear(LCD_SCLK_PIN);
        MB<<=1;
    }
    disable_cs_pin();  //CS high
}


void lcd_240x240_init_test(void)
{
    LCD_GPIO_Init();

    lcd_240x240_reset();

    LCD240x240_WriteCMD(0x11); //退出睡眠
    nrf_delay_ms(120);     
    
    LCD240x240_WriteCMD(0x36); // Memory Data Access Control
    LCD240x240_WriteDAT(0x00); 
    
    LCD240x240_WriteCMD(0x3A); // Interface Pixel Format
    LCD240x240_WriteDAT(0x55);
    
    LCD240x240_WriteCMD(0xB2); //Porch Setting
    LCD240x240_WriteDAT(0x0C); 
    LCD240x240_WriteDAT(0x0C); 
    LCD240x240_WriteDAT(0x00); 
    LCD240x240_WriteDAT(0x33); 
    LCD240x240_WriteDAT(0x33); 

   // LCD240x240_WriteCMD(0x13);//Normal Display Mode On
    
    LCD240x240_WriteCMD(0xB7); // Gate Control
    LCD240x240_WriteDAT(0x75); 
    
    LCD240x240_WriteCMD(0xC2); //VDV and VRH Command Enable
    LCD240x240_WriteDAT(0x01); 
    
    LCD240x240_WriteCMD(0xC3); //VRH Set
    LCD240x240_WriteDAT(0x19); 
    
    LCD240x240_WriteCMD(0xC4);//VDV Set 
    LCD240x240_WriteDAT(0x20);

    LCD240x240_WriteCMD(0xC6); //Frame Rate Control in Normal Mode
    LCD240x240_WriteDAT(0x0F); 
    
    LCD240x240_WriteCMD(0xD0); // Power Control 1
    LCD240x240_WriteDAT(0xA4); 
    LCD240x240_WriteDAT(0xA1); 
    
    LCD240x24

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值