LCD Custom Characters - A Tutorial

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Posts: 306
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 60 times

LCD Custom Characters - A Tutorial

Postby Docara » Sat Feb 04, 2017 4:45 pm

Recently I've needed to produce a couple of custom characters for an HD44780 16x2 LCD based display and found the process rather painful, so I thought I'd knock up a quick tutorial on how I eventually achieved my goal.
Whilst the actual connections and pin spacings on this Shield are configured for the Arduino Uno, there is no reason why it couldn't be configured to be used with other systems.
First off credit where credit is due, I did not actually SOLVE a problem of displaying custom characters. I have used postings from Leigh and Benj (Matrix) and their external links together with a web searches. I have just combined my experience with different pieces of information to produced this HowTo guide.

LCD Display 16x2 LCD Arduino Shield (Maplin Code N07DH).
Maplin Link

Additional Sources

Leigh's Link
Web Site1
Web Site2

The hardware I used was an Arduino Unu R3 and to use it with FC configure the 16x2 (EB005) Macro as follows .
a) Drag the 16x2 LCD (EB005) over to a Dashboard Panel and configure as follows

    LCD.................... Arduino
    Pin Data_0.............PortD.4
    Pin Data_1.............PortD.5
    Pin Data_2.............PortD.6
    Pin Data_3.............PortD.7

Additionally, though not used here the five buttons on this Shield can be read via analogue port A0 using the ADC Input Macro in FC. I setup a Byte variable, used the LCD GetByte(variable) and the LCD PrintNumber(variable) to display the (analogue) values for these buttons.

Mine were UP=40, DOWN=86, left=128, RIGHT=4 AND SELECT=182 NOTHING PRESSED =249

Right, down to business

You need to remember a couple of constraints before you can successfully use custom characters with these displays.

    1.) There is a maximum of eight locations available for characters - therefore only 8 characters available!
    2.) The custom characters are numbered 0 to 7
    3.) You MUST define the characters BEFORE USE
    4.) If you try and redefine ANY character after one has been displayed or they will all be lost/not be displayed
    5.) You CANNOT setup - display-change-setup-display etc to increase the number of characters
    6.) Use PrintASC(0), PrintAsc(1).........PrintASC(7) with in FC to display one of your custom characters
    7.) FC requires an 5x8 grid based character, though the last line should be left blank (0) to allow for the cursor.
    8.) Nothing we do here will show up in simulation ONLY ON HARDWARE

For simplicity I would suggest if you intend to use custom character(s) within your FC program do it in the beginning during the normal setting up variables, Interrupt initialisation phase etc
During testing of this I found that you can define the shape you want without carrying out an LCDStart macro - but this could be a quirk I would suggest you stick to the FC convention and setup the LCD properly by issuing the Start function before defining the shape.

Designing the Character

So in practice before you start coding you need to figure out what you are going to display. Therefore, if you click on Leigh's Link above it will bring you to a web site that will allow you to design a shape. Because I want to demonstrate the numbering system, my shape is based on the descending number 16 to 9 (as shown below)

Character Capture.JPG
Character Capture
Character Capture.JPG (28.69 KiB) Viewed 6411 times

Note the numbers in the decimal section above. The corresponding bit (pixel) information set on the display is expanded below.

Description.jpg (19.32 KiB) Viewed 6411 times

You can see the numbers on the left are made up from the addition of the numbers along the top (if black) and start at the top and work down on a row by row basis - in my case 16 to 9. The other thing to notice is that in FC the first row(top) is defined as d0 and so on until d7 at the bottom.
So, in order to understand the next section you need to acknowledge / be aware that from the above

d0=16, d1=15, d2=14, d3=13, d4=12, d5=11, d6=10, d7=9

⦁ These numbers against d0 to d7 above will be entered in a LCD Component Macro(RAMWrite command )later

Setting Up the Character

We know have a shape ready to be displayed and the corresponding eight numbers which correspond to it. The next step is to decide how to display it/them. You will remember right at the beginning (point 1) I said there are only eight custom characters or locations available now is the time to assign a custom character to a location.
Quite simply, at the moment, this is nothing more than a pen & paper or memory exercise. If you have one character defined it could 'live' at any of the eight locations from location 0 to location 7. This is difficult to try and explain but for now look at the contents of the red boxes in the following image. In the next section we will put all this information together.

Setting Up the Character - Flowcode

FC Screen1.jpg
FC Screen Capture
(127.48 KiB) Downloaded 1116 times

At this stage I'm presuming you have an LCD display and configured. We will now configure FC to setup and display the new character.
Remember, ALL the new shape(s) need to be setup and sent to the LCD before the use. (In the screen image above Shape 1 is the character from previous sections and Shape 2 is an inverse capital E)
On you new flowchart drag a Component Macro over to your chart and make sure it is the first item (ideally). Either Double Click or Right Click to get the properties window. Then click on the RAMWrite as shown above. You will be presented with a Parameter box as shown above.
Looking at the contents of the blue box first you will see the numbers mentioned in the previous sections already entered. You will also note that to the left are the d0 - d7 data labels against which you enter your shape data.
The top of this section is where you specify the character location information. FC uses the term "Index" for this property. Remember there is only eight locations within the LCD hardware to hold custom characters. Theses are addressed sequentially from 0 to 7. In our example location "0" is used to hold the character in this tutorial.
You will notice I have included a second shape (inverse E) at location "6" AND that it is defined BEFORE any other commands. So in theory there could be a MAXIMUM of 8 RAMWrite in this start of your chart, Indexed 0 to 7.

To Display the Custom Shape

Once the shape and location has been defined with the RAMWrite macro it can know be used whenever needed by issuing the "PrintASC(location)" command withing the LCD Component Macro.
With reference to the above image you will see there are two shapes defined at locations 0 and 6, and PrintASC(0) and a PrintASC(6) have been used to display the shapes when needed.

In Conclusion

I have include some information pertaining to Arduino. The slight annoyance with the pre-made Arduino system is they use their own terminology for the ports on the board so I have included a schematic to cross reference. I also had occasional issues trying to program the Uno within FC - some times it worked some times not and found xLoader to be a fantastic little program to use. Just use FC to compile the hex code and use xLoader to do the rest.

I hope everything was transferred correctly from Word to the forum - if not please led me know

Happy Coding
Last edited by Docara on Thu Feb 09, 2017 12:39 pm, edited 1 time in total.
These users thanked the author Docara for the post (total 5):
JohnCrow (Sat Feb 04, 2017 5:21 pm) • jgu1 (Sat Feb 04, 2017 6:24 pm) • medelec35 (Sat Feb 04, 2017 11:04 pm) • Benj (Thu Feb 09, 2017 12:08 pm) • petesmart (Mon Feb 27, 2017 10:46 am)
Rating: 26.32%

User avatar
Matrix Staff
Posts: 14566
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4596 times
Been thanked: 4239 times

Re: LCD Custom Characters - A Tutorial

Postby Benj » Thu Feb 09, 2017 12:09 pm

Hi Matt,

A very nice tutorial there, many thanks for sharing.
These users thanked the author Benj for the post:
Docara (Thu Feb 09, 2017 3:10 pm)
Rating: 5.26%

Posts: 3
Joined: Fri Mar 03, 2017 10:30 am
Been thanked: 1 time

Re: LCD Custom Characters - A Tutorial

Postby paullarry » Mon Apr 24, 2017 10:53 am

This one seems preety nice, Thanks for sharing this tutorial here Docara.