A GDI+ Based Character LCD Control
This is a renew. |
A GDI+ Based Character LCD Control
by Conmajia
Character liquid crystal display (LCD) modules are widely used in electronic devices, instruments and handiworks. They are simple, flexible, clear to view, and low power. Fig.1 shows an example of character LCD used in an amateur project.
Fig.1 LCD in An Amateur Instrument
Very cool, isn't it? What if I told you that you could implement this hardware part as a software UI control and used it in your applications? To accomplish this, you have to get to know some of the hardware details.
Inside an LCD module, there are matrixed liquid crystal dots. Built-in controllers scan rows (COMn) and columns (SEGn) to activate dots to constitute characters and symbols. The process is shown in fig.2.
Fig.2 LCD Display Principle
One thing above all you should know is the register set that controls all display content of the control: display data RAM (DDRAM), character generator RAM/ROM (CGRAM/ROM).
The DDRAM is an 80-byte buffer which can hold up to 40×2 of display data. That is the largest size of a single LCD controller (HD44xxx series) supports. You change characters on the screen by changing bytes in the DDRAM. CGRAM/ROM are used to generate custom characters or symbols, or just simply load pre-defined character/symbols in the ROM. With the character generator, you can do lots tricks such as display animations, icons or Chinese characters.
With all the hardware knowledges you just learned, you can now have your "soft" LCDs. Fig.3 demonstrates one of my implementations.
Fig.3 Demo of My LCD Control
The LCD control is a standard WinForm control derived from the UserControl
class.
public class DotMatrixLcd : UserControl
A 2-D array works as the DDRAM to store all characters to be displayed.
DotMatrixCharacter[][] characters;
The DotMatrixCharacter
represents a single character in the DDRAM. I made it a Control
derived class to easy my work. You are welcome to optimize this if you found it to heavy to use.
public class DotMatrixCharacter : Control
To generate raw character data, a CG class is defined as below.
public sealed class CharacterGenerator
{
/// Get character data from DDRAM by address.
public static byte[] GetDdram(byte address)
{
return charset[address];
}
/// Get character data from DDRAM to match the given character.
public static byte[] GetDdram(char character)
{
return charset[(byte)character];
}
// 8 cgram chars
static byte[][] cgram = new byte[8][];
// for dummy
static byte[] emptyChar ={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/// Store character data in CGRAM registers by index.
public static void SetCgram(byte[] data, int index)
{
if (data == null || data.Length != 8)
return;
if (index < 0 || index > 7)
return;
cgram[index] = data;
}
/// Get CGRAM character data by index.
public static byte[] GetCgram(int index)
{
if (index < 0 || index > 7)
return emptyChar;
return cgram[index];
}
// 256x8 bytes (1024 bytes) characters
static readonly byte[][] charset =
{
// 0000 0000
new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
// 0000 0001
new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
// ...
Now all the data is ready. Now the next todo is on the canvas. To paint a character, a renderer is built in the DotMatrixCharacter
control.
void drawBlocks(Graphics g)
{
byte[] charData;
// check source of char to display for CGRAM support
switch (charSource)
{
case DisplaySource.CGRAM:
if (cgramData == null || cgramData.Length != DOT_ROWS)
// invalid data, draw empty
// all 0x00
charData = new byte[DOT_ROWS];
else
charData = cgramData;
break;
case DisplaySource.DDRAM:
default:
charData = CharacterGenerator.GetDdram(ddramAddress);
break;
}
// ready to draw
byte mask;
for (int i = 0; i < DOT_ROWS; i++)
{
// if use mask = 0x01 (right to left)
// the output will be vertical mirrored
mask = 0x01 << (DOT_COLS - 1);
for (int j = 0; j < DOT_COLS; j++)
{
if ((mask & charData[i]) == 0)
{
// 0 - empty
if (circleBlock)
g.FillEllipse(
inactiveBrush,
j * (blockSize.Width + spacing),
i * (blockSize.Height + spacing),
blockSize.Width,
blockSize.Height
);
else
g.FillRectangle(
inactiveBrush,
j * (blockSize.Width + spacing),
i * (blockSize.Height + spacing),
blockSize.Width,
blockSize.Height
);
}
else
{
// 1 - fill
if (circleBlock)
g.FillEllipse(
activeBrush,
j * (blockSize.Width + spacing),
i * (blockSize.Height + spacing),
blockSize.Width,
blockSize.Height
);
else
g.FillRectangle(
activeBrush,
j * (blockSize.Width + spacing),
i * (blockSize.Height + spacing),
blockSize.Width,
blockSize.Height
);
}
// next bit
//mask <<= 1;
// msb to lsb
mask >>= 1;
}
}
}
With the built-in renderer, the final LCD module control can obtain the extensibility to switch between different display contents like character displays, graphic dot matrix display, etc.
Source Code & Demo Executive
Download 'em here:
References
- How to Use Character LCD Module, chan@elm-chan.org
A GDI+ Based Character LCD Control的更多相关文章
- 阅读Deep Packet Inspection based Application-Aware Traffic Control for Software Defined Networks
Deep Packet Inspection based Application-Aware Traffic Control for Software Defined Networks Globlec ...
- 📟 Character Liquid Crystal Display Control (English)
A replica CLCD module control. Initiated on May 5, 2012 Updated on Feb 21, 2017 Copyright 2012-2017 ...
- Mecanim Control
http://www.ufe3d.com/doku.php/mecanimcontrol Mecanim Control Your ultimate solution for Mecanim base ...
- linux驱动之LCD
LCD程序步骤:1. 分配一个fb_info 2. 设置 3. 硬件相关的操作4. 注册 register_framebuffer 5.入口函数 6.出口函数 #include <linux/s ...
- 驱动05.lcd设备驱动程序
参考s3c2410fb.c总结出框架 1.代码分析 1.1 入口函数 int __devinit s3c2410fb_init(void) { return platform_driver_regis ...
- LCD 显示异常定位分析方法
第一种情况: 进入kernel或android 后,如果LCM图像示异常,可以通过如下步骤来判断问题出现在哪个层面. step1:通过DMMS截图,来判断上面刷到LCM的数据是否有问题. 若DMMS获 ...
- lcd驱动框架
目录 lcd驱动框架 框图 程序分析 入口 打开open 读read 初始化registered_fb 注册 小结 程序设计 测试 方式一操作fb0 方式二操作tty 方式三操作终端 完整程序 tit ...
- Linux学习: LCD驱动
一.LCD驱动框架: 1.分配一个fb_info结构体:s3c_lcd = framebuffer_alloc(0,NULL); 2.设置fb_info(s3c_lcd): ID.固定参数.可变参数. ...
- 关于Unity树形插件Tree View Control的相关搜集
博客http://blog.csdn.net/qq_15267341/article/details/51997926 的这个 Script Based Runtime Tree-Vie ...
随机推荐
- swiper插件的使用demo
老习惯,废话不多说,直接上代码 1.PC端,swiper2,滑动效果 先要引入idangerous.swiper2.7.6.css和idangerous.swiper2.7.6.js(需要先引入jqu ...
- js实现Mac触摸板双指事件(上、下、左、右、放大、缩小)
前言 这几天在修复一个web问题时,需要捕获Mac触摸板双指事件(上.下.左.右.放大.缩小),但发现并没有现成的轮子,还是要自己造. 例如:jquery.mousewheel.js(添加跨浏览器的鼠 ...
- 转换器2:ThinkPhp模板转Django模板
前天写了个<ThinkPhp模板转Flask模板> 居然被同事鄙视了,原因是他用Django,我用Flask,为了避免被他继续安利Django的强大.我决定写一个Django模板转换器. ...
- Spark_总结五
Spark_总结五 1.Storm 和 SparkStreaming区别 Storm 纯实时的流式处理,来一条数据就立即进行处理 SparkStreaming ...
- H5 拖放
HTML 5 拖放 HTML5 音频 HTML5 画布 拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中, ...
- xgboost-python参数深入理解
由于在工作中应用到xgboost做特征训练预测,因此需要深入理解xgboost训练过程中的参数的意思和影响. 通过search,https://www.analyticsvidhya.com/blog ...
- MVC学习笔记3 - JsRender
许多发展平台减少代码和简化维护,使用模板和 HTML5 和 JavaScript 也不例外. JsRender 是一个 JavaScript 库使您可以一次定义一个样板文件结构,并使用它来动态地生成 ...
- opencv配置(win10+VS2015+opencv3.1)
Step 1:准备工作 a.win10 b.vs2015 c.opencv3.1[从http://opencv.org/downloads.html下载] Step 2.开始安装 a. 双击openc ...
- HackerRank The Chosen One [预处理][gcd]
题解:tags:[预处理][gcd]故事背景:光头钻进了茫茫人海.这是一个典型の通过前缀后缀和来降低复杂度的问题.先用pre数组与suf数组分别维护前缀gcd和后缀gcd.如果 a[i] % gcd( ...
- 老李分享:loadrunne动态查询db2数据库
老李分享:loadrunne动态查询db2数据库 poptest老李认为性能测试脚本开发不仅仅涉及到脚本开发的技术层面,同时也要对一些其他技术有所了解动态链接库的技术,线程安全等等,建议在做下面的 ...