Maker Pro
Maker Pro

LCD Display

C

Craig

This probably has a really simple answer but I have yet to find it using
google etc.

I am using c to write a program for a pic and for the most part I am fairly
on top of it.

The problem I do have is this,

I have an unsigned char variable that is incremented at various points
throughout the program and so could hold any value between 0 - 255. I can't
figure out how to write this value to an LCD.

I can write individual characters to the lcd no problem but I assume that if
the value contained in the variable was eg 123, I would have to pass the
characters '1', '2' and '3' to the lcd, or their ascii code.

Any help would be greatly appreciated.
 
A

Alexander

Het volgende bericht werd op ons ingehakt door Craig
This probably has a really simple answer but I have yet to find it
using google etc.

I am using c to write a program for a pic and for the most part I am
fairly on top of it.

The problem I do have is this,

I have an unsigned char variable that is incremented at various points
throughout the program and so could hold any value between 0 - 255. I
can't figure out how to write this value to an LCD.

I can write individual characters to the lcd no problem but I assume
that if the value contained in the variable was eg 123, I would have
to pass the characters '1', '2' and '3' to the lcd, or their ascii
code.
Any help would be greatly appreciated.
Yes, you have to write the ASCII code to the LCD.
This means that you cannot increment the values.
The only way to increment it is in a specified range, the ASCII tables has
from a base point 0123456789 so you can inrement it 9 times.
Also this is true for ABC.... and abc......
Perhaps a lookup table might help you in certain ways.

I also suggest using the 18F series because you can add 1 to a value and
then use an instruction for BCD-adjust.
If after this instruction there's a Carry, simply add 1 to another byte.

If the problem is writing to and driving the LCD, I have some experience
with it but only in ASM.
If you have a specific question just ask.

Good luck,

Alexander
 
R

Rich Webb

This probably has a really simple answer but I have yet to find it using
google etc.

I am using c to write a program for a pic and for the most part I am fairly
on top of it.

The problem I do have is this,

I have an unsigned char variable that is incremented at various points
throughout the program and so could hold any value between 0 - 255. I can't
figure out how to write this value to an LCD.

I can write individual characters to the lcd no problem but I assume that if
the value contained in the variable was eg 123, I would have to pass the
characters '1', '2' and '3' to the lcd, or their ascii code.

Use sprintf() into a buffer and then write the buffer to the LCD. Let
the library code do what the library code was intended to do.

If sprintf() is to bulky (and it does tend to haul in a lot of
conversions that you may not need/want) see if your compiler supports an
itoa() function (integer-to-ASCII). This is a non-standard "inversion"
of the standard atoi() and goes by various names. Some implementations
return a pointer to a static buffer, others require you to pass it a
pointer to a buffer. It saves the space that the printf() library may
use but still relies on the compiler library.

Alternately, put on your thinking cap. One approach is to start with an
integer division by 100; add 0x30 to the result. Subtract the original
result times 100 from your starting number. Integer divide by 10. Etc.
 
T

Teunis van Beelen

Craig said:
This probably has a really simple answer but I have yet to find it using
google etc.

I am using c to write a program for a pic and for the most part I am fairly
on top of it.

The problem I do have is this,

I have an unsigned char variable that is incremented at various points
throughout the program and so could hold any value between 0 - 255. I can't
figure out how to write this value to an LCD.

I can write individual characters to the lcd no problem but I assume that if
the value contained in the variable was eg 123, I would have to pass the
characters '1', '2' and '3' to the lcd, or their ascii code.

Any help would be greatly appreciated.

Is this what you where looking for?

void print_dec(unsigned char x)
{
unsigned char r=0;
while(x > 99) // hundreds
{
x = x - 100;
r++;
}
putch('0' + r);
r=0;
while(x > 9) // tens
{
x = x - 10;
r++;
}
putch('0' + r);
putch('0' + x); // units
}


The function putch() is a routine to write to
a serial port, console or maybe an lcd...

Grtz, Teuniz
 
A

Alexander

...............
You then have to add 0x30 to each nibble to convert
the binary value to an ascii number for printing to the lcd.
..............

Good tip, I didn't thought of that, will try it sometimes.
I used an lookup table :( or an increment loop starting at ......
 
C

Craig

Thanks for all replies,

I eventually used a while loop something like that below, which is like some
of the posts received

while(number)
{
unit++;
if(unit > 9)
{
unit = 0;
ten++;
}
if(ten > 9)
{
ten = 0;
hundred++;
}
number--;
}

or something similar. I am not a brilliant programmer anyway and a mental
block made my limited knowledge worse.

Regards,

Craig.
 
A

Alexander

Het volgende bericht werd op ons ingehakt door Alexander
Good tip, I didn't thought of that, will try it sometimes.
I used an lookup table :( or an increment loop starting at ......

It Works ;)
 
Top