LCD display text programming _

In the blog post, the realization of the painting point operation, and then realized on the basis of drawing a line drawn point on the circle of operation. In fact the text display is realized on the basis of points on the drawing.

The text is made up of dots, then these are the lattice where to get it?

Just open a core file, search font, it will come out a lot of files. Here, select font_8 * 16.c.

A character on the show, which is the principle of the display text.

First look at, observe the contents of this array fontdata_8 * 16 inside, you will find:

When ascII is 0, it occupies 16 bytes. Initial index in the array is 0

When ascII is 1, occupies 16 bytes. Initial index in the array is 16

When ascII is c, the array index of C * 16

As shown above, there are eight each row of pixels, each pixel is determined by whether a byte lattice.

Therefore, in the program, you can do a loop, progressive scan.

 1 extern const unsigned char fontdata_8x16[];
 2 /* 获得LCD参数 */
 3 static unsigned int fb_base;
 4 static int xres, yres, bpp;
 5 
 6 void font_init(void)
 7 {
 8     get_lcd_params(&fb_base, &xres, &yres, &bpp);
 9 }
10 
11 /* 根据字母的点阵在LCD上描画文字 */
12 
13 void fb_print_char(int x, int y, char c, unsigned int color)
14 {
15     int i, j;
16     
17     /* 根据c的ascii码在fontdata_8x16中得到点阵数据 */
18     unsigned char *dots = &fontdata_8x16[c * 16];
19 
20     unsigned char data;
21     int bit;
22 
23     /* 根据点阵来设置对应象素的颜色 */
24     for (j = y; j < y+16; j++)
25     {
26         data = *dots++; /*先将点阵中一行数据取出来,即一个字节,8位。我们需要对这8位数据,依次进行判断,看看是不是需要描点*/
27         bit = 7;
28         for (i = x; i < x+8; i++)
29         {
30             /* 根据点阵的某位决定是否描颜色 */
31             if (data & (1<<bit))
32                 fb_put_pixel(i, j, color);
33             bit--;
34         }
35     }
36 }
37 
38 
39 /* "abc\n\r123" */
40 void fb_print_string(int x, int y, char* str, unsigned int color)
41 {
42     int i = 0, j;
43     
44     while (str[i])
45     {
46         if (str[i] == '\n')
47             y = y+16;
48         else if (str[i] == '\r')
49             x = 0;
50 
51         else
52         {
53             fb_print_char(x, y, str[i], color);
54             x = x+8;
55             if (x >= xres) /* 换行 */
56             {
57                 x = 0;
58                 y = y+16;
59             }
60         }
61         i++;
62     }
63 }

 

Guess you like

Origin www.cnblogs.com/-glb/p/11372157.html