打印
[DemoCode下载]

ILI9341初始化方法

[复制链接]
595|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dongnanxibei|  楼主 | 2023-12-18 21:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*-----------------------------------------------*/
// Write control registers of LCD module  
//
/*-----------------------------------------------*/
#if PH_CTRL_RS
void LCD_WR_REG(uint16_t cmd)
{
    CLR_RS
    EBI0_WRITE_DATA16(0x00000000, cmd);
    SET_RS

}

#else
void LCD_WR_REG(uint16_t cmd)
{
    EBI0_WRITE_DATA16(0x00000000, cmd);
}

#endif


/*-----------------------------------------------*/
// Write data to SRAM of LCD module  
//
/*-----------------------------------------------*/
void LCD_WR_DATA(uint16_t dat)
{
    EBI0_WRITE_DATA16(0x00030000, dat);

}


/*-----------------------------------------------*/
// Read data from SRAM of LCD module
//
/*-----------------------------------------------*/
uint16_t LCD_RD_DATA(void)
{
    return EBI0_READ_DATA16(0x00030000);

}

/********************************************************************
*
*       LcdWriteDataMultiple
*
*   Function description:
*   Writes multiple values to a display register.
*/
static void LcdWriteDataMultiple(uint16_t * pData, int NumItems)
{
    while (NumItems--) {
        EBI0_WRITE_DATA16(0x00030000,*pData++);
    }
}

/********************************************************************
*
*       LcdReadDataMultiple
*
*   Function description:
*   Reads multiple values from a display register.
*/
static void LcdReadDataMultiple(uint16_t * pData, int NumItems)
{
    while (NumItems--) {
        *pData++ = EBI0_READ_DATA16(0x00030000);
    }
}

/*-----------------------------------------------*/
// Set cursor positon on the LCD screen
//
/*-----------------------------------------------*/
#if 0
void LCD_SetCursor(uint16_t x_s, uint16_t y_s)
{
    uint16_t x_e = x_s+1;
    uint16_t y_e = y_s+1;
        
    /* X range */
    LCD_WR_REG(0x2A);
    LCD_WR_DATA(x_s>>8);
    LCD_WR_DATA(x_s);
    LCD_WR_DATA(x_e>>8);
    LCD_WR_DATA(x_e);

    /* Y range */
    LCD_WR_REG(0x2B);
    LCD_WR_DATA(y_s>>8);
    LCD_WR_DATA(y_s);
    LCD_WR_DATA(y_e>>8);
    LCD_WR_DATA(y_e);
        
    /* Memory write */
    LCD_WR_REG(0x2C);
   
}
#endif

/*-----------------------------------------------*/
// Initial LIL9341 LCD driver chip
//
/*-----------------------------------------------*/
void ILI9341_Initial(void)
{
    uint16_t Reg = 0;
   
    /* Hardware reset */
    SET_RST;
    CLK_SysTickDelay(5000);     // Delay 5ms
   
    CLR_RST;
    CLK_SysTickDelay(20000);    // Delay 20ms
   
    SET_RST;
    CLK_SysTickDelay(40000);    // Delay 40ms

    /* Initial control registers */
    LCD_WR_REG(0xCB);
    LCD_WR_DATA(0x39);
    LCD_WR_DATA(0x2C);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x34);
    LCD_WR_DATA(0x02);

    LCD_WR_REG(0xCF);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0xC1);
    LCD_WR_DATA(0x30);

    LCD_WR_REG(0xE8);
    LCD_WR_DATA(0x85);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x78);

    LCD_WR_REG(0xEA);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x00);

    LCD_WR_REG(0xED);
    LCD_WR_DATA(0x64);
    LCD_WR_DATA(0x03);
    LCD_WR_DATA(0x12);
    LCD_WR_DATA(0x81);

    LCD_WR_REG(0xF7);
    LCD_WR_DATA(0x20);

    LCD_WR_REG(0xC0);
    LCD_WR_DATA(0x23);

    LCD_WR_REG(0xC1);
    LCD_WR_DATA(0x10);

    LCD_WR_REG(0xC5);
    LCD_WR_DATA(0x3e);
    LCD_WR_DATA(0x28);

    LCD_WR_REG(0xC7);
    LCD_WR_DATA(0x86);

    LCD_WR_REG(0x36);
    LCD_WR_DATA(0x48);

    LCD_WR_REG(0x3A);
    LCD_WR_DATA(0x55);
        
    LCD_WR_REG(0xB1);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x18);

    LCD_WR_REG(0xB6);
    LCD_WR_DATA(0x08);
    LCD_WR_DATA(0x82);
    LCD_WR_DATA(0x27);

    LCD_WR_REG(0xF2);
    LCD_WR_DATA(0x00);

    LCD_WR_REG(0x26);
    LCD_WR_DATA(0x01);

    LCD_WR_REG(0xE0);
    LCD_WR_DATA(0x0F);
    LCD_WR_DATA(0x31);
    LCD_WR_DATA(0x2B);
    LCD_WR_DATA(0x0C);
    LCD_WR_DATA(0x0E);
    LCD_WR_DATA(0x08);
    LCD_WR_DATA(0x4E);
    LCD_WR_DATA(0xF1);
    LCD_WR_DATA(0x37);
    LCD_WR_DATA(0x07);
    LCD_WR_DATA(0x10);
    LCD_WR_DATA(0x03);
    LCD_WR_DATA(0x0E);
    LCD_WR_DATA(0x09);
    LCD_WR_DATA(0x00);

    LCD_WR_REG(0xE1);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x0E);
    LCD_WR_DATA(0x14);
    LCD_WR_DATA(0x03);
    LCD_WR_DATA(0x11);
    LCD_WR_DATA(0x07);
    LCD_WR_DATA(0x31);
    LCD_WR_DATA(0xC1);
    LCD_WR_DATA(0x48);
    LCD_WR_DATA(0x08);
    LCD_WR_DATA(0x0F);
    LCD_WR_DATA(0x0C);
    LCD_WR_DATA(0x31);
    LCD_WR_DATA(0x36);
    LCD_WR_DATA(0x0F);

    LCD_WR_REG(0x11);
    CLK_SysTickDelay(200000);   // Delay 200ms
   
    LCD_WR_REG(0x29);           //Display on

    LCD_WR_REG(0x0A);
    Reg = LCD_RD_DATA();
    Reg = LCD_RD_DATA();
    printf("0Ah = %02x.\n", Reg);
   
    LCD_WR_REG(0x0B);
    Reg = LCD_RD_DATA();
    Reg = LCD_RD_DATA();
    printf("0Bh = %02x.\n", Reg);
   
    LCD_WR_REG(0x0C);
    Reg = LCD_RD_DATA();
    Reg = LCD_RD_DATA();
    printf("0Ch = %02x.\n", Reg);

    printf("Initial ILI9341 LCD Module done.\n\n");

}


使用特权

评论回复
沙发
734774645| | 2023-12-18 22:24 | 只看该作者
另外可以将这些指令放到数组里,用循环写入方式写入芯片。

使用特权

评论回复
板凳
734774645| | 2023-12-18 22:25 | 只看该作者
直接写这么多看着就太长了,放数组写入可以让程序看着更加简洁

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

207

主题

3605

帖子

16

粉丝