LCD custom character with array

Discussion in 'Programmer's Corner' started by ecka333, Mar 31, 2012.

  1. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    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:

    Code ( (Unknown Language)):
    1. const char character[]={4,14,21,4,4,17,31,0};
    2. void CustomChar(char pos_row, char pos_char)
    3.     {
    4.     char i;
    5.     Lcd_Cmd(64);
    6.     for (i = 0; i<=7; i++) Lcd_Chr_CP(character[i]);
    7.     Lcd_Cmd(_LCD_RETURN_HOME);
    8.     Lcd_Chr(pos_row, pos_char, 0);
    9.     }
    10.  
    11. void Menu(){CustomChar(1,5);}
    12.  
    13. void main()
    14.     {
    15.     for(;;){Menu();}
    16.     }[/i]
    In this case everything works fine. But if i change code to this:

    Code ( (Unknown Language)):
    1. void CustomChar(char pos_row, char pos_char)
    2.     {
    3.     char i;
    4.     Lcd_Cmd(64);
    5.     for (i = 0; i<=7; i++) Lcd_Chr_CP(character[i]);
    6.     Lcd_Cmd(_LCD_RETURN_HOME);
    7.     Lcd_Chr(pos_row, pos_char, 0);
    8.     }
    9.  
    10. void Menu()
    11.     {
    12.     const char character[]={4,14,21,4,4,17,31,0};
    13.     CustomChar(1,5);
    14.     }
    15.  
    16. void main()
    17.     {
    18.     for(;;){Menu();}
    19.     }[/i]
    compiler gives me errors. So i need to show different characters like:

    Code ( (Unknown Language)):
    1. void Menu()
    2.     {
    3.     const char character[]={4,14,21,4,4,17,31,0};
    4.     CustomChar(1,5);
    5.    
    6.     const char character[]={0,0,0,0,0,17,31,0};
    7.      CustomChar(2,5);
    8.    
    9.     .....
    10.     }
    So how simply and effective write the code?
     
  2. panic mode

    Senior Member

    Oct 10, 2011
    1,319
    304
    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

    Code ( (Unknown Language)):
    1. CustomChar(alpha, 1,5);
    2. CustomChar(degree, 1,6);
    3. CustomChar(aleph, 1,7);
    you don't mention what error you get from compiler but it seam to be scope of character[].
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990

    And the line causing the error.
     
Loading...