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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s