/* 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************/
Previous article:STM32 controls the LCD driver driven by ILI9341 (continued)
Next article:STM32 FSMC control LCD function explanation
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What is the file with the suffix jed? What is its function?
- EEWORLD University ---- ESP32 MicroPython Video Tutorial
- Relationship between PN conduction voltage drop and current and temperature
- [GD32L233C-START Review] 15. RT-Thread message queue, multi-threaded use
- High-speed rail Spring Festival travel benefits?
- NXP Rapid IoT Review Summary and Highlights (Updated January 25)
- Essence ESP-S3-12K (Part 1) ---- Unboxing
- Medical device EMC and safety testing
- [Xingkong board Python programming learning main control board] Open source - Xingkong board expansion board (conversion board) design
- Teaching flowchart template sharing