基于STM32F4的2.8寸TFT-LCD触摸屏(HAL库)(一)

前言

TFT-LCD 触摸屏是目前广泛应用于各种设备(如手机、平板、工业控制器、汽车导航等)中的一种显示与交互界面。它结合了 TFT-LCD(薄膜晶体管液晶显示器)显示技术和触摸感应技术,实现了图像显示与人机交互功能。

单片机使用的是嘉立创的天空星青春版stm32f4vzt6

本实验LCD采用ILI9341驱动芯片

一.CubexMX配置

配置外部高速晶振

Serial Wire

TIM1,用于提供us级延时

tim1时钟频率168mhz,其他84mhz

I2C,默认即可,用对AT24CXX进行读写操作

SPI1,用于点亮LCD,如果使用杜邦线且LCD无法正常显示,可尝试降低频率

模拟SPI,实现触摸功能(PC10,PC11,PC12)

GPIO配置

蓝色部分为LCD显示部分,红色为触摸部分

时钟树配置

记得勾选生成独立.c.h文件

二. TFT-LCD(显示部分)

TFT-LCD 是一种利用液晶分子的光电效应来控制光线透射的显示技术,TFT(薄膜晶体管)则是用于控制每个像素亮度的开关器件。它的基本工作原理如下:

  • 背光源:TFT-LCD 本身并不发光,需要通过背光源提供照明。常用的背光源有 LED 和 CCFL。
  • 液晶层:液晶分子位于两片偏光板之间,受到电场影响时,液晶分子的排列方式会发生变化,从而改变光线的透过率。
  • TFT 控制器:每个像素都有一个独立的 TFT 开关,控制液晶层的电压,从而控制每个像素的亮度。
  • RGB 色彩控制:通过 RGB 三原色滤光片,每个像素能够显示不同颜色的组合,从而形成彩色图像
  • 2.1 TFT-LCD (代码)

  • 用于显示内容
  • LCD代码(初始化)

  • LED.c
  • #include "lcd.h"
    #include "spi.h"
    #include "main.h" 
    #include "MySPI.h" 
    //管理LCD重要参数
    //默认为竖屏
    _lcd_dev lcddev;
    
    //画笔颜色,背景颜色
    uint16_t POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF;  
    uint16_t DeviceCode;	 
    
    /*****************************************************************************
     * @name       :void LCD_WR_REG(uint8_t data)
     * @date       :2018-08-09 
     * @function   :Write an 8-bit command to the LCD screen
     * @parameters :data:Command value to be written
     * @retvalue   :None
    ******************************************************************************/
    void LCD_WR_REG(uint8_t data)
    { 
      	LCD_CS_CLR;     
    	LCD_DC_CLR;	  
        SPI_WriteByte(SPI1,data);
        LCD_CS_SET;	
    }
    
    /*****************************************************************************
     * @name       :void LCD_WR_DATA(uint8_t data)
     * @date       :2018-08-09 
     * @function   :Write an 8-bit data to the LCD screen
     * @parameters :data:data value to be written
     * @retvalue   :None
    ******************************************************************************/
    void LCD_WR_DATA(uint8_t data)
    {
        LCD_CS_CLR;
    	LCD_DC_SET;
        SPI_WriteByte(SPI1,data);
        LCD_CS_SET;
    }
    
    /*****************************************************************************
     * @name       :void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
     * @date       :2018-08-09 
     * @function   :Write data into registers
     * @parameters :LCD_Reg:Register address
                    LCD_RegValue:Data to be written
     * @retvalue   :None
    ******************************************************************************/
    void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
    {	
    	LCD_WR_REG(LCD_Reg);  
    	LCD_WR_DATA(LCD_RegValue);	    		 
    }	   
    
    /*****************************************************************************
     * @name       :void LCD_WriteRAM_Prepare(void)
     * @date       :2018-08-09 
     * @function   :Write GRAM
     * @parameters :None
     * @retvalue   :None
    ******************************************************************************/	 
    void LCD_WriteRAM_Prepare(void)
    {
    	LCD_WR_REG(lcddev.wramcmd);
    }	 
    
    /*****************************************************************************
     * @name       :void Lcd_WriteData_16Bit(uint16_t Data)
     * @date       :2018-08-09 
     * @function   :Write an 16-bit command to the LCD screen
     * @parameters :Data:Data to be written
     * @retvalue   :None
    ******************************************************************************/	 
    void Lcd_WriteData_16Bit(uint16_t Data)
    {	
        LCD_CS_CLR;
        LCD_DC_SET;  
        SPI_WriteByte(SPI1,Data>>8);
    	SPI_WriteByte(SPI1,Data);
        LCD_CS_SET;
    }
    
    /*****************************************************************************
     * @name       :void LCD_DrawPoint(uint16_t x,uint16_t y)
     * @date       :2018-08-09 
     * @function   :Write a pixel data at a specified location
     * @parameters :x:the x coordinate of the pixel
                    y:the y coordinate of the pixel
     * @retvalue   :None
    ******************************************************************************/	
    void LCD_DrawPoint(uint16_t x,uint16_t y)
    {
    	LCD_SetCursor(x,y);
    	Lcd_WriteData_16Bit(POINT_COLOR); 
    }
    
    /*****************************************************************************
     * @name       :void LCD_Clear(uint16_t Color)
     * @date       :2018-08-09 
     * @function   :Full screen filled LCD screen
     * @parameters :color:Filled color
     * @retvalue   :None
    ******************************************************************************/	
    void LCD_Clear(uint16_t Color)
    {
      unsigned int i,m;  
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);   
    	LCD_CS_CLR;
    	LCD_DC_SET;
    	for(i=0;i<lcddev.height;i++)
    	{
        for(m=0;m<lcddev.width;m++)
        {	
    			Lcd_WriteData_16Bit(Color);
    		}
    	}
    	 LCD_CS_SET;
    } 
    
    /*****************************************************************************
     * @name       :void LCD_RESET(void)
     * @date       :2018-08-09 
     * @function   :Reset LCD screen
     * @parameters :None
     * @retvalue   :None
    ******************************************************************************/	
    void LCD_RESET(void)
    {
    	LCD_RST_CLR;
    	HAL_Delay(100);	
    	LCD_RST_SET;
    	HAL_Delay(50);
    }
    
    /*****************************************************************************
     * @name       :void LCD_RESET(void)
     * @date       :2018-08-09 
     * @function   :Initialization LCD screen
     * @parameters :None
     * @retvalue   :None
    ******************************************************************************/	 	 
    void LCD_Init(void)
    {  
    									 
     	LCD_RESET(); //LCD ��λ
    //*************2.8inch ILI9341��ʼ��**********//	
    	LCD_WR_REG(0xCF);  
    	LCD_WR_DATA(0x00); 
    	LCD_WR_DATA(0xC9); //C1 
    	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(0x00);   //SAP[2:0];BT[3:0] 01 
    	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(0x08); 
    	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
    	HAL_Delay(120);
    	LCD_WR_REG(0x29); //display on		
    
        LCD_direction(USE_HORIZONTAL);//设置LCD显示方向
    	LCD_LED_SET;//点亮背光	 
    	LCD_Clear(WHITE);//清全屏白色
    }
     
    /*****************************************************************************
     * @name       :void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd)
     * @date       :2018-08-09 
     * @function   :Setting LCD display window
     * @parameters :xStar:the bebinning x coordinate of the LCD display window
    								yStar:the bebinning y coordinate of the LCD display window
    								xEnd:the endning x coordinate of the LCD display window
    								yEnd:the endning y coordinate of the LCD display window
     * @retvalue   :None
    ******************************************************************************/ 
    void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd)
    {	
    	LCD_WR_REG(lcddev.setxcmd);	
    	LCD_WR_DATA(xStar>>8);
    	LCD_WR_DATA(0x00FF&xStar);		
    	LCD_WR_DATA(xEnd>>8);
    	LCD_WR_DATA(0x00FF&xEnd);
    
    	LCD_WR_REG(lcddev.setycmd);	
    	LCD_WR_DATA(yStar>>8);
    	LCD_WR_DATA(0x00FF&yStar);		
    	LCD_WR_DATA(yEnd>>8);
    	LCD_WR_DATA(0x00FF&yEnd);
    
    	LCD_WriteRAM_Prepare();	//开始写入GRAM					
    }   
    
    /*****************************************************************************
     * @name       :void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
     * @date       :2018-08-09 
     * @function   :Set coordinate value
     * @parameters :Xpos:the  x coordinate of the pixel
    								Ypos:the  y coordinate of the pixel
     * @retvalue   :None
    ******************************************************************************/ 
    void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
    {	  	    			
    	LCD_SetWindows(Xpos,Ypos,Xpos,Ypos);	
    } 
    
    /*****************************************************************************
     * @name       :void LCD_direction(uint8_t direction)
     * @date       :2018-08-09 
     * @function   :Setting the display direction of LCD screen
     * @parameters :direction:0-0 degree
                              1-90 degree
    													2-180 degree
    													3-270 degree
     * @retvalue   :None
    ******************************************************************************/ 
    void LCD_direction(uint8_t direction)
    { 
    			lcddev.setxcmd=0x2A;
    			lcddev.setycmd=0x2B;
    			lcddev.wramcmd=0x2C;
    	switch(direction){		  
    		case 0:						 	 		
    			lcddev.width=LCD_W;
    			lcddev.height=LCD_H;		
    			LCD_WriteReg(0x36,(1<<3)|(0<<6)|(0<<7));//BGR==1,MY==0,MX==0,MV==0
    		break;
    		case 1:
    			lcddev.width=LCD_H;
    			lcddev.height=LCD_W;
    			LCD_WriteReg(0x36,(1<<3)|(0<<7)|(1<<6)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
    		break;
    		case 2:						 	 		
    			lcddev.width=LCD_W;
    			lcddev.height=LCD_H;	
    			LCD_WriteReg(0x36,(1<<3)|(1<<6)|(1<<7));//BGR==1,MY==0,MX==0,MV==0
    		break;
    		case 3:
    			lcddev.width=LCD_H;
    			lcddev.height=LCD_W;
    			LCD_WriteReg(0x36,(1<<3)|(1<<7)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
    		break;	
    		default:break;
    	}		
    }	 
    
    LED.h
  • #ifndef __LCD_H
    #define __LCD_H		 
    #include "stdlib.h"
    #include "stdint.h"
    #include "main.h"
    
    //LCD重要参数集
    typedef struct  
    {										    
    	uint16_t width;			//LCD 宽度
    	uint16_t height;		//LCD 高度
    	uint16_t id;			//LCD ID
    	uint8_t  dir;			//横屏还是竖屏控制:0,竖屏;1,横屏	
    	uint16_t wramcmd;		//开始写gram指令
    	uint16_t  setxcmd;		//设置x坐标指令
    	uint16_t  setycmd;		//设置y坐标指令	 
    }_lcd_dev; 	
    
    //LCD参数
    extern _lcd_dev lcddev;	//管理LCD重要参数
    /用户配置区///	 
    #define USE_HORIZONTAL  2/*定义液晶屏顺时针旋转方向 0: 0度旋转,1: 90度旋转,
                                                      2: 180度旋转,3: 270度旋转*/
    
    //	  
    //定义LCD的尺寸
    #define LCD_W 240
    #define LCD_H 320
    
    //TFTLCD部分外要调用的函数	   
    extern uint16_t  POINT_COLOR;//默认红色    
    extern uint16_t  BACK_COLOR; //背景颜色.默认为白色
    
    
    #define	LCD_CS_SET  LCD_CS_GPIO_Port->BSRR = LCD_CS_Pin			
    #define	LCD_DC_SET  LCD_DC_GPIO_Port->BSRR = LCD_DC_Pin	
    #define	LCD_RST_SET  LCD_RST_GPIO_Port->BSRR = LCD_RST_Pin	
    #define	LCD_LED_SET  LCD_BLK_GPIO_Port->BSRR = LCD_BLK_Pin
    
    #define	LCD_CS_CLR  LCD_CS_GPIO_Port->BSRR = (uint32_t)LCD_CS_Pin<<16U
    #define	LCD_DC_CLR  LCD_DC_GPIO_Port->BSRR = (uint32_t)LCD_DC_Pin<<16U
    #define	LCD_RST_CLR  LCD_RST_GPIO_Port->BSRR = (uint32_t)LCD_RST_Pin<<16U
    #define	LCD_LED_CLR  LCD_BLK_GPIO_Port->BSRR = (uint32_t)LCD_BLK_Pin<<16U
    
    
    
    //画笔颜色
    #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 //灰色
    //GUI颜色
    
    #define DARKBLUE      	 0X01CF	//深蓝色
    #define LIGHTBLUE      	 0X7D7C	//浅蓝色 
    #define GRAYBLUE       	 0X5458 //灰蓝色
    //以上三色为PANEL的颜色 
     
    #define LIGHTGREEN    0X841F //浅绿色
    #define LIGHTGRAY     0XEF5B //浅灰色(PANNEL)
    #define LGRAY 		  0XC618 //浅灰色(PANNEL),窗体背景色
    
    #define LGRAYBLUE      	0XA651  //浅灰蓝色(中间层颜色)
    #define LBBLUE          0X2B12 //浅棕蓝色(选择条目的反色)
    	    															  
    void LCD_Init(void);
    void LCD_DisplayOn(void);
    void LCD_DisplayOff(void);
    void LCD_Clear(uint16_t Color);	 
    void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
    void LCD_DrawPoint(uint16_t x,uint16_t y);//画点
    uint16_t  LCD_ReadPoint(uint16_t x,uint16_t y); //读点
    void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
    void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);		   
    void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd);
    
    uint16_t LCD_RD_DATA(void);//读取LCD数据								    
    void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);
    void LCD_WR_DATA(uint8_t data);
    uint16_t LCD_ReadReg(uint8_t LCD_Reg);
    void LCD_WriteRAM_Prepare(void);
    void LCD_WriteRAM(uint16_t RGB_Code);
    uint16_t LCD_ReadRAM(void);		   
    uint16_t LCD_BGR2RGB(uint16_t c);
    void LCD_SetParam(void);
    void Lcd_WriteData_16Bit(uint16_t Data);
    void LCD_direction(uint8_t direction );
    
    
    //如果仍然觉得速度不够快,可以使用下面的宏定义,提高速度.
    //注意要去掉lcd.c中void LCD_WR_DATA(u16 data)函数定义哦
    /*
    #if LCD_USE8BIT_MODEL==1使用8位并行数据总线模式
    	#define LCD_WR_DATA(data){\
    	LCD_RS_SET;\
    	LCD_CS_CLR;\
    	DATAOUT(data);\
    	LCD_WR_CLR;\
    	LCD_WR_SET;\
    	DATAOUT(data<<8);\
    	LCD_WR_CLR;\
    	LCD_WR_SET;\
    	LCD_CS_SET;\
    	}
    	#else//使用16位并行数据总线模式
    	#define LCD_WR_DATA(data){\
    	LCD_RS_SET;\
    	LCD_CS_CLR;\
    	DATAOUT(data);\
    	LCD_WR_CLR;\
    	LCD_WR_SET;\
    	LCD_CS_SET;\
    	} 	
    #endif
    */
    				  		 
    #endif  
    	 
    	 
    

    GUI代码(绘图)

  • GUI.c
  • #include "lcd.h"
    #include "string.h"
    #include "font.h" 
    #include "gui.h"
    
    /*******************************************************************
     * @name       :void GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
     * @date       :2018-08-09 
     * @function   :draw a point in LCD screen
     * @parameters :x:the x coordinate of the point
                    y:the y coordinate of the point
    								color:the color value of the point
     * @retvalue   :None
    ********************************************************************/
    void GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
    {
    	LCD_SetCursor(x,y);//设置光标位置 
    	Lcd_WriteData_16Bit(color); 
    }
    
    /*******************************************************************
     * @name       :void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color)
     * @date       :2018-08-09 
     * @function   :fill the specified area
     * @parameters :sx:the bebinning x coordinate of the specified area
                    sy:the bebinning y coordinate of the specified area
    								ex:the ending x coordinate of the specified area
    								ey:the ending y coordinate of the specified area
    								color:the filled color value
     * @retvalue   :None
    ********************************************************************/
    void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color)
    {  	
    	uint16_t i,j;			
    	uint16_t width=ex-sx+1; 		//得到填充的宽度
    	uint16_t height=ey-sy+1;		//高度
    	LCD_SetWindows(sx,sy,ex,ey);//设置显示窗口
    	for(i=0;i<height;i++)
    	{
    		for(j=0;j<width;j++)
    		Lcd_WriteData_16Bit(color);	//写入数据 	 
    	}
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口设置为全屏
    }
    
    /*******************************************************************
     * @name       :void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
     * @date       :2018-08-09 
     * @function   :Draw a line between two points
     * @parameters :x1:the bebinning x coordinate of the line
                    y1:the bebinning y coordinate of the line
    								x2:the ending x coordinate of the line
    								y2:the ending y coordinate of the line
     * @retvalue   :None
    ********************************************************************/
    void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
    {
    	uint16_t t; 
    	int xerr=0,yerr=0,delta_x,delta_y,distance; 
    	int incx,incy,uRow,uCol; 
    
    	delta_x=x2-x1; //计算坐标增量 
    	delta_y=y2-y1; 
    	uRow=x1; 
    	uCol=y1; 
    	if(delta_x>0)incx=1; //设置单步方向 
    	else if(delta_x==0)incx=0;//垂直线 
    	else {incx=-1;delta_x=-delta_x;} 
    	if(delta_y>0)incy=1; 
    	else if(delta_y==0)incy=0;//水平线
    	else{incy=-1;delta_y=-delta_y;} 
    	if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴 
    	else distance=delta_y; 
    	for(t=0;t<=distance+1;t++ )//画线输出 
    	{  
    		LCD_DrawPoint(uRow,uCol);//画点  
    		xerr+=delta_x ; 
    		yerr+=delta_y ; 
    		if(xerr>distance) 
    		{ 
    			xerr-=distance; 
    			uRow+=incx; 
    		} 
    		if(yerr>distance) 
    		{ 
    			yerr-=distance; 
    			uCol+=incy; 
    		} 
    	}  
    } 
    
    /*****************************************************************************
     * @name       :void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
     * @date       :2018-08-09 
     * @function   :Draw a rectangle
     * @parameters :x1:the bebinning x coordinate of the rectangle
                    y1:the bebinning y coordinate of the rectangle
    								x2:the ending x coordinate of the rectangle
    								y2:the ending y coordinate of the rectangle
     * @retvalue   :None
    ******************************************************************************/
    void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
    {
    	LCD_DrawLine(x1,y1,x2,y1);
    	LCD_DrawLine(x1,y1,x1,y2);
    	LCD_DrawLine(x1,y2,x2,y2);
    	LCD_DrawLine(x2,y1,x2,y2);
    }  
    
    /*****************************************************************************
     * @name       :void LCD_DrawFillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
     * @date       :2018-08-09 
     * @function   :Filled a rectangle
     * @parameters :x1:the bebinning x coordinate of the filled rectangle
                    y1:the bebinning y coordinate of the filled rectangle
    								x2:the ending x coordinate of the filled rectangle
    								y2:the ending y coordinate of the filled rectangle
     * @retvalue   :None
    ******************************************************************************/  
    void LCD_DrawFillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
    {
    	LCD_Fill(x1,y1,x2,y2,POINT_COLOR);
    }
     
    /*****************************************************************************
     * @name       :void _draw_circle_8(int xc, int yc, int x, int y, uint16_t c)
     * @date       :2018-08-09 
     * @function   :8 symmetry circle drawing algorithm (internal call)
     * @parameters :xc:the x coordinate of the Circular center 
                    yc:the y coordinate of the Circular center 
    								x:the x coordinate relative to the Circular center 
    								y:the y coordinate relative to the Circular center 
    								c:the color value of the circle
     * @retvalue   :None
    ******************************************************************************/  
    void _draw_circle_8(int xc, int yc, int x, int y, uint16_t c)
    {
    	GUI_DrawPoint(xc + x, yc + y, c);
    
    	GUI_DrawPoint(xc - x, yc + y, c);
    
    	GUI_DrawPoint(xc + x, yc - y, c);
    
    	GUI_DrawPoint(xc - x, yc - y, c);
    
    	GUI_DrawPoint(xc + y, yc + x, c);
    
    	GUI_DrawPoint(xc - y, yc + x, c);
    
    	GUI_DrawPoint(xc + y, yc - x, c);
    
    	GUI_DrawPoint(xc - y, yc - x, c);
    }
    
    /*****************************************************************************
     * @name       :void gui_circle(int xc, int yc,uint16_t c,int r, int fill)
     * @date       :2018-08-09 
     * @function   :Draw a circle of specified size at a specified location
     * @parameters :xc:the x coordinate of the Circular center 
                    yc:the y coordinate of the Circular center 
    								r:Circular radius
    								fill:1-filling,0-no filling
     * @retvalue   :None
    ******************************************************************************/  
    void gui_circle(int xc, int yc,uint16_t c,int r, int fill)
    {
    	int x = 0, y = r, yi, d;
    
    	d = 3 - 2 * r;
    
    
    	if (fill) 
    	{
    		// 如果填充(画实心圆)
    		while (x <= y) {
    			for (yi = x; yi <= y; yi++)
    				_draw_circle_8(xc, yc, x, yi, c);
    
    			if (d < 0) {
    				d = d + 4 * x + 6;
    			} else {
    				d = d + 4 * (x - y) + 10;
    				y--;
    			}
    			x++;
    		}
    	} else 
    	{
    		// 如果不填充(画空心圆)
    		while (x <= y) {
    			_draw_circle_8(xc, yc, x, y, c);
    			if (d < 0) {
    				d = d + 4 * x + 6;
    			} else {
    				d = d + 4 * (x - y) + 10;
    				y--;
    			}
    			x++;
    		}
    	}
    }
    
    /*****************************************************************************
     * @name       :void Draw_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
     * @date       :2018-08-09 
     * @function   :Draw a triangle at a specified position
     * @parameters :x0:the bebinning x coordinate of the triangular edge 
                    y0:the bebinning y coordinate of the triangular edge 
    								x1:the vertex x coordinate of the triangular
    								y1:the vertex y coordinate of the triangular
    								x2:the ending x coordinate of the triangular edge 
    								y2:the ending y coordinate of the triangular edge 
     * @retvalue   :None
    ******************************************************************************/ 
    void Draw_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
    {
    	LCD_DrawLine(x0,y0,x1,y1);
    	LCD_DrawLine(x1,y1,x2,y2);
    	LCD_DrawLine(x2,y2,x0,y0);
    }
    
    static void _swap(uint16_t *a, uint16_t *b)
    {
    	uint16_t tmp;
      tmp = *a;
    	*a = *b;
    	*b = tmp;
    }
    
    /*****************************************************************************
     * @name       :void Fill_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
     * @date       :2018-08-09 
     * @function   :filling a triangle at a specified position
     * @parameters :x0:the bebinning x coordinate of the triangular edge 
                    y0:the bebinning y coordinate of the triangular edge 
    								x1:the vertex x coordinate of the triangular
    								y1:the vertex y coordinate of the triangular
    								x2:the ending x coordinate of the triangular edge 
    								y2:the ending y coordinate of the triangular edge 
     * @retvalue   :None
    ******************************************************************************/ 
    void Fill_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
    {
    	uint16_t a, b, y, last;
    	int dx01, dy01, dx02, dy02, dx12, dy12;
    	long sa = 0;
    	long sb = 0;
     	if (y0 > y1) 
    	{
        _swap(&y0,&y1); 
    		_swap(&x0,&x1);
     	}
     	if (y1 > y2) 
    	{
        _swap(&y2,&y1); 
    		_swap(&x2,&x1);
     	}
      if (y0 > y1) 
    	{
        _swap(&y0,&y1); 
    		_swap(&x0,&x1);
      }
    	if(y0 == y2) 
    	{ 
    		a = b = x0;
    		if(x1 < a)
        {
    			a = x1;
        }
        else if(x1 > b)
        {
    			b = x1;
        }
        if(x2 < a)
        {
    			a = x2;
        }
    		else if(x2 > b)
        {
    			b = x2;
        }
    		LCD_Fill(a,y0,b,y0,POINT_COLOR);
        return;
    	}
    	dx01 = x1 - x0;
    	dy01 = y1 - y0;
    	dx02 = x2 - x0;
    	dy02 = y2 - y0;
    	dx12 = x2 - x1;
    	dy12 = y2 - y1;
    	
    	if(y1 == y2)
    	{
    		last = y1; 
    	}
      else
    	{
    		last = y1-1; 
    	}
    	for(y=y0; y<=last; y++) 
    	{
    		a = x0 + sa / dy01;
    		b = x0 + sb / dy02;
    		sa += dx01;
        sb += dx02;
        if(a > b)
        {
    			_swap(&a,&b);
    		}
    		LCD_Fill(a,y,b,y,POINT_COLOR);
    	}
    	sa = dx12 * (y - y1);
    	sb = dx02 * (y - y0);
    	for(; y<=y2; y++) 
    	{
    		a = x1 + sa / dy12;
    		b = x0 + sb / dy02;
    		sa += dx12;
    		sb += dx02;
    		if(a > b)
    		{
    			_swap(&a,&b);
    		}
    		LCD_Fill(a,y,b,y,POINT_COLOR);
    	}
    }
    
    /*****************************************************************************
     * @name       :void LCD_ShowChar(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Display a single English character
     * @parameters :x:the bebinning x coordinate of the Character display position
                    y:the bebinning y coordinate of the Character display position
    								fc:the color value of display character
    								bc:the background color of display character
    								num:the ascii code of display character(0~94)
    								size:the size of display character
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/ 
    void LCD_ShowChar(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode)
    {  
        uint8_t temp;
        uint8_t pos,t;
    	uint16_t colortemp=POINT_COLOR;      
    		   
    	num=num-' ';//得到偏移后的值
    	LCD_SetWindows(x,y,x+size/2-1,y+size-1);//设置单个文字显示窗口
    	if(!mode) //非叠加方式
    	{		
    		for(pos=0;pos<size;pos++)
    		{
    			if(size==12)temp=asc2_1206[num][pos];//调用1206字体
    			else temp=asc2_1608[num][pos];		 //调用1608字体
    			for(t=0;t<size/2;t++)
    		    {                 
    		        if(temp&0x01)Lcd_WriteData_16Bit(fc); 
    				else Lcd_WriteData_16Bit(bc); 
    				temp>>=1; 
    				
    		    }
    			
    		}	
    	}else//叠加方式
    	{
    		for(pos=0;pos<size;pos++)
    		{
    			if(size==12)temp=asc2_1206[num][pos];//调用1206字体
    			else temp=asc2_1608[num][pos];		 //调用1608字体
    			for(t=0;t<size/2;t++)
    		    {   
    				POINT_COLOR=fc;              
    		        if(temp&0x01)LCD_DrawPoint(x+t,y+pos);//画一个点      
    		        temp>>=1; 
    		    }
    		}
    	}
    	POINT_COLOR=colortemp;	
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口为全屏        	   	 	  
    }
    
    /*****************************************************************************
     * @name       :void LCD_ShowString(uint16_t x,uint16_t y,uint8_t size,uint8_t *p,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Display English string
     * @parameters :x:the bebinning x coordinate of the English string
                    y:the bebinning y coordinate of the English string
    								p:the start address of the English string
    								size:the size of display character
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/   	  
    void LCD_ShowString(uint16_t x,uint16_t y,uint8_t size,uint8_t *p,uint8_t mode)
    {         
        while((*p<='~')&&(*p>=' '))//判断是不是非法字符!
        {   
    		if(x>(lcddev.width-1)||y>(lcddev.height-1)) 
    		return;     
            LCD_ShowChar(x,y,POINT_COLOR,BACK_COLOR,*p,size,mode);
            x+=size/2;
            p++;
        }  
    } 
    
    /*****************************************************************************
     * @name       :uint32_t mypow(uint8_t m,uint8_t n)
     * @date       :2018-08-09 
     * @function   :get the nth power of m (internal call)
     * @parameters :m:the multiplier
                    n:the power
     * @retvalue   :the nth power of m
    ******************************************************************************/ 
    uint32_t mypow(uint8_t m,uint8_t n)
    {
    	uint32_t result=1;	 
    	while(n--)result*=m;    
    	return result;
    }
    
    /*****************************************************************************
     * @name       :void LCD_ShowNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size)
     * @date       :2018-08-09 
     * @function   :Display number
     * @parameters :x:the bebinning x coordinate of the number
                    y:the bebinning y coordinate of the number
    								num:the number(0~4294967295)
    								len:the length of the display number
    								size:the size of display number
     * @retvalue   :None
    ******************************************************************************/  			 
    void LCD_ShowNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size)
    {         	
    	uint8_t t,temp;
    	uint8_t enshow=0;						   
    	for(t=0;t<len;t++)
    	{
    		temp=(num/mypow(10,len-t-1))%10;
    		if(enshow==0&&t<(len-1))
    		{
    			if(temp==0)
    			{
    				LCD_ShowChar(x+(size/2)*t,y,POINT_COLOR,BACK_COLOR,' ',size,0);
    				continue;
    			}else enshow=1; 
    		 	 
    		}
    	 	LCD_ShowChar(x+(size/2)*t,y,POINT_COLOR,BACK_COLOR,temp+'0',size,0); 
    	}
    } 
    
    /*****************************************************************************
     * @name       :void GUI_DrawFont16(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Display a single 16x16 Chinese character
     * @parameters :x:the bebinning x coordinate of the Chinese character
                    y:the bebinning y coordinate of the Chinese character
    								fc:the color value of Chinese character
    								bc:the background color of Chinese character
    								s:the start address of the Chinese character
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/ 
    void GUI_DrawFont16(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode)
    {
    	uint8_t i,j;
    	uint16_t k;
    	uint16_t HZnum;
    	uint16_t x0=x;
    	HZnum=sizeof(tfont16)/sizeof(typFNT_GB16);	//自动统计汉字数目
    	
    			
    	for (k=0;k<HZnum;k++) 
    	{
    	  if ((tfont16[k].Index[0]==*(s))&&(tfont16[k].Index[1]==*(s+1)))
    	  { 	LCD_SetWindows(x,y,x+16-1,y+16-1);
    		    for(i=0;i<16*2;i++)
    		    {
    				for(j=0;j<8;j++)
    		    	{	
    					if(!mode) //非叠加方式
    					{
    						if(tfont16[k].Msk[i]&(0x80>>j))	Lcd_WriteData_16Bit(fc);
    						else Lcd_WriteData_16Bit(bc);
    					}
    					else
    					{
    						POINT_COLOR=fc;
    						if(tfont16[k].Msk[i]&(0x80>>j))	LCD_DrawPoint(x,y);//画一个点
    						x++;
    						if((x-x0)==16)
    						{
    							x=x0;
    							y++;
    							break;
    						}
    					}
    
    				}
    				
    			}
    			
    			
    		}				  	
    		continue;  //查找到对应点阵字库立即退出,防止多个汉字重复取模带来影响
    	}
    
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口为全屏  
    } 
    
    /*****************************************************************************
     * @name       :void GUI_DrawFont24(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Display a single 24x24 Chinese character
     * @parameters :x:the bebinning x coordinate of the Chinese character
                    y:the bebinning y coordinate of the Chinese character
    								fc:the color value of Chinese character
    								bc:the background color of Chinese character
    								s:the start address of the Chinese character
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/ 
    void GUI_DrawFont24(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode)
    {
    	uint8_t i,j;
    	uint16_t k;
    	uint16_t HZnum;
    	uint16_t x0=x;
    	HZnum=sizeof(tfont24)/sizeof(typFNT_GB24);	//�Զ�ͳ�ƺ�����Ŀ
    		
    			for (k=0;k<HZnum;k++) 
    			{
    			  if ((tfont24[k].Index[0]==*(s))&&(tfont24[k].Index[1]==*(s+1)))
    			  { 	LCD_SetWindows(x,y,x+24-1,y+24-1);
    				    for(i=0;i<24*3;i++)
    				    {
    							for(j=0;j<8;j++)
    							{
    								if(!mode) //�ǵ��ӷ�ʽ
    								{
    									if(tfont24[k].Msk[i]&(0x80>>j))	Lcd_WriteData_16Bit(fc);
    									else Lcd_WriteData_16Bit(bc);
    								}
    							else
    							{
    								POINT_COLOR=fc;
    								if(tfont24[k].Msk[i]&(0x80>>j))	LCD_DrawPoint(x,y);//��һ����
    								x++;
    								if((x-x0)==24)
    								{
    									x=x0;
    									y++;
    									break;
    								}
    							}
    						}
    					}
    					
    					
    				}				  	
    				continue;  //���ҵ���Ӧ�����ֿ������˳�����ֹ��������ظ�ȡģ����Ӱ��
    			}
    
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//�ָ�����Ϊȫ��  
    }
    
    /*****************************************************************************
     * @name       :void GUI_DrawFont32(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Display a single 32x32 Chinese character
     * @parameters :x:the bebinning x coordinate of the Chinese character
                    y:the bebinning y coordinate of the Chinese character
    								fc:the color value of Chinese character
    								bc:the background color of Chinese character
    								s:the start address of the Chinese character
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/ 
    void GUI_DrawFont32(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode)
    {
    	uint8_t i,j;
    	uint16_t k;
    	uint16_t HZnum;
    	uint16_t x0=x;
    	HZnum=sizeof(tfont32)/sizeof(typFNT_GB32);	
    	for (k=0;k<HZnum;k++) 
    			{
    			  if ((tfont32[k].Index[0]==*(s))&&(tfont32[k].Index[1]==*(s+1)))
    			  { 	LCD_SetWindows(x,y,x+32-1,y+32-1);
    				    for(i=0;i<32*4;i++)
    				    {
    						for(j=0;j<8;j++)
    				    	{
    							if(!mode) //�ǵ��ӷ�ʽ
    							{
    								if(tfont32[k].Msk[i]&(0x80>>j))	Lcd_WriteData_16Bit(fc);
    								else Lcd_WriteData_16Bit(bc);
    							}
    							else
    							{
    								POINT_COLOR=fc;
    								if(tfont32[k].Msk[i]&(0x80>>j))	LCD_DrawPoint(x,y);
    								x++;
    								if((x-x0)==32)
    								{
    									x=x0;
    									y++;
    									break;
    								}
    							}
    						}
    					}
    					
    					
    				}				  	
    				continue;  //
    			}
    	
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);
    } 
    
    /*****************************************************************************
     * @name       :void Show_Str(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Display Chinese and English strings
     * @parameters :x:the bebinning x coordinate of the Chinese and English strings
                    y:the bebinning y coordinate of the Chinese and English strings
    								fc:the color value of Chinese and English strings
    								bc:the background color of Chinese and English strings
    								str:the start address of the Chinese and English strings
    								size:the size of Chinese and English strings
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/	   		   
    void Show_Str(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode)
    {					
    	uint16_t x0=x;							  	  
      	uint8_t bHz=0;     //�ַ��������� 
        while(*str!=0)//�������
        { 
            if(!bHz)
            {
    			if(x>(lcddev.width-size/2)||y>(lcddev.height-size)) 
    			return; 
    	        if(*str>0x80)bHz=1; 
    	        else              
    	        {          
    		        if(*str==0x0D)
    		        {         
    		            y+=size;
    					x=x0;
    		            str++; 
    		        }  
    		        else
    				{
    					if(size>16)
    					{  
    					LCD_ShowChar(x,y,fc,bc,*str,16,mode);
    					x+=8; 
    					}
    					else
    					{
    					LCD_ShowChar(x,y,fc,bc,*str,size,mode);
    					x+=size/2;  
    					}
    				} 
    				str++; 
    		        
    	        }
            }else//���� 
            {   
    			if(x>(lcddev.width-size)||y>(lcddev.height-size)) 
    			return;  
                bHz=0;    
    			if(size==32)
    			GUI_DrawFont32(x,y,fc,bc,str,mode);	 	
    			else if(size==24)
    			GUI_DrawFont24(x,y,fc,bc,str,mode);	
    			else
    			GUI_DrawFont16(x,y,fc,bc,str,mode);
    				
    	        str+=2; 
    	        x+=size;    
            }						 
        }   
    }
    
    /*****************************************************************************
     * @name       :void Gui_StrCenter(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode)
     * @date       :2018-08-09 
     * @function   :Centered display of English and Chinese strings
     * @parameters :x:the bebinning x coordinate of the Chinese and English strings
                    y:the bebinning y coordinate of the Chinese and English strings
    								fc:the color value of Chinese and English strings
    								bc:the background color of Chinese and English strings
    								str:the start address of the Chinese and English strings
    								size:the size of Chinese and English strings
    								mode:0-no overlying,1-overlying
     * @retvalue   :None
    ******************************************************************************/ 
    void Gui_StrCenter(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode)
    {
    	uint16_t len=strlen((const char *)str);
    	uint16_t x1=(lcddev.width-len*8)/2;
    	Show_Str(x1,y,fc,bc,str,size,mode);
    } 
     
    /*****************************************************************************
     * @name       :void Gui_Drawbmp16(uint16_t x,uint16_t y,const unsigned char *p)
     * @date       :2018-08-09 
     * @function   :Display a 16-bit BMP image
     * @parameters :x:the bebinning x coordinate of the BMP image
                    y:the bebinning y coordinate of the BMP image
    								p:the start address of image array
     * @retvalue   :None
    ******************************************************************************/ 
    void Gui_Drawbmp16(uint16_t x,uint16_t y,const unsigned char *p) 
    {
      	int i; 
    	unsigned char picH,picL; 
    	LCD_SetWindows(x,y,x+40-1,y+40-1);//��������
        for(i=0;i<40*40;i++)
    	{	
    	 	picL=*(p+i*2);	//���ݵ�λ��ǰ
    		picH=*(p+i*2+1);				
    		Lcd_WriteData_16Bit(picH<<8|picL);  						
    	}	
    	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);	
    }
    
    GUI.h
  • 
    #ifndef __GUI_H__
    #define __GUI_H__
    
    void GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
    void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color);
    void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
    void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
    void Draw_Circle(uint16_t x0,uint16_t y0,uint16_t fc,uint8_t r);
    void Draw_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
    void Fill_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
    void LCD_ShowChar(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode);
    void LCD_ShowNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size);
    void LCD_Show2Num(uint16_t x,uint16_t y,uint16_t num,uint8_t len,uint8_t size,uint8_t mode);
    void LCD_ShowString(uint16_t x,uint16_t y,uint8_t size,uint8_t *p,uint8_t mode);
    void GUI_DrawFont16(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode);
    void GUI_DrawFont24(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode);
    void GUI_DrawFont32(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *s,uint8_t mode);
    void Show_Str(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode);
    void Gui_Drawbmp16(uint16_t x,uint16_t y,const unsigned char *p); //��ʾ40*40 QQͼƬ
    void gui_circle(int xc, int yc,uint16_t c,int r, int fill);
    void Gui_StrCenter(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode);
    void LCD_DrawFillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
    #endif
    
    
    font.h
  • 注意字体
  • 
    #ifndef __FONT_H
    #define __FONT_H 	   
    //常用ASCII�??
    //偏移�??32
    //ASCII字�?�集
    //偏移�??32
    //大小:12*6
    const unsigned char asc2_1206[95][12]={
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
    {0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x04,0x00,0x00},/*"!",1*/
    {0x00,0x14,0x0A,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
    {0x00,0x00,0x14,0x14,0x3F,0x14,0x0A,0x3F,0x0A,0x0A,0x00,0x00},/*"#",3*/
    {0x00,0x04,0x1E,0x15,0x05,0x06,0x0C,0x14,0x15,0x0F,0x04,0x00},/*"$",4*/
    {0x00,0x00,0x12,0x15,0x0D,0x0A,0x14,0x2C,0x2A,0x12,0x00,0x00},/*"%",5*/
    {0x00,0x00,0x04,0x0A,0x0A,0x1E,0x15,0x15,0x09,0x36,0x00,0x00},/*"&",6*/
    {0x00,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
    {0x00,0x20,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x20,0x00},/*"(",8*/
    {0x00,0x02,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x04,0x02,0x00},/*")",9*/
    {0x00,0x00,0x00,0x04,0x15,0x0E,0x0E,0x15,0x04,0x00,0x00,0x00},/*"*",10*/
    {0x00,0x00,0x04,0x04,0x04,0x1F,0x04,0x04,0x04,0x00,0x00,0x00},/*"+",11*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x01},/*",",12*/
    {0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00},/*".",14*/
    {0x00,0x10,0x08,0x08,0x08,0x04,0x04,0x02,0x02,0x02,0x01,0x00},/*"/",15*/
    {0x00,0x00,0x0E,0x11,0x11,0x11,0x11,0x11,0x11,0x0E,0x00,0x00},/*"0",16*/
    {0x00,0x00,0x04,0x06,0x04,0x04,0x04,0x04,0x04,0x0E,0x00,0x00},/*"1",17*/
    {0x00,0x00,0x0E,0x11,0x11,0x08,0x04,0x02,0x01,0x1F,0x00,0x00},/*"2",18*/
    {0x00,0x00,0x0E,0x11,0x10,0x0C,0x10,0x10,0x11,0x0E,0x00,0x00},/*"3",19*/
    {0x00,0x00,0x08,0x0C,0x0A,0x0A,0x09,0x1E,0x08,0x18,0x00,0x00},/*"4",20*/
    {0x00,0x00,0x1F,0x01,0x01,0x0F,0x10,0x10,0x11,0x0E,0x00,0x00},/*"5",21*/
    {0x00,0x00,0x0E,0x09,0x01,0x0F,0x11,0x11,0x11,0x0E,0x00,0x00},/*"6",22*/
    {0x00,0x00,0x1F,0x09,0x08,0x04,0x04,0x04,0x04,0x04,0x00,0x00},/*"7",23*/
    {0x00,0x00,0x0E,0x11,0x11,0x0E,0x11,0x11,0x11,0x0E,0x00,0x00},/*"8",24*/
    {0x00,0x00,0x0E,0x11,0x11,0x11,0x1E,0x10,0x12,0x0E,0x00,0x00},/*"9",25*/
    {0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x04,0x00,0x00},/*":",26*/
    {0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x04,0x00},/*";",27*/
    {0x00,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x00,0x00},/*"<",28*/
    {0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x1F,0x00,0x00,0x00,0x00},/*"=",29*/
    {0x00,0x02,0x04,0x08,0x10,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*">",30*/
    {0x00,0x00,0x0E,0x11,0x11,0x08,0x04,0x04,0x00,0x04,0x00,0x00},/*"?",31*/
    {0x00,0x00,0x0E,0x11,0x19,0x15,0x15,0x1D,0x01,0x1E,0x00,0x00},/*"@",32*/
    {0x00,0x00,0x04,0x04,0x0C,0x0A,0x0A,0x1E,0x12,0x33,0x00,0x00},/*"A",33*/
    {0x00,0x00,0x0F,0x12,0x12,0x0E,0x12,0x12,0x12,0x0F,0x00,0x00},/*"B",34*/
    {0x00,0x00,0x1E,0x11,0x01,0x01,0x01,0x01,0x11,0x0E,0x00,0x00},/*"C",35*/
    {0x00,0x00,0x0F,0x12,0x12,0x12,0x12,0x12,0x12,0x0F,0x00,0x00},/*"D",36*/
    {0x00,0x00,0x1F,0x12,0x0A,0x0E,0x0A,0x02,0x12,0x1F,0x00,0x00},/*"E",37*/
    {0x00,0x00,0x1F,0x12,0x0A,0x0E,0x0A,0x02,0x02,0x07,0x00,0x00},/*"F",38*/
    {0x00,0x00,0x1C,0x12,0x01,0x01,0x39,0x11,0x12,0x0C,0x00,0x00},/*"G",39*/
    {0x00,0x00,0x33,0x12,0x12,0x1E,0x12,0x12,0x12,0x33,0x00,0x00},/*"H",40*/
    {0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"I",41*/
    {0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x09,0x07,0x00},/*"J",42*/
    {0x00,0x00,0x37,0x12,0x0A,0x06,0x0A,0x0A,0x12,0x37,0x00,0x00},/*"K",43*/
    {0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x22,0x3F,0x00,0x00},/*"L",44*/
    {0x00,0x00,0x1B,0x1B,0x1B,0x1B,0x15,0x15,0x15,0x15,0x00,0x00},/*"M",45*/
    {0x00,0x00,0x3B,0x12,0x16,0x16,0x1A,0x1A,0x12,0x17,0x00,0x00},/*"N",46*/
    {0x00,0x00,0x0E,0x11,0x11,0x11,0x11,0x11,0x11,0x0E,0x00,0x00},/*"O",47*/
    {0x00,0x00,0x0F,0x12,0x12,0x0E,0x02,0x02,0x02,0x07,0x00,0x00},/*"P",48*/
    {0x00,0x00,0x0E,0x11,0x11,0x11,0x11,0x17,0x19,0x0E,0x18,0x00},/*"Q",49*/
    {0x00,0x00,0x0F,0x12,0x12,0x0E,0x0A,0x12,0x12,0x37,0x00,0x00},/*"R",50*/
    {0x00,0x00,0x1E,0x11,0x01,0x06,0x08,0x10,0x11,0x0F,0x00,0x00},/*"S",51*/
    {0x00,0x00,0x1F,0x15,0x04,0x04,0x04,0x04,0x04,0x0E,0x00,0x00},/*"T",52*/
    {0x00,0x00,0x33,0x12,0x12,0x12,0x12,0x12,0x12,0x0C,0x00,0x00},/*"U",53*/
    {0x00,0x00,0x33,0x12,0x12,0x0A,0x0A,0x0C,0x04,0x04,0x00,0x00},/*"V",54*/
    {0x00,0x00,0x15,0x15,0x15,0x0E,0x0A,0x0A,0x0A,0x0A,0x00,0x00},/*"W",55*/
    {0x00,0x00,0x1B,0x0A,0x0A,0x04,0x04,0x0A,0x0A,0x1B,0x00,0x00},/*"X",56*/
    {0x00,0x00,0x1B,0x0A,0x0A,0x04,0x04,0x04,0x04,0x0E,0x00,0x00},/*"Y",57*/
    {0x00,0x00,0x1F,0x09,0x08,0x04,0x04,0x02,0x12,0x1F,0x00,0x00},/*"Z",58*/
    {0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x1C,0x00},/*"[",59*/
    {0x00,0x02,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x00,0x00},/*"\",60*/
    {0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0E,0x00},/*"]",61*/
    {0x00,0x04,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F},/*"_",63*/
    {0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
    {0x00,0x00,0x00,0x00,0x00,0x0C,0x12,0x1C,0x12,0x3C,0x00,0x00},/*"a",65*/
    {0x00,0x00,0x03,0x02,0x02,0x0E,0x12,0x12,0x12,0x0E,0x00,0x00},/*"b",66*/
    {0x00,0x00,0x00,0x00,0x00,0x1C,0x12,0x02,0x02,0x1C,0x00,0x00},/*"c",67*/
    {0x00,0x00,0x18,0x10,0x10,0x1C,0x12,0x12,0x12,0x3C,0x00,0x00},/*"d",68*/
    {0x00,0x00,0x00,0x00,0x00,0x0C,0x12,0x1E,0x02,0x1C,0x00,0x00},/*"e",69*/
    {0x00,0x00,0x38,0x04,0x04,0x1E,0x04,0x04,0x04,0x1E,0x00,0x00},/*"f",70*/
    {0x00,0x00,0x00,0x00,0x00,0x3C,0x12,0x0C,0x02,0x1E,0x22,0x1C},/*"g",71*/
    {0x00,0x00,0x03,0x02,0x02,0x0E,0x12,0x12,0x12,0x37,0x00,0x00},/*"h",72*/
    {0x00,0x00,0x04,0x00,0x00,0x06,0x04,0x04,0x04,0x0E,0x00,0x00},/*"i",73*/
    {0x00,0x00,0x08,0x00,0x00,0x0C,0x08,0x08,0x08,0x08,0x08,0x07},/*"j",74*/
    {0x00,0x00,0x03,0x02,0x02,0x3A,0x0A,0x0E,0x12,0x37,0x00,0x00},/*"k",75*/
    {0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"l",76*/
    {0x00,0x00,0x00,0x00,0x00,0x0F,0x15,0x15,0x15,0x15,0x00,0x00},/*"m",77*/
    {0x00,0x00,0x00,0x00,0x00,0x0F,0x12,0x12,0x12,0x37,0x00,0x00},/*"n",78*/
    {0x00,0x00,0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0C,0x00,0x00},/*"o",79*/
    {0x00,0x00,0x00,0x00,0x00,0x0F,0x12,0x12,0x12,0x0E,0x02,0x07},/*"p",80*/
    {0x00,0x00,0x00,0x00,0x00,0x1C,0x12,0x12,0x12,0x1C,0x10,0x38},/*"q",81*/
    {0x00,0x00,0x00,0x00,0x00,0x1B,0x06,0x02,0x02,0x07,0x00,0x00},/*"r",82*/
    {0x00,0x00,0x00,0x00,0x00,0x1E,0x02,0x0C,0x10,0x1E,0x00,0x00},/*"s",83*/
    {0x00,0x00,0x00,0x04,0x04,0x0E,0x04,0x04,0x04,0x18,0x00,0x00},/*"t",84*/
    {0x00,0x00,0x00,0x00,0x00,0x1B,0x12,0x12,0x12,0x3C,0x00,0x00},/*"u",85*/
    {0x00,0x00,0x00,0x00,0x00,0x37,0x12,0x0A,0x0C,0x04,0x00,0x00},/*"v",86*/
    {0x00,0x00,0x00,0x00,0x00,0x15,0x15,0x0E,0x0A,0x0A,0x00,0x00},/*"w",87*/
    {0x00,0x00,0x00,0x00,0x00,0x1B,0x0A,0x04,0x0A,0x1B,0x00,0x00},/*"x",88*/
    {0x00,0x00,0x00,0x00,0x00,0x37,0x12,0x0A,0x0C,0x04,0x04,0x03},/*"y",89*/
    {0x00,0x00,0x00,0x00,0x00,0x1E,0x08,0x04,0x04,0x1E,0x00,0x00},/*"z",90*/
    {0x00,0x18,0x08,0x08,0x08,0x04,0x08,0x08,0x08,0x08,0x18,0x00},/*"{",91*/
    {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08},/*"|",92*/
    {0x00,0x06,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x06,0x00},/*"}",93*/
    {0x02,0x25,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} /*"~",94*/
    }; 
    const unsigned char asc2_1608[95][16]={
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
    {0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00},/*"!",1*/
    {0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
    {0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00},/*"#",3*/
    {0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08},/*"$",4*/
    {0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00},/*"%",5*/
    {0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00},/*"&",6*/
    {0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
    {0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00},/*"(",8*/
    {0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00},/*")",9*/
    {0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00},/*"*",10*/
    {0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00},/*"+",11*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03},/*",",12*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00},/*".",14*/
    {0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00},/*"/",15*/
    {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",16*/
    {0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",17*/
    {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00},/*"2",18*/
    {0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00},/*"3",19*/
    {0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00},/*"4",20*/
    {0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00},/*"5",21*/
    {0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",22*/
    {0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00},/*"7",23*/	 
    {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",24*/
    {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00},/*"9",25*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",26*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04},/*";",27*/
    {0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00},/*"<",28*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},/*"=",29*/
    {0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*">",30*/
    {0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00},/*"?",31*/
    {0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00},/*"@",32*/
    {0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00},/*"A",33*/
    {0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00},/*"B",34*/
    {0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00},/*"C",35*/
    {0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00},/*"D",36*/
    {0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00},/*"E",37*/
    {0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00},/*"F",38*/
    {0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00},/*"G",39*/
    {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"H",40*/
    {0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"I",41*/
    {0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F},/*"J",42*/
    {0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00},/*"K",43*/
    {0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00},/*"L",44*/
    {0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00},/*"M",45*/
    {0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00},/*"N",46*/
    {0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00},/*"O",47*/
    {0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00},/*"P",48*/
    {0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00},/*"Q",49*/
    {0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00},/*"R",50*/
    {0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00},/*"S",51*/
    {0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00},/*"T",52*/
    {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"U",53*/
    {0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00},/*"V",54*/
    {0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00},/*"W",55*/
    {0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00},/*"X",56*/
    {0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00},/*"Y",57*/
    {0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00},/*"Z",58*/
    {0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00},/*"[",59*/
    {0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40},/*"\",60*/
    {0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00},/*"]",61*/
    {0x00,0x38,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},/*"_",63*/
    {0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00},/*"a",65*/
    {0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00},/*"b",66*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00},/*"c",67*/
    {0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00},/*"d",68*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00},/*"e",69*/
    {0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"f",70*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C},/*"g",71*/
    {0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"h",72*/
    {0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"i",73*/
    {0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E},/*"j",74*/
    {0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00},/*"k",75*/
    {0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"l",76*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00},/*"m",77*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"n",78*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"o",79*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07},/*"p",80*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0},/*"q",81*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"r",82*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00},/*"s",83*/
    {0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00},/*"t",84*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00},/*"u",85*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00},/*"v",86*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00},/*"w",87*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00},/*"x",88*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07},/*"y",89*/
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00},/*"z",90*/
    {0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00},/*"{",91*/
    {0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10},/*"|",92*/
    {0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00},/*"}",93*/
    {0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/
    }; 
    typedef struct 
    {
           unsigned char Index[4];	
           char Msk[32];
    }typFNT_GB16; 
    
    const typFNT_GB16 tfont16[]=   
    {
    
    "��",0x40,0x00,0x40,0x80,0x41,0x40,0x41,0x40,0x41,0x30,0x41,0x18,0x41,0x07,0xFE,0x01,
    0x81,0x00,0x41,0x03,0x41,0x0C,0x41,0x30,0x41,0x60,0x41,0xC0,0x61,0xC0,0x40,0x80,
    "��",0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0xFF,0xFF,
    0x40,0x80,0x40,0x80,0x40,0x80,0x40,0x80,0x40,0x80,0x60,0x80,0x40,0x80,0x00,0xC0,
    "��",0x40,0xC0,0x40,0x40,0xFE,0x7F,0x40,0x20,0x40,0x21,0x00,0x01,0x80,0x00,0xF8,0xFF,
    0x80,0x00,0x40,0x00,0xFF,0x3F,0x40,0x00,0x20,0x08,0x20,0x18,0xF0,0x0F,0x00,0xE0,
    "��",0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFE,0xFF,
    0x21,0x00,0x21,0x00,0x41,0x00,0x41,0x00,0xC1,0x00,0x81,0x01,0x01,0x00,0x01,0x00,
    
    };
    typedef struct 
    {
           unsigned char Index[4];	
           char Msk[72];
    }typFNT_GB24; 
    
    const typFNT_GB24 tfont24[]=
    {
    
    "��",0x00,0x01,0x80,0x00,0x01,0x80,0x01,0x01,0x40,0x01,0x01,0x60,0x01,0x01,0x30,0x01,
    0x01,0x18,0x01,0x01,0x0C,0x01,0x01,0x07,0x01,0xC1,0x03,0x01,0xF9,0x00,0xFF,0x3F,
    0x00,0xFF,0x03,0x00,0x01,0x01,0x00,0x01,0x0F,0x00,0x01,0x31,0x00,0x01,0xC1,0x00,
    0x01,0x81,0x03,0x01,0x01,0x06,0x01,0x01,0x0C,0x01,0x01,0x18,0x01,0x01,0x38,0x81,
    0x01,0x70,0x80,0x01,0x70,0x00,0x01,0x60,/*"��",0*/
    "��",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
    0xFF,0xFE,0xFF,0xFF,0x02,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,
    0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x06,0x00,0x00,0x06,0x00,0x00,
    0x04,0x00,0x00,0x00,0x80,0x00,0x00,0x80,/*"��",1*/
    "��",0x00,0x02,0x60,0x00,0x02,0x60,0x00,0x02,0x20,0xFF,0xFF,0x3F,0x02,0x02,0x10,0x00,
    0x02,0x10,0x00,0x13,0x08,0x00,0x0A,0x08,0x00,0x08,0x04,0x00,0x08,0x00,0xF8,0xFF,
    0xFF,0xF8,0xFF,0xFF,0x00,0x04,0x00,0x00,0x02,0x00,0x00,0x02,0x00,0xFF,0xFF,0x0F,
    0xFF,0xFF,0x0F,0x00,0x01,0x01,0x80,0x00,0x01,0x80,0x00,0x02,0x40,0x00,0x06,0xE0,
    0xFF,0x03,0xC0,0x00,0x80,0x00,0x00,0xF8,/*"��",2*/
    "��",0x01,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x01,
    0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x01,0x00,
    0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x81,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x00,
    0x01,0x03,0x00,0x01,0x06,0x00,0x01,0x06,0x00,0x01,0x0E,0x00,0x01,0x3C,0x00,0x01,
    0x38,0x00,0x01,0x00,0x00,0x01,0x00,0x00,/*"��",3*/
    
    };  
    typedef struct 
    {
           unsigned char Index[4];	
           char Msk[128];
    }typFNT_GB32; 
    
    const typFNT_GB32 tfont32[]=
    {
    
    
    "��",0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x80,0x02,0x20,0x00,0xC0,
    0x02,0x20,0x00,0x60,0x02,0x20,0x00,0x20,0x02,0x20,0x00,0x30,0x02,0x20,0x00,0x18,
    0x02,0x20,0x00,0x0E,0x02,0x20,0x00,0x07,0x02,0x20,0xC0,0x03,0x02,0x20,0xF0,0x01,
    0x02,0x20,0x7E,0x00,0x02,0xE0,0x1F,0x00,0xFE,0xFF,0x07,0x00,0xFE,0x7F,0x00,0x00,
    0x02,0x20,0x00,0x00,0x02,0xE0,0x00,0x00,0x02,0x20,0x07,0x00,0x02,0x20,0x1C,0x00,
    0x02,0x20,0x70,0x00,0x02,0x20,0xC0,0x01,0x02,0x20,0x80,0x03,0x02,0x20,0x00,0x0E,
    0x02,0x20,0x00,0x1C,0x03,0x20,0x00,0x3C,0x03,0x20,0x00,0x78,0x03,0x30,0x00,0x70,
    0x02,0x38,0x00,0xF0,0x00,0x38,0x00,0xE0,0x00,0x30,0x00,0xE0,0x00,0x20,0x00,0xC0,/*"��",0*/
    "��",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,
    0x02,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,
    0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,
    0x00,0x20,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x38,0x00,0x00,
    0x00,0x30,0x00,0x00,0x00,0x20,0x00,0x80,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,/*"��",1*/
    "��",0x00,0x20,0x00,0xE0,0x00,0x20,0x00,0x60,0x00,0x20,0x00,0x70,0xFE,0xFF,0xFF,0x3F,
    0xFE,0xFF,0xFF,0x3F,0xFC,0xFF,0xFF,0x1F,0x04,0x20,0x00,0x18,0x00,0x20,0x00,0x08,
    0x00,0x30,0x01,0x0C,0x00,0x30,0x01,0x04,0x00,0x20,0x01,0x04,0x00,0x80,0x00,0x02,
    0x00,0x80,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xE0,0xFF,0xFF,0xFF,0x60,0x40,0x00,0x80,
    0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x10,0x00,0x00,
    0xFF,0xFF,0xFF,0x0F,0xFF,0xFF,0xFF,0x07,0x03,0x08,0x00,0x00,0x00,0x08,0x40,0x00,
    0x00,0x04,0x40,0x00,0x00,0x04,0x80,0x00,0x00,0x02,0x80,0x01,0x00,0x02,0x80,0x03,
    0x00,0xFF,0xFF,0x01,0x00,0xFF,0xFF,0x00,0x00,0x02,0x00,0x80,0x00,0x00,0x00,0xFF,/*"��",2*/
    "��",0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
    0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
    0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
    0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,
    0x02,0x04,0x00,0x00,0x02,0x08,0x00,0x00,0x02,0x08,0x00,0x00,0x02,0x18,0x00,0x00,
    0x02,0x30,0x00,0x00,0x02,0x30,0x00,0x00,0x02,0x70,0x00,0x00,0x02,0xE0,0x00,0x00,
    0x02,0xE0,0x01,0x00,0x02,0xC0,0x03,0x00,0x02,0xC0,0x07,0x00,0x02,0x80,0x0F,0x00,
    0x03,0x00,0x06,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,/*"��",3*/
    
    };
      
    #endif
    

### STM32 HAL TFT液晶屏驱动 示例代码 使用教程 #### 1. 初始化硬件资源 为了使STM32微控制器能够与TFT液晶屏幕通信,需先初始化SPI接口和其他必要的外设。这步骤通常涉及设置GPIO引脚模式以及配置SPI参数。 ```c // 配置SPI和GPIO引脚 void MX_SPI1_Init(void) { /* 定义SPI句柄 */ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; // 设置为主模式 hspi1.Init.Direction = SPI_DIRECTION_2LINES; // 双向传输 hspi1.Init.DataSize = SPI_DATASIZE_8BIT; // 数据大小为8位 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; // SCLK空闲状态低电平 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; // 第跳变沿采样数据 hspi1.Init.NSS = SPI_NSS_SOFT; // 软件管理NSS信号 if (HAL_SPI_Init(&hspi1) != HAL_OK){ Error_Handler(); } } ``` 此部分代码展示了如何使用HAL来初始化SPI模块[^1]。 #### 2. 控制命令发送至LCD显示屏 旦完成了上述的初始化工作,则可以通过编写特定的功能函数来操作TFT显示器。下面是个简单的例子,用于向LCD发送指令: ```c /* 向LCD写入单字节命令 */ static void LCD_WriteCommand(uint8_t reg) { GPIO_ResetBits(LCD_CS_GPIO_PORT, LCD_CS_PIN); // CS拉低选通 GPIO_ResetBits(LCD_DC_GPIO_PORT, LCD_DC_PIN); // DC=0表示命令 HAL_SPI_Transmit(&hspi1, &reg, 1, HAL_MAX_DELAY); GPIO_SetBits(LCD_CS_GPIO_PORT, LCD_CS_PIN); // CS拉高取消选通 } /* 向LCD写入单字节数据 */ static void LCD_WriteData(uint8_t data) { GPIO_ResetBits(LCD_CS_GPIO_PORT, LCD_CS_PIN); // CS拉低选通 GPIO_SetBits(LCD_DC_GPIO_PORT, LCD_DC_PIN); // DC=1表示数据 HAL_SPI_Transmit(&hspi1, &data, 1, HAL_MAX_DELAY); GPIO_SetBits(LCD_CS_GPIO_PORT, LCD_CS_PIN); // CS拉高取消选通 } ``` 这些辅助方法允许程序轻松地执行诸如清屏、设定颜色等动作。 #### 3. 屏幕初始化序列 每种型号的TFT都有其独特的启动过程,在实际编程前应该查阅具体器件的数据手册了解详情。这里给出了般性的初始化流程作为参考: ```c void LCD_Init(void) { uint8_t cmd[]={ 0x11, // Sleep Out 0x29, // Display On ... }; for(int i=0;i<sizeof(cmd)/sizeof(*cmd);i++){ LCD_WriteCommand(cmd[i]); HAL_Delay(100); // 延迟等待完成相应操作 } // 更多初始化命令... } ``` 这段代码片段说明了怎样按照指定顺序发出系列控制命令以激活并准备好显示面板的工作环境[^2]。 #### 4. 绘图基础——绘制像素点 有了前面的基础之后就可以尝试些更复杂的绘图任务了。比如画个单独的颜色点可以这样做: ```c void DrawPixel(int16_t x,int16_t y,uint16_t color) { if(x >= 0 && x < LCD_WIDTH && y >= 0 && y < LCD_HEIGHT){ SetCursor(x,y); WriteWord(color); } } /** * @brief 移动光标到指定位置 * * @param Xpos 横坐标X轴方向的位置 * @param Ypos 纵坐标Y轴方向的位置 */ void SetCursor(int16_t Xpos, int16_t Ypos) { LCD_WriteCommand(ST77XX_CASET); // 列地址范围设置 LCD_WriteData((uint8_t)(Xpos >> 8)); LCD_WriteData((uint8_t)(Xpos & 0xFF)); LCD_WriteData((uint8_t)((Xpos + 15) >> 8)); // 这里假设宽度固定为16px LCD_WriteData((uint8_t)((Xpos + 15) & 0xFF)); LCD_WriteCommand(ST77XX_RASET); // 行地址范围设置 LCD_WriteData((uint8_t)(Ypos >> 8)); LCD_WriteData((uint8_t)(Ypos & 0xFF)); LCD_WriteData((uint8_t)((Ypos + 15) >> 8)); // 这里假设高度固定为16px LCD_WriteData((uint8_t)((Ypos + 15) & 0xFF)); LCD_WriteCommand(ST77XX_RAMWR); // 内存写入准备就绪 } ``` 以上实现了最基本的图形渲染单元——像素级别的修改功能[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值