使用fsmc总线驱动彩屏的特点是速度快,与使用IO口模拟的时序的做法相比,FSMC稳定性好,缺点是配置复杂,较难理解。现将配置步骤总结如下:
1.配置引脚
配置函数如下:
void LCD_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
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_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOG, &GPIO_InitStructure);
}
2.配置fsmc总线
void LCD_FSMAC_Config(void)
{
FSMC_NORSRAMInitTypeDef fsmc_config;
FSMC_NORSRAMTimingInitTypeDefp;
p.FSMC_AccessMode=FSMC_AccessMode_A;
p.FSMC_AddressHoldTime=0;
p.FSMC_AddressSetupTime=2;
p.FSMC_BusTurnAroundDuration=0;
p.FSMC_CLKDivision=0;
p.FSMC_DataLatency=0;
p.FSMC_DataSetupTime=2;
fsmc_config.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable;
fsmc_config.FSMC_Bank=FSMC_Bank1_NORSRAM4;
fsmc_config.FSMC_BurstAccessMode=FSMC_BurstAccessMode_Disable;
fsmc_config.FSMC_DataAddressMux=FSMC_DataAddressMux_Disable;
fsmc_config.FSMC_ExtendedMode=FSMC_ExtendedMode_Disable;
fsmc_config.FSMC_MemoryDataWidth=FSMC_MemoryDataWidth_16b;
fsmc_config.FSMC_MemoryType=FSMC_MemoryType_PSRAM;
fsmc_config.FSMC_ReadWriteTimingStruct=&p;
fsmc_config.FSMC_WaitSignal=FSMC_WaitSignal_Disable;
fsmc_config.FSMC_WaitSignalActive=FSMC_WaitSignalActive_BeforeWaitState;
fsmc_config.FSMC_WaitSignalPolarity=FSMC_WaitSignalPolarity_Low;
fsmc_config.FSMC_WrapMode=FSMC_WrapMode_Disable;
fsmc_config.FSMC_WriteBurst=FSMC_WriteBurst_Disable;
fsmc_config.FSMC_WriteOperation=FSMC_WriteOperation_Enable;
fsmc_config.FSMC_WriteTimingStruct=&p;
FSMC_NORSRAMInit(&fsmc_config);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
}
#define LCD_REG_ADDR (*((unsigned short int *)0x6c000000))
#define LCD_RAM_ADDR (*((unsigned short int *)0x6c000002))
#define Lcd_Reg (LCD_REG_ADDR)
#define Lcd_Ram (LCD_RAM_ADDR)
void LCD_WriteReg(u16 lcd_reg,u16 lcd_regval)
{
Lcd_Reg=lcd_reg;
Lcd_Ram=lcd_regval;
}
u16 LCD_ReadReg(u8 addr)
{
u16 data;
data=Lcd_Ram;
return data;
}
void LCD_WriteRAM(u16 color)
{
Lcd_Ram=color;
}
void LCD_WriteRAM_Prepare(void)
{
Lcd_Reg= R34;
}
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{
LCD_WriteReg(0x06,Ypos》》8);
LCD_WriteReg(0x07,Ypos);
LCD_WriteReg(0x02,Xpos》》8);
LCD_WriteReg(0x03,Xpos);
}
来源;21ic
评论
查看更多