Customized characters on the LCD

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

Moderators: Benj, Mods

Post Reply

Please rate this article out of 5: (1 being the worst and 5 being the best)

1
0
No votes
2
0
No votes
3
1
7%
4
2
13%
5
12
80%
 
Total votes: 15

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Customized characters on the LCD

Post by Steve »

Image


Introduction
Flowcode's LCD component is useful for quickly displaying text and numbers onto a HD44780 (or compatible) LCD. However there are other features of this display that have not been implemented by the component and implementing some of these features is remarkably simple.

For example, this display can shift the display left or right, giving you a scrolling text feature. Another untapped feature is the ability to display up to 8 custom characters, and this is the feature we will investigate in this article.

Warning: this article involved changing one of Flowcode's key files (i.e. the code for the LCD component), make sure you back up this file first before you begin editing it.

Customising the component's C code

I've created a new function for the LCD - LCD_RAM_Write - which allows you to create 8 custom characters for use in your display. The first thing to do is to incorporate this new function into the "LCDDisplay_Code.c" file - you will find this file in the "Components" folder of the Flowcode installation (by default, this is C:\Program Files\Matrix Multimedia\Flowcode V3\Components). Open this file in a text editor and find the line "//internal function prototypes". The existing code should look like this:

Code: Select all

//internal function prototypes
void %i_RawSend(char nIn, char nMask);

//internal function implementations
void %i_RawSend(char nIn, char nMask)
{
   unsigned char pt;
   unsigned char outVal;

...etc...
Change this so it includes the new function:

Code: Select all

//internal function prototypes
void %i_RawSend(char nIn, char nMask);
void LCD_Set_CGRAM(char nIdx, char d0,  char d1,  char d2,  char d3,  char d4,  char d5,  char d6,  char d7);

//internal function implementations
void LCD_RAM_Write(char nIdx, char d0,  char d1,  char d2,  char d3,  char d4,  char d5,  char d6,  char d7)
{
   //set CGRAM address
   %i_RawSend(64 + (nIdx << 3), 0);
   delay_ms(2);

   //write CGRAM data
   %i_RawSend(d0, 0x10);
   %i_RawSend(d1, 0x10);
   %i_RawSend(d2, 0x10);
   %i_RawSend(d3, 0x10);
   %i_RawSend(d4, 0x10);
   %i_RawSend(d5, 0x10);
   %i_RawSend(d6, 0x10);
   %i_RawSend(d7, 0x10);

   //Clear the display
   %i_RawSend(0x01, 0);
   delay_ms(2);
   %i_RawSend(0x02, 0);
   delay_ms(2);
}

void %i_RawSend(char nIn, char nMask)
{
   unsigned char pt;
   unsigned char outVal;

...etc...
Save and close this file.

Displaying the character within your Flowcode program

To access this code within your Flowcode program, use a C icon. For example, the following code will set the first character to a circle:

Code: Select all

LCD_RAM_Write(0,0,14,17,17,17,14,0,0);
To print this character on the display, simply use the normal "PrintASCII" component macro for the LCD with the parameter 0. Note that this is the number zero, and not a character.

While researching this, I found this useful web-based utility for creating the codes for custom characters: http://www.quinapalus.com/hd44780udg.html

If you find the size of the custom character is too limiting (after all, there is not much you can do in 5x8 pixels), you can use place different custom characters next to each other to display a larger graphic. Using 4 custom characters in a 2x2 grid would give you a 10x16 image, which should give you more artistic freedom.

My attached modified C code file is attached. Also attached is a sample Flowcode program which illustrates this new feature: a simple bar graph display.

Please note: this new "LCD_RAM_Write" function will not simulate - you will need to download it to the chip to see your results.
Attachments
LCD_Custom_Characters.zip
(3.7 KiB) Downloaded 1251 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Customized characters on the LCD

Post by Enamul »

Excellent post to create custom character in LCD. I should try to make my native language characters if could make up to 50 characters.
Enamul
University of Nottingham
enamul4mm@gmail.com

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Customized characters on the LCD

Post by medelec35 »

This is a great article for Flowcode V3.

For Flowcode V4 & V5 please see:
http://www.matrixmultimedia.com/mmforum ... 26&t=11987
Martin

Post Reply