您的位置 首页 电子

stm32操控lcd写字符,画线,汉字等

1、画直线算法对于画直线,在lcd上由于显示的粒度问题,就区别到x,y轴上的步调问题。涉及到步调问题,就牵扯到,斜率问题。因此,画线算法…

1、画直线算法

关于画直线,在lcd上因为显现的粒度问题,就区别到x,y轴上的步骤问题。涉及到步骤问题,就牵扯到,斜率问题。因而,画线算法就算迁就完成了,还要留意相关于lcd来说,x,y轴又是什么一个方向。现完成一个比较大略的画线算法。

void lcd_line(u16 x1,u16 y1,u16 x2,u16 y2,u16 Color)

{

u16 temp,x,y;

Set_direction(0);

if((x1 == x2) && (y1 == y2))

{

//画原点

LCD_open_windows(x1,y1,1,1);

}

else if(abs(y1-y2)>abs(x1-x2))

{

//走y轴,一起判别巨细,进行交流

if(y1 > y2)

{

x1 ^= x2 ^= x1 ^= x2;

y1 ^= y2 ^= y1 ^= y2;

}

for( y = y1 ; y <= y2; y ++)

{

x = x1 + (y – y1) * (x2 – x1) / (y2 – y1);

LCD_ColorPoint(x ,y ,Color);

}

}

else

{

if(x1 > x2)

{

x1 ^= x2 ^= x1 ^= x2;

y1 ^= y2 ^= y1 ^= y2;

}

for( x = x1 ; x <= x2; x ++)

{

y = y1 + (x – x1) * (y2 – y1) / (x2 – x1);

LCD_ColorPoint(x ,y ,Color);

}

}

}

首要是要重视,斜率问题,以及了解lcd的特点,斜率大于1,要知道,走y轴,才干密布x轴,而不会呈现一个显着的断点。

2、写ascii。

对应写ascii,能够先做一个字模,取对应的字模,如8 * 16,因为lcd写ascii的原理,首要是打点,因而,能够对A写一个简略的程序

unsigned char code_A[]=

{

/*——————————————————————————

;若数据乱码,请查看字模格局设置,留意挑选正确的取模方向和字节位次序。

;源文件/文字: A

;宽×高(像素): 8×16

;字模格局/巨细:单色点阵液晶字模,横向取模,字节正序/16字节

;数据转化日期 : 2015/2/10 15:00:31

——————————————————————————*/

//0x08,0x10,0x01,//宽的像素数,高的像素数,宽的字节数,参数设置可选

0x00,0x00,0x00,0x08,0x08,0x0C,0x14,0x14,0x12,0x1E,0x22,0x21,0x21,0x73,0x00,0x00,

};

//8 * 16的ascii字符

void lcd_ascii(u16 x,u16 y,const u8 *str,u16 Color)

{

u8 i , j;

u8 temp;

for (i = 0;i < 16 ; i ++)

{

temp = str[i];

for(j = 0 ;j < 8 ; j ++)

{

if((temp >> (7 – j) ) & 0x01 == 0x01)

{

LCD_ColorPoint(x + (j) ,y + i,Color);

}

}

}

}

首要原理是,取得要显现的每一位值,是1写对应的值即可。

unsigned char code_A_24x48[]=

