初级会员
- 积分
- 123
- 金钱
- 123
- 注册时间
- 2019-11-24
- 在线时间
- 44 小时
|
楼主 |
发表于 2022-11-15 18:19:54
|
显示全部楼层
我要把这些函数全部改成寄存器版本,
对照芯片引脚,把端口和程序一一对应出来,
慢慢改成寄存器驱动,LCD控制器是ILI9327。
void TFTLCD_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;//声明一个结构体,名字是GPIO_InitStructure,结构体原型由GPIO_InitTypeDef 确定引脚
//模式
//端口速率
//输出类型
//上下拉选择
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|
RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG, ENABLE);//使能PD,PE,PF,PG时钟
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC); // FSMC_D0-FSMC_D15
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FSMC); //
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC); //FSMC_NOE
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC); //FSMC_NWE
GPIO_PinAFConfig(GPIOF,GPIO_PinSource12,GPIO_AF_FSMC);//FSMC_A6
GPIO_PinAFConfig(GPIOG,GPIO_PinSource12,GPIO_AF_FSMC);//FSMC_NE4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 //FMSC D2+D3+ FMSC NOE
| GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9//FMSC NWE D13+D14
| GPIO_Pin_10 | GPIO_Pin_14| GPIO_Pin_15;//PD0,1,4,5,8,9,10,14,15 D15+D0+D1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 //FMSC D4+D5+D6
| GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12//FMSC D7+D8+D9
| GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;//PE7~15 FMSC D10+D11+D12
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;//PF12,FSMC_A6
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;//PG12,FSMC_NE4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化
}
void TFTLCD_FSMC_Init(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_ReadNORSRAMTiming;
FSMC_NORSRAMTimingInitTypeDef FSMC_WriteNORSRAMTiming;
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);//使能FSMC时钟
FSMC_ReadNORSRAMTiming.FSMC_AddressSetupTime = 0X01; //地址建立时间(ADDSET)为2个HCLK 1/168M=6ns*2=12ns
FSMC_ReadNORSRAMTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(ADDHLD)模式A未用到
FSMC_ReadNORSRAMTiming.FSMC_DataSetupTime = 0x0f; //数据保存时间为16个HCLK 因为液晶驱动IC的读数据的时候,速度不能太快
FSMC_ReadNORSRAMTiming.FSMC_BusTurnAroundDuration = 0x00;
FSMC_ReadNORSRAMTiming.FSMC_CLKDivision = 0x00;
FSMC_ReadNORSRAMTiming.FSMC_DataLatency = 0x00;
FSMC_ReadNORSRAMTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
#ifdef TFTLCD_ILI9488
FSMC_WriteNORSRAMTiming.FSMC_AddressSetupTime =0x03; //地址建立时间(ADDSET)为1个HCLK
FSMC_WriteNORSRAMTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(A
FSMC_WriteNORSRAMTiming.FSMC_DataSetupTime = 0x08; //数据保存时间为6ns*9个HCLK=54ns
FSMC_WriteNORSRAMTiming.FSMC_BusTurnAroundDuration = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_CLKDivision = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_DataLatency = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
#endif
#ifdef TFTLCD_NT35510
FSMC_WriteNORSRAMTiming.FSMC_AddressSetupTime =0x03; //地址建立时间(ADDSET)为1个HCLK
FSMC_WriteNORSRAMTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(A
FSMC_WriteNORSRAMTiming.FSMC_DataSetupTime = 0x02; //数据保存时间为6ns*9个HCLK=54ns
FSMC_WriteNORSRAMTiming.FSMC_BusTurnAroundDuration = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_CLKDivision = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_DataLatency = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
#endif
#ifdef TFTLCD_HX8352C
FSMC_WriteNORSRAMTiming.FSMC_AddressSetupTime =0x10; //地址建立时间(ADDSET)为1个HCLK
FSMC_WriteNORSRAMTiming.FSMC_AddressHoldTime = 0x10; //地址保持时间(A
FSMC_WriteNORSRAMTiming.FSMC_DataSetupTime = 0x18; //数据保存时间为6ns*9个HCLK=54ns
FSMC_WriteNORSRAMTiming.FSMC_BusTurnAroundDuration = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_CLKDivision = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_DataLatency = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
#endif
#ifdef TFTLCD_ILI9327
FSMC_WriteNORSRAMTiming.FSMC_AddressSetupTime =0x10; //地址建立时间(ADDSET)为1个HCLK
FSMC_WriteNORSRAMTiming.FSMC_AddressHoldTime = 0x10; //地址保持时间(A
FSMC_WriteNORSRAMTiming.FSMC_DataSetupTime = 0x18; //数据保存时间为6ns*9个HCLK=54ns
FSMC_WriteNORSRAMTiming.FSMC_BusTurnAroundDuration = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_CLKDivision = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_DataLatency = 0x00;
FSMC_WriteNORSRAMTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A
#endif
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;// 这里我们使用NE4 ,也就对应BTCR[6],[7]。
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; // 不复用数据地址
FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM;// FSMC_MemoryType_SRAM; //SRAM
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//存储器数据宽度为16bit
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable;// FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable;
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_Enable; // 读写使用不同的时序
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_ReadNORSRAMTiming; //读写时序
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_WriteNORSRAMTiming; //写时序
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC配置
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE); // 使能BANK1
}
————————————————
|
|