- #include "stm32f10x.h"
- #include "Lcd_Driver.h"
- #include "delay.h"
- /***************************************************************************************
- STM32测试平台介绍:
- 开发板:正点原子MiniSTM32开发板
- MCU :STM32_F103_RBT6
- 晶振 :12MHZ
- 主频 :72MHZ
- 接线说明:
- //-------------------------------------------------------------------------------------
- #define LCD_CTRL GPIOB //定义TFT数据端口
- #define LCD_LED GPIO_Pin_9 //PB9 连接至TFT -LED
- #define LCD_RS GPIO_Pin_10 //PB10连接至TFT --RS
- #define LCD_CS GPIO_Pin_11 //PB11 连接至TFT --CS
- #define LCD_RST GPIO_Pin_12 //PB12连接至TFT --RST
- #define LCD_SCL GPIO_Pin_13 //PB13连接至TFT -- CLK
- #define LCD_SDA GPIO_Pin_15 //PB15连接至TFT - SDI
- //VCC:可以接5V也可以接3.3V
- //LED:可以接5V也可以接3.3V或者使用任意空闲IO控制(高电平使能)
- //GND:接电源地
- //说明:如需要尽可能少占用IO,可以将LCD_CS接地,LCD_LED接3.3V,LCD_RST接至单片机复位端,
- //将可以释放3个可用IO
- //接口定义在Lcd_Driver.h内定义,
- //如需变更IO接法,请根据您的实际接线修改相应IO初始化LCD_GPIO_Init()
- //-----------------------------------------------------------------------------------------
- 例程功能说明:
- 1. 简单刷屏测试
- 2. 英文显示测试示例
- 3. 中文显示测试示例
- 4. 数码管字体显示示例
- 5. 图片显示示例
- 6. 2D按键菜单示例
- 7. 本例程支持横屏/竖屏切换(开启宏USE_HORIZONTAL,详见Lcd_Driver.h)
- 8. 本例程支持软件模拟SPI/硬件SPI切换(开启宏USE_HARDWARE_SPI,详见Lcd_Driver.h)
- **********************************************************************************************/
- //---------------------------------function----------------------------------------------------//
- /****************************************************************************
- * 名 称: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;
- }
- }
- /****************************************************************************
- * 名 称:u8 SPI_WriteByte(SPI_TypeDef* SPIx,u8 Byte)
- * 功 能:STM32_硬件SPI读写一个字节数据底层函数
- * 入口参数:SPIx,Byte
- * 出口参数:返回总线收到的数据
- * 说 明:STM32_硬件SPI读写一个字节数据底层函数
- ****************************************************************************/
- u8 SPI_WriteByte(SPI_TypeDef* SPIx,u8 Byte)
- {
- while((SPIx->SR&SPI_I2S_FLAG_TXE)==RESET); //等待发送区空
- SPIx->DR=Byte; //发送一个byte
- while((SPIx->SR&SPI_I2S_FLAG_RXNE)==RESET);//等待接收完一个byte
- return SPIx->DR; //返回收到的数据
- }
- /****************************************************************************
- * 名 称:void SPI_SetSpeed(SPI_TypeDef* SPIx,u8 SpeedSet)
- * 功 能:设置SPI的速度
- * 入口参数:SPIx,SpeedSet
- * 出口参数:无
- * 说 明:SpeedSet:1,高速;0,低速;
- ****************************************************************************/
- void SPI_SetSpeed(SPI_TypeDef* SPIx,u8 SpeedSet)
- {
- SPIx->CR1&=0XFFC7;
- if(SpeedSet==1)//高速
- {
- SPIx->CR1|=SPI_BaudRatePrescaler_2;//Fsck=Fpclk/2
- }
- else//低速
- {
- SPIx->CR1|=SPI_BaudRatePrescaler_32; //Fsck=Fpclk/32
- }
- SPIx->CR1|=1<<6; //SPI设备使能
- }
- /****************************************************************************
- * 名 称:SPI2_Init(void)
- * 功 能:STM32_SPI2硬件配置初始化
- * 入口参数:无
- * 出口参数:无
- * 说 明:STM32_SPI2硬件配置初始化
- ****************************************************************************/
- void SPI2_Init(void)
- {
- SPI_InitTypeDef SPI_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
-
- //配置SPI2管脚
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- //SPI2配置选项
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 ,ENABLE);
-
- SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
- SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
- SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
- SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
- SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
- SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
- SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
- SPI_InitStructure.SPI_CRCPolynomial = 7;
- SPI_Init(SPI2, &SPI_InitStructure);
- //使能SPI2
- SPI_Cmd(SPI2, ENABLE);
- }
- /****************************************************************************
- * 名 称: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;
- delay_ms(100);
- LCD_RST_SET;
- delay_ms(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_WriteIndex(0xCB);
- Lcd_WriteData(0x39);
- Lcd_WriteData(0x2C);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x34);
- Lcd_WriteData(0x02);
- Lcd_WriteIndex(0xCF);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0XC1);
- Lcd_WriteData(0X30);
- Lcd_WriteIndex(0xE8);
- Lcd_WriteData(0x85);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x78);
- Lcd_WriteIndex(0xEA);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x00);
- Lcd_WriteIndex(0xED);
- Lcd_WriteData(0x64);
- Lcd_WriteData(0x03);
- Lcd_WriteData(0X12);
- Lcd_WriteData(0X81);
- Lcd_WriteIndex(0xF7);
- Lcd_WriteData(0x20);
- Lcd_WriteIndex(0xC0); //Power control
- Lcd_WriteData(0x23); //VRH[5:0]
- Lcd_WriteIndex(0xC1); //Power control
- Lcd_WriteData(0x10); //SAP[2:0];BT[3:0]
- Lcd_WriteIndex(0xC5); //VCM control
- Lcd_WriteData(0x3e); //对比度调节
- Lcd_WriteData(0x28);
- Lcd_WriteIndex(0xC7); //VCM control2
- Lcd_WriteData(0x86); //--
- Lcd_WriteIndex(0x36); // Memory Access Control
- #ifdef USE_HORIZONTAL
- Lcd_WriteData(0xE8); //C8 //48 68竖屏//28 E8 横屏
- #else
- Lcd_WriteData(0x48);
- #endif
- Lcd_WriteIndex(0x3A);
- Lcd_WriteData(0x55);
- Lcd_WriteIndex(0xB1);
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x18);
- Lcd_WriteIndex(0xB6); // Display Function Control
- Lcd_WriteData(0x08);
- Lcd_WriteData(0x82);
- Lcd_WriteData(0x27);
- Lcd_WriteIndex(0xF2); // 3Gamma Function Disable
- Lcd_WriteData(0x00);
- Lcd_WriteIndex(0x26); //Gamma curve selected
- Lcd_WriteData(0x01);
- Lcd_WriteIndex(0xE0); //Set Gamma
- Lcd_WriteData(0x0F);
- Lcd_WriteData(0x31);
- Lcd_WriteData(0x2B);
- Lcd_WriteData(0x0C);
- Lcd_WriteData(0x0E);
- Lcd_WriteData(0x08);
- Lcd_WriteData(0x4E);
- Lcd_WriteData(0xF1);
- Lcd_WriteData(0x37);
- Lcd_WriteData(0x07);
- Lcd_WriteData(0x10);
- Lcd_WriteData(0x03);
- Lcd_WriteData(0x0E);
- Lcd_WriteData(0x09);
- Lcd_WriteData(0x00);
- Lcd_WriteIndex(0XE1); //Set Gamma
- Lcd_WriteData(0x00);
- Lcd_WriteData(0x0E);
- Lcd_WriteData(0x14);
- Lcd_WriteData(0x03);
- Lcd_WriteData(0x11);
- Lcd_WriteData(0x07);
- Lcd_WriteData(0x31);
- Lcd_WriteData(0xC1);
- Lcd_WriteData(0x48);
- Lcd_WriteData(0x08);
- Lcd_WriteData(0x0F);
- Lcd_WriteData(0x0C);
- Lcd_WriteData(0x31);
- Lcd_WriteData(0x36);
- Lcd_WriteData(0x0F);
- Lcd_WriteIndex(0x11); //Exit Sleep
- delay_ms(120);
-
- Lcd_WriteIndex(0x29); //Display on
- Lcd_WriteIndex(0x2c);
-
- }
- /*************************************************
- 函数名:LCD_Set_XY
- 功能:设置lcd显示起始点
- 入口参数:xy坐标
- 返回值:无
- *************************************************/
- void Lcd_SetXY(u16 Xpos, u16 Ypos)
- {
- Lcd_WriteIndex(0x2a);
- Lcd_WriteData_16Bit(Xpos);
- Lcd_WriteIndex(0x2b);
- Lcd_WriteData_16Bit(Ypos);
- Lcd_WriteIndex(0x2c);
- }
- /*************************************************
- 函数名:LCD_Set_Region
- 功能:设置lcd显示区域,在此区域写点数据自动换行
- 入口参数:xy起点和终点
- 返回值:无
- *************************************************/
- //设置显示窗口
- void Lcd_SetRegion(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd)
- {
- Lcd_WriteIndex(0x2a);
- Lcd_WriteData_16Bit(xStar);
- Lcd_WriteData_16Bit(xEnd);
- Lcd_WriteIndex(0x2b);
- Lcd_WriteData_16Bit(yStar);
- Lcd_WriteData_16Bit(yEnd);
- Lcd_WriteIndex(0x2c);
- }
-
- /*************************************************
- 函数名: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);
- }
- }
- #include "stm32f10x.h"
- #include "Lcd_Driver.h"
- #include "GUI.h"
- #include "delay.h"
- #include "font.h"
- //从ILI93xx读出的数据为GBR格式,而我们写入的时候为RGB格式。
- //通过该函数转换
- //c:GBR格式的颜色值
- //返回值:RGB格式的颜色值
- u16 LCD_BGR2RGB(u16 c)
- {
- u16 r,g,b,rgb;
- b=(c>>0)&0x1f;
- g=(c>>5)&0x3f;
- r=(c>>11)&0x1f;
- rgb=(b<<11)+(g<<5)+(r<<0);
- return(rgb);
- }
- void Gui_Circle(u16 X,u16 Y,u16 R,u16 fc)
- {//Bresenham算法
- unsigned short a,b;
- int c;
- a=0;
- b=R;
- c=3-2*R;
- while (a<b)
- {
- Gui_DrawPoint(X+a,Y+b,fc); // 7
- Gui_DrawPoint(X-a,Y+b,fc); // 6
- Gui_DrawPoint(X+a,Y-b,fc); // 2
- Gui_DrawPoint(X-a,Y-b,fc); // 3
- Gui_DrawPoint(X+b,Y+a,fc); // 8
- Gui_DrawPoint(X-b,Y+a,fc); // 5
- Gui_DrawPoint(X+b,Y-a,fc); // 1
- Gui_DrawPoint(X-b,Y-a,fc); // 4
- if(c<0) c=c+4*a+6;
- else
- {
- c=c+4*(a-b)+10;
- b-=1;
- }
- a+=1;
- }
- if (a==b)
- {
- Gui_DrawPoint(X+a,Y+b,fc);
- Gui_DrawPoint(X+a,Y+b,fc);
- Gui_DrawPoint(X+a,Y-b,fc);
- Gui_DrawPoint(X-a,Y-b,fc);
- Gui_DrawPoint(X+b,Y+a,fc);
- Gui_DrawPoint(X-b,Y+a,fc);
- Gui_DrawPoint(X+b,Y-a,fc);
- Gui_DrawPoint(X-b,Y-a,fc);
- }
-
- }
- //画线函数,使用Bresenham 画线算法
- void Gui_DrawLine(u16 x0, u16 y0,u16 x1, u16 y1,u16 Color)
- {
- int dx, // difference in x's
- dy, // difference in y's
- dx2, // dx,dy * 2
- dy2,
- x_inc, // amount in pixel space to move during drawing
- y_inc, // amount in pixel space to move during drawing
- error, // the discriminant i.e. error i.e. decision variable
- index; // used for looping
- Lcd_SetXY(x0,y0);
- dx = x1-x0;//计算x距离
- dy = y1-y0;//计算y距离
- if (dx>=0)
- {
- x_inc = 1;
- }
- else
- {
- x_inc = -1;
- dx = -dx;
- }
-
- if (dy>=0)
- {
- y_inc = 1;
- }
- else
- {
- y_inc = -1;
- dy = -dy;
- }
- dx2 = dx << 1;
- dy2 = dy << 1;
- if (dx > dy)//x距离大于y距离,那么每个x轴上只有一个点,每个y轴上有若干个点
- {//且线的点数等于x距离,以x轴递增画点
- // initialize error term
- error = dy2 - dx;
- // draw the line
- for (index=0; index <= dx; index++)//要画的点数不会超过x距离
- {
- //画点
- Gui_DrawPoint(x0,y0,Color);
-
- // test if error has overflowed
- if (error >= 0) //是否需要增加y坐标值
- {
- error-=dx2;
- // move to next line
- y0+=y_inc;//增加y坐标值
- } // end if error overflowed
- // adjust the error term
- error+=dy2;
- // move to the next pixel
- x0+=x_inc;//x坐标值每次画点后都递增1
- } // end for
- } // end if |slope| <= 1
- else//y轴大于x轴,则每个y轴上只有一个点,x轴若干个点
- {//以y轴为递增画点
- // initialize error term
- error = dx2 - dy;
- // draw the line
- for (index=0; index <= dy; index++)
- {
- // set the pixel
- Gui_DrawPoint(x0,y0,Color);
- // test if error overflowed
- if (error >= 0)
- {
- error-=dy2;
- // move to next line
- x0+=x_inc;
- } // end if error overflowed
- // adjust the error term
- error+=dx2;
- // move to the next pixel
- y0+=y_inc;
- } // end for
- } // end else |slope| > 1
- }
- void Gui_box(u16 x, u16 y, u16 w, u16 h,u16 bc)
- {
- Gui_DrawLine(x,y,x+w,y,0xEF7D);
- Gui_DrawLine(x+w-1,y+1,x+w-1,y+1+h,0x2965);
- Gui_DrawLine(x,y+h,x+w,y+h,0x2965);
- Gui_DrawLine(x,y,x,y+h,0xEF7D);
- Gui_DrawLine(x+1,y+1,x+1+w-2,y+1+h-2,bc);
- }
- void Gui_box2(u16 x,u16 y,u16 w,u16 h, u8 mode)
- {
- if (mode==0) {
- Gui_DrawLine(x,y,x+w,y,0xEF7D);
- Gui_DrawLine(x+w-1,y+1,x+w-1,y+1+h,0x2965);
- Gui_DrawLine(x,y+h,x+w,y+h,0x2965);
- Gui_DrawLine(x,y,x,y+h,0xEF7D);
- }
- if (mode==1) {
- Gui_DrawLine(x,y,x+w,y,0x2965);
- Gui_DrawLine(x+w-1,y+1,x+w-1,y+1+h,0xEF7D);
- Gui_DrawLine(x,y+h,x+w,y+h,0xEF7D);
- Gui_DrawLine(x,y,x,y+h,0x2965);
- }
- if (mode==2) {
- Gui_DrawLine(x,y,x+w,y,0xffff);
- Gui_DrawLine(x+w-1,y+1,x+w-1,y+1+h,0xffff);
- Gui_DrawLine(x,y+h,x+w,y+h,0xffff);
- Gui_DrawLine(x,y,x,y+h,0xffff);
- }
- }
- /**************************************************************************************
- 功能描述: 在屏幕显示一凸起的按钮框
- 输 入: u16 x1,y1,x2,y2 按钮框左上角和右下角坐标
- 输 出: 无
- **************************************************************************************/
- void DisplayButtonDown(u16 x1,u16 y1,u16 x2,u16 y2)
- {
- Gui_DrawLine(x1, y1, x2,y1, GRAY2); //H
- Gui_DrawLine(x1+1,y1+1,x2,y1+1, GRAY1); //H
- Gui_DrawLine(x1, y1, x1,y2, GRAY2); //V
- Gui_DrawLine(x1+1,y1+1,x1+1,y2, GRAY1); //V
- Gui_DrawLine(x1, y2, x2,y2, WHITE); //H
- Gui_DrawLine(x2, y1, x2,y2, WHITE); //V
- }
- /**************************************************************************************
- 功能描述: 在屏幕显示一凹下的按钮框
- 输 入: u16 x1,y1,x2,y2 按钮框左上角和右下角坐标
- 输 出: 无
- **************************************************************************************/
- void DisplayButtonUp(u16 x1,u16 y1,u16 x2,u16 y2)
- {
- Gui_DrawLine(x1, y1, x2,y1, WHITE); //H
- Gui_DrawLine(x1, y1, x1,y2, WHITE); //V
-
- Gui_DrawLine(x1+1,y2-1,x2,y2-1, GRAY1); //H
- Gui_DrawLine(x1, y2, x2,y2, GRAY2); //H
- Gui_DrawLine(x2-1,y1+1,x2-1,y2, GRAY1); //V
- Gui_DrawLine(x2 ,y1 ,x2,y2, GRAY2); //V
- }
- void Gui_DrawFont_GBK16(u16 x, u16 y, u16 fc, u16 bc, u8 *s)
- {
- unsigned char i,j;
- unsigned short k,x0;
- x0=x;
- while(*s)
- {
- if((*s) < 128)
- {
- k=*s;
- if (k==13)
- {
- x=x0;
- y+=16;
- }
- else
- {
- if (k>32) k-=32; else k=0;
-
- for(i=0;i<16;i++)
- for(j=0;j<8;j++)
- {
- if(asc16[k*16+i]&(0x80>>j)) Gui_DrawPoint(x+j,y+i,fc);
- else
- {
- if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
- }
- }
- x+=8;
- }
- s++;
- }
-
- else
- {
-
- for (k=0;k<hz16_num;k++)
- {
- if ((hz16[k].Index[0]==*(s))&&(hz16[k].Index[1]==*(s+1)))
- {
- for(i=0;i<16;i++)
- {
- for(j=0;j<8;j++)
- {
- if(hz16[k].Msk[i*2]&(0x80>>j)) Gui_DrawPoint(x+j,y+i,fc);
- else {
- if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
- }
- }
- for(j=0;j<8;j++)
- {
- if(hz16[k].Msk[i*2+1]&(0x80>>j)) Gui_DrawPoint(x+j+8,y+i,fc);
- else
- {
- if (fc!=bc) Gui_DrawPoint(x+j+8,y+i,bc);
- }
- }
- }
- }
- }
- s+=2;x+=16;
- }
-
- }
- }
- void Gui_DrawFont_GBK24(u16 x, u16 y, u16 fc, u16 bc, u8 *s)
- {
- unsigned char i,j;
- unsigned short k;
- while(*s)
- {
- if( *s < 0x80 )
- {
- k=*s;
- if (k>32) k-=32; else k=0;
- for(i=0;i<16;i++)
- for(j=0;j<8;j++)
- {
- if(asc16[k*16+i]&(0x80>>j))
- Gui_DrawPoint(x+j,y+i,fc);
- else
- {
- if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
- }
- }
- s++;x+=8;
- }
- else
- {
- for (k=0;k<hz24_num;k++)
- {
- if ((hz24[k].Index[0]==*(s))&&(hz24[k].Index[1]==*(s+1)))
- {
- for(i=0;i<24;i++)
- {
- for(j=0;j<8;j++)
- {
- if(hz24[k].Msk[i*3]&(0x80>>j))
- Gui_DrawPoint(x+j,y+i,fc);
- else
- {
- if (fc!=bc) Gui_DrawPoint(x+j,y+i,bc);
- }
- }
- for(j=0;j<8;j++)
- {
- if(hz24[k].Msk[i*3+1]&(0x80>>j)) Gui_DrawPoint(x+j+8,y+i,fc);
- else {
- if (fc!=bc) Gui_DrawPoint(x+j+8,y+i,bc);
- }
- }
- for(j=0;j<8;j++)
- {
- if(hz24[k].Msk[i*3+2]&(0x80>>j))
- Gui_DrawPoint(x+j+16,y+i,fc);
- else
- {
- if (fc!=bc) Gui_DrawPoint(x+j+16,y+i,bc);
- }
- }
- }
- }
- }
- s+=2;x+=24;
- }
- }
- }
- void Gui_DrawFont_Num32(u16 x, u16 y, u16 fc, u16 bc, u16 num)
- {
- unsigned char i,j,k,c;
- //lcd_text_any(x+94+i*42,y+34,32,32,0x7E8,0x0,sz32,knum[i]);
- // w=w/8;
- for(i=0;i<32;i++)
- {
- for(j=0;j<4;j++)
- {
- c=*(sz32+num*32*4+i*4+j);
- for (k=0;k<8;k++)
- {
-
- if(c&(0x80>>k)) Gui_DrawPoint(x+j*8+k,y+i,fc);
- else {
- if (fc!=bc) Gui_DrawPoint(x+j*8+k,y+i,bc);
- }
- }
- }
- }
- }
- /* --------------------------Includes ---------------------------------------------*/
- #include "stm32f10x.h"
- #include "Lcd_Driver.h"
- #include "GUI.h"
- #include "delay.h"
- #include "Picture.h"
- #include "QDTFT_demo.h"
- /* ----------------------End of Includes ---------------------------------------------*/
- unsigned char Num[10]={0,1,2,3,4,5,6,7,8,9};
- //绘制测试菜单
- //2D按键按钮示例
- void Redraw_Mainmenu(void)
- {
- Lcd_Clear(GRAY0);
-
- Gui_DrawFont_GBK16(16,2,BLUE,GRAY0,"全动电子技术");
- Gui_DrawFont_GBK16(16,20,RED,GRAY0,"液晶测试程序");
- DisplayButtonUp(15,38,113,58); //x1,y1,x2,y2
- Gui_DrawFont_GBK16(16,40,GREEN,GRAY0,"颜色填充测试");
- DisplayButtonUp(15,68,113,88); //x1,y1,x2,y2
- Gui_DrawFont_GBK16(16,70,BLUE,GRAY0,"文字显示测试");
- DisplayButtonUp(15,98,113,118); //x1,y1,x2,y2
- Gui_DrawFont_GBK16(16,100,RED,GRAY0,"图片显示测试");
- //Gui_DrawFont_GBK16(16,120,BLUE,GRAY0,"Welcome");
- Gui_DrawFont_GBK16(16,140,RED,GRAY0, "Welcome");
-
- Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[5]);
- delay_ms(1000);
- Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[4]);
- delay_ms(1000);
- Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[3]);
- delay_ms(1000);
- Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[2]);
- delay_ms(1000);
- Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[1]);
- delay_ms(1000);
- Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[0]);
- }
- //测试数码管字体
- void Num_Test(void)
- {
- u8 i=0;
- Lcd_Clear(GRAY0);
- Gui_DrawFont_GBK16(16,20,RED,GRAY0,"Num Test");
- delay_ms(1000);
- Lcd_Clear(GRAY0);
- for(i=0;i<10;i++)
- {
- Gui_DrawFont_Num32((i%3)*40,32*(i/3)+30,RED,GRAY0,Num[i+1]);
- delay_ms(100);
- }
-
- }
- //中英文显示测试
- void Font_Test(void)
- {
- Lcd_Clear(GRAY0);
- Gui_DrawFont_GBK16(16,10,BLUE,GRAY0,"文字显示测试");
- delay_ms(1000);
- Lcd_Clear(GRAY0);
- Gui_DrawFont_GBK16(16,30,RED,GRAY0,"全动电子技术");
- Gui_DrawFont_GBK16(16,50,BLUE,GRAY0,"专注液晶批发");
- Gui_DrawFont_GBK16(16,70,RED,GRAY0, "全程技术支持");
- Gui_DrawFont_GBK16(0,100,BLUE,GRAY0,"Tel:15989313508");
- Gui_DrawFont_GBK16(0,130,RED,GRAY0, "www*qdtech*net");
- delay_ms(1500);
- }
- //简单刷屏测试
- void Color_Test(void)
- {
- u8 i=1;
- Lcd_Clear(GRAY0);
-
- Gui_DrawFont_GBK16(20,10,BLUE,GRAY0,"颜色填充测试");
- delay_ms(1200);
- while(i--)
- {
- Lcd_Clear(WHITE); delay_ms(500);
- Lcd_Clear(BLACK); delay_ms(500);
- Lcd_Clear(RED); delay_ms(500);
- Lcd_Clear(GREEN); delay_ms(500);
- Lcd_Clear(BLUE); delay_ms(500);
- }
- }
- //文字显示测试
- //16位BMP 40X40 QQ图像取模数据
- //Image2LCD取模选项设置
- //水平扫描
- //16位
- //40X40
- //不包含图像头数据
- //自左至右
- //自顶至底
- //低位在前
- void showimage(const unsigned char *p) //显示40*40 QQ图片
- {
- int i,j,k;
- unsigned char picH,picL;
- Lcd_Clear(GRAY0);
- Gui_DrawFont_GBK16(16,10,BLUE,GRAY0,"图片显示测试");
- delay_ms(1000);
- Lcd_Clear(GRAY0);
- for(k=0;k<6;k++)
- {
- for(j=0;j<8;j++)
- {
- Lcd_SetRegion(40*j,40*k,40*j+39,40*k+39); //坐标设置
- for(i=0;i<40*40;i++)
- {
- picL=*(p+i*2); //数据低位在前
- picH=*(p+i*2+1);
- Lcd_WriteData_16Bit(picH<<8|picL);
- }
- }
- }
- }
- //综合测试函数
- void QDTFT_Test_Demo(void)
- {
- Lcd_Init();
- LCD_LED_SET;//通过IO控制背光亮
- Redraw_Mainmenu();//绘制主菜单(部分内容由于分辨率超出物理值可能无法显示)
- Color_Test();//简单纯色填充测试
- Num_Test();//数码管字体测试
- Font_Test();//中英文显示测试
- showimage(gImage_qq);//图片显示示例
- delay_ms(1500);
- LCD_LED_CLR;//IO控制背光灭
- }
- //////////////////////////////////////////////////////////////////////////////////
- //本程序只供学习使用,未经作者许可,不得用于其它任何用途
- //测试硬件:正点原子战舰 STM32开发板/mini开发板
- //1.8寸SPI串口TFT液晶驱动
- //xiao冯@ShenZhen QDtech co.,LTD
- //我司提供技术支持,任何技术问题欢迎随时交流学习
- //固话(传真) :+86 0755-23594567
- //手机:15989313508(冯工)
- //邮箱:QDtech2008@gmail.com
- //Skype:QDtech2008
- //创建日期:2013/5/13
- //版本:V1.1
- //版权所有,盗版必究。
- //Copyright(C) 深圳市全动电子技术有限公司 2009-2019
- //All rights reserved
- //////////////////////////////////////////////////////////////////////////////////
- /***************************************************************************************
- STM32测试平台介绍:
- 开发板:正点原子MiniSTM32开发板
- MCU :STM32_F103_RBT6
- 晶振 :12MHZ
- 主频 :72MHZ
- 接线说明:
- //-------------------------------------------------------------------------------------
- #define LCD_CTRL GPIOB //定义TFT数据端口
- #define LCD_LED GPIO_Pin_9 //PB9 连接至TFT -LED
- #define LCD_RS GPIO_Pin_10 //PB10连接至TFT --RS
- #define LCD_CS GPIO_Pin_11 //PB11 连接至TFT --CS
- #define LCD_RST GPIO_Pin_12 //PB12连接至TFT --RST
- #define LCD_SCL GPIO_Pin_13 //PB13连接至TFT -- CLK
- #define LCD_SDA GPIO_Pin_15 //PB15连接至TFT - SDI
- //VCC:可以接5V也可以接3.3V
- //LED:可以接5V也可以接3.3V或者使用任意空闲IO控制(高电平使能)
- //GND:接电源地
- //说明:如需要尽可能少占用IO,可以将LCD_CS接地,LCD_LED接3.3V,LCD_RST接至单片机a复位端,
- //将可以释放3个可用IO
- //接口定义在Lcd_Driver.h内定义,
- //如需变更IO接法,请根据您的实际接线修改相应IO初始化LCD_GPIO_Init()
- //-----------------------------------------------------------------------------------------
- 例程功能说明:
- 1. 简单刷屏测试
- 2. 英文显示测试示例
- 3. 中文显示测试示例
- 4. 数码管字体显示示例
- 5. 图片显示示例
- 6. 2D按键菜单示例
- 7. 本例程支持横屏/竖屏切换(开启宏USE_HORIZONTAL,详见Lcd_Driver.h)
- 8. 本例程支持软件模拟SPI/硬件SPI切换(开启宏USE_HARDWARE_SPI,详见Lcd_Driver.h)
- **********************************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "delay.h"
- #include "QDTFT_demo.h"
- int main(void)
- {
- SystemInit(); //System init.
- delay_init(72);//Delay init.
- while(1)
- {
- QDTFT_Test_Demo(); //See the test details in QDTFT_Demo.c
- }
- }
- /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
复制代码 |