查看: 4520|回复: 0

驱动ILI9341 spi屏幕

[复制链接]
  • TA的每日心情
    无聊
    2017-4-26 18:34
  • 签到天数: 3 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2017-6-13 22:55:20 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 dadangjiasp 于 2017-6-13 23:08 编辑

          我看了下网友提供的历程,没有ILI9341相关的代码,我参照店家给的代码添加到init程序中,spi屏幕可以正常运行。
    webwxgetmsgimg.jpg
    1在lcd_driver.h修改定义
    1. //-------------------------ÆÁÄ»ÎïÀíÏñËØÉèÖÃ--------------------------------------//
    2. #define LCD_X_SIZE                176
    3. #define LCD_Y_SIZE                220
    4. #define DIR                 4
    5. /////////////////////////////////////ÎïÀíÅäÖÃÇø///////////////////////////////////         
    6. //Èç¹ûʹÓúáÆÁ
    7. #define USE_HORIZONTAL                  1        //ÊÇ·ñʹÓúáÆÁ                 0,²»ÊµÓà 1,ʹÓÃ.

    8. #if USE_HORIZONTAL//ºáÆÁ
    9. #define X_MAX_PIXEL                LCD_Y_SIZE
    10. #define Y_MAX_PIXEL                LCD_X_SIZE
    11. #else
    12. #define X_MAX_PIXEL                LCD_X_SIZE
    13. #define Y_MAX_PIXEL                LCD_Y_SIZE
    14. #endif
    15. //////////////////////////////////////////////////////////////////////////////////

    16. //Òº¾§¿ØÖÆ¿ÚÖÃ1²Ù×÷Óï¾äºê¶¨Òå
    17. #define        LCD_RST_SET          gpio_bit_set(GPIOB,GPIO_PIN_12)
    18. #define        LCD_RS_SET          gpio_bit_set(GPIOB,GPIO_PIN_11)
    19. #define        LCD_SDA_SET          gpio_bit_set(GPIOA,GPIO_PIN_7)
    20. #define        LCD_SCL_SET          gpio_bit_set(GPIOC,GPIO_PIN_4)
    21. #define        LCD_CS_SET          gpio_bit_set(GPIOC,GPIO_PIN_5)

    22. //Òº¾§¿ØÖÆ¿ÚÖÃ0²Ù×÷Óï¾äºê¶¨Òå
    23. #define        LCD_RST_CLR          gpio_bit_reset(GPIOB,GPIO_PIN_12)
    24. #define        LCD_RS_CLR          gpio_bit_reset(GPIOB,GPIO_PIN_11)
    25. #define        LCD_SDA_CLR          gpio_bit_reset(GPIOA,GPIO_PIN_7)
    26. #define        LCD_SCL_CLR          gpio_bit_reset(GPIOC,GPIO_PIN_4)
    27. #define        LCD_CS_CLR           gpio_bit_reset(GPIOC,GPIO_PIN_5)
    复制代码
    2在lcd_driver.c添加一个初始化定义,在main.函数中,注意要设置为Lcd_Init(4); 才使用ILI9341的代码,如果使用其他的spi屏幕,可以在初始化中添加更多的代码。修改好的程序见附件,引脚定义有和原网友提供的一致。
    1. else if(dir==4)//Init for ILI9341
    2. {
    3. //************* Start Initial Sequence **********//
    4.   Lcd_WriteIndex(0x02); Lcd_WriteData_16Bit(0x0100); // set 1 line inversion
    5. #if USE_HORIZONTAL//ºáÆÁ
    6.         //R01H:SM=0,GS=0,SS=0 (for details,See the datasheet of ILI9225)
    7.         LCD_WriteReg(0x01, 0x001C); // set the display line number and display direction
    8.         //R03H:BGR=1,ID0=1,ID1=1,AM=1 (for details,See the datasheet of ILI9225)
    9.         LCD_WriteReg(0x03, 0x1038); // set GRAM write direction .
    10. #else//ÊúÆÁ
    11.         //R01H:SM=0,GS=0,SS=1 (for details,See the datasheet of ILI9225)
    12.         LCD_WriteReg(0x01, 0x011C); // set the display line number and display direction
    13.         //R03H:BGR=1,ID0=1,ID1=1,AM=0 (for details,See the datasheet of ILI9225)
    14.         LCD_WriteReg(0x03, 0x1030); // set GRAM write direction.
    15. #endif

    16.   Lcd_WriteIndex(0x08); Lcd_WriteData_16Bit(0x0808); // set BP and FP
    17.   Lcd_WriteIndex(0x0B); Lcd_WriteData_16Bit(0x1100); //frame cycle
    18.   Lcd_WriteIndex(0x0C); Lcd_WriteData_16Bit(0x0000); // RGB interface setting R0Ch=0x0110 for RGB 18Bit and R0Ch=0111for RGB16Bit
    19.   Lcd_WriteIndex(0x0F); Lcd_WriteData_16Bit(0x1401); // Set frame rate----0801
    20.   Lcd_WriteIndex(0x15); Lcd_WriteData_16Bit(0x0000); //set system interface
    21.   Lcd_WriteIndex(0x20); Lcd_WriteData_16Bit(0x0000); // Set GRAM Address
    22.   Lcd_WriteIndex(0x21); Lcd_WriteData_16Bit(0x0000); // Set GRAM Address
    23.   //*************Power On sequence ****************//
    24.   delay_1ms(50);                         // Delay 50ms
    25.   Lcd_WriteIndex(0x10); Lcd_WriteData_16Bit(0x0800); // Set SAP,DSTB,STB----0A00
    26.   Lcd_WriteIndex(0x11); Lcd_WriteData_16Bit(0x1F3F); // Set APON,PON,AON,VCI1EN,VC----1038
    27.   delay_1ms(50);                         // Delay 50ms
    28.   Lcd_WriteIndex(0x12); Lcd_WriteData_16Bit(0x0121); // Internal reference voltage= Vci;----1121
    29.   Lcd_WriteIndex(0x13); Lcd_WriteData_16Bit(0x006F); // Set GVDD----0066
    30.   Lcd_WriteIndex(0x14); Lcd_WriteData_16Bit(0x4349); // Set VCOMH/VCOML voltage----5F60
    31.   //-------------- Set GRAM area -----------------//
    32.   Lcd_WriteIndex(0x30); Lcd_WriteData_16Bit(0x0000);
    33.   Lcd_WriteIndex(0x31); Lcd_WriteData_16Bit(0x00DB);
    34.   Lcd_WriteIndex(0x32); Lcd_WriteData_16Bit(0x0000);
    35.   Lcd_WriteIndex(0x33); Lcd_WriteData_16Bit(0x0000);
    36.   Lcd_WriteIndex(0x34); Lcd_WriteData_16Bit(0x00DB);
    37.   Lcd_WriteIndex(0x35); Lcd_WriteData_16Bit(0x0000);
    38.   Lcd_WriteIndex(0x36); Lcd_WriteData_16Bit(0x00AF);
    39.   Lcd_WriteIndex(0x37); Lcd_WriteData_16Bit(0x0000);
    40.   Lcd_WriteIndex(0x38); Lcd_WriteData_16Bit(0x00DB);
    41.   Lcd_WriteIndex(0x39); Lcd_WriteData_16Bit(0x0000);
    42.   // ----------- Adjust the Gamma Curve ----------//
    43.   Lcd_WriteIndex(0x50); Lcd_WriteData_16Bit(0x0001);  //0400
    44.   Lcd_WriteIndex(0x51); Lcd_WriteData_16Bit(0x200B);  //060B
    45.   Lcd_WriteIndex(0x52); Lcd_WriteData_16Bit(0x0000);  //0C0A
    46.   Lcd_WriteIndex(0x53); Lcd_WriteData_16Bit(0x0404);  //0105
    47.   Lcd_WriteIndex(0x54); Lcd_WriteData_16Bit(0x0C0C);  //0A0C
    48.   Lcd_WriteIndex(0x55); Lcd_WriteData_16Bit(0x000C);  //0B06
    49.   Lcd_WriteIndex(0x56); Lcd_WriteData_16Bit(0x0101);  //0004
    50.   Lcd_WriteIndex(0x57); Lcd_WriteData_16Bit(0x0400);  //0501
    51.   Lcd_WriteIndex(0x58); Lcd_WriteData_16Bit(0x1108);  //0E00
    52.   Lcd_WriteIndex(0x59); Lcd_WriteData_16Bit(0x050C);  //000E
    53.   delay_1ms(50);                                     // Delay 50ms
    54.   Lcd_WriteIndex(0x07); Lcd_WriteData_16Bit(0x1017);
    55.   Lcd_WriteIndex(0x22);
    56.         
    57.         return;
    58. }                                                                                                                                               
    复制代码

    GD32F450_Template.zip

    350.29 KB, 下载次数: 62

    ILI9341

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-11-15 08:06 , Processed in 0.101290 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.