NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » LCD Custom Characters Help

August 16, 2009
by Walter
Walter's Avatar

I am having trouble uploading custom characters to the LCD. I have the USB nerdkit with everything hooked up in the default circuit. I've been trying to find my way through some examples I've found online but I'm clearly doing something wrong.

Here's what I have:

// Includes, etc.

int main() {
    uint8_t i;

    char arrow[] = {
         0b00000000,
         0b00000100,
         0b00000010,
         0b00011111,
         0b00000010,
         0b00000100,
         0b00000000,
         0b00000000,
        };

    lcd_init();
    lcd_home();

    lcd_set_type_command();
    lcd_write_byte(0x40 + (1 << 3)); // Set the pointer to CGRAM
    delay_ms(1);

    for(i = 0; i < 8; ++i) {
            lcd_write_byte(arrow[i]); // Upload the character
            delay_ms(1);
    }

    lcd_clear_and_home();
    lcd_write_string(PSTR("\1"));  // Try and use it

    while(1) { }

    return 0;

}

I'm sure there's a lot I'm doing wrong but I've tried many different variations and can't seem to get it to work

Thank you in advance for your help!

August 16, 2009
by wayward
wayward's Avatar

Hey Walter,

I didn't read closely, but it seems to me that you are having the same issue as some other forum members, only under a different guise. Please try this instead of the for() loop to see if my hunch is correct:

lcd_write_byte(0b00000000); delay_ms(1);
lcd_write_byte(0b00000100); delay_ms(1);
lcd_write_byte(0b00000010); delay_ms(1);
lcd_write_byte(0b00011111); delay_ms(1);
lcd_write_byte(0b00000010); delay_ms(1);
lcd_write_byte(0b00000100); delay_ms(1);
lcd_write_byte(0b00000000); delay_ms(1);
lcd_write_byte(0b00000000); delay_ms(1);   // i.e. ditch the array

If this happens to work and your common C sense is turned upside down, here's what's going on.

Cheers, Zoran

August 16, 2009
by wayward
wayward's Avatar

By the way, did you try writing characters 0x7e and 0x7f? They should be encoding arrow-left and arrow-right, same shape as the one you drew above. That is, unless you have the A02 version ROM on your HD44780 chip which has with Cyrillic characters instead of symbols, but that's unlikely.

August 17, 2009
by Walter
Walter's Avatar

Well, I wasn't really going to use the arrow, it's just a place holder for now

Okay I managed to get it to work, Here's the new code:

int main() {

    lcd_init();
    lcd_home();

    lcd_set_type_command();
    lcd_write_byte(0x40 | (1<<3)); // Replace the 1 with another number to get a different bank

    lcd_write_byte(0b00001000); delay_ms(1);
    lcd_write_byte(0b00000100); delay_ms(1);
    lcd_write_byte(0b00000010); delay_ms(1);
    lcd_write_byte(0b00011111); delay_ms(1);
    lcd_write_byte(0b00000010); delay_ms(1);
    lcd_write_byte(0b00000100); delay_ms(1);
    lcd_write_byte(0b00001000); delay_ms(1);
    lcd_write_byte(0b00000000); delay_ms(1);

    lcd_clear_and_home();

    lcd_write_string(PSTR("\1")); // Print the character

    while(1) { }

    return 0;
}

Thank you for your help wayward! Is there something wrong with arrays with avr-gcc?

August 17, 2009
by Walter
Walter's Avatar

I realized I missed a part of the code,

under

lcd_write_byte(0x40 | (1<<3));

write:

lcd_set_type_data();
November 19, 2011
by BStory
BStory's Avatar

Very helpful old thread and library entry :) For some reason I can't use the 0th bit using escape sequence.

I stored characters in spaces 0 through 4, dumped them to the lcd screen, and the "0" character doesn't print out.

I know my character is stored in CGRAM because I can call it out using: lcd_write_data(0);

I wonder though, is there an issue with using the "\0" escape sequence?: lcd_write_string(PSTR("\0"));

Post a Reply

Please log in to post a reply.

Did you know that NerdKits also has extra parts available for its customers? Learn more...