标题:
STM32 gui TFTLCD驱动程序
[打印本页]
作者:
henry9803
时间:
2018-1-18 16:49
标题:
STM32 gui TFTLCD驱动程序
根据网上的例程,自己总结的TFT-LCD驱动,我用的是STM32FX103芯片
单片机源程序如下:
#include "gui.h"
#ifdef USE_FONT_UPDATE
#include "ff.h"
#include "diskio.h"
#endif
#ifdef USE_FLASH_CHAR
#include "flash.h"
#else
#include "asciicode.h"
#endif
#ifdef USE_FONT_UPDATE
#include "malloc.h"
#endif
/****************************************************************************
* Function Name : GUI_Dot
* Description : 在彩屏上面画一点
* Input : x:点的X坐标
* * y:点的Y坐标
* * color:点的颜色
* Output : None
* Return : None
****************************************************************************/
void GUI_Dot(uint16_t x, uint16_t y, uint16_t color)
{
TFT_SetWindow(x, y, x, y); //设置点的位置
TFT_WriteData(color); //画点
}
void GUI_Line(u16 xStart, u16 yStart, u16 xEnd, u16 yEnd, u16 color)
{
u16 t;
int xerr = 0, yerr = 0, delta_x, delta_y, distance;
int incx, incy;
u16 row, col;
delta_x = xEnd - xStart;//计算坐标增量
delta_y = yEnd - yStart;
col = xStart;
row = yStart;
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);
xerr += delta_x;
yerr += delta_y;
if(xerr > distance)
{
xerr -= distance;
col += incx;
}
if(yerr > distance)
{
yerr -= distance;
row += incy;
}
}
}
/****************************************************************************
* Function Name : GUI_Box
* Description : 给一个区域涂上颜色
* Input : sx:起始X坐标, sy:其实Y坐标,
* * ex:终止X坐标, ey:终止Y坐标,
* * color:方框的颜色
* Output : None
* Return : None
****************************************************************************/
void GUI_Box(uint16_t xState, uint16_t yState, uint16_t xEnd, uint16_t yEnd, uint16_t color)
{
uint16_t temp;
if((xState > xEnd) || (yState > yEnd))
{
return;
}
TFT_SetWindow(xState, yState, xEnd, yEnd);
xState = xEnd - xState + 1;
yState = yEnd - yState + 1;
while(xState--)
{
temp = yState;
while (temp--)
{
TFT_WriteData(color);
}
}
}
/****************************************************************************
* Function Name : GUI_DrowSign
* Description : 画一个十字的标记
* Input : x:标记的X坐标;
* * y:标记的Y坐标
* * color:标记的颜色
* Output : None
* Return : None
****************************************************************************/
void GUI_DrowSign(uint16_t x, uint16_t y, uint16_t color)
{
uint8_t i;
/* 画点 */
TFT_SetWindow(x-1, y-1, x+1, y+1);
for(i=0; i<9; i++)
{
TFT_WriteData(color);
}
/* 画竖 */
TFT_SetWindow(x-4, y, x+4, y);
for(i=0; i<9; i++)
{
TFT_WriteData(color);
}
/* 画横 */
TFT_SetWindow(x, y-4, x, y+4);
for(i=0; i<9; i++)
{
TFT_WriteData(color);
}
}
#ifndef USE_FLASH_CHAR
/****************************************************************************
* Function Name : GUI_Show12ASCII
* Description : 写12号ASCII码
* Input : x:起始X坐标
* * y:起始Y坐标
* * p:字符串首地址
* * wordColor:字体颜色
* * backColor:背景颜色
* Output : None
* Return : None
****************************************************************************/
void GUI_Show12ASCII(uint16_t x, uint16_t y, uint8_t *p,
uint16_t wordColor, uint16_t backColor)
{
uint8_t i, wordByte, wordNum;
uint16_t color;
while(*p != '\0') //检测是否是最后一个字
{
/* 在字库中的ASCII码是从空格开始的也就是32开始的,所以减去32 */
wordNum = *p - 32;
TFT_SetWindow(x, y, x+7, y+15); //字宽*高为:8*16
for (wordByte=0; wordByte<16; wordByte++) //每个字模一共有16个字节
{
color = ASCII8x16[wordNum][wordByte];
for (i=0; i<8; i++)
{
if ((color&0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}
}
p++; //指针指向下一个字
/* 屏幕坐标处理 */
x += 8;
if(x > 233) //TFT_XMAX -8
{
x = 0;
y += 16;
}
}
}
#else
/****************************************************************************
* Function Name : GUI_Show12Char
* Description : 通过FLASH字库显示12号字母和汉字(使用GBK)
* Input : x:起始X坐标
* * y:起始Y坐标
* * ch:字符串首地址
* * wordColor:字体颜色
* * backColor:背景颜色
* Output : None
* Return : None
****************************************************************************/
void GUI_Show12Char(uint16_t x, uint16_t y, uint8_t *ch,
uint16_t wordColor, uint16_t backColor)
{
uint8_t i, j, color, buf[32];
uint16_t asc;
uint32_t wordAddr = 0;
while(*ch != '\0')
{
/*显示字母 */
if(*ch < 0x80) //ASCII码从0~127
{
/* 在字库中的ASCII码是从空格开始的也就是32开始的,所以减去32 */
wordAddr = *ch - 32;
wordAddr *= 16;
wordAddr += GUI_FLASH_ASCII_ADDR;
/* 读取FLASH中该字的字模 */
FLASH_ReadData(buf, wordAddr, 16);
/* 显示该文字 */
TFT_SetWindow(x, y, x+7, y+15); //字宽*高为:8*16
for (j=0; j<16; j++) //每个字模一共有16个字节
{
color = buf[j];
for (i=0; i<8; i++)
{
if ((color&0x80) == 0x80)
{
TFT_WriteData(wordColor);
}
else
{
TFT_WriteData(backColor);
}
color <<= 1;
}
}
ch++; //指针指向下一个字
/* 屏幕坐标处理 */
x += 8;
if(x > 233) //TFT_XMAX -8
{
x = 0;
y += 16;
}
}
/* 显示汉字 */
else
{
/* 将汉字编码转换成在FLASH中的地址 */
asc = *ch - 0x81; //高字节是表示分区,分区是从0x81到0xFE,所以转换成地址-0x80
wordAddr = asc * 190; //每个分区一共有190个字
asc = *(ch + 1); //低字节代表每个字在每个分区的位置,它是从0x40到0xFF
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
程序可能还有一些问题未解决,求大佬帮助调试:
gui.rar
(5.5 KB, 下载次数: 93)
2018-1-18 16:47 上传
点击文件名下载附件
TFTLCD
下载积分: 黑币 -5
作者:
sdsdsdsdsdsd
时间:
2020-4-28 22:14
怎么显示动态变量呢
作者:
sdsdsdsdsdsd
时间:
2020-4-28 22:14
我的显示不出来动态变量呢 ,不刷新
作者:
Hangover97
时间:
2020-9-27 14:33
不行啊
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1