下面是自己的接线,用的 TFT 芯片驱动型号是 :ILI9341
fmc 接口
FMC_D15——>PD10
FMC_D14——>PD9
FMC_D13——>PD8
FMC_D12——>PE15
FMC_D11——>PE14
FMC_D10——>PE13
FMC_D9 ——>PE12
FMC_D8 ——>PE11
FMC_D7 ——>PE10
FMC_D6 ——>PE9
FMC_D5 ——>PE8
FMC_D4 ——>PE7
FMC_D3 ——>PD1
FMC_D2 ——>PD0
FMC_D1 ——>PD15
FMC_D0 ——>PD14
LCD(背光)---->PB5
LCD_CS——>FMC_NE4
LCD_RS——>FMC_A21(这里A21作为数据命令区分线,在16位数据总线时STM32内部地址会右移一位对齐
FMC的好像跟F429的也差不多。下面是初始化
//初始化lcd
void LCD_Init(void)
{
GPIO_InitTypeDef GPIO_Initure;
FMC_NORSRAM_TimingTypeDef FMC_ReadWriteTim;
FMC_NORSRAM_TimingTypeDef FMC_WriteTim;
__HAL_RCC_GPIOB_CLK_ENABLE(); //开启GPIOB时钟
GPIO_Initure.Pin=GPIO_PIN_5|GPIO_PIN_6; //PB5,背光控制
GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP; //推挽输出
GPIO_Initure.Pull=GPIO_PULLUP; //上拉
GPIO_Initure.Speed=GPIO_SPEED_HIGH; //高速
HAL_GPIO_Init(GPIOB,&GPIO_Initure);
SRAM_Handler.Instance=FMC_NORSRAM_DEVICE;
SRAM_Handler.Extended=FMC_NORSRAM_EXTENDED_DEVICE;
SRAM_Handler.Init.NSBank=FMC_NORSRAM_BANK1; //使用NE1
SRAM_Handler.Init.DataAddressMux=FMC_DATA_ADDRESS_MUX_DISABLE; //地址/数据线不复用
SRAM_Handler.Init.MemoryType=FMC_MEMORY_TYPE_SRAM; //SRAM
SRAM_Handler.Init.MemoryDataWidth=FMC_NORSRAM_MEM_BUS_WIDTH_16; //16位数据宽度
SRAM_Handler.Init.BurstAccessMode=FMC_BURST_ACCESS_MODE_DISABLE; //是否使能突发访问,仅对同步突发存储器有效,此处未用到
SRAM_Handler.Init.WaitSignalPolarity=FMC_WAIT_SIGNAL_POLARITY_LOW;//等待信号的极性,仅在突发模式访问下有用
SRAM_Handler.Init.WaitSignalActive=FMC_WAIT_TIMING_BEFORE_WS; //存储器是在等待周期之前的一个时钟周期还是等待周期期间使能NWAIT
SRAM_Handler.Init.WriteOperation=FMC_WRITE_OPERATION_ENABLE; //存储器写使能
SRAM_Handler.Init.WaitSignal=FMC_WAIT_SIGNAL_DISABLE; //等待使能位,此处未用到
SRAM_Handler.Init.ExtendedMode=FMC_EXTENDED_MODE_ENABLE; //读写使用不同的时序
SRAM_Handler.Init.AsynchronousWait=FMC_ASYNCHRONOUS_WAIT_DISABLE;//是否使能同步传输模式下的等待信号,此处未用到
SRAM_Handler.Init.WriteBurst=FMC_WRITE_BURST_DISABLE; //禁止突发写
SRAM_Handler.Init.ContinuousClock=FMC_CONTINUOUS_CLOCK_SYNC_ASYNC;
SRAM_Handler.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
SRAM_Handler.Init.PageSize = FMC_PAGE_SIZE_NONE;
// //FMC读时序控制寄存器
FMC_ReadWriteTim.AddressSetupTime=15; //地址建立时间(ADDSET)为15个HCLK 1/216M*15=4.6ns*15
FMC_ReadWriteTim.AddressHoldTime=15;
FMC_ReadWriteTim.DataSetupTime=255; //数据保存时间(DATAST)为255个HCLK =4.6*255
FMC_ReadWriteTim.BusTurnAroundDuration = 15;
FMC_ReadWriteTim.CLKDivision=16;
FMC_ReadWriteTim.DataLatency =17;
FMC_ReadWriteTim.AccessMode=FMC_ACCESS_MODE_A; //模式A
//FMC写时序控制寄存器
FMC_WriteTim.AddressSetupTime=15; //地址建立时间(ADDSET)为17个HCLK=82.5ns
FMC_WriteTim.AddressHoldTime=15;
FMC_WriteTim.DataSetupTime=255; //数据保存时间(DATAST)为5.5ns*17个HCLK=82.5ns
FMC_WriteTim.BusTurnAroundDuration = 15;
FMC_WriteTim.CLKDivision=16;
FMC_WriteTim.DataLatency =17;
FMC_WriteTim.AccessMode=FMC_ACCESS_MODE_A; //模式A
HAL_SRAM_Init(&SRAM_Handler,&FMC_ReadWriteTim,&FMC_WriteTim);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_RESET); //RST
delay_ms(100); // delay 50 ms
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_SET); //RST
delay_ms(50);
delay_ms(50); // delay 50 ms
//尝试9341 ID的读取
LCD_WR_REG(0XD3);
lcddev.id=LCD_RD_DATA(); //dummy read
lcddev.id=LCD_RD_DATA(); //读到0X00
lcddev.id=LCD_RD_DATA(); //读取93
lcddev.id<<=8;
lcddev.id|=LCD_RD_DATA(); //读取41
LCD_WR_REG(0xCF);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0xC1);
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
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);
LCD_WR_DATA(0x0A);
LCD_WR_DATA(0x0F);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_REG(0XE1); //Set Gamma
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x15);
LCD_WR_DATA(0x17);
LCD_WR_DATA(0x07);
LCD_WR_DATA(0x11);
LCD_WR_DATA(0x06);
LCD_WR_DATA(0x2B);
LCD_WR_DATA(0x56);
LCD_WR_DATA(0x3C);
LCD_WR_DATA(0x05);
LCD_WR_DATA(0x10);
LCD_WR_DATA(0x0F);
LCD_WR_DATA(0x3F);
LCD_WR_DATA(0x3F);
LCD_WR_DATA(0x0F);
LCD_WR_REG(0x2B);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x3f);
LCD_WR_REG(0x2A);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0xef);
LCD_WR_REG(0x11); //Exit Sleep
delay_ms(120);
LCD_WR_REG(0x29); //display on
//初始化完成以后,提速
//重新配置写时序控制寄存器的时序
FMC_Bank1E->BWTR[0]&=~(0XF<<0); //地址建立时间(ADDSET)清零
FMC_Bank1E->BWTR[0]&=~(0XF<<8); //数据保存时间清零
FMC_Bank1E->BWTR[0]|=4<<0; //地址建立时间(ADDSET)为4个HCLK =21ns
FMC_Bank1E->BWTR[0]|=4<<8; //数据保存时间(DATAST)为5.2ns*4个HCLK=21ns
LCD_Display_Dir(0); //默认为竖屏
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_SET); //PB5点亮背光
LCD_Clear(WHITE);
}
程序太多了~~
竟然说超过字数了~~~ |