#include "GBK_LibDrive.h" ////////////////////////////////////////////////////////////////////////////////// //汉字字库--驱动代码 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //******************************************************************************** ////////////////////////////////////////////////////////////////////////////////// void GBK_Lib_Init(void) { #if Used_FontIO GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOF, ENABLE);//使能GPIOB,C,F时钟 //PB1,2初始化设置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PB2 设置为上拉输入 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //输入模式 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉 GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PB0设置为推挽输出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //输出模式 GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //PC13设置为推挽输出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //输出模式 GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //PF11设置推挽输出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //输出模式 GPIO_Init(GPIOF, &GPIO_InitStructure); //初始化 FCLK_SET;//空闲状态为高电平 #endif GBK_ReadID(); //读取加密关键字节. --使用字库前,必须先读取一次字库关键字符串, //确认字库已经解锁,否则会出现缺失字符的现象 } ////////////////////////////////////////////////////////////////////////////////// //延时函数--驱动代码 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //******************************************************************************** ////////////////////////////////////////////////////////////////////////////////// void GBK_delay(unsigned char Time) { unsigned char m,n; for(n=0;n>16)); //发送24bit地址 Font_SPI_WR((u8)((ReadAddr)>>8)); Font_SPI_WR((u8)ReadAddr); for(i=0;i0x80)bHz=1;//中文 else //字符 { if(x>(x0+width-size/2))//换行 { y+=size; x=x0; } if(y>(y0+height-size))break;//越界返回 if(*str==13)//换行符号 { y+=size; x=x0; str++; } else GBK_ShowASCII(x, y, str, size, D_Color, B_Color, mode); //LCD_ShowChar(x,y,*str,size,mode);//有效部分写入 str++; x+=size/2; //字符,为全字的一半 } } else//中文 { bHz=0;//有汉字库 if(x>(x0+width-size))//换行 { y+=size; x=x0; } if(y>(y0+height-size))break; //越界返回 GBK_Show_Font(x,y,str,size, D_Color, B_Color, mode); //显示这个汉字,空心显示 str+=2; x+=size;//下一个汉字偏移 } } } /////////////////////////////////////在指定宽度的中间显示字符串///////////////////////////////////////////////////////////////////////////// //函数:void GBK_Show_StrMid(uint16_t x,uint16_t y, uint8_t size, uint8_t len, uint16_t D_Color, uint16_t B_Color,uint8_t*str) //在指定宽度的中间显示字符串 //如果字符长度超过了len,则用GBK_Show__Str显示 //len:指定要显示的宽度 //D_Color:点阵字颜色 --16位 //B_Color:背景颜色 --16位 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //******************************************************************************** ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void GBK_Show_StrMid(uint16_t x,uint16_t y, uint8_t size, uint8_t len, uint16_t D_Color, uint16_t B_Color,uint8_t*str) { uint16_t strlenth=0; strlenth=strlen((const char*)str); strlenth*=size/2; if(strlenth>len)GBK_Show_Str(x,y,lcddev.width,lcddev.height,str,size,D_Color,B_Color,1); else { strlenth=(len-strlenth)/2; GBK_Show_Str(strlenth+x,y,lcddev.width,lcddev.height,str,size,D_Color,B_Color,1); } } //**************************************************************************************/ //函数:void DrawFont_GBK12B(u16 x,u16 y, u16 color, u8*str) //函数功能:在指定位置开始显示一个12x12点阵的--字符串,支持自动换行(至屏幕一行的终点后,自动换到下一个x起点位置) //参数: //(x,y):起始坐标 //color,字符颜色 //str :字符串 //非叠加方式;非点阵字符的部分,填充背景颜色 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //**************************************************************************************/ void DrawFont_GBK12B(u16 x,u16 y, u16 color, u8*str) { u16 width; u16 height; width=lcddev.width-x; height=lcddev.height-y; GBK_Show_Str(x,y,width,height, str, 12, color,BACK_COLOR, 0); } //**************************************************************************************/ //函数:void DrawFont_GBK16B(u16 x,u16 y, u16 color, u8*str) //函数功能:在指定位置开始显示一个16x16点阵的--字符串,支持自动换行(至屏幕一行的终点后,自动换到下一个x起点位置) //参数: //(x,y):起始坐标 //color,字符颜色 //str :字符串 //非叠加方式;非点阵字符的部分,填充背景颜色 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //**************************************************************************************/ void DrawFont_GBK16B(u16 x,u16 y, u16 color, u8*str) { u16 width; u16 height; width=lcddev.width-x; height=lcddev.height-y; GBK_Show_Str(x,y,width,height, str, 16, color,BACK_COLOR, 0); } //**************************************************************************************/ //函数:void DrawFont_GBK24B(u16 x,u16 y, u16 color, u8*str) //函数功能:在指定位置开始显示一个24x24点阵的--字符串,支持自动换行(至屏幕一行的终点后,自动换到下一个x起点位置) //参数: //(x,y):起始坐标 //color,字符颜色 //str :字符串 //非叠加方式;非点阵字符的部分,填充背景颜色 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //**************************************************************************************/ void DrawFont_GBK24B(u16 x,u16 y, u16 color, u8*str) { u16 width; u16 height; width=lcddev.width-x; height=lcddev.height-y; GBK_Show_Str(x,y,width,height, str, 24, color,BACK_COLOR, 0); } //**************************************************************************************/ //函数:void DrawFont_GBK32B(u16 x,u16 y, u16 color, u8*str) //函数功能:在指定位置开始显示一个32x32点阵的--字符串,支持自动换行(至屏幕一行的终点后,自动换到下一个x起点位置) //参数: //(x,y):起始坐标 //color,字符颜色 //str :字符串 //非叠加方式;非点阵字符的部分,填充背景颜色 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //**************************************************************************************/ void DrawFont_GBK32B(u16 x,u16 y, u16 color, u8*str) { u16 width; u16 height; width=lcddev.width-x; height=lcddev.height-y; GBK_Show_Str(x,y,width,height, str, 32, color,BACK_COLOR, 0); } //**************************************************************************************/ //函数:void DrawFontASC_GBK48B(u16 x,u16 y, u16 color, u8*str) //函数功能:在指定位置开始显示一个24x48点阵的--ACSII码 (本字库只支持ASCII码),支持自动换行(至屏幕一行的终点后,自动换到下一个x起点位置) //参数: //(x,y):起始坐标 //color,字符颜色 //str :字符串 //非叠加方式;非点阵字符的部分,填充背景颜色 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //**************************************************************************************/ void DrawFontASC_GBK48B(u16 x,u16 y, u16 color, u8*str) { u16 width; u16 height; width=lcddev.width-x; height=lcddev.height-y; GBK_Show_Str(x,y,width,height, str, 48, color,BACK_COLOR, 0); } //**************************************************************************************/ //函数:void DrawFontASC_GBK64B(u16 x,u16 y, u16 color, u8*str) //函数功能:在指定位置开始显示一个32x64点阵的--ACSII码 (本字库只支持ASCII码),支持自动换行(至屏幕一行的终点后,自动换到下一个x起点位置) //参数: //(x,y):起始坐标 //color,字符颜色 //str :字符串 //非叠加方式;非点阵字符的部分,填充背景颜色 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com //**************************************************************************************/ void DrawFontASC_GBK64B(u16 x,u16 y, u16 color, u8*str) { u16 width; u16 height; width=lcddev.width-x; height=lcddev.height-y; GBK_Show_Str(x,y,width,height, str, 64, color,BACK_COLOR, 0); } //****************************************************************************************/ //函数:void GBK_LibFont_Test(void) //功能描述: GBK字体字形显示测试 //DevEBox 大越创新 //淘宝店铺:mcudev.taobao.com //淘宝店铺:shop389957290.taobao.com /****************************************************************************************/ void GBK_LibFont_Test(void) { LCD_Clear(GRAY0); DrawFont_GBK16B(24,16,BLUE,"2: GBK字库--显示测试"); delay_ms(1000); LCD_Clear(GRAY0); GBK_Show_Str(24,0,240,32,"十种字库测试",32,D_Color,GRAY0,0); GBK_Show_Str(16,40,240,16,"设计:大越电子",16,D_Color,B_Color,0); GBK_Show_Str(16,56,240,16,"From: mcudev.taobao.com",16,D_Color,B_Color,0); DrawFont_GBK12B(16,72,BLUE,"Date: 2019/05/08"); GBK_Show_StrMid(16,96,12,200,BLUE,GRAY0,"居中显示函数: 2019/05/08");//居中显示 GBK_Show_Str(16,120,240,12,"汉字12x12-GBK字库:",12,D_Color,B_Color,0); //显示内码低字节 GBK_Show_Str(16,136,240,16,"汉字16x16字库:",16,D_Color,B_Color,0); //显示内码低字节 GBK_Show_Str(16,156,240,24,"24x24字库:",24,D_Color,B_Color,0); //显示内码低字节 DrawFont_GBK32B(16,184,BLUE,"32x32字库:"); //显示内码低字节 //GBK_Show_Str(16,220,240,48,"48",48,D_Color,B_Color,0); DrawFontASC_GBK48B(16,220,BLUE,"48"); //GBK_Show_Str(120,220,240,64,"64",64,D_Color,B_Color,0); DrawFontASC_GBK64B(120,220,BLUE,"64"); delay_ms(3000); }