目录复制
上电后显示功能界面,5S倒计时,然后就是颜色刷屏测试,接下来是数码管数字1-9显示,中文显示,最后是显示图片。
程序代码
文档资料
SPI通信时序,这个可以参考下,具体以可以查下标准SPI通信时序
以下以32代码为例,
/**************************************************************************** * 名 称:void LCD_GPIO_Init(void) * 功 能:STM32_模拟SPI所用到的GPIO初始化 * 入口参数:无 * 出口参数:无 * 说 明:初始化模拟SPI所用的GPIO ****************************************************************************/ void LCD_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB ,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); }
/**************************************************************************** * 名 称:void SPIv_WriteData(u8 Data) * 功 能:STM32_模拟SPI写一个字节数据底层函数 * 入口参数:Data * 出口参数:无 * 说 明:STM32_模拟SPI读写一个字节数据底层函数 ****************************************************************************/ void SPIv_WriteData(u8 Data) { unsigned char i=0; for(i=8;i>0;i--) { if(Data&0x80) LCD_SDA_SET; //输出数据 else LCD_SDA_CLR; LCD_SCL_CLR; LCD_SCL_SET; Data<<=1; } } /**************************************************************************** * 名 称:Lcd_WriteIndex(u8 Index) * 功 能:向液晶屏写一个8位指令 * 入口参数:Index 寄存器地址 * 出口参数:无 * 说 明:调用前需先选中控制器,内部函数 ****************************************************************************/ void Lcd_WriteIndex(u8 Index) { LCD_CS_CLR; LCD_RS_CLR; #if USE_HARDWARE_SPI SPI_WriteByte(SPI2,Index); #else SPIv_WriteData(Index); #endif LCD_CS_SET; } /**************************************************************************** * 名 称:Lcd_WriteData(u8 Data) * 功 能:向液晶屏写一个8位数据 * 入口参数:dat 寄存器数据 * 出口参数:无 * 说 明:向控制器指定地址写入数据,内部函数 ****************************************************************************/ void Lcd_WriteData(u8 Data) { LCD_CS_CLR; LCD_RS_SET; #if USE_HARDWARE_SPI SPI_WriteByte(SPI2,Data); #else SPIv_WriteData(Data); #endif LCD_CS_SET; } /**************************************************************************** * 名 称:void LCD_WriteReg(u8 Index,u16 Data) * 功 能:写寄存器数据 * 入口参数:Index,Data * 出口参数:无 * 说 明:本函数为组合函数,向Index地址的寄存器写入Data值 ****************************************************************************/ void LCD_WriteReg(u8 Index,u16 Data) { Lcd_WriteIndex(Index); Lcd_WriteData_16Bit(Data); } /**************************************************************************** * 名 称:void Lcd_WriteData_16Bit(u16 Data) * 功 能:向液晶屏写一个16位数据 * 入口参数:Data * 出口参数:无 * 说 明:向控制器指定地址写入一个16位数据 ****************************************************************************/ void Lcd_WriteData_16Bit(u16 Data) { Lcd_WriteData(Data>>8); Lcd_WriteData(Data); } /**************************************************************************** * 名 称:void Lcd_Reset(void) * 功 能:液晶硬复位函数 * 入口参数:无 * 出口参数:无 * 说 明:液晶初始化前需执行一次复位操作 ****************************************************************************/ void Lcd_Reset(void) { LCD_RST_CLR; DelayMs(100); LCD_RST_SET; DelayMs(50); }
/**************************************************************************** * 名 称:void Lcd_Init(void) * 功 能:液晶初始化函数 * 入口参数:无 * 出口参数:无 * 说 明:液晶初始化_ILI9225_176X220 ****************************************************************************/ void Lcd_Init(void) { #if USE_HARDWARE_SPI //使用硬件SPI SPI2_Init(); #else LCD_GPIO_Init();//使用模拟SPI #endif Lcd_Reset(); //Reset before LCD Init. //LCD Init For 2.2inch LCD Panel with ILI9225. LCD_WriteReg(0x10, 0x0000); // Set SAP,DSTB,STB LCD_WriteReg(0x11, 0x0000); // Set APON,PON,AON,VCI1EN,VC LCD_WriteReg(0x12, 0x0000); // Set BT,DC1,DC2,DC3 LCD_WriteReg(0x13, 0x0000); // Set GVDD LCD_WriteReg(0x14, 0x0000); // Set VCOMH/VCOML voltage DelayMs(40); // Delay 20 ms // Please follow this power on sequence LCD_WriteReg(0x11, 0x0018); // Set APON,PON,AON,VCI1EN,VC LCD_WriteReg(0x12, 0x1121); // Set BT,DC1,DC2,DC3 LCD_WriteReg(0x13, 0x0063); // Set GVDD LCD_WriteReg(0x14, 0x3961); // Set VCOMH/VCOML voltage LCD_WriteReg(0x10, 0x0800); // Set SAP,DSTB,STB DelayMs(10); // Delay 10 ms LCD_WriteReg(0x11, 0x1038); // Set APON,PON,AON,VCI1EN,VC DelayMs(30); // Delay 30 ms LCD_WriteReg(0x02, 0x0100); // set 1 line inversion #if USE_HORIZONTAL//如果定义了横屏 //R01H:SM=0,GS=0,SS=0 (for details,See the datasheet of ILI9225) LCD_WriteReg(0x01, 0x001C); // set the display line number and display direction //R03H:BGR=1,ID0=1,ID1=1,AM=1 (for details,See the datasheet of ILI9225) LCD_WriteReg(0x03, 0x1038); // set GRAM write direction . #else//竖屏 //R01H:SM=0,GS=0,SS=1 (for details,See the datasheet of ILI9225) LCD_WriteReg(0x01, 0x011C); // set the display line number and display direction //R03H:BGR=1,ID0=1,ID1=1,AM=0 (for details,See the datasheet of ILI9225) LCD_WriteReg(0x03, 0x1030); // set GRAM write direction. #endif LCD_WriteReg(0x07, 0x0000); // Display off LCD_WriteReg(0x08, 0x0808); // set the back porch and front porch LCD_WriteReg(0x0B, 0x1100); // set the clocks number per line LCD_WriteReg(0x0C, 0x0000); // CPU interface LCD_WriteReg(0x0F, 0x0501); // Set Osc LCD_WriteReg(0x15, 0x0020); // Set VCI recycling LCD_WriteReg(0x20, 0x0000); // RAM Address LCD_WriteReg(0x21, 0x0000); // RAM Address //------------------------ Set GRAM area --------------------------------// LCD_WriteReg(0x30, 0x0000); LCD_WriteReg(0x31, 0x00DB); LCD_WriteReg(0x32, 0x0000); LCD_WriteReg(0x33, 0x0000); LCD_WriteReg(0x34, 0x00DB); LCD_WriteReg(0x35, 0x0000); LCD_WriteReg(0x36, 0x00AF); LCD_WriteReg(0x37, 0x0000); LCD_WriteReg(0x38, 0x00DB); LCD_WriteReg(0x39, 0x0000); // ---------- Adjust the Gamma 2.2 Curve -------------------// LCD_WriteReg(0x50, 0x0603); LCD_WriteReg(0x51, 0x080D); LCD_WriteReg(0x52, 0x0D0C); LCD_WriteReg(0x53, 0x0205); LCD_WriteReg(0x54, 0x040A); LCD_WriteReg(0x55, 0x0703); LCD_WriteReg(0x56, 0x0300); LCD_WriteReg(0x57, 0x0400); LCD_WriteReg(0x58, 0x0B00); LCD_WriteReg(0x59, 0x0017); LCD_WriteReg(0x0F, 0x0701); // Vertical RAM Address Position LCD_WriteReg(0x07, 0x0012); // Vertical RAM Address Position DelayMs(50); // Delay 50 ms LCD_WriteReg(0x07, 0x1017); // Vertical RAM Address Position }
/************************************************* 函数名:LCD_Set_XY 功能:设置lcd显示起始点 入口参数:xy坐标 返回值:无 *************************************************/ void Lcd_SetXY(u16 Xpos, u16 Ypos) { #if USE_HORIZONTAL//如果定义了横屏 LCD_WriteReg(0x21,Xpos); LCD_WriteReg(0x20,Ypos); #else//竖屏 LCD_WriteReg(0x20,Xpos); LCD_WriteReg(0x21,Ypos); #endif Lcd_WriteIndex(0x22); } /************************************************* 函数名:LCD_Set_Region 功能:设置lcd显示区域,在此区域写点数据自动换行 入口参数:xy起点和终点 返回值:无 *************************************************/ //设置显示窗口 void Lcd_SetRegion(u8 xStar, u8 yStar,u8 xEnd,u8 yEnd) { #if USE_HORIZONTAL//如果定义了横屏 LCD_WriteReg(0x38,xEnd); LCD_WriteReg(0x39,xStar); LCD_WriteReg(0x36,yEnd); LCD_WriteReg(0x37,yStar); LCD_WriteReg(0x21,xStar); LCD_WriteReg(0x20,yStar); #else//竖屏 LCD_WriteReg(0x36,xEnd); LCD_WriteReg(0x37,xStar); LCD_WriteReg(0x38,yEnd); LCD_WriteReg(0x39,yStar); LCD_WriteReg(0x20,xStar); LCD_WriteReg(0x21,yStar); #endif Lcd_WriteIndex(0x22); } /************************************************* 函数名:LCD_DrawPoint 功能:画一个点 入口参数:xy坐标和颜色数据 返回值:无 *************************************************/ void Gui_DrawPoint(u16 x,u16 y,u16 Data) { Lcd_SetXY(x,y); Lcd_WriteData_16Bit(Data); } /************************************************* 函数名:Lcd_Clear 功能:全屏清屏函数 入口参数:填充颜色COLOR 返回值:无 *************************************************/ void Lcd_Clear(u16 Color) { unsigned int i,m; Lcd_SetRegion(0,0,X_MAX_PIXEL-1,Y_MAX_PIXEL-1); for(i=0;i<X_MAX_PIXEL;i++) for(m=0;m<Y_MAX_PIXEL;m++) { Lcd_WriteData_16Bit(Color); } }
GUI函数太多这里就不发出来了,需要可看资料获取
int main(void) { SystemInit(); //System init. DelayInit();//Delay init. Lcd_Init(); while(1) { QDTFT_Test_Demo(); //See the test details in QDTFT_Demo.c } }
文字提取:
图形提取
加群私聊群主可免费获得,也可加群学习交流 群号:1041406448