图纸yd是什么意思:STM32 FSMC TFT LCD

来源:百度文库 编辑:偶看新闻 时间:2024/04/19 09:03:34

STM32+SSD1963+TFT(FSMC)已调试通过的代码。

其中要注意的两点:

1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。

 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。 
2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。

// ssd1963 #d/c   -------- STM32F103VCT6 A18

 

#define LCD_COMM_ADD  *((volatile u16 *)0X60000000)
 #define LCD_DATA_ADD  *((volatile u16 *)0X60080000)

 #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}
 #define WriteData(data)  {LCD_DATA_ADD = data;}

 

void LCDFSMCConfig(void)
{
  FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  FSMC_NORSRAMTimingInitTypeDef  p;
  GPIO_InitTypeDef GPIO_InitStructure;
/*-- FSMC Configuration ------------------------------------------------------*/

/* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
             RCC_APB2Periph_AFIO, ENABLE);

/*===========GPIO For the LCD_Bus========================*/ 
  /*  Data /Address lines configuration */
  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_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  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_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /*  Address lines configuration: A18*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
  GPIO_Init(GPIOD, &GPIO_InitStructure); 

  /*===========GPIO For the Control========================*/
 /*!< NOE and NWE configuration */ 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
 
 GPIO_Init(GPIOD, &GPIO_InitStructure);
 
 /*!< NE1 configuration */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
 
 /*!< NADV configuration */
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
 #ifdef LCD_USE_TE
 /*TE :busy*/
   GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 
   GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);
    #endif
 /*!< NBL0, NBL1 configuration */
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
// GPIO_Init(GPIOE, &GPIO_InitStructure);
  GPIO_SetBits(GPIOD, GPIO_Pin_7);   //CS=1
  GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);   
  GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);  
  GPIO_ResetBits(GPIOE, GPIO_Pin_0);
  GPIO_ResetBits(GPIOE, GPIO_Pin_1);   //RESET=0
  GPIO_SetBits(GPIOD, GPIO_Pin_4);      //RD=1
  GPIO_SetBits(GPIOD, GPIO_Pin_5);   //WR=1    
 /*-- FSMC Configuration ------------------------------------------------------*/
 
/*----------------------- SRAM Bank 1----------------------------------------*/
  /* FSMC_Bank1_NORSRAM1 configuration */
  p.FSMC_AddressSetupTime = 0x02;//1;
  p.FSMC_AddressHoldTime = 0x00;//0;
  p.FSMC_DataSetupTime = 0x05;//5//2;
  p.FSMC_BusTurnAroundDuration = 0;
  p.FSMC_CLKDivision = 0;
  p.FSMC_DataLatency = 0;
  p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;
  /* Color LCD configuration ------------------------------------
     LCD configured as follow:
        - Data/Address MUX = Enable
        - Memory Type = SRAM
        - Data Width = 16bit
        - Write Operation = Enable
        - Extended Mode = Enable
        - Asynchronous Wait = Disable */
  FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
  FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;  //hy@
 // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;  //hy@ 
 // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
  FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//

  FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
//  FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_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); 
  /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
  FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}

 

/**
  * @brief  Initializes the LCD.
  * @param  None
  * @retval None
  */
void IzLCDDisplayInit(void)
{

/* Configure the FSMC Parallel interface -------------------------------------*/
  LCDFSMCConfig();
 
  DelayLoop(5); /* delay 50 ms */
  //LCD_SetFont(&LCDDEFAULTFONT);
  LCDSetFont(&LCDDEFAULTFONT);
  InitSSD1963();


}