Custom characters to HD44780 LCD.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
LasseKilde
Posts: 2
Joined: Wed May 14, 2008 12:20 pm
Contact:

Custom characters to HD44780 LCD.

Post by LasseKilde »

Greetings.

We are quite new at this and we just want to know, how to make a custom character in flowcode, for a HD44780 LCD.
The thing is that we want to make a 8 pixels high non filled square, the only non filled square there is in the predefenied are only 6 pixels high. So how do we make the big one, we know we have to use a command, but not which.
Thanks in advance.

Best regards

Lasse and Christian.

PS. Hope you can understand the text above.

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

Re: Custom characters to HD44780 LCD.

Post by Steve »

Hi,

I've looked into how to do this and it's fairly easy, but it does involve some C code and you will need to edit the C code file for the LCD.

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.

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);
The first parameter of this function is the character you are modifying (0 to 7). The remaining parameters are the values for each line of the character, starting at the top. There are 5 pixels for each line, so the appropriate values are between 0 and 31.

To print this character on the display, simply use the normal "PrintASCII" component macro for the LCD with the parameter 0.

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

My attached modified C code file is attached, as is a sample program that illustrates this new feature. Note that this new function will not simulate - you will need to download it to the chip.

I hope you and others find this useful.
Attachments
bar graph.fcf
(6 KiB) Downloaded 773 times
LCDDisplay_Code.c
(7.93 KiB) Downloaded 645 times

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Re: Custom characters to HD44780 LCD.

Post by jimhumphries »

Steve:

On your bar graph.fcf, I had to change the x value in the LCD cursor position macro from 0 to idx to get the bar graph display to step with "number" (from 0, 0 to idx, 0). What I get then is a growing bar of dark squares. The bar "recedes" if I replace the 0 x value in the second LCD cursor position macro with idx and change the second print ASCII parameter to " " (quote, space, quote). Am I not seeing what you intended because I haven't edited the LCD component code yet? I'll try that. Hmmmm .. no change with the changes to the LCDDisplay_Code.c file. What did I miss?

Question: When I get the hang of this, can I edit the LCD init macro code to include the custom character description code and the write-to-LCD-RAM code so that my LCDs always initialize with my custom characters "installed"?

Jim

LasseKilde
Posts: 2
Joined: Wed May 14, 2008 12:20 pm
Contact:

Re: Custom characters to HD44780 LCD.

Post by LasseKilde »

Thanks for the help, we got it working.

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

Re: Custom characters to HD44780 LCD.

Post by Steve »

I'm glad you got it working, Lasse and Christian.

Jim - I don't know what your problem could be. If you edit the LCD code file as described and then compile the "bar graph" Flowcode program I posted, then post the C code file generated by Flowcode and I will have a look at why it is not working.

And yes, you could put the code into the LCD "start" macro to always have your custom characters available.

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Re: Custom characters to HD44780 LCD.

Post by jimhumphries »

Steve:

I was trying to run it in the simulator. When I compiled it and ran it on my target system, it worked fine.

Thanks,

Jim

cruzxia
Posts: 88
Joined: Wed Jan 04, 2006 7:34 am
Been thanked: 8 times
Contact:

Re: Custom characters to HD44780 LCD.

Post by cruzxia »

Hi Steve

I have used the custom Character code, I want to add a custom character as the next location after some text on the LCD display.
If I remove the two instructions
//Clear the display
%i_RawSend(0x01, 0);
%i_RawSend(0x02,0);

And replace them with direct DD ram address
%i_RawSend(0xCE,0);
This places the Character at the end of line 2 on the 16 x 2 LCD

How can I just have it come up as the next character with out using the direct DD Ram address command?

Andrew

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

Re: Custom characters to HD44780 LCD.

Post by Steve »

Do not modify the "LCD_RAM_Write" function as this writes the data to the internal RAM of the device and not to the display itself. I.e. it is used to create the custom character, but not to actually print it.

To print the character on the display itself, just use the "Print_ASCII" macro with the appropriate number of your custom character (i.e. 0 to 7).

cruzxia
Posts: 88
Joined: Wed Jan 04, 2006 7:34 am
Been thanked: 8 times
Contact:

Re: Custom characters to HD44780 LCD.

Post by cruzxia »

I am using "Print_ASCII" macro and 0 to print the character, But with your code as illustrated, it always clears the display and then prints the character at the start of line 1 on the display.

When I removed the (//Clear the display %i_RawSend(0x01, 0);) it still printed at the start, but on top of my other words. E.g. HELLO became #ELLO

I am trying to get HELLO # on the display (where # is the custom character)

Using the standard Flowcode LCD macros, the words/numbers and strings print on the LCD directly after each other in the order they are sent.

It wont do this with the Custom character.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Custom characters to HD44780 LCD.

Post by Benj »

You could use the cursor command to move the display cursor position before using the PrintASCII command.

15, 0 should get you to the last characters on the first line.

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

Re: Custom characters to HD44780 LCD.

Post by Steve »

Are you creating the custom graphics at the same time as printing them? The beginning of your program should create the custom graphics.

Then, later in your program, you should be printing them to the screen. E.g.

Code: Select all

LCD_RAM_Write()
.
.
.
.
.
Clear()
PrintString("Hello")
PrintASCII(0)
.
.
.
.

cruzxia
Posts: 88
Joined: Wed Jan 04, 2006 7:34 am
Been thanked: 8 times
Contact:

Re: Custom characters to HD44780 LCD.

Post by cruzxia »

Ok I have worked out what is going on. :shock:

If you do the flow chart as follows, it will be incorrect:

Print String "HELLO " - setup the Custom Character "#" - Print ASCII "0" = it will print #ELLO


If your flow chart is as follows, it will work correctly:

setup the Custom Character "#" - Print String "HELLO " - Print ASCII "0" = it will print HELLO #

You must define the custom characters before printing anything for it to work correctly. 8)

Post Reply