replica character liquid crystal display control

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

Copyright 2012-2017 Conmajia

Nobi's LCM Display

Simple Demo

Here is a demo screenplay of the LCM control. Just in case you understand what I'm talking 'bout.

Basic Background

Character liquid crystal display module (CLCD, or simply LCD/LCM) module is one of the display devices well used for electronic equipments.

Panel Organization

An LCM panel that displays alpha-numeric characters is controlled by its core controller chip like Hitachi's HD44780 or HD44100. Panels are organized in general as shown below.

Inside The Controller

Two things among all the hardware details that you should pay attention are the DDRAM and the CGRAM/CGROM.

DDRAM

DDRAM (display data RAM) is an 80-byte buffer which can hold up to 40 columns by 2 rows of display data. You change a DDRAM byte, you change that character on the screen.

CGRAM/CGROM

Character generator is formed by 2 parts: the CGRAM and the CGROM. With the character generator you can draw custom characters such as symbols, icons and simple Chinese characters.

Implementation

The LCD control is a standard WinForm control derived from the UserControl class.

[ToolboxBitmap("Lcd\\lcd_logo.bmp")]
public partial class DotMatrixLcd : UserControl

With a 2-D array stores all characters to display.

DotMatrixCharacter[][] characters;

A DotMatrixCharacter represents the data of a character to display. I made this class a Control so that it can do much more than storing data.

public class DotMatrixCharacter : Control
public byte Ddram
public byte[] Cgram
public char Character

Generate Character

A generator class is designed to return raw character data for the control.

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 prepared.

Paint A Character

The characters renderer is inside 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.

Full Project Source & Demo Executive

You can download them here:
Project source code: → Click to download
Demo executive file: → Click to download

References

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

keywords: LCD、LCM、液晶显示、编程、图形界面、硬件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值