#include "LSM/ILI9325.h"
#include "Function.h"
#include "ASCll.h"
#include "Chainese.h"
#include "poto.h"
/*******************************************************************************
TFT屏显示功能函数
*******************************************************************************/
/********************************************************************************
画点 *
*
*********************************************************************************/
void Draw_points(U8 x,U16 y,U16 color)
{
TFT_setwindow(x,y,x,y);
TFT_write_data_u16(color);
}
/******************************************************************************
画线
这个线可以完美运行
x0,y0:起始位置
x1,y1:结束位置
*******************************************************************************/
void Draw_lines(U8 x0,U16 y0,U8 x1,U16 y1,U16 color)
{
U16 t;
int xerr = 0, yerr = 0, delta_x, delta_y, distance;
int incx, incy;
U16 row, col;
delta_x = x1 - x0;//计算坐标增量
delta_y = y1 - y0;
col = x0;
row = y0;
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_Dot(col, row, color);
TFT_setwindow(col,row,col,row);
TFT_write_data_u16(color);
xerr += delta_x;
yerr += delta_y;
if(xerr > distance)
{
xerr -= distance;
col += incx;
}
if(yerr > distance)
{
yerr -= distance;
row += incy;
}
}
}
/******************************************************************************
画面
x0,y0:起始位置
x,y:相当于长和宽,不是结束位置,它是你想要的面积。相当于x*y
*******************************************************************************/
void Draw_picture(U8 x0,U16 y0,U8 x,U16 y,U16 color)
{
U16 num,y1 = 0;
U8 n,x1 = 0;
x1 = x+x0;
y1 = y+y0;
TFT_setwindow(x0,y0,x1,y1);
for(n=x0;n<(x1+1);n++)
{
for(num=y0;num<(y1+1);num++)
{
TFT_write_data_u16(color);
}
}
}
/**********************************************************************************
方框
基于公式y1 = k*x0*x1+y0,x0 == x1
***********************************************************************************/
void Matrix(U8 x0,U16 y0,U8 x1,U16 y1,U16 color)
{
Draw_lines(x0,y0,x1,y0,color);
Draw_lines(x0,y0,x0,y1,color);
Draw_lines(x0,y1,x1,y1,color);
Draw_lines(x1,y0,x1,y1,color);
}
/**********************************************************************************
抛物线(未完工)
基于公式y1 = k*x0*x1+y0,x0 == x1
***********************************************************************************/
//void Draw_line_two(U8 x0,U8 x1,U16 a,U16 color)
//{
// U16 k,y1;
// k = (float)((x1-x0)/2);
// for(x0;x0<k;x0++)
// {
// y1 = a*x0*x0;
// Draw_points(x0,y1,color);
// Draw_points(x1,y1,color);
// x1--;
// }
//}
/**********************************************************************************
圆(未完工)
***********************************************************************************/
//void Round(U8 x0,U16 y0,U8 r,U16 color)
//{
// U8 x,y,y1;
// x1 = r*2;
// while(x0!=x1)
// {
// y1 = sqrt(x-r*r)+y0;
// Draw_points(x0,y0,color);
// Draw_points(x1,y1,color);
// x0++;
// x1--;
// x=(x1-x0)*(x1-x0);
// }
//}
/*******************************************************************************
* 功能描述 : RGB颜色混合
* 函数属性 : 外部
* 输入参数 : R(红色分量)0-255,G(绿色分量)0-255,B(蓝色分量)0-255
* 返回参数 : 混合后的颜色码
* 函数详解 : 通过电脑拾色板获得 R,G,B分量,将分量交给函数处理,函数会返回一个颜色码
*******************************************************************************/
U16 RGB(U8 R,U8 G,U8 B)
{
return((U16)(R&0XF8)<<8|(U16)(G&0XFC)<<3|(U16)(B&0XF8)>>3);
}
/**********************************************************************************
x0,y0:起始位置
x1,y1:结束位置
color:颜色
线段
目前还存在缺漏,位置会存在很大的误差
***********************************************************************************/
void Draw_line_four(U8 x0,U16 y0,U8 x1,U16 y1,U16 color)
{
U8 x;
U16 y,t = 0;
float tan0;//定义tan0作为斜率
if((x1!=x0)&&(y1!=y0))
{
if(x1>x0)
{
tan0 = ((y1+1)-y0)/((x1+1)-x0);
if((((U16)tan0*10%10)>5)||(((U16)tan0*10%10)==5))//四舍五入
{
tan0+=1;
}
for(x = x0;x < (x1+1);x++)
{
y = x*tan0+y0;
Draw_points(x,y,color);
}
}
if(x0>x1)
{
tan0 = ((y1+1)-y0)/((x0+1)-x1);
if((((U16)tan0*10%10)>5)||(((U16)tan0*10%10)==5))
{
tan0+=1;
}
for(x = x0;x > (x1+1);x--)
{
y = y1 - x*tan0+1;
Draw_points(x,y,color);
}
}
}
else//当要竖线或直线时
{
if(x1==x0)
{
for(y = y0;y<y1;y++)
{
Draw_points(x0,y,color);
}
}
if(y1==y0)
{
for(x = x0;x<x1;x++)
{
Draw_points(x,y0,color);
}
}
}
}
/***********************************************************************************
x0,y0 :起始位置 *
word :字数 *
lie :字的宽 *
pass ;字的总高/8 *
num : 数组下标 *
color :填入颜色 *
************************************************************************************/
void Chainese_1(U8 x0,U16 y0,U8 word,U8 lie,U8 pass,U16 num,U16 color)
{
U8 k;
U8 n=0;
U8 m=0;
U8 passage;//段
U8 row;//列
U8 byte;//字节
for(k = 0; k<word;k++)//字数
{
for(passage=0;passage<pass;passage++)//段数
{
for(row=0;row<lie;row++)//字宽多少列就为多少列
{
for(byte = 0;byte < 8;byte++)//判断字节的八位
{
if(Chainese[num]&(0x80>>byte))//一位一位的取
{
Draw_points(x0+row+n,y0+byte+m,color);
}
}num++;//当上面的for语句结束时,数组下表自动进一位
}
m+=8;//分两段执行,当不要下面的语句时,可以竖着显示
}
/*横向显示*/
n+=lie;//自宽多少列就多少列
m = 0;//需要清0,也可以根据需要修改
}
}
/*******************************************************************************
* 功能描述 : 显示英文或数字字符
* 函数属性 : 外部
* 输入参数 : (x,y) 是显示内容的开始坐标,c:显示的字符,
color:颜色,b_color:背景颜色。
* 返回参数 : 无
* 函数详解 :
*******************************************************************************/
void GUI_sprintf_char(U8 x, U16 y,U8 c, U16 color,U16 b_color)
{
U8 s_x ,s_y, temp ;
c = c - 32;
for( s_y=0 ; s_y < 16 ; s_y++ )
{
if(s_y+y<320)
{
temp = font16x8[(U16)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)) )
{
Draw_points(x+s_x, y+s_y,color);
}
else
{
Draw_points(x+s_x, y+s_y,b_color);
}
}
}
}
}
}
/*******************************************************************************
* 功能描述 : 在指定位置上显示英文字符串
* 函数属性 : 外部
* 输入参数 : (x,y) 字符串的开始坐标(字符串的左上角坐标), *s:英文字符串指针
* color : 字符串颜色, b_color: 背
TFT_LCD.zip_TFT LCD
版权申诉
5星 · 超过95%的资源 131 浏览量
2022-09-24
20:06:06
上传
评论
收藏 90KB ZIP 举报
小贝德罗
- 粉丝: 70
- 资源: 1万+