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:

Source Code

Demo

References

  1. How to Use Character LCD Module, chan@elm-chan.org

↑Go top

A GDI+ Based Character LCD Control的更多相关文章

  1. 阅读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 ...

  2. 📟 Character Liquid Crystal Display Control (English)

    A replica CLCD module control. Initiated on May 5, 2012 Updated on Feb 21, 2017 Copyright 2012-2017 ...

  3. Mecanim Control

    http://www.ufe3d.com/doku.php/mecanimcontrol Mecanim Control Your ultimate solution for Mecanim base ...

  4. linux驱动之LCD

    LCD程序步骤:1. 分配一个fb_info 2. 设置 3. 硬件相关的操作4. 注册 register_framebuffer 5.入口函数 6.出口函数 #include <linux/s ...

  5. 驱动05.lcd设备驱动程序

    参考s3c2410fb.c总结出框架 1.代码分析 1.1 入口函数 int __devinit s3c2410fb_init(void) { return platform_driver_regis ...

  6. LCD 显示异常定位分析方法

    第一种情况: 进入kernel或android 后,如果LCM图像示异常,可以通过如下步骤来判断问题出现在哪个层面. step1:通过DMMS截图,来判断上面刷到LCM的数据是否有问题. 若DMMS获 ...

  7. lcd驱动框架

    目录 lcd驱动框架 框图 程序分析 入口 打开open 读read 初始化registered_fb 注册 小结 程序设计 测试 方式一操作fb0 方式二操作tty 方式三操作终端 完整程序 tit ...

  8. Linux学习: LCD驱动

    一.LCD驱动框架: 1.分配一个fb_info结构体:s3c_lcd = framebuffer_alloc(0,NULL); 2.设置fb_info(s3c_lcd): ID.固定参数.可变参数. ...

  9. 关于Unity树形插件Tree View Control的相关搜集

    博客http://blog.csdn.net/qq_15267341/article/details/51997926      的这个   Script Based Runtime Tree-Vie ...

随机推荐

  1. 服务器数据库搭建流程(CentOs+mysql)

    前言: 服务器上数据库搭建需要知道Linux系统的版本,以前的Ubuntu14.04直接在终端下输入apt-get install (package)便可方便的下载并安装mysql,但是在centOs ...

  2. DotNet友元程序集解析

    项目开发的过程中,调试使用的可能是最多的操作.任何代码写出来都需要经过调试和整合,以此扩展和提升程序的稳定性和可靠性.谈到.NET的单元测试,在这里就得提提.NET的友元程序集这一特性,也借用.NET ...

  3. ViewPager详解

    一.ViewPager简介 ViewPager 如其名所述,是负责翻页的一个 View.准确说是一个 ViewGrop,包含多个 View 页,在手指横向滑动屏幕时,其负责对 View 进行切换.为了 ...

  4. POJ 2182 解题报告

    Lost Cows Time Limit: 1000 MS Memory Limit: 65536 KB Description N (2 <= N <= 8,000) cows have ...

  5. 10分钟精通SharePoint - SharePoint拓扑结构

    SharePoint服务器角色:前端,应用程序和数据库服务器 应用程序服务:搜索.Office文档.User Profile和App等应用服务器 数据库类型:内容数据库.应用程序数据库和配置数据库 规 ...

  6. Mac 上的 outlook 一直让输入密码

    Mac 上的 outlook 即便输入了正确的密码,依然提示密码错误,让重新输入,需要输入多遍之后才能连上服务器. 出现这个问题的原因可能是证书过期了. 解决方式如下: 1.找到 2. 删掉 Exch ...

  7. android添加权限--eclipse

    首先进入清单文件 2.点击下面的permissions----Add 3.选择Uses permission-----OK 4.选择需要的权限 5.查看代码,,已经添加完毕

  8. Java语言定义的线程状态分析

    说到线程,一定要谈到线程状态,不同的状态说明线程正处于不同的工作机制下,不同的工作机制下某些动作可能对线程产生不同的影响. Java语言定义了6中状态,而同一时刻,线程有且仅有其中的一种状态.要获取J ...

  9. MySQL自动化审核平台部署说明

    背景: 关于MySQL的审核的重要性就不说明了,本文的自动化审核是通过Inception和SQLAdvisor实现的,具体的使用可以看它们各自的说明文档.这里大致介绍下如何部署和使用它们,其实该文章也 ...

  10. YII2.0 ——安装yii2项目

    有两种安装方式 第一种:使用composer进行安装 composer global require"fxp/composer-asset-plugin:^1.2.0" compo ...