MrSykkox
MrSykkox

Reputation: 528

Printing custom characters to LCD

I'm trying to make some custom characters to a 20x2 LCD. I'm using a Atmega µController to control the LCD with 4 bit interface. All my commands to the LCD seems to work fine (except the custom char)?

Well my code to create the character are as follows:

  /***********************/
 // Custom Characters
 /***********************/
void LCD_CreateCustomCharacters (void) 
{

 // make CGRAM data available from MPU and set custom characters in CGRAM 1-5
 // make CGRAM data available from MPU and set custom characters in CGRAM 1-5

LCD_cmd (0x40); //starts customization at first CGRAM place

// 0 bar character

LCD_prt (0x00);
LCD_prt (0x00);
LCD_prt (0x00);
LCD_prt (0x00);
LCD_prt (0x00);
LCD_prt (0x00);
LCD_prt (0x00);
LCD_prt (0x00);

// 1 bar character

LCD_prt (0x10);
LCD_prt (0x10);
LCD_prt (0x10);
LCD_prt (0x10);
LCD_prt (0x10);
LCD_prt (0x10);
LCD_prt (0x10);
LCD_prt (0x00);

// 2 bar character

LCD_prt (0x18);
LCD_prt (0x18);
LCD_prt (0x18);
LCD_prt (0x18);
LCD_prt (0x18);
LCD_prt (0x18);
LCD_prt (0x18);
LCD_prt (0x00);

// 3 bar character

LCD_prt (0x1C);
LCD_prt (0x1C);
LCD_prt (0x1C);
LCD_prt (0x1C);
LCD_prt (0x1C);
LCD_prt (0x1C);
LCD_prt (0x1C);
LCD_prt (0x00);

// 4 bar character

LCD_prt (0x1E);
LCD_prt (0x1E);
LCD_prt (0x1E);
LCD_prt (0x1E);
LCD_prt (0x1E);
LCD_prt (0x1E);
LCD_prt (0x1E);
LCD_prt (0x00);

//5 bar character

LCD_prt (0x1F);
LCD_prt (0x1F);
LCD_prt (0x1F);
LCD_prt (0x1F);
LCD_prt (0x1F);
LCD_prt (0x1F);
LCD_prt (0x1F);
LCD_prt (0x00);

LCD_cmd (0x80); //returns to DDRAM

}

^ That code seems to ALMOST do the job but still there's something wrong when outputting some of the characters. At my display when i try to do a print of 0x1 which should be a "|" becomes to " | | ". The rest of the characters works fine.

And i try to print the constructed characters with this command:

char customs[6] = {0x5, 0x4, 0x3,0x2,0x1,'\0'};
LCD_string(customs);

The code should construct 5 characters which should be used as a progress bar. But it only prints out a "||" sign and a "|" sign?

Do you have any idea what im doing wrong? If you need more code or information feel free to ask ! :)

Btw the full source code I've written can be found here. I've added a picture of the "wrong character I get" IMGUR LCD DISP

Upvotes: 1

Views: 1589

Answers (2)

Neekon Saadat
Neekon Saadat

Reputation: 417

Another way to do this would be to create binary characters. This is very easy and you can draw this by hand as well before coding it;

byte exampleCustomCharacter[8] = { B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000, }; The code above would use only one pixel block on the LCD (hence it being 8 lines tall and 5 lines wide), and would print a 1 column wide section for the progress bar. The 1's are powered pixels and the 0's are pixels turned off. Every column on the LCD will be a column of 1's on this. Hope this helped a bit.

Upvotes: 1

RadioActiveEd
RadioActiveEd

Reputation: 120

You should look at your initialization routine and verify all timing constraints are met there as well as in the normal code.

These displays can require the use of delays that are fairly long. A microcontroller can execute a single instruction in no time at all, so your delays need to be carefully crafted.

Displays are fun but you must treat them well to perform properly!

Upvotes: 2

Related Questions