正点原子I.MX6U-MINI应用篇6嵌入式Linux在LCD屏幕上显示字符
Posted 果果小师弟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了正点原子I.MX6U-MINI应用篇6嵌入式Linux在LCD屏幕上显示字符相关的知识,希望对你有一定的参考价值。
一、原始方式: 取模显示字符
LCD显示屏是由width * height个像素点构成的,显示字符,一个非常容易想到的方法便是对字符取模,然后在LCD屏上打点显示字符;如果大家以前学习过单片机,想必接触过一些显示屏,譬如 oled、或者其它一些点阵式的显示屏,其实这些显示屏显示字符的原理都是一样的,如下所示:
我们可以通过一些字符取模软件获取到字符的子模;所谓子模,其实就是一个二维数组,用于表示字符点阵中,哪些小方块应该要填充颜色、哪些小方块不填充颜色。譬如上图果字符点阵,这是一个宽度为64(64 个小方块)、高度为 86(86 个小方块)的字符点阵,我们会使用一个二维数组来表示这个字符点阵:
unsigned char arr[86][8];
也就是一个86行8列的unsigned char类型数组,数组存储的其实就是字符的位图数据,字符点阵中的每一个小方块对应一个 bit 位,因为一行一共有64个小方块、也就对应8个字节(8 * 8 = 64);将填充颜色的方块使用1表示、不填充颜色的方块使用0来表示,所以一个小方块刚好可以使用一个bit 位来描述。
这里我是使用的的是PCtoLCD2002.exe
这个软件。获取几个字符的子模,然后在我们的 LCD 屏上去显示这些字符。按照下图的方式设置,就可以生成字模了。
1.1 源码
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>
#define FB_DEV "/dev/fb0" //LCD设备节点
static int width; //LCD宽度
static int height; //LCD高度
static unsigned short *screen_base = NULL;//LCD显存基地址
static unsigned char ch_char1[86][8] =
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0x00,0xF8,0x07,0xC0,0x7F,0x00,
0x00,0xFF,0x00,0xF8,0x07,0xC0,0x7F,0x00,
0x00,0xFF,0x00,0xF8,0x07,0xC0,0x7F,0x00,
0x00,0xFF,0x00,0xF8,0x07,0xC0,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0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FF,0xFF,0xFF,0xFF,0x0F,
0x00,0x00,0xE0,0xFF,0xFF,0x01,0x00,0x00,
0x00,0x00,0xF0,0xFF,0xFF,0x07,0x00,0x00,
0x00,0x00,0xFC,0xFF,0xFF,0x1F,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xF7,0x7F,0x00,0x00,
0x00,0xC0,0xFF,0xFB,0xE7,0xFF,0x01,0x00,
0x00,0xF8,0xFF,0xF9,0xC7,0xFF,0x0F,0x00,
0x00,0xFF,0x7F,0xF8,0x87,0xFF,0x7F,0x00,
0xE0,0xFF,0x3F,0xF8,0x07,0xFE,0xFF,0x07,
0xFC,0xFF,0x1F,0xF8,0x07,0xFC,0xFF,0x1F,
0xFC,0xFF,0x07,0xF8,0x07,0xF8,0xFF,0x1F,
0xF8,0xFF,0x03,0xF8,0x07,0xE0,0xFF,0x0F,
0xF8,0xFF,0x00,0xF8,0x07,0x80,0xFF,0x0F,
0xF0,0x3F,0x00,0xF8,0x07,0x00,0xFE,0x07,
0xF0,0x0F,0x00,0xF8,0x07,0x00,0xF8,0x07,
0xE0,0x01,0x00,0xF8,0x07,0x00,0xC0,0x03,
0x60,0x00,0x00,0xF8,0x07,0x00,0x00,0x03,
0x00,0x00,0x00,0xF8,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,正点原子I.MX6U-MINI应用篇8嵌入式Linux网络通信socket编程
正点原子I.MX6U-MINI应用篇5嵌入式Linux在LCD上显示BMPJPGPNG图片
正点原子I.MX6U-MINI应用篇9嵌入式Linux中的多线程编程pthread
正点原子I.MX6U-MINI驱动篇1字符设备驱动开发-Hello驱动(不涉及硬件操作)