STM32F10XX series uses FSMC interface to drive LCD

Publisher:独享留白1028Latest update time:2016-08-14 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Friends who have used the STM32F10XX series know that there are generally two ways to drive the LCD; one is to use the IO port to simulate the operation of the LCD, and the other is to use the FSMC interface of the STM32F10XX to operate the LCD; of course, the latter is definitely faster than the former, because FSMC is a peripheral of STM32, you just need to throw the data to it and it will complete the driving for you. As long as the FSMC interface is set up, the C language code for transmitting data can be simplified to one sentence, and the CPU utilization is greatly increased.
I have used STM32F103RBT to make an MP3 with display before. At that time, I used IO to simulate the LCD. It was a bit troublesome to control because many macro definitions were needed to package some IO port operations. Just writing a piece of data required several instructions. Reading and writing also required changing the input and output direction of the IO port. Therefore, using IO port to simulate the LCD was much slower than the FSMC interface driver. From the execution point of view, FSMC is parallel with other codes, while IO port simulation is serial with other codes. Which one do you think is faster? Well, without further ado, I will show you the FSMC interface I set up.
/**********************************************
 * 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 pins */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    /* Configure LCD reset control pin */
   /* LCD reset is together with system reset, so no other pins are used for reset */ (I did not use other IO to reset it. The PE1 below is not used. I connected it to the LED)
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; 
    GPIO_Init(GPIOE, &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 Read
   * PD5-FSMC_NWE: LCD-WR write
   * PD7-FSMC_NE1: LCD-CS chip select
   * PD11-FSMC_A16 :LCD-RS/DC command/data
 **********************************************/
    GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_7|GPIO_Pin_11; 
    GPIO_Init(GPIOD, &GPIO_InitStructure);
}
 
/**********************************************
 * 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 establishment time
    p.FSMC_AddressHoldTime = 0x00; //Address hold time
    p.FSMC_DataSetupTime = 0x05; //Data establishment time
    p.FSMC_BusTurnAroundDuration = 0x00;
    p.FSMC_CLKDivision = 0x00;
    p.FSMC_DataLatency = 0x00;
    p.FSMC_AccessMode = FSMC_AccessMode_B;
    
    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;
    FSMC_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);  
}
 
FSMC can work with this setting (of course it can also be changed to other working modes). I use A16 as the data and command selection line. Add the following two sentences
 #define LCD_REG (*(__IO u16 *)((uint32_t)0x60000000))
 #define LCD_RAM ​​(*(__IO u16 *)((uint32_t)0x60020000)) We can then read and write the LCD as two addresses, which is very convenient.
I'll stop here. If you have other opinions, please feel free to raise them.
Reference address:STM32F10XX series uses FSMC interface to drive LCD

Previous article:STM32F10XX Application Notes - GPIO Settings
Next article:STM32 directly drives ov7670 development notes

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号