最近做点小东西时用到了压箱底N久的一块屏(SED1335控制器,320×240单色),我将其挂在FSMC总线上,然后配置FSMC总线时用到如下子程序:
=========================我是分割线=========================
void FSMC_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD
| RCC_APB2Periph_GPIOE
| RCC_APB2Periph_GPIOF
| RCC_APB2Periph_GPIOG, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 // PD.0 → D2
| GPIO_Pin_1 // PD.1 → D3
| GPIO_Pin_4 // PD.4 → NOE
| GPIO_Pin_5 // PD.5 → NWE
| GPIO_Pin_14 // PD.14 → D0
| GPIO_Pin_15; // PD.15 → D1
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 // PE.7 → D4
| GPIO_Pin_8 // PE.8 → D5
| GPIO_Pin_9 // PE.9 → D6
| GPIO_Pin_10; // PE.10 → D7
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // PF.0 → A0
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // PG.12 → NE4
GPIO_Init(GPIOG, &GPIO_InitStructure);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
// Set the BANK and the chip select signal
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
// Set whether the data bus and address bus time-multiplexing
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
// Set the type of memory
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
// Data width settings
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
// Set whether to use burst mode access
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
// Set up "WAIT" an effective signal level
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
// Set whether to use loop-back mode
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
// Set "WAIT" signal the effective time
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
// Set whether to "write" operation
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
// Set whether or not to use "WAIT" signal
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
// Set whether or not to use an independent "write" timing
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
// Set whether to use burst mode to write
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
// Set up "reading" & "write" timing
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 0; // ADDSET
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime = 0; // ADDHOLD
FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime = 7; // DATAST
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration = 0; // BUSTURN
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 0; // CLKDIV
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency = 0; // DATLAT
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A; // ACCMOD
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
}
=========================我是分割线=========================
然后向LCD总线读写时要搞成这样才正确(拿写命令的子程序举例):
__inline void LCD_Write_Control_Byte(UINT32 DATA)
{
UINT32 i;
i = 7; while(i--); // 这个延时如果不加,那显示就出错
*((volatile UINT8 * )0x6C000001) = DATA;
}
=========================我是分割线=========================
现在有一点没搞明白...我看人家的例程都是直接读写丝毫不见延时痕迹的,而我的却要用i = 7; while(i--);这样的延时才能显示正常,这是怎么回事呢?屏的关系么?还是FSMC总线写入需要时间,上一个操作还没完成我下一个数据又送过去了?另外这句延时是否和上面FSMC配置中FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime = 7; // DATAST
有所关联?? |