Page 1 of 1

Customized characters on the LCD

Posted: Fri Aug 08, 2008 10:39 am
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.

Re: Customized characters on the LCD

Posted: Fri Mar 01, 2013 11:02 am
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.

Re: Customized characters on the LCD

Posted: Sat Mar 02, 2013 8:42 pm
by medelec35
This is a great article for Flowcode V3.

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