热度 15
2013-7-9 20:50
1834 次阅读|
0 个评论
三、说了这么久的理论,来个实例分析更加形象了,首先硬件连线要明白 在原理图或者开发手册上面能够确定引脚复用问题 地址引脚: (A0-A5 :PF0 - PF5) (A6-A9: F12-F15 ) (A10-A15:PG0-PG5) (A16-A18:PD11-PD13) (A19-A22:PE3-PE6) (A23-PE2) 片选信号(NEx:PG12)因为我选择的是block4 写使能(NWR:PD5) 读使能(NOE:PD4) 至此控制引脚基本完成 下面就是数据引脚: PD14-FSMC-D0 ----LCD-DB0 PD15-FSMC-D1 ----LCD-DB1 PD0-FSMC-D2 ----LCD-DB2 PD1-FSMC-D3 ----LCD-DB3 PE7-FSMC-D4 ----LCD-DB4 PE8-FSMC-D5 ----LCD-DB5 PE9-FSMC-D6 ----LCD-DB6 PE10-FSMC-D7 ----LCD-DB7 PE11-FSMC-D8 ----LCD-DB8 PE12-FSMC-D9 ----LCD-DB9 PE13-FSMC-D10 ----LCD-DB10 PE14-FSMC-D11 ----LCD-DB11 PE15-FSMC-D12 ----LCD-DB12 PD8-FSMC-D13 ----LCD-DB13 PD9-FSMC-D14 ----LCD-DB14 PD10-FSMC-D15 ----LCD-DB15 有了这些硬件连线是没有任何问题的 四、正式分析 程序 1、硬件引脚 配置 函数 01 void LCD_CtrlLinesConfig(void) 02 { 03 GPIO_InitTypeDef GPIO_InitStructure; 04 /* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */ 05 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); //使能FSMC 06 07 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | 08 RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG | 09 RCC_APB2Periph_AFIO, ENABLE); 10 //IO口复用功能时钟 11 /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14), 12 PD.10(D15), PD.14(D0), PD.15(D1) as alternate 13 function push pull */ 14 15 /*D端口初始化*/ 16 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | 17 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | 18 GPIO_Pin_15; 19 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 20 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 21 GPIO_Init(GPIOD, GPIO_InitStructure); 22 23 /*E端口初始化*/ 24 /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10), 25 PE.14(D11), PE.15(D12) as alternate function push pull */ 26 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | 28 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | 29 GPIO_Pin_15; 30 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 31 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 32 GPIO_Init(GPIOE, GPIO_InitStructure); //将配置写入GPIOE管脚 33 34 /*A0地址线*/ 35 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; 36 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 38 GPIO_Init(GPIOF, GPIO_InitStructure); 39 40 /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */ 41 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 ; 42 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 43 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 44 GPIO_Init(GPIOG, GPIO_InitStructure); 45 46 47 /*复位端口PE6*/ 48 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 49 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 50 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 51 GPIO_Init(GPIOE, GPIO_InitStructure); 52 53 54 GPIO_ResetBits(GPIOE,GPIO_Pin_6); //复位脚 55 56 DelayMs(50); //延时50ms 57 58 GPIO_SetBits(GPIOE, GPIO_Pin_6); //将复位脚拉高 59 } 细心观察,能够发现就是上面说的那些引脚嘛! 2、接下来的就是比较重要的FSMC的配置了 先上 代码 ,然后慢慢分析吧 01 void LCD_FSMCConfig(void) 02 { 03 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; 04 FSMC_NORSRAMTimingInitTypeDef p; 05 06 /*-- FSMC Configuration ------------------------------------------------------*/ 07 /*----------------------- SRAM Bank 4 ----------------------------------------*/ 08 /* FSMC_Bank1_NORSRAM4 configuration */ 09 p.FSMC_AddressSetupTime = 0; 10 p.FSMC_AddressHoldTime = 0; 11 p.FSMC_DataSetupTime = 2; 12 p.FSMC_BusTurnAroundDuration = 0; 13 p.FSMC_CLKDivision = 0; 14 p.FSMC_DataLatency = 0; 15 p.FSMC_AccessMode = FSMC_AccessMode_A; 16 17 /* 18 Color LCD configuration ------------------------------------ 19 LCD configured as follow: 20 - Data/Address MUX = Disable 21 - Memory Type = SRAM 22 - Data Width = 16bit 23 - Write Operation = Enable 24 - Extended Mode = Enable 25 - Asynchronous Wait = Disable 26 */ 27 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4; 28 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; 29 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; 30 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; 31 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; 32 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; 33 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; 34 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_Be " " target= "_blank" for eWaitState; 35 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; 36 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; 37 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; 38 //FSMC_NORSRAMInitStructure.FSMC_AsyncWait = FSMC_AsyncWait_Disable; 39 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; 40 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = p; 41 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = p; 42 43 FSMC_NORSRAMInit(FSMC_NORSRAMInitStructure); 44 45 /* BANK 4 (of NOR/SRAM Bank 1~4) is enabled */ 46 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); 47 } a、首先是时间参数的配置,我们在初始化的时候设置的bank4,所以这里对应的也是bank4,本函数主要使用了两种类型的结构体对FSMC进行配置,第一种 为 FSMC_NORSRAMInitTypeDef类型的结构体主要用于NOR FLASH的模式配置,包括存储器类型、数据宽度等。另一种的类型为FSMC_NORSRAMTimingInitTypeDef