EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: Simon on October 07, 2019, 08:04:49 pm

Title: Peter Fleury LCD library
Post by: Simon on October 07, 2019, 08:04:49 pm
http://homepage.hispeed.ch/peterfleury/doxygen/avr-gcc-libraries/group__pfleury__lcd.html (http://homepage.hispeed.ch/peterfleury/doxygen/avr-gcc-libraries/group__pfleury__lcd.html)

which of the functions listed at the bottom am I using to send a number or rather a variable value?

void lcd_data    (    uint8_t     data   )    ?
Title: Re: Peter Fleury LCD library
Post by: madires on October 07, 2019, 08:21:29 pm
That library doesn't include a function to display a number. So you have to convert the number/value into a string first, and then call lcd_puts() to display the string.
Title: Re: Peter Fleury LCD library
Post by: Simon on October 08, 2019, 07:15:13 am
Ah, I thought so. So I need to do something like keep dividing the number by 10 to get each digit and then add the values to the ASCII code for "0" so that I send the digits in ASCII to the screen.
Title: Re: Peter Fleury LCD library
Post by: Whales on October 08, 2019, 07:43:06 am
Depending on what micro & development environment you are using: you may also have access to some form of standard library with sprintf()/snprintf() or similar.
Title: Re: Peter Fleury LCD library
Post by: Simon on October 08, 2019, 08:21:46 am
Atmel studio
Title: Re: Peter Fleury LCD library
Post by: madires on October 08, 2019, 08:34:03 am
Ah, I thought so. So I need to do something like keep dividing the number by 10 to get each digit and then add the values to the ASCII code for "0" so that I send the digits in ASCII to the screen.

Yep, or use a library function like ultoa() (https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga34f41757388f40e340f31e370ac009b5.html (https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga34f41757388f40e340f31e370ac009b5.html)).
Title: Re: Peter Fleury LCD library
Post by: Simon on October 08, 2019, 04:44:15 pm
As always, near 0 instructions..... I am fairly comfortable with the mechanism to convert a variable to ascii codes but i suspect i need to play pointers to get a string, I have the book for that now.
Title: Re: Peter Fleury LCD library
Post by: maginnovision on October 08, 2019, 07:14:47 pm
I do something like this...

Code: [Select]
case lcd.write_line(char* alias data, int line): {
                lcd_setcursor(1, line, rs, e, data_port);
                string_len[line] = strlen(data) > COLUMNS ? COLUMNS : strlen(data);
                str_len = string_len[line] > MAX_PRINT ? MAX_PRINT : string_len[line];

                //Send data to LCD
                for (size_t i = 0; i < str_len; ++i)
                    lcd_write(data[i], rs, e, data_port);

                //Make sure no extra chars draw, copy string
                for (size_t i = str_len; i < MAX_PRINT; ++i) lcd_write(SPACE, rs, e, data_port);
                strcpy(lcd_data[line], data);

                //Reset scrolling logic
                if (line == cursor_line) {
                    LCDTIMER :> last_scroll;
                    start_char = roll_time = 0;
                }
                break;
            }