STM32 controls the LCD driver driven by ILI9341

Publisher:心想的45号Latest update time:2017-09-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/* Select BANK1-BORSRAM1 to connect TFT, address range is 0X60000000~0X63FFFFFF
* FSMC_A16 connects to DC (register/data select) pin of LCD
* 16 bit => FSMC[24:0] corresponds to HADDR[25:1]
* Register base address = 0X60000000
* RAM base address = 0X60020000 = 0X60000000+2^16*2 = 0X60000000 + 0X20000 = 0X60020000
* When a different address line is selected, the address needs to be recalculated.
*/
//#define Bank1_LCD_D ((u32)0x60020000) //Disp Data ADDR
//#define Bank1_LCD_C ((u32)0x60000000) //Disp Reg ADDR

/*Select LCD specified register*/
//#define LCD_WR_REG(index) ((*(__IO u16 *) (Bank1_LCD_C)) = ((u16)index))
/*Set the index register in LCD to val value*/
//#define LCD_WR_CMD(index,val) do{(*(__IO u16 *) (Bank1_LCD_C)) = ((u16)index); (*(__IO u16 *) (Bank1_LCD_D)) = ((u16)(val));}while(0)
/*Write data to LCD GRAM*/
//#define LCD_WR_Data(val) ((*(__IO u16 *) (Bank1_LCD_D)) = ((u16)(val)))   

void ILI9341_LCD_Init(void);
/**********FSMC**********/
/***********************************************
* Function name: LCD_GPIO_Config
* Description: Configure LCD I/O according to FSMC
* Input: None 
* Output: None
* Example: None
* Note: None
************************************************/  

void LCD_GPIO_Config(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    
    /* Enable FSMC clock*/
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
    
    /* Enable FSMC corresponding to the corresponding pin clock*/
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE , ENABLE);
    
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;
    
    /* Configure LCD backlight control pin*/
    //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;        
    //GPIO_Init(GPIOD, &GPIO_InitStructure);
    
    /* Configure LCD reset control pin*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 ;      
    GPIO_Init(GPIOD, &GPIO_InitStructure);             
    
    /* Configure the data lines corresponding to FSMC, FSMC-D0~D15: PD 14 15 0 1,PE 7 8 9 10 11 12 13 14 15,PD 8 9 10*/    
    GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 
                                  | GPIO_Pin_14 | GPIO_Pin_ 15;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | 
                                  GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | 
                                  GPIO_Pin_15;
    GPIO_Init(GPIOE, &GPIO_InitStructure); 
    
    /* Configure the corresponding control lines of FSMC
     * PD4-FSMC_NOE :LCD-RD
   * PD5-FSMC_NWE :LCD-WR
     * PD7-FSMC_NE1 :LCD-CS
   * PD11-FSMC_A16: LCD-DC
     */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; 
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; 
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO _Pin_7; 
    GPIO_Init(GPIOD, &GPIO_InitStructure);  
    
    GPIO_InitStructure .GPIO_Pin = GPIO_Pin_11; 
    GPIO_Init(GPIOD, &GPIO_InitStructure);  
    
    /* tft control gpio init */     
    //GPIO_SetBits(GPIOD, GPIO_Pin_13); // Backlight on
    //GPIO_ResetBits(GPIOE, GPIO_Pin_1); // RST = 1   
    //GPIO_SetBits(GPIOD, GPIO_Pin_4); // RD = 1  
   // GPIO_SetBits(GPIOD, GPIO_Pin_5); // WR = 1 
   // GPIO_SetBits(GPIOD, GPIO_Pin_7); // CS = 1 
    
    GPIO_SetBits(GPIOD, GPIO_Pin_3); // RST = 1
   // GPIO_SetBits(GPIOD, GPIO_Pin_6); 
}

/******************* ************************
* Function name: LCD_FSMC_Config
* Description: LCD FSMC mode configuration
* Input: None 
* Output: None
* Example: None
* Note : None
************************************************/ 
void LCD_FSMC_Config(void)
{
    FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
    FSMC_NORSRAMTimingInitTypeDef p; 
    
    
    p.FSMC_AddressSetupTime = 0x02; //Address setup time
    p.FSMC_AddressHoldTime = 0x00; //Address hold time
    p.FSMC_DataSetupTime = 0x05; //Data setup time
    p.FSMC_BusTurnAroundDuration = 0x00;
    p.FSMC_CLKDivision = 0x00;
    p.FSMC_DataLatency = 0x00;
    p.FSMC_AccessMode = FSMC_AccessMode_B; // Normally use mode B to control LCD
    
    FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
    FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
    FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
    FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode
    = FSMC_BurstAccessMode_Disable;
    NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode
    = FSMC_WrapMode_Disable;
    FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
    FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
    FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
    FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
    FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
    FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
    FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; 
    
    FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); 
    
    /* Enable FSMC Bank1_SRAM Bank */
    FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);  
}

