cmicrocontrolleravrlcd

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


Solution

  • 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!