# LCD interfacing with msp430

I am making a contact less tachometer based on magnets .I am using msp430g2253 micro controller and HD44780 lcd. I have done certain calculations for calculating rpm in the main code and now i want the values to be printed on the LCD but here i am not able to understand how to do it.

rpm = cycles*60/1000000; //This is what i want to print on the lcd i.e the value stored
in variable rpm


The code of lcd which i have used takes only *char as input , so i am not able to find out a way to convert the integer to char(I know it sounds lame but ...stilll.....) and print it on lcd.

The code below is a part of the whole lcd code, but this is used to print on lcd.

void lcdprint(char *text)
{
char *c;
c = text;
while((c !=0) && (*c!=0))
{
SendByte(*c , dat);
c++;
}
}


So how should i modify this code to print the integer value on lcd. Do i need to create a function for this purpose or what??

Some details: 1.Microcontroller used : MSP430G2253 2.Software for coding: Code composer studio (CCS) 3.LCD: HD44780

I do not have programming experience for TI uCs. I mostly use PICs. In the programs where I need to output numbers on the LCD screen I print char by char on the LCD.

Let's assume that I need to print out the number 123.
First I make a function which divides the number in individual numbers.
Then I display each number on LCD. You can improve the code by your needs.
Example-

unsigned char hundreds=0,tens=0,ones=0; //are public to all functions

void
convert_int_char(int input_integer)
{
ones = input_integer % 10; // will give value of 3
tens = ((input_integer % 100) - ones)/10; // will give value of 2
hundreds = (input_integer - ((tens*10)+ones)) / 100; // will give out value of 1
}

void
lcd_display_char(unsigned char number)
{
SendByte(number+48 , dat); // Part of your function, to make things more clear.
}
//+48 stands to make the number ascii number. Please see ASCII table.

• i had the same code in my mind, but here i need to print an unknown value, which can be of any power either in tens or hundreds or thousand etc,so using the above code does not solve this problem,am i right? – Abhishek Tyagi Feb 6 '15 at 16:17
• Just add more thousands, ten_thousand, hundred_thousands. – Triak Feb 6 '15 at 16:20
• ok...i think i can give it a try.Thanks for your inputs – Abhishek Tyagi Feb 6 '15 at 16:27

With any luck, your compiler already has the itoa() or sprintf() function.

If not, you have to implement it yourself. The important thing is that this must be done from the right to the left:

const char *number_to_string(unsigned int number)
{
#define BUFFER_SIZE 12
static char buffer[BUFFER_SIZE];  /* must be static to be able to return it */
char *p;

p = &buffer[BUFFER_SIZE - 1];
*p-- = '\0';  /* end of string */
do {
unsigned int digit = number % 10;
*p-- = '0' + digit;
number = number / 10;
} while (number > 0);
return p;  /* first digit might not be at the start of the buffer */
}


If you divide by less than 1000000, you can output fractional digits by inserting the decimal point at the appropiate place.

• the compiler do have itoa() function, but when i use that it gives me some sort of error...i will check that and get back to u again. – Abhishek Tyagi Feb 6 '15 at 16:18