|
STM32F103VET接5V 240*128液晶 T6963控制器,现在屏上有显示,但是乱码。FSMC配置为8位数据宽度SRAM模式,数据地址非复用。NE1为片选,FSMC的A16为命令(状态)数据选择口线。所以我对写命令(读状态)地址:*((__IO uint8_t *)((uint32_t)0x60020001)) // 命令 A16=1(C/D=1) 。读写数据地址:*((__IO uint8_t *)((uint32_t)0x60000001)) // 数据 A16=0(C/D=0)。
程序如下,请大家给指点一下。
// PD.4 → NOE(RD)
// PD.5 → NWE(WE)
// PD.7 → NE1(CS)
// PD.11 → A16(C/D)
// PD.14 → D0
// PD.15 → D1
// PD.0 → D2
// PD.1 → D3
// PE.7 → D4
// PE.8 → D5
// PE.9 → D6
// PE.10 → D7
void SMC_LCD_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | 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_OD; //设置为漏开
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 // PD.0 → D2
| GPIO_Pin_1 // PD.1 → D3
| GPIO_Pin_4 // PD.4 → NOE(RD)
| GPIO_Pin_5 // PD.5 → NWE(WE)
| GPIO_Pin_7 // PD.7 → NE1(CS)
| GPIO_Pin_11 // PD.11 → A16(C/D)
| GPIO_Pin_14 // PD.14 → D0
| GPIO_Pin_15; // PD.15 → D1
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 // PE.1 → RST
| 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);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;//选择NE1
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //地址数据非复用
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//SRAM
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;//数据宽度8位
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_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 2; // ADDSET
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime = 2; // ADDHOLD
FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime = 7; // DATAST
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration = 1; // BUSTURN
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 1; // CLKDIV
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency = 2; // 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_NORSRAM1, ENABLE);
}
#define Lcd_Cmd_Reg *((__IO uint8_t *)((uint32_t)0x60020001)) // 命令 状态 C/D(A16)=1
#define Lcd_Data_Reg *((__IO uint8_t *)((uint32_t)0x60000001)) //数据 C/D(A16)=0
//写无参数指令代码
__inline void lcdwc(uint8_t cmdcode)
{
while((Lcd_Cmd_Reg&0x3)!=0x3); //当Lcd_Cmd_Reg低两位不同时为1
Lcd_Cmd_Reg=cmdcode;//写命令字
}
//写双参数指令代码
__inline void lcdwc3(uint8_t cmdcode,uint8_t cmddata,uint8_t cmddata2)
{
while((Lcd_Cmd_Reg&0x3)!=0x3);
Lcd_Data_Reg=cmddata;
while((Lcd_Cmd_Reg&0x3)!=0x3);
Lcd_Data_Reg=cmddata2;
while((Lcd_Cmd_Reg&0x3)!=0x3);
Lcd_Cmd_Reg=cmdcode;
}
//写数据
__inline void lcdwd(uint8_t dispdata)
{
while((Lcd_Cmd_Reg&0x3)!=0x3);
Lcd_Data_Reg=dispdata;
while((Lcd_Cmd_Reg&0x3)!=0x3);
Lcd_Cmd_Reg = LC_UNCHANGED_WR;
}
//读数据
__inline uint8_t lcdrdata(void)
{
uint8_t tmp;
while((Lcd_Cmd_Reg&0x3)!=0x3);
Lcd_Cmd_Reg = LC_UNCHANGED_RD;
while((Lcd_Cmd_Reg&0x3)!=0x3);
tmp = Lcd_Data_Reg;
return tmp;
}
|
|