新手上路
- 积分
- 21
- 金钱
- 21
- 注册时间
- 2021-5-21
- 在线时间
- 3 小时
|
1金钱
static void ILI9806G_GPIO_Config ( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 使能FSMC对应相应管脚时钟*/
RCC_AHB1PeriphClockCmd (
/*控制信号*/
ILI9806G_CS_CLK|ILI9806G_DC_CLK|ILI9806G_WR_CLK|
ILI9806G_RD_CLK |ILI9806G_BK_CLK|
/*数据信号*/
ILI9806G_D0_CLK|ILI9806G_D1_CLK| ILI9806G_D2_CLK |
ILI9806G_D3_CLK | ILI9806G_D4_CLK|ILI9806G_D5_CLK|
ILI9806G_D6_CLK | ILI9806G_D7_CLK|ILI9806G_D8_CLK|
ILI9806G_D9_CLK | ILI9806G_D10_CLK|ILI9806G_D11_CLK|
ILI9806G_D12_CLK | ILI9806G_D13_CLK|ILI9806G_D14_CLK|
ILI9806G_D15_CLK , ENABLE );
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
/* 配置FSMC相对应的数据线,FSMC-D0~D15 */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = ILI9806G_D0_PIN;
GPIO_Init(ILI9806G_D0_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D0_PORT,ILI9806G_D0_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D1_PIN;
GPIO_Init(ILI9806G_D1_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D1_PORT,ILI9806G_D1_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D2_PIN;
GPIO_Init(ILI9806G_D2_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D2_PORT,ILI9806G_D2_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D3_PIN;
GPIO_Init(ILI9806G_D3_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D3_PORT,ILI9806G_D3_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D4_PIN;
GPIO_Init(ILI9806G_D4_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D4_PORT,ILI9806G_D4_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D5_PIN;
GPIO_Init(ILI9806G_D5_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D5_PORT,ILI9806G_D5_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D6_PIN;
GPIO_Init(ILI9806G_D6_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D6_PORT,ILI9806G_D6_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D7_PIN;
GPIO_Init(ILI9806G_D7_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D7_PORT,ILI9806G_D7_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D8_PIN;
GPIO_Init(ILI9806G_D8_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D8_PORT,ILI9806G_D8_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D9_PIN;
GPIO_Init(ILI9806G_D9_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D9_PORT,ILI9806G_D9_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D10_PIN;
GPIO_Init(ILI9806G_D10_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D10_PORT,ILI9806G_D10_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D11_PIN;
GPIO_Init(ILI9806G_D11_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D11_PORT,ILI9806G_D11_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D12_PIN;
GPIO_Init(ILI9806G_D12_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D12_PORT,ILI9806G_D12_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D13_PIN;
GPIO_Init(ILI9806G_D13_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D13_PORT,ILI9806G_D13_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D14_PIN;
GPIO_Init(ILI9806G_D14_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D14_PORT,ILI9806G_D14_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_D15_PIN;
GPIO_Init(ILI9806G_D15_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_D15_PORT,ILI9806G_D15_PinSource,FSMC_AF);
/* 配置FSMC相对应的控制线
* FSMC_NOE CD-RD
* FSMC_NWE CD-WR
* FSMC_NE1 CD-CS
* FSMC_A0 CD-DC
*/
GPIO_InitStructure.GPIO_Pin = ILI9806G_RD_PIN;
GPIO_Init(ILI9806G_RD_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_RD_PORT,ILI9806G_RD_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_WR_PIN;
GPIO_Init(ILI9806G_WR_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_WR_PORT,ILI9806G_WR_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_CS_PIN;
GPIO_Init(ILI9806G_CS_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_CS_PORT,ILI9806G_CS_PinSource,FSMC_AF);
GPIO_InitStructure.GPIO_Pin = ILI9806G_DC_PIN;
GPIO_Init(ILI9806G_DC_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ILI9806G_DC_PORT,ILI9806G_DC_PinSource,FSMC_AF);
/* 配置LCD复位RST控制管脚*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/* 配置LCD背光控制管脚BK*/
GPIO_InitStructure.GPIO_Pin = ILI9806G_BK_PIN;
GPIO_Init ( ILI9806G_BK_PORT, & GPIO_InitStructure );
}
void ILI9806G_FSMC_Config(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef readWriteTiming;
FSMC_NORSRAMTimingInitTypeDef writeTiming;
/*使能FSMC外设时钟*/
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
readWriteTiming.FSMC_AddressSetupTime = 0XF; //地址建立时间(ADDSET)为16个HCLK 1/168M=6ns*16=96ns
readWriteTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(ADDHLD)模式A未用到
readWriteTiming.FSMC_DataSetupTime = 60; //数据保存时间为60个HCLK =6*60=360ns
readWriteTiming.FSMC_BusTurnAroundDuration = 0x00;
readWriteTiming.FSMC_CLKDivision = 0x00;
readWriteTiming.FSMC_DataLatency = 0x00;
//选择控制的模式
//模式B,异步NOR FLASH模式,与ILI9806G的8080时序匹配
readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_B;
writeTiming.FSMC_AddressSetupTime =9; //地址建立时间(ADDSET)为9个HCLK =54ns
writeTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(A
writeTiming.FSMC_DataSetupTime = 8; //数据保存时间为6ns*9个HCLK=54ns
writeTiming.FSMC_BusTurnAroundDuration = 0x00;
writeTiming.FSMC_CLKDivision = 0x00;
writeTiming.FSMC_DataLatency = 0x00;
writeTiming.FSMC_AccessMode = FSMC_AccessMode_B;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAMx;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
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_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readWriteTiming;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &writeTiming;
FSMC_NORSRAMInit ( & FSMC_NORSRAMInitStructure );
/* 使能 FSMC_Bank1_NORSRAM3 */
FSMC_NORSRAMCmd ( FSMC_Bank1_NORSRAMx, ENABLE );
}
static void ILI9806G_REG_Config (void)
{
}
__inline void ILI9806G_Write_Cmd ( uint16_t usCmd )
{
* ( __IO uint16_t * ) ( FSMC_Addr_ILI9806G_CMD ) = usCmd;
}
/**
* @brief 向ILI9806G写入数据
* @param usData :要写入的数据
* @retval 无
*/
__inline void ILI9806G_Write_Data ( uint16_t usData )
{
* ( __IO uint16_t * ) ( FSMC_Addr_ILI9806G_DATA ) = usData;
}
__inline uint16_t ILI9806G_Read_Data ( void )
{
return ( * ( __IO uint16_t * ) ( FSMC_Addr_ILI9806G_DATA ) );
}
uint16_t LCD_GET_ID(void)
{
uint16_t id;
ILI9806G_Write_Cmd(0xd3);
ILI9806G_Read_Data();
ILI9806G_Read_Data();
//高位
id |= ILI9806G_Read_Data();
id<<=8;
//低位
id |= ILI9806G_Read_Data();
return id;
}
void ILI9806G_Init ( void )
{
ILI9806G_GPIO_Config ();
ILI9806G_FSMC_Config ();
ILI9806G_REG_Config ();
}
初始化代码如上
我是参考野火改的,程序能跑但是一直都是返回0xffff,不知道哪里出了问题
|
最佳答案
查看完整内容[请看2#楼]
这个是正常的。
你得看下读数据正常不,先看读RAM,比如你依次将lcd的D0~D15接高/低电平,看读出来的数据对不对?
以此辅助分析问题。
|