GPIO_Init(GPIOD, &GPIO_InitStructure); //PD5-FSMC_NWE :LCD-WR
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOG, &GPIO_InitStructure); //PG12-FSMC_NE4 :LCD-CS GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOG, &GPIO_InitStructure); //PE2-FSMC_A10 :LCD-DC发送的数据代表是命令还是显示数据
}
void LCD_FSMC_Config(void) {
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef WRITE_USER;
FSMC_NORSRAMTimingInitTypeDef READ_USER; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); READ_USER.FSMC_AddressSetupTime = 0x01; //地址建立时间
//地址保持时间 //数据建立时间
READ_USER.FSMC_AddressHoldTime = 0x00; READ_USER.FSMC_DataSetupTime = 0x0f;
READ_USER.FSMC_BusTurnAroundDuration = 0x00; READ_USER.FSMC_CLKDivision = 0x00; READ_USER.FSMC_DataLatency = 0x00;
READ_USER.FSMC_AccessMode = FSMC_AccessMode_A; //
WRITE_USER.FSMC_AddressSetupTime = 0x00; //地址建立时间
WRITE_USER.FSMC_AddressHoldTime = 0x00; //地址保持时间 WRITE_USER.FSMC_DataSetupTime = 0x03;
//数据建立时间
WRITE_USER.FSMC_BusTurnAroundDuration = 0x00;// WRITE_USER.FSMC_CLKDivision = 0x00;// WRITE_USER.FSMC_DataLatency = 0x00;//
WRITE_USER.FSMC_AccessMode = FSMC_AccessMode_A; //
34
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4; //选择外接
存储区域的地址
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux
FSMC_DataAddressMux_Disable;//配置数据线和地址线是否复用
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;//配置外接存储器的类型
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth
FSMC_MemoryDataWidth_16b;//设置FSMC接口的数据宽度 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode
FSMC_BurstAccessMode_Disable;//配置访问模式 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity
FSMC_WaitSignalPolarity_Low;//配置等待信号的极性
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;//配置
是否使用非对齐方式
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive
FSMC_WaitSignalActive_BeforeWaitState;//配置等待信号什么时间产生 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;//
配置是否使用等待信号
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;//配置是否允许突发写操作
FSMC_NORSRAMInitStructure.FSMC_WriteOperation FSMC_WriteOperation_Enable;//配置写操作使能 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode
FSMC_ExtendedMode_Enable ;//配置是否使用扩展模式
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &READ_USER;//读
时序
= = = = = = = =
35
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &WRITE_USER; //写时
序
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); }
void LCD_init_RGB(void) {
Delay(50); // delay 50 ms
LCD_WriteReg(0x0000,0x0001);
Delay(50); // delay 50 ms
lcddev.id = LCD_ReadReg(0x0000);
if(lcddev.id<0XFF||lcddev.id==0XFFFF||lcddev.id==0X9300)//读到ID不正确,
新增lcddev.id==0X9300判断,因为9341在未被复位的情况下会被读成9300
{
LCD_WR_REG(0XD3); LCD_RD_DATA();
//dummy read
LCD_RD_DATA(); //读到0X00
lcddev.id=LCD_RD_DATA(); //读取93 lcddev.id<<=8;
lcddev.id|=LCD_RD_DATA(); //读取41
if(lcddev.id!=0X9341)lcddev.id=0x9341;//用于识别9341
}
if(lcddev.id==0X9341) {
LCD_WR_REG(0xCF); LCD_WR_DATA(0x00); LCD_WR_DATA(0xC1);
//9341初始化 使用的是扩展模式
36
LCD_WR_DATA(0X30); LCD_WR_REG(0xED); LCD_WR_DATA(0x64); LCD_WR_DATA(0x03); LCD_WR_DATA(0X12); LCD_WR_DATA(0X81); LCD_WR_REG(0xE8); LCD_WR_DATA(0x85); LCD_WR_DATA(0x10); LCD_WR_DATA(0x7A); LCD_WR_REG(0xCB); LCD_WR_DATA(0x39); LCD_WR_DATA(0x2C); LCD_WR_DATA(0x00); LCD_WR_DATA(0x34); LCD_WR_DATA(0x02); LCD_WR_REG(0xF7); LCD_WR_DATA(0x20); LCD_WR_REG(0xEA); LCD_WR_DATA(0x00); LCD_WR_DATA(0x00);
LCD_WR_REG(0xC0); //Power control LCD_WR_DATA(0x1B); //VRH[5:0] LCD_WR_REG(0xC1); //Power control LCD_WR_DATA(0x01); //SAP[2:0];BT[3:0] LCD_WR_REG(0xC5); //VCM control LCD_WR_DATA(0x30); //3F
37
LCD_WR_DATA(0x30); //3C
LCD_WR_REG(0xC7); //VCM control2 LCD_WR_DATA(0XB7);
LCD_WR_REG(0x36); // Memory Access Control LCD_WR_DATA(0x48); LCD_WR_REG(0x3A); LCD_WR_DATA(0x55); LCD_WR_REG(0xB1); LCD_WR_DATA(0x00); LCD_WR_DATA(0x1A); LCD_WR_REG(0xB6); // Display Function Control LCD_WR_DATA(0x0A); LCD_WR_DATA(0xA2); LCD_WR_REG(0xF2); // 3Gamma Function Disable LCD_WR_DATA(0x00); LCD_WR_REG(0x26); //Gamma curve selected LCD_WR_DATA(0x01); LCD_WR_REG(0xE0); //Set Gamma LCD_WR_DATA(0x0F); LCD_WR_DATA(0x2A); LCD_WR_DATA(0x28); LCD_WR_DATA(0x08); LCD_WR_DATA(0x0E); LCD_WR_DATA(0x08); LCD_WR_DATA(0x54); LCD_WR_DATA(0XA9); LCD_WR_DATA(0x43);
38