Creating a Custom LCD Character in MikroC PRO for PIC

By , February 13, 2010 7:30 pm

In this video I demonstrate how to create a custom LCD character using MikroC Pro for PIC and the EasyPIC Development board by MikroElektronika http://www.mikroe.com . The microcontroller used in this tutorial is the Microchip PIC18F4685.

Here is the source code for the project:

I_heart_mikroC_Project.zip

12 Responses to “Creating a Custom LCD Character in MikroC PRO for PIC”

  1. Thats a nice little video, very informative and the code for it too, awesome. :)

  2. Mohamed Omar says:

    Thanks .

  3. Ahmed Lazreg says:

    Hi,
    you can also use GLCD Font Creator MikroElektronika edition. It can also generate and let you create custom char projects for HD44780 controller.

  4. Filip says:

    Great tutorial! Keep it going. Looking forward for more!

  5. me me says:

    hello there, how can i do this on a 128 x64 lcd, it doesnt have any custom charcter function. i use mikro C 8.2 and pic 18f4550.

  6. Andrew says:

    My suggestion for you would be to look into the free MikroElektronika GLCD Font Creator to create characters for 128x64 GLCDs.

  7. Siarhey says:

    This function CustomCharacter doesn't work two times.

    void CustomChar(char pos_row, char pos_char,int n) {
    short i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(character[n][i]);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
    }

    This string below doesn't work correctly:
    CustomChar(1,3,2);
    CustomChar(1,4,4);

  8. Andrew says:

    Hi Siarhey.

    MikroElektronika has a great tech support team that I have found really helpful. They could probably answer your question better than I can.

    I don't have my easyPIC dev board near by right now to try this out but as a work-around to your issue you might try something like making a copy of the CustomChar function with a unique name like CustomCharA and CustomCharB and see if it responds differently.

    const char characterA[] = {0,10,31,31,14,4,0,0};
    const char characterB[] = {0,10,31,31,14,4,0,0};

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

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

    Then try using the following commands:

    CustomCharA(1,6);
    CustomCharB(2,6);

    Good Luck!

    Regards,
    Andrew

  9. anna says:

    I wanted to ask is it possible to make text only in the second row shift left and right while the text in the first row remains?

  10. Andrew says:

    Hi Anna.

    It has been a while since I have used a traditional 16x2 LCD screen with MikroC Pro for PIC.

    Here is a link to the MikroC Pro for PIC - LCD Library page. In their library example they demonstrate the _LCD_SHIFT_LEFT and _LCD_SHIFT_RIGHT Lcd Commands.

    If you are not satisfied with the results from the MikroC shift commands you could create your own Circular Buffer array that would allow you to scroll text independently on either LCD row.

    Regards,
    Andrew Hazelden

  11. Muaz says:

    Hey Andrew.

    Wish you are fine and in good health.

    I have a small problem that I need your help on as fast as possible. I am trying to make two custom characters in mikroC. First is an up arrow and the second is a down arrow. When I write the code and run the program the LCD shows the two characters up arrow. I don't know why so I need your help as fast as possible. This is the used code:

    // LCD module connections
    sbit LCD_RS at RB4_bit;
    sbit LCD_EN at RB5_bit;
    sbit LCD_D4 at RB0_bit;
    sbit LCD_D5 at RB1_bit;
    sbit LCD_D6 at RB2_bit;
    sbit LCD_D7 at RB3_bit;

    sbit LCD_RS_Direction at TRISB4_bit;
    sbit LCD_EN_Direction at TRISB5_bit;
    sbit LCD_D4_Direction at TRISB0_bit;
    sbit LCD_D5_Direction at TRISB1_bit;
    sbit LCD_D6_Direction at TRISB2_bit;
    sbit LCD_D7_Direction at TRISB3_bit;
    // End LCD module connections

    const char characterUp[] = {0,4,4,10,17,4,4,4};

    void CustomCharUp(char pos_row, char pos_char) {
    char i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(characterUp[i]);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
    }

    const char characterDown[] = {4,4,4,4,17,10,4,4};

    void CustomCharDown(char pos_row, char pos_char) {
    char i;
    Lcd_Cmd(64);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(characterDown[i]);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
    }

    I need your help if you can. Thanks in advance.

    Best Regards,
    Muaz

  12. Andrew says:

    Hi Muaz.

    Here is a link to a MikroElektronika forum post that discusses the issue you are experiencing:
    http://www.mikroe.com/forum/viewtopic.php?f=13&t=27000

    According to Filip in the MikroE Forums the value in Lcd_Cmd(64); should be incremented by 8 address positions for each call.

    Example:

    Lcd_Cmd(64);
    Lcd_Cmd(72);
    Lcd_Cmd(80);

    Also you need to change the third value in LCD_Chr for each custom character address:

    LCD_Chr(pos_row, pos_char, 0);
    LCD_Chr(pos_row, pos_char, 1);
    LCD_Chr(pos_row, pos_char, 2);
    ...

    Try something like this:

    const char characterUp[] = {0,4,4,10,17,4,4,4};

    void CustomCharUp(char pos_row, char pos_char) {
    char i;
    Lcd_Cmd(64);
    for (i = 0; i< =7; i++) Lcd_Chr_CP(characterUp[i]);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 0);
    }

    const char characterDown[] = {4,4,4,4,17,10,4,4};

    void CustomCharDown(char pos_row, char pos_char) {
    char i;
    Lcd_Cmd(72);
    for (i = 0; i<=7; i++) Lcd_Chr_CP(characterDown[i]);
    Lcd_Cmd(_LCD_RETURN_HOME);
    Lcd_Chr(pos_row, pos_char, 1);
    }

    Regards,
    Andrew

Leave a Reply

Note: Comments will have spelling errors corrected before they are posted. If you have a specific question please provide your email address so I can send you a direct reply.