/**************************************
* Function Name: LCD_Rst
* Description: LCD software reset
* Input: None 
* Output: None
* Example: None
* Note: None
******************************************/
void LCD_Rst(void)
{            
    GPIO_ResetBits(GPIOD, GPIO_Pin_3);
    SysTickDelay(100);                       
    GPIO_SetBits(GPIOD, GPIO_Pin_3);              
    SysTickDelay(100);    
}

void Lcd_data_start(void)
{
         LCD_WR_REG(0X2C);
}
/**********************************
* Function name: Lcd_init_conf
* Description: LCD register initial configuration
* Input: None
* Output: None
* Example: None
* Note: None
******************************************/
void Lcd_init_conf(void)
{
LCD_WR_REG(0xCF);
LCD_WR_Data(0x00);
LCD_WR_Data(0x81);
LCD_WR_Data(0x30);

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

LCD_WR_REG(0xE8);
LCD_WR_Data(0x85);
LCD_WR_Data(0x10);
LCD_WR_Data(0x78);

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(0xF7);
WR_Data(0x20);

LCD_WR_REG(0xEA);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);

LCD_WR_REG(0xB1);
LCD_WR_Data(0x00);
LCD_WR_Data(0x1B);

LCD_WR_REG(0xB6);
LCD_WR_Data(0x0A);
LCD_WR_Data(0xA2);

REG(0xC0);
LCD_WR_Data(0x35);

LCD_WR_REG(0xC1);
LCD_WR_Data(0x11);

LCD_WR_REG(0xC5); LCD_WR_Data( 0x45
);
LCD_WR_Data(0x45); LCD_WR_REG( 0xC7 ) ; LCD_WR_Data ( 0xA2) ; LCD_WR_REG( 0xF2); LCD_WR_Data ( 0x00); LCD_WR_REG (0x26 ; A8) ; LCD_WR_Data ( 0x46); LCD_WR_Data(0x0C); LCD_WR_Data(0x17); LCD_WR_Data(0x09);























LCD_WR_Data(0x0F);
LCD_WR_Data(0x07);
LCD_WR_Data(0x00);
LCD_WR_REG(0XE1); //Set Gamma
LCD_WR_Data(0x00);
LCD_WR_Data(0x19);
LCD_WR_Data(0x1B);
LCD_WR_Data(0x04);
LCD_WR_Data(0x10);
LCD_WR_Data (0x07);
LCD_WR_Data(0x2A);
LCD_WR_Data(0x47);
LCD_WR_Data(0x39);
LCD_WR_Data(0x03);
LCD_WR_Data(0x06);
LCD_WR_Data(0x06);
LCD_WR_Data(0x30);
LCD_WR_Data(0x38); LCD_WR_Data
(0x0F);

(0x36); 
LCD_WR_Data(0x08);

LCD_WR_REG(0X2A); 
LCD_WR_Data(0x00)
;
LCD_WR_Data(0x00);
LCD_WR_Data(0x00 ) ; LCD_WR_Data (

0xEF  ); LCD_WR_REG(0X2B); LCD_WR_REG(0x3a); // Memory Access Control LCD_WR_Data(0x55); LCD_WR_REG(0x11); //Exit Sleep SysTickDelay(120); LCD_WR_REG(0x29); //display on LCD_WR_REG(0x2c);  } /***** ************************************ * Function name: LCD_Init * Description: LCD control I/O initialization *LCD FSMC initialization *LCD Controller HX8347 Initialization  * Input: None * Output: None * Example: None * Note: None ****************************** ************/     void TFT_Draw_Point(u16 x,u8 y,u16 color) { LCD_WR_REG(0X2A);  LCD_WR_Data(x>>8); LCD_WR_Data(x&0xFF); LCD_WR_REG(0X2B);  LCD_WR_Data (0x00); LCD_WR_Data(y); LCD_WR_REG(0x2C);//Start writing LCD_WR_Data(color); } void ILI9341_LCD_Init(void) {     unsigned long i;        LCD_GPIO_Config();     LCD_FSMC_Config();             LCD_Rst();     Lcd_init_conf();                  Lcd_data_start();        for(i=0; i<(320*240); i++)                      {         LCD_WR_Data(0xF800);                              }     TFT_Draw_Point(319,120,0x07E0);    } /************FSMC************/























































Keywords:STM32 Reference address:STM32 controls the LCD driver driven by ILI9341

Previous article:STM32 controls the LCD driver driven by ILI9341 (continued)
Next article:STM32 FSMC control LCD function explanation

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号