作者:GWD 时间:2019.7.25
一、课程内容
概述:实现LCD显示字符
第一步、从linux内核中拷出font_8*16.c文件,并修改
第二步、写字符显示函数
extern const unsigned char fontdata_8x16[ ];
static unsigned int fb_base;
static int xres, yres, bpp;
void font_get_lcd_params(void)
{
get_lcd_params(&fb_base,&xres,&yres,&bpp);
}
void fb_print_char(int x,int y,char c,unsigned int color)
{
int i,j;
unsigned char *dots = &fontdata_8x16[c*16];
unsigned char dat ;
int bit ;
for(j=y;j<y+16;j++)
{
bit = 7;
dat = *dots++;
for(i=x;i<x+8;i++)
{
if(dat &(1<<bit))
{
fb_put_pixel(i,j,color);
}
bit --;
}
}
}
void fb_print_string(int x, int y, char* str, unsigned int color)
{
int i = 0, j;
while (str[i])
{
if (str[i] == '\n')
y = y+16;
else if (str[i] == '\r')
x = 0;
else
{
fb_print_char(x, y, str[i], color);
x = x+8;
if (x >= xres) /* 换行 */
{
x = 0;
y = y+16;
}
}
i++;
}
}
第三步、测试函数
#include "geometry.h"
#include "font.h"
void lcd_test(void)
{
unsigned int fb_base;
int xres, yres, bpp;
/* 初始化LCD */
lcd_init();
/* 使能LCD */
lcd_enable();
get_lcd_params(&fb_base, &xres, &yres, &bpp);
fb_get_lcd_params( );
font_get_lcd_params( );
clear_screen( );
draw_line(0, 0, xres - 1, 0, 0);
draw_line(xres - 1, 0, xres - 1, yres - 1, 0);
draw_line(0, yres - 1, xres - 1, yres - 1, 0);
draw_line(0, 0, 0, yres - 1, 0);
draw_line(0, 0, xres - 1, yres - 1, 0);
draw_line(xres - 1, 0, 0, yres - 1, 0);
draw_circle(xres/2, yres/2, yres/4, 0);
fb_print_string(10,10,"www.100ask.net\n\r100ask.taobao.com",0);
}
二、LCD部分的完整框架