Problem with custom characters on LCD

General discussion on mikroC.
Post Reply
Author
Message
crocu
Posts: 71
Joined: 18 Jun 2008 09:28
Location: France, Macon

Problem with custom characters on LCD

#1 Post by crocu » 26 Sep 2010 11:32

Hello

I need to have 3 differents custom characters in my project, here is the code for each of them :

Code: Select all

// Custom character : °
const char degre[] = {6,9,9,6,0,0,0,0};
void symbol_degre(char pos_row, char pos_char) {
  char i;
    LCD_Cmd(64);
    for (i = 0; i<=7; i++) LCD_Chr_Cp(degre[i]);
    LCD_Cmd(LCD_RETURN_HOME);
    LCD_Chr(pos_row, pos_char, 0);}

    
// Custom character : °C
const char degreC[] = {6,9,9,6,0,0,0,0};
void symbol_degreC(char pos_row, char pos_char) {
  char i;
    LCD_Cmd(64);
    for (i = 0; i<=7; i++) LCD_Chr_Cp(degreC[i]);
    LCD_Cmd(LCD_RETURN_HOME);
    LCD_Chr(pos_row, pos_char, 0);}

    
// Custom character : Tin
const char Tin[] = {0,0,16,0,23,21,21,21};
void symbol_Tin(char pos_row, char pos_char) {
  char i;
    LCD_Cmd(64);
    for (i = 0; i<=7; i++) LCD_Chr_Cp(Tin[i]);
    LCD_Cmd(LCD_RETURN_HOME);
    LCD_Chr(pos_row, pos_char, 0);
}
But when i call the characters in the main loop, it always displays the same character : "°" whatever i use the following :
:arrow:

Code: Select all

symbol_degreC(3,9);                     // Display °C custom character
symbol_degre(1,5);                      // Display ° custom character
symbol_Tin(2,7);                         // Display Tin custom character
The 2 others customs characters : "°C" and "Tin" are always displays as "°" , it is not normal .

Can you tell me what is wrong ? :?
Is it a compiler bug ?

Many thanks for your help,

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Problem with custom characters on LCD

#2 Post by filip » 28 Sep 2010 10:44

Hi,

In order to make this code work, you need to modify it so the custom characters occupy different memory locations.
If you want 3 different custom characters, then you should place them on the 3 different memory locations.
Basically, in your example you have overwritten the first two characters by the third one, because they were placed on the same memory location.

The start memory address for custom characters in CGRAM is 64, and the characters will occupy 8 bits each, so the location for the next character is 70 and so on.

To understand this thoroughly, please read the following datasheet :
http://www.datasheetcatalog.org/datashe ... 271_DS.pdf

This is the corrected code :

Code: Select all

void symbol_degre(char pos_row, char pos_char) {
  char i;
    LCD_Cmd(64);
    for (i = 0; i<=7; i++) 
      LCD_Chr_Cp(degre[i]);
    LCD_Cmd(_LCD_RETURN_HOME);
    LCD_Chr(pos_row, pos_char, 0);
}

void symbol_degreC(char pos_row, char pos_char) {
  char i;
    LCD_Cmd(72);
    for (i = 0; i<=7; i++) 
      LCD_Chr_Cp(degreC[i]);
    LCD_Cmd(_LCD_RETURN_HOME);
    LCD_Chr(pos_row, pos_char, 1);}

void symbol_Tin(char pos_row, char pos_char) {
  char i;
    LCD_Cmd(80);
    for (i = 0; i<=7; i++) 
      LCD_Chr_Cp(Tin[i]);
    LCD_Cmd(_LCD_RETURN_HOME);
    LCD_Chr(pos_row, pos_char, 2);
}
Regards,
Filip.

crocu
Posts: 71
Joined: 18 Jun 2008 09:28
Location: France, Macon

Re: Problem with custom characters on LCD

#3 Post by crocu » 30 Sep 2010 14:00

Many thanks , it works fine now.

fvgm
Posts: 96
Joined: 30 Oct 2007 16:16
Location: Brazil

Re: Problem with custom characters on LCD

#4 Post by fvgm » 10 Feb 2011 00:39

Thanks. solved my problem too.

Post Reply

Return to “mikroC General”