- #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****/
復制代碼 |