本帖最后由 ligping 于 2012-6-8 00:13 编辑
各位大侠、哥哥姐姐好。小弟最近在调液晶HX8347D(2.8寸)的驱动,用STM32的FSMC外部扩展口跟LCD相连,接口如下:
LCD接口 STM32的I/O口
D0~D1 ----------------- PD14~PD15
D2~D3-------------------PD0~PD1
D4~D12-----------------PE7~PE15
D13~D15----------------PD8~PD10
RS -------------------PD11(FSMC_A16)
CS--------------------PD7(NE1)
RST------------------PD13
WR------------------PD5(NWE)
RD-------------------PD4(NOE)
程序如下:
#define LCD_REG *((__IO u16 *)0x60000000) //寄存器
#define LCD_RAM *((__IO u16 *)0x60020000) //数据C/D(A16)
/*---------------------- Graphic LCD size definitions ------------------------*/
#define WIDTH 240 /* Screen Width (in pixels)*/
#define HEIGHT 320 / * Screen Hight (in pixels)*/
#define LCD_RstHigh() GPIO_WriteBit(GPIOD, GPIO_Pin_13, Bit_SET)
#define LCD_RstLow() GPIO_WriteBit(GPIOD, GPIO_Pin_13, Bit_RESET)
void LCD_WriteReg (u16 reg, u16 val)
{
LCD_REG=reg;
LCD_RAM=val;
}
u16 LCD_ReadReg (u16 reg)
{
LCD_REG=reg;
reg = LCD_RAM;
return reg;
}
void LCD_BSP_Init(void)
{
GPIO_InitTypeDef
GPIO_InitStructure;
TIM_TimeBaseInitTypeDef
TIM_TimeBaseStructure;
TIM_OCInitTypeDef
TIM_OCInitStructure;
RCC_ClocksTypeDef
RCC_ClocksStatus;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode
= GPIO_Mode_AF_PP;
// 设置为Alternate function push-pull
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_8// PD.8→D13
| GPIO_Pin_9// PD.9→D14
| GPIO_Pin_10// PD.10→D15
| GPIO_Pin_11// PD.11→A16(RS)
| GPIO_Pin_14// PD.14→D0
| GPIO_Pin_15;// PD.15→D1
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin= 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_Pin_11// PE.10→D8
| GPIO_Pin_12// PE.10→D9
| GPIO_Pin_13// PE.10→D10
| GPIO_Pin_14// PE.10→D11
| GPIO_Pin_15;// PE.10→D12
GPIO_Init(GPIOE, &GPIO_InitStructure);
/ /* Set PD3(BLCD ) ,PD13(LCD_RST)as alternate function push pull
*/
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3|GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* Configure the FSMC Parallel interface -------------------------------------*/
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_16b;
//数据宽度16位
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= 0;// ADDSET
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime= 0;// ADDHOLD
FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime= 1;// DATAST
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration = 0;// BUSTURN
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision= 1;// CLKDIV
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency= 0;// DATLAT
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_B;// ACCMOD
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* Enable FSMC_Bank1_NORSRAM1 */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
void LCD_OSL_Init(void)
{
// 复位LCD
LCD_RstHigh();
LCD_Delayms(100);
LCD_RstLow();
LCD_Delayms(100);
LCD_RstHigh();
OSTimeDlyHMSM (0, 0, 0, 100);
//Driving ability Setting
LCD_WriteReg(0xEA,0x00);
LCD_WriteReg(0xEB,0x20);
LCD_WriteReg(0xEC,0x0C);
LCD_WriteReg(0xED,0xC4);
LCD_WriteReg(0xE8,0x40);
LCD_WriteReg(0xE9,0x38);
LCD_WriteReg(0xF1,0x01);
LCD_WriteReg(0xF2,0x10);
LCD_WriteReg(0x27,0xA3);
//Gamma setting
LCD_WriteReg(0x40,0x01);
LCD_WriteReg(0x41,0x00);
LCD_WriteReg(0x42,0x00);
LCD_WriteReg(0x43,0x10);
LCD_WriteReg(0x44,0x0E);
LCD_WriteReg(0x45,0x24);
LCD_WriteReg(0x46,0x04);
LCD_WriteReg(0x47,0x50);
LCD_WriteReg(0x48,0x02);
LCD_WriteReg(0x49,0x13);
LCD_WriteReg(0x4A,0x19);
LCD_WriteReg(0x4B,0x19);
LCD_WriteReg(0x4C,0x16);
LCD_WriteReg(0x50,0x1B);
LCD_WriteReg(0x51,0x31);
LCD_WriteReg(0x52,0x2F);
LCD_WriteReg(0x53,0x3F);
LCD_WriteReg(0x54,0x3F);
LCD_WriteReg(0x55,0x3E);
LCD_WriteReg(0x56,0x2F);
LCD_WriteReg(0x57,0x7B);
LCD_WriteReg(0x58,0x09);
LCD_WriteReg(0x59,0x06);
LCD_WriteReg(0x5A,0x06);
LCD_WriteReg(0x5B,0x0C);
LCD_WriteReg(0x5C,0x1D);
LCD_WriteReg(0x5D,0xCC);
// ----------- Power Voltage Setting ----------//
LCD_WriteReg(0x1B,0x18);
LCD_WriteReg(0x1A,0x01);
LCD_WriteReg(0x24,0x15);
LCD_WriteReg(0x25,0x50);
LCD_WriteReg(0x23,0x8B);
LCD_WriteReg(0x18,0x36);
LCD_WriteReg(0x19,0x01);
LCD_WriteReg(0x01,0x00);
LCD_WriteReg(0x1F,0x88);
LCD_Delayms(5);
LCD_WriteReg(0x1F,0x80);
LCD_Delayms(5);
LCD_WriteReg(0x1F,0x90);
LCD_Delayms(5);
LCD_WriteReg(0x1F,0xD0);
LCD_Delayms(5);
LCD_WriteReg(0x17,0x05);
LCD_WriteReg(0x36,0x00);
LCD_WriteReg(0x28,0x38);
LCD_Delayms(40);
LCD_WriteReg(0x28,0x3C);
//------------------ Set GRAM area ---------------//
LCD_WriteReg(0x02,0x00);
LCD_WriteReg(0x03,0x00);
LCD_WriteReg(0x04,0x00);
LCD_WriteReg(0x05,0xEF);
LCD_WriteReg(0x06,0x00);
LCD_WriteReg(0x07,0x00);
LCD_WriteReg(0x08,0x01);
LCD_WriteReg(0x09,0x3F);
LCD_WriteReg(0x22,0x00);
} |
|