{

/*——————————————————————————

;若数据乱码,请查看字模格局设置,留意挑选正确的取模方向和字节位次序。

;源文件/文字: A

;宽×高(像素): 24×48

;字模格局/巨细:单色点阵液晶字模,横向取模,字节正序/144字节

;数据转化日期 : 2015/2/10 15:09:19

——————————————————————————*/

//0x18,0x30,0x03,//宽的像素数,高的像素数,宽的字节数,参数设置可选

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x38,0x00,0x00,0x3C,0x00,0x00,0x7C,

0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x6C,0x00,0x00,0xCE,0x00,0x00,0xCE,0x00,

0x00,0xCE,0x00,0x00,0xC6,0x00,0x01,0x87,0x00,0x01,0x87,0x00,0x01,0x87,0x00,0x01,

0x83,0x00,0x03,0x03,0x80,0x03,0x03,0x80,0x03,0x03,0x80,0x03,0x03,0x80,0x06,0x01,

0xC0,0x07,0xFF,0xC0,0x06,0x01,0xC0,0x06,0x01,0xC0,0x0C,0x01,0xE0,0x0C,0x00,0xE0,

0x0C,0x00,0xE0,0x0C,0x00,0xE0,0x18,0x00,0xF0,0x18,0x00,0x70,0x18,0x00,0x70,0x18,

0x00,0x70,0x38,0x00,0x78,0xFE,0x01,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

void lcd_ascii_24x48(u16 x,u16 y,const u8 *str,u16 Color)

{

u8 i,j,k;

u8 buffer[3];

for (i = 0;i < 48 ; i ++)

{

for(j = 0; j < 3 ; j ++)

{

buffer[j] = str[i * 3 + j];

}

for( j = 0; j < 3 ; j ++)

{

for (k = 0 ; k < 8 ; k++)

{

if( ( buffer[j] >> (7 – k)) & 0x01 == 0x01)

{

LCD_ColorPoint(x + 8 * (j) + k,y + i,Color);

}

}

}

}

}

3、写汉字

unsigned char yuan[]=

{

/*——————————————————————————

;若数据乱码,请查看字模格局设置,留意挑选正确的取模方向和字节位次序。

;源文件/文字:袁

;宽×高(像素): 48×48

;字模格局/巨细:单色点阵液晶字模,横向取模,字节正序/288字节

;数据转化日期 : 2015/2/10 13:17:47

——————————————————————————*/

//0x30,0x30,0x06,//宽的像素数,高的像素数,宽的字节数,参数设置可选

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,

0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,

0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x0C,0x00,0x00,0x00,0x00,0xC0,0x1E,0x00,

0x00,0x1F,0xFF,0xFF,0xFF,0x00,0x00,0x08,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,

0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x40,0x00,0x00,

0x00,0xC0,0x00,0xE0,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x10,0x00,0x00,0x06,0x00,0x00,

0x3C,0x00,0x00,0x07,0xFF,0xFF,0xFC,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,

0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,

0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0x00,0x00,0x38,0x00,0x00,0x07,0xFF,0xFF,

0xF8,0x00,0x00,0x07,0xFF,0xFF,0xF8,0x00,0x00,0x07,0x0F,0x10,0x31,0x80,0x00,0x04,

0x1E,0x18,0x03,0xC0,0x00,0x00,0x3C,0x08,0x07,0xE0,0x00,0x00,0x78,0x0C,0x0F,0x00,

0x00,0x00,0xF8,0x06,0x1C,0x00,0x00,0x01,0xF8,0x07,0x70,0x00,0x00,0x07,0xB8,0x03,

0xC0,0x00,0x00,0x0E,0x38,0x01,0xC0,0x00,0x00,0x1C,0x38,0x00,0xE0,0x00,0x00,0x70,

0x38,0x00,0x70,0x00,0x01,0xC0,0x38,0x10,0x7C,0x00,0x03,0x00,0x38,0xE0,0x3F,0x00,

0x0C,0x00,0x3B,0xC0,0x0F,0xE0,0x10,0x00,0x3F,0x00,0x07,0xFC,0x00,0x00,0x7E,0x00,

0x03,0xF0,0x00,0x00,0x38,0x00,0x00,0xE0,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

//lcd显现48 * 48字符

void lcd_show_48x48(u16 x,u16 y,const u8 *str,u16 Color)

{

u8 i,j,k;

u8 buffer[6];

for (i = 0;i < 48 ; i ++)

{

for(j = 0; j < 6 ; j ++)

{

buffer[j] = str[i * 6 + j];

}

for( j = 0; j < 6 ; j ++)

{

for (k = 0 ; k < 8 ; k++)

{

if( ( buffer[j] >> 7 – k) & 0x01 == 0x01)

{

LCD_ColorPoint(x + 8 * (j) + k,y + i,Color);

}

}

}

}

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/dianzi/252288.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部