你好,分享一下画点画线写汉字等函数,其中blended_address_buffer数组即是TLI显示时使用的数组,其实只要知道画点,剩下的函数就比较简单了。
#include "gd32f4xx.h"
#include <stdio.h>
#include <gd_lcd.h>
#include <font.h>
#include "gd32f450i_eval.h"
#include "systick.h"
unsigned char temp =0;
uint16_t blended_address_buffer[96000];
uint16_t WHITE=0xFFff; //白色
uint16_t BLACK =0x0000; //黑色
uint16_t BLUE =0x001F; //蓝色
void lcd_point_set(uint16_t xpos, uint16_t ypos, uint16_t color) //画点
{
*(__IO uint16_t*)(blended_address_buffer + ((480*ypos) + xpos)) = color;
}
//在指定位置显示一个字符
//x,y:起始坐标
//num:要显示的字符
void LCD_ShowChar(uint16_t xpos,uint16_t ypos,uint8_t num)
{
unsigned int i,xpos_temp,ypos_temp=0;
unsigned char line_x,line_xx,line_y=0;
i=0;
line_x =0;
line_y =0;
ypos_temp =ypos;
xpos_temp =xpos;
for(line_y=0;line_y<32;line_y++) //32 x 16
{
xpos =xpos_temp;
for(line_xx=0;line_xx<2;line_xx++) //2*8bit =16bit 行写
{
temp=char_buffer[num][i];
while(line_x < 8)
{
if(temp&0x80)
{
lcd_point_set(xpos,ypos,0x001f);
}
else
{
lcd_point_set(xpos,ypos,0xffff);
}
xpos=xpos+1;
temp=temp<<1;
line_x++;
}
i++;
line_x =0;
temp =0;
}
ypos++; //行
}
}
void show_num(uint16_t x, uint16_t y,int num_num) //显示数字
{
int a,b,c;
if(num_num<10)
{
LCD_ShowChar(x,y,num_num);
}
else if(num_num>=10&&num_num<100)
{
a=num_num%100/10;
b=num_num%10;
LCD_ShowChar(x,y,a);
delay_1ms(1);
LCD_ShowChar(x+16,y,b);
}
else if(num_num>=100)
{
a=num_num/100;
b=num_num%100/10;
c=num_num%10;
LCD_ShowChar(x,y,a);
LCD_ShowChar(x+16,y,b);
LCD_ShowChar(x+32,y,c);
}
}
void draw_line(uint16_t x1, uint16_t y1,uint16_t x2, uint16_t y2) //画线
{
uint16_t t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; //计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=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++ )//画线输出
{
lcd_point_set(uRow,uCol,0x001f);//画点
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
void draw_font(uint16_t xpos, uint16_t ypos,unsigned char num) //写汉字
{
unsigned int i=0,xpos_temp,ypos_temp=0;
unsigned char line_x,line_xx,line_y=0;
unsigned char temp =0;
line_x =0;
line_y =0;
ypos_temp =ypos;
xpos_temp =xpos;
for(line_y=0;line_y<32;line_y++) //32 x 32
{
xpos =xpos_temp;
for(line_xx=0;line_xx<4;line_xx++) //4*8bit =32bit 行写
{
temp=blended_address_buffer2[num][i];
while(line_x < 8)
{
if(temp&0x80)
{
lcd_point_set(xpos,ypos,0x0000);
}
else
{
lcd_point_set(xpos,ypos,0xffff);
}
xpos=xpos+1;
temp=temp<<1;
line_x++;
}
i++;
line_x =0;
temp =0;
}
ypos++; //行
}
}
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)//画矩形
{
draw_line(x1,y1,x2,y1);
draw_line(x1,y1,x1,y2);
draw_line(x1,y2,x2,y2);
draw_line(x2,y1,x2,y2);
}
void LCD_Draw_Circle(uint16_t x0,uint16_t y0,uint8_t r) //画圆
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1); //判断下个点位置的标志
while(a<=b)
{
lcd_point_set(x0+a,y0-b,0x0000); //5
lcd_point_set(x0+b,y0-a,0x0000); //0
lcd_point_set(x0+b,y0+a,0x0000); //4
lcd_point_set(x0+a,y0+b,0x0000); //6
lcd_point_set(x0-a,y0+b,0x0000); //1
lcd_point_set(x0-b,y0+a,0x0000);
lcd_point_set(x0-a,y0-b,0x0000); //2
lcd_point_set(x0-b,y0-a,0x0000); //7
a++;
//使用Bresenham算法画圆
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
}
}
|