📄 gui.c
字号:
/*******************************************************************************
名 称:GUI函数********底层TFT液晶驱动函数为ILI9325的驱动函数
功 能:本c文件封装了对12864液晶的一些简单的基本读写操作.
封装函数:
void GUI_clearscreen(uint b_color);//清屏
void GUI_Point(uchar x, uint y, uint color);//画点
void GUI_sprintf_chartobit(uchar x, uint y,uchar dat, uint color,uint b_color);//无符号字符型数以二进制形式显示
void GUI_sprintf_chartohex(uchar x, uint y,uchar dat, uint color,uint b_color);//无符号字符型数以十六进制形式显示
void GUI_sprintf_chartodec(uchar x,uint y,uchar dat,uint color,uint b_color);//无符号字符型数以十进制形式显示
void GUI_sprintf_nu(uchar x, uint y,uchar nu, uint color,uint b_color);//显示1位16进制数
void GUI_HLine(uchar x, uint y, uchar length, uint color);//画横线
void GUI_RLine(uchar x, uint y, uint high, uint color);//画竖线
void GUI_line(uint x1,uint y1,uint x2,uint y2,uint color);//画直线
void GUI_DisPicture(uchar x, uint y, uchar length, uint high,uchar *pBuff);//显示图片(图标)
void GUI_sprintf_char(uchar x, uint y,uchar c, uint color,uint b_color);//显示英文或数字字符
void GUI_sprintf_string(uchar x, uint y,char code *s, uint color,uint b_color);//显示英文字符串
void GUI_sprintf_HZ(uchar x, uint y, uint color,uint b_color);//显示预定义汉字字符串
void GUI_box(uchar sx,uint sy,uchar ex,uint ey,uint color);//画实心矩形
void GUI_rectangle( uchar sx,uint sy,uchar ex,uint ey,uint color);//画空心矩形
void GUI_wrul(uchar x, uint y, unsigned long num, uint color,uint b_color);//以十进制形式显示无符号长整型数
void GUI_wrlval(uchar x, uint y,unsigned long num,uchar bits,uchar dp,uint color,uint b_color);//以十进制形式显示长变量
uint RGB(uchar R,uchar G,uchar B);//RGB颜色混合
作 者:青涩的小黄瓜
最后修改时间:2011年12月24号
备注:
定义常用颜色的颜色码
#define RED 0xf800 //红
#define YELLOW 0xffe0 //黄
#define GREEN 0x07e0 //绿
#define CYAN 0x07ff //青
#define BLUE 0x001f //蓝
#define PURPLE 0xf81f //紫
#define BLACK 0x0000 //黑
#define WHITE 0xffff //白
#define GRAY 0x7bef //灰
典型应用:
以上函数均进行测试可以正常使用
*******************************************************************************/
#include "stm32f10x.h"
#include "gui.h"
#include "ILI9325.h"
//#include "bmp.h"
#include "16x8.h"
#include "chinese.h"
/************************************
清屏
入口参数: b_color是背景颜色。
出口参数: 无
说明:使用背景颜色清除TFT模块屏幕的全部显示内容。
*************************************/
void GUI_clearscreen(uint b_color)
{
uint i,j;
ILI9325_SetWindow(0,0,240,320);
for (i=0;i<320;i++)
{
for(j=0;j<240;j++)
ILI9325_WriteDataU16(b_color);
}
}
/*********************************************
画点
入口参数: (x,y)是点的坐标,color 是点的颜色。
出口参数: 无
说明:用指定的颜色在指定的坐标位置上画出一个点。
**********************************************/
void GUI_Point(uchar x, uint y, uint color)
{
ILI9325_SetXY(x,y);
ILI9325_WriteDataU16(color);
}
/**********************************************************
无符号字符型数以二进制形式显示
入口参数:(x,y)是显示内容的左上角坐标,color 是显示字符的颜色,
b_color是背景颜色。
出口参数: 无
说明:无符号字符型数用指定的颜色和背景颜色在指定的坐标位置上
以二进制形式显示出来。
************************************************************/
void GUI_sprintf_chartobit(uchar x, uint y,uchar dat, uint color,uint b_color)
{
uchar i ;
for(i=0;i<8;i++)
{
if((dat&(0x80>>i))==(0x80>>i))
{
GUI_sprintf_nu(x,y,1,color,b_color) ;
}
else
{
GUI_sprintf_nu(x,y,0,color,b_color) ;
}
x+=8 ;
}
}
/**********************************************************
无符号字符型数以十六进制形式显示
入口参数:(x,y)是显示内容的左上角坐标,dat 是欲显示的无符号字符型数,
color 是显示字符的颜色,b_color是背景颜色。
出口参数: 无
说明:无符号字符型数用指定的颜色和背景颜色在指定的坐标位置上
以十六进制形式显示出来。
************************************************************/
void GUI_sprintf_chartohex(uchar x, uint y,uchar dat, uint color,uint b_color)
{
GUI_sprintf_nu(x,y,dat>>4,color,b_color) ;
x+=8 ;
GUI_sprintf_nu(x,y,dat&0x0f,color,b_color) ;
}
/**********************************************************
无符号字符型数以十进制形式显示
入口参数:(x,y)是显示内容的左上角坐标,dat是欲显示的无符号字符型数,
color 是显示字符的颜色,b_color是背景颜色。
出口参数: 无
说明:无符号字符型数用指定的颜色和背景颜色在指定的坐标位置上
以十进制形式显示出来。
************************************************************/
void GUI_sprintf_chartodec(uchar x,uint y,uchar dat,uint color,uint b_color)
{
GUI_sprintf_char(x,y,dat/100+'0',color,b_color);
GUI_sprintf_char(x+8,y,dat/10%10+'0',color,b_color);
GUI_sprintf_char(x+16,y,dat%10+'0',color,b_color);
}
/*********************************************
显示1位16进制数
入口参数: (x,y) 是显示内容的左上角坐标,c:欲显示的1位16进制数,color:颜色,b_color:背景颜色。
出口参数: 无
说明:用指定位置上显示1位16进制数。
**********************************************/
void GUI_sprintf_nu(uchar x, uint y,uchar nu, uint color,uint b_color)
{
uchar s_x=0 ,s_y=0, temp=0 ;
uint j;
if (nu>9)
{nu=nu+7;}
nu=nu+16;
for(s_y=0;s_y<16;s_y++)
{
if(s_y+y<320)
{
j=nu;
j=j*16+s_y;
temp=font16x8[j];
//temp = font16x8[nu*16+s_y] ;
for( s_x=0 ; s_x<8 ; s_x++ )
{
if(x+s_x<240)
{
if((temp&(0x80>>(s_x))) == (0x80>>(s_x)) )
{
GUI_Point(x+s_x, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x, y+s_y,b_color) ;
}
}
}
}
}
}
/**********************************************************
画横线
入口参数: (x,y)是横线起点坐标,length是横线长度,color 是横线颜色。
出口参数: 无
说明:用指定的颜色在指定位置上画出指定长度的一条横线。
************************************************************/
void GUI_HLine(uchar x, uint y, uchar length, uint color)
{
ILI9325_SetWindow(x,y,x+length-1,y);
do
{
ILI9325_WriteDataU16(color);//逐点显示,描出水平线
length--;
}while(length);
}
/**********************************************************
画竖线
入口参数: (x,y)是竖线起点坐标,high 竖线高度,color 是竖线颜色。
出口参数: 无
说明:用指定的颜色在指定位置上画出指定长度的一条竖线。
************************************************************/
void GUI_RLine(uchar x, uint y, uint high, uint color)
{
ILI9325_SetWindow(x,y,x,y+high-1);
do
{
ILI9325_WriteDataU16(color);// 逐点显示,描出垂直线
high--;
}while(high);
}
/********************************************************************
画直线(可以画任意方向直线,包括横线、竖线、斜线)。
入口参数: (x1,y1)起点, (x2,y2)终点, color颜色。
出口参数: 无
说明:用指定的颜色在指定的两点间画出一条直线。
***********************************************************************/
void GUI_line(uint x1,uint y1,uint x2,uint y2,uint color)
{
uint t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy;
uint row,col;
delta_x = x2-x1;//计算坐标增量
delta_y = y2-y1;
col=x1;
row=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++)
{ //画线输出
GUI_Point(col, row, color);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
col+=incx;
}
if(yerr>distance)
{
yerr-=distance;
row+=incy;
}
}
}
/**********************************************************
显示图片(图标)
入口参数:(x,y)是开始点的坐标,length是图片长度,high是图片高度。*pBuff 图片数组的指针
出口参数: 无
说明:用指定位置上显示事先定义的图片。
建议用Image2Lcd软件将你要显示的图象自动转换为数组数据。
************************************************************/
//void GUI_DisPicture(uchar x, uint y, uchar length, uint high ,const uchar *pic)
void GUI_DisPicture(uchar x, uint y, uchar length, uint high,const uchar *pBuff)
{
uint temp=0,tmp=0,num=0;
ILI9325_SetWindow(x,y,x+length-1,y+high-1);
num=length*high*2;
do
{
//temp=pic[tmp]|( pic[tmp+1]<<8);
temp=pBuff[tmp+1];
temp=temp<<8;
temp=temp|pBuff[tmp];
ILI9325_WriteDataU16(temp);//逐点显示
tmp+=2;
}while(tmp<num);
}
/*********************************************
显示英文或数字字符
入口参数:(x,y) 是显示内容的左上角坐标,c:显示的英文字符,
color:颜色,b_color:背景颜色。
出口参数: 无
说明:用指定位置上显示单个英文字符或数字字符。
**********************************************/
void GUI_sprintf_char(uchar x, uint y,uchar c, uint color,uint b_color)
{
uchar s_x ,s_y, temp ;
uint j;
c -= 32;
for( s_y=0 ; s_y < 16 ; s_y++ )
{
if(s_y+y<320)
{
j=c;
j=j*16+s_y;
temp=font16x8[j];
//temp = font16x8[c*16+s_y] ;
for( s_x=0 ; s_x<8 ; s_x++ )
{
if(x+s_x<240)
{
if((temp&(0x80>>(s_x))) == (0x80>>(s_x)) )
{
GUI_Point(x+s_x, y+s_y,color) ;
}
else
{
GUI_Point(x+s_x, y+s_y,b_color) ;
}
}
}
}
}
}
/*********************************************
显示英文字符串
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -