STM32F407ZGT6? FSMC接口 FSMC A0 PF0 FSMC A1 PF1 FSMC A2 PF2 FSMC A3 PF3 FSMC A4 PF4 FSMC A5 PF5 FSMC A6 PF12 FSMC A7 PF13 FSMC A8 PF14 FSMC A9 PF15 FSMC A10 PG0 FSMC A11 PG1 FSMC A12 PG2 FSMC A13 PG3 FSMC A14 PG4 FSMC A15 PG5 FSMC A16 PD11 FSMC A17 PD12 FSMC A18 PD13 FSMC NBL0 PE0 FSMC NBL1 PE1 FSMC NE3 PG10 FSMC NE4 PG12
FSMC NOE PD4 FSMC NWE PD5 T_CS PC13 T_SCK PB0 T_PEN PB1 T_MOSI PF11 T_MISO PB2 BOOT1
FSMC D0 PD14 FSMC D1 PD15 FSMC D2 PD0 FSMC D3 PD1 FSMC D4 PE7 FSMC D5 PE8 FSMC D6 PE9 FSMC D7 PE10 FSMC D8 PE11 FSMC D9 PE12 FSMC D10 PE13 FSMC D11 PE14 FSMC D12 PE15 FSMC D13 PD8 FSMC D14 PD9 FSMC D15 PD10
************************************************************** tftlcd.H文件
************************************************************** ************************************************************** #ifndef _tftlcd_H #define _tftlcd_H #include "system.h"
//定义LCD彩屏的驱动类型 可根据自己手上的彩屏背面型号来选择打开哪种驱动
//#define TFTLCD_HX8357D //#define TFTLCD_HX8352C
//#define TFTLCD_ILI9488
//#define TFTLCD_ST7793
#define TFTLCD_ILI9327
//#define TFTLCD_NT35510
//TFTLCD地址结构体
typedef struct { u16 LCD_CMD; u16 LCD_DATA; }TFTLCD_TypeDef; //使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A6作为数据命令区分线
//注意设置时STM32内部会右移一位对齐! 111 1110=0X7E #define TFTLCD_BASE ((u32)(0x6C000000 | 0x0000007E)) #define TFTLCD ((TFTLCD_TypeDef *) TFTLCD_BASE) //TFTLCD重要参数集
typedef struct { u16 width;//LCD 宽度 u16 height;//LCD 高度 u16 id;//LCD ID u8 dir; //LCD 方向 }_tftlcd_data; //LCD参数
extern _tftlcd_data tftlcd_data;//管理LCD重要参数 //LCD的前端颜色和背景色 extern u16 FRONT_COLOR;//前端颜色 默认红色 extern u16 BACK_COLOR; //背景颜色.默认为白色 //画笔颜色
#define WHITE 0xFFFF #define BLACK 0x0000 #define BLUE 0x001F #define BRED 0XF81F #define GRED 0XFFE0 #define GBLUE 0X07FF #define RED 0xF800 #define MAGENTA 0xF81F #define GREEN 0x07E0 #define CYAN 0x7FFF #define YELLOW 0xFFE0 #define BROWN 0XBC40 //棕色 #define BRRED 0XFC07 //棕红色 #define GRAY 0X8430 //灰色 void LCD_WriteCmd(u16 cmd);
void LCD_WriteData(u16 data); void LCD_WriteCmdData(u16 cmd,u16 data); void LCD_WriteData_Color(u16 color); void TFTLCD_Init(void); //初始化
void LCD_Set_Window(u16 sx,u16 sy,u16 width,u16 height); void LCD_Clear(u16 Color); //清屏 void LCD_Fill(u16 xState,u16 yState,u16 xEnd,u16 yEnd,u16 color); void LCD_DrawPoint(u16 x,u16 y);//画点 void LCD_DrawFRONT_COLOR(u16 x,u16 y,u16 color); u16 LCD_ReadPoint(u16 x,u16 y); void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2); void LCD_DrawLine_Color(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); void LCD_DrowSign(uint16_t x, uint16_t y, uint16_t color); void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2); void LCD_Draw_Circle(u16 x0,u16 y0,u8 r); void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode); void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size); void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode); void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p); void LCD_ShowFontHZ(u16 x, u16 y, u8 *cn); void LCD_ShowPicture(u16 x, u16 y, u16 wide, u16 high,u8 *pic); #endif
************************************************************** tftlcd.C文件 第一部分 GPIO_Init FSMC_Init ************************************************************** **************************************************************
#include "tftlcd.h" #include "SysTick.h" #include "usart.h" #include "font.h" //LCD的画笔颜色和背景色
u16 FRONT_COLOR=BLACK;//画笔颜色 u16 BACK_COLOR=WHITE; //背景色 _tftlcd_data tftlcd_data;
void TFTLCD_GPIO_Init(void)
{ GPIO_InitTypeDef GPIO_InitStructure;
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 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14| GPIO_Pin_15;//PD0,1,4,5,8,9,10,14,15 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 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;//PE7~15 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
#ifdefTFTLCD_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
#ifdefTFTLCD_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
}
|