LCD custom character with array

Thread Starter

ecka333

Joined Oct 1, 2009
76
Hello, i am working with 4x20 LCD and PIC microcontroller . Compiler - mikroC from mikroelektronika. I need to show several custom characters in LCD, in different rows and positions. Simplified structure of my code is:

Rich (BB code):
const char character[]={4,14,21,4,4,17,31,0};
void CustomChar(char pos_row, char pos_char) 
    {
    char i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(character);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
    }

void Menu(){CustomChar(1,5);}

void main()
    {
    for(;;){Menu();}
    }
In this case everything works fine. But if i change code to this:

Rich (BB code):
void CustomChar(char pos_row, char pos_char) 
    {
    char i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(character);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
    }

void Menu()
    {
    const char character[]={4,14,21,4,4,17,31,0};
    CustomChar(1,5);
    }

void main()
    {
    for(;;){Menu();}
    }
compiler gives me errors. So i need to show different characters like:

Rich (BB code):
void Menu()
    {
    const char character[]={4,14,21,4,4,17,31,0};
    CustomChar(1,5);
    
    const char character[]={0,0,0,0,0,17,31,0};
     CustomChar(2,5);
    
    .....
    }
So how simply and effective write the code?
 

panic mode

Joined Oct 10, 2011
2,753
i would:
- store all characters into a table or array
- give name (macro) to each character so it is easy to use
- modify CustomChar to include char reference such as
"CustomChar(char_name, line ,position);" or

Rich (BB code):
CustomChar(alpha, 1,5);
CustomChar(degree, 1,6);
CustomChar(aleph, 1,7);
you don't mention what error you get from compiler but it seam to be scope of character[].
 
Top