Printing integers on the LCD display

To print a binary integer on the LCD display in as a string it is necessary to convert the binary integer into an array of ascii characters. The function itoa() which is in the stdlib.h library can be used to do this.

You first need to include the stdlib.h an define a character array to hold the coverted ascii string. This must be at least as long as the number of characters that you require.


#include <stdlib.h>

char buffer[5];             //Output of the itoa function

You need call the itoa() function as shown below where int_value is the number that you wish to convert and the final parameter is the base for conversion ( in this case 10 for conversion to a decimal string)


itoa(int_value, buffer, 10); //Convert the read value to an ascii string

The ascii string that is then in buffer can be written to the LCD display or sent over the USART to a terminal program.

Leave a comment