Searching \ for '[PIC]: displaying a value on LCD' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/lcd/pic.htm?key=lcd
Search entire site for: 'displaying a value on LCD'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: displaying a value on LCD'
2002\03\18@025120 by MATTHEWS, DEAN (D.)

picon face
I am currently reading in an analogue value and converting it to digital using a PIC16F877 written in C.  I display the digital value (stored in value=Read_adc()) on 10 leds to confirm that my a/d converter is working correctly.

I am also able to output information and text onto an LCD screen.  What I would ideally like to do is display the a/d conversion stored in value on the LCD screen.  Can anyone recommend a quick and easy way to do this.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\03\18@034356 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
Hi,

Dean wrote:
<snip>
>What I would ideally like to do is display the a/d conversion stored in
value on the LCD screen.
>Can anyone recommend a quick and easy way to do this.
<snip>

Yep,

http://www.piclist.com/techref/microchip/math/radix/index.htm


Nuf said :)

/Tony

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\03\18@172654 by Kyle Palmer

flavicon
face
Depending on your C compiler, you should have some form of sprintf or printf
to format numbers to a string.  I know that this is easy to do with CCS
using a target function.

Kyle

{Original Message removed}

2002\03\18@200555 by Nick Veys

flavicon
face
> I am also able to output information and text onto an LCD
> screen.  What I would ideally like to do is display the a/d
> conversion stored in value on the LCD screen.  Can anyone
> recommend a quick and easy way to do this.

Here's a little snippet where I did exactly that:

--------------------------------

BINARY_TO_BCD
 movwf BCD_TEMP                                ; save our number
 movlw 8
 movwf BCD_COUNTER                             ; load counter w/8 (8bit
#)
 clrf TENS                                     ; zero out TENS
 clrf ONES                                     ; zero out ONES
BCDLOOP
BCD_TENS_TEST                                   ; if TENS digit is >= 5,
add 3
 movlw 5
 subwf TENS,w
 btfss STATUS,C                                ; if TENS < 5
   goto BCD_ONES_TEST                          ; goto next test
 movlw 3                                       ; otherwise add 3
 addwf TENS,f
BCD_ONES_TEST                                   ; if ONES digit is >= 5,
add 3
 movlw 5
 subwf ONES,w
 btfss STATUS,C                                ; if ONES < 5
   goto BCD_SHIFT                              ; goto shift section
 movlw 3                                       ; otherwise add 3
 addwf ONES,f
BCD_SHIFT                                       ; shift left all the way
through
 rlf TENS,f                                    ; shift TENS left
 rlf ONES,f                                    ; shift ONES left
 btfss ONES,4                                  ; check for shift-out
bit
   goto BCD_TEMP_SHIFT                         ; if nothing, move on
 movlw 1                                       ; otherwise add 1 to
TENS
 addwf TENS,f
BCD_TEMP_SHIFT
 rlf BCD_TEMP,f                                ; shift the value left
 btfss STATUS,C                                ; if there's no carryout
   goto BCD_SHIFTDONE                          ; move on
 movlw 1                                       ; otherwise add 1 to
ONES
 addwf ONES,f
BCD_SHIFTDONE
 movlw 0x0F                                    ; we only need lower
nybble
 andwf ONES,f                                  ; mask out dead bits
 andwf TENS,f                                  ; mask out dead bits
 decfsz BCD_COUNTER,f                          ; decrement BCD_COUNTER
   goto BCDLOOP                                ; if !=0 goto BCDLOOP
 return                                        ; otherwise we should be
done

LCD_OUT_TEMPS
 movf TENS,w                                   ; load value
 addlw 48                                      ; shift it to its ASCII
value
 call LCD_OUT_DATA                             ; spit it out
 movf ONES,w                                   ; load value
 addlw 48                                      ; shift it to its ASCII
value
 call LCD_OUT_DATA                             ; spit her out too
 return

---------------------------------

Not sure if you're familiar w/reading assembly, but the comments should
be enough to explain the algorithm.  I found it on some university
class' web site for bin -> bcd conversion, then a simple addition of '0'
to the number will give it the ascii value for output.

If anything, doing it in C should be easier. :)  This isn't exactly
optimal either, but it works perfectly.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\03\19@025534 by MATTHEWS, DEAN (D.)

picon face
Kyle,

I am using the CCs compiler and to output text onto the LCD I use the putc() function and set up string arrays of the text I want to output. So would I be right in saying that printf is an easier way than putc()?

Going back to my original question, if for example I had a value of 200 stored in a variable called NUMBER and I wanted to output the value stored in number onto the LCD screen could I simply just do:

printf("value in memory is %02x",NUMBER);

the 2 denotes the width of the field and %x denotes to an unsigned hex integer.

Regards,
Dean Matthews

{Original Message removed}

2002\03\19@090139 by Dale Botkin

flavicon
face
On Tue, 19 Mar 2002, MATTHEWS, DEAN (D.) wrote:

> I am using the CCs compiler and to output text onto the LCD I use the
> putc() function and set up string arrays of the text I want to output.
> So would I be right in saying that printf is an easier way than
> putc()?

Well...  if it's just text that doesn't need to be formatted putc() may be
more efficient in terms of memory.  It certainly is easier to use printf()
for anything needing numbers formatted.

> Going back to my original question, if for example I had a value of
> 200 stored in a variable called NUMBER and I wanted to output the
> value stored in number onto the LCD screen could I simply just do:
>
> printf("value in memory is %02x",NUMBER);

Yes, this is exactly what you would do, assuming your LCD is attached
serially.  Another nice feature of printf() is that you can send the
output to another function, one character at a time, like this:

printf(lcd_putc,"value in memory is %02x",NUMBER);

You'd use this if you need touse lcd_putc() to talk to the LCD.  You can
also use sprintf() to direct the output to a variable.

Dale
--
"Curiosity is the very basis of education and if you tell me that
curiosity killed the cat, I say only the cat died nobly."
         - Arnold Edinborough

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@091200 by michael brown

flavicon
face
> printf(lcd_putc,"value in memory is %02x",NUMBER);

Now I'm confused.  Do you mean fprintf?  If so, what C compiler are you
using where a FILE * is the same as a function pointer?  Or does your
compiler have a "different" implementation of printf that can take an
"optional" first argument specifying a putchar type routine to be used for
the output?


> You'd use this if you need touse lcd_putc() to talk to the LCD.  You can
> also use sprintf() to direct the output to a variable.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@092859 by Dale Botkin

flavicon
face
On Tue, 19 Mar 2002, michael brown wrote:

> > printf(lcd_putc,"value in memory is %02x",NUMBER);
>
> Now I'm confused.  Do you mean fprintf?

Nope.

> If so, what C compiler are you using where a FILE * is the same as a
> function pointer?  Or does your compiler have a "different"
> implementation of printf that can take an "optional" first argument
> specifying a putchar type routine to be used for the output?

Yep.  CCS' printf() does exactly that.

Dale

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@101536 by MATTHEWS, DEAN (D.)

picon face
Dale,

Im extremely confused, again! I am sending bytes of data into the Lcd as nibbles(using 4 data pins and two control pins) and not serially using the following function:

void lcd_send_byte(byte rs, byte n)
{
port_c=rs;
delay_ms(500);
lcd_send_nibble(n>>4);
lcd_send_nibble(n&0xf);
}

I simply want to output the value stored in a variable onto the LCD.  I am reading in an analogue value and converting to digital using the PICs onboard A/D converter.  To ensure that my A/D converter is working I need to know what the digital value is.  At the moment I am using 10 leds to do this connected to 10 pins which is a bit messy.  Ideally I would like to display this a/d value on the LCD as this would free up 10 pins.

Regards,
----Original Message-----
From: Dale Botkin [spam_OUTdaleTakeThisOuTspamBOTKIN.ORG]
Sent: 19 March 2002 14:00
To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
Subject: Re: [PIC]: displaying a value on LCD


On Tue, 19 Mar 2002, MATTHEWS, DEAN (D.) wrote:

> I am using the CCs compiler and to output text onto the LCD I use the
> putc() function and set up string arrays of the text I want to output.
> So would I be right in saying that printf is an easier way than
> putc()?

Well...  if it's just text that doesn't need to be formatted putc() may be
more efficient in terms of memory.  It certainly is easier to use printf()
for anything needing numbers formatted.

> Going back to my original question, if for example I had a value of
> 200 stored in a variable called NUMBER and I wanted to output the
> value stored in number onto the LCD screen could I simply just do:
>
> printf("value in memory is %02x",NUMBER);


printf(lcd_putc,"value in memory is %02x",NUMBER);

You'd use this if you need touse lcd_putc() to talk to the LCD.  You can
also use sprintf() to direct the output to a variable.

Dale
--
"Curiosity is the very basis of education and if you tell me that
curiosity killed the cat, I say only the cat died nobly."
         - Arnold Edinborough

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@103750 by Dale Botkin

flavicon
face
On Tue, 19 Mar 2002, MATTHEWS, DEAN (D.) wrote:

> Dale,
>
> Im extremely confused, again! I am sending bytes of data into the Lcd
> as nibbles(using 4 data pins and two control pins) and not serially
> using the following function:
>
> void lcd_send_byte(byte rs, byte n)
> {
> port_c=rs;
> delay_ms(500);
> lcd_send_nibble(n>>4);
> lcd_send_nibble(n&0xf);
> }

Hmmm.  Are you using the CCS LCD driver file, lcd.c?  It looks like you
might be, since that file includes lcd_send_nibble().  If so, it's also
got an lcd_putc() function you can use to save yourself some tmie and
effort.  I'm not sure what the rs parameter of the function above is
doing, but lcd_send_byte() needs two parameters.  I think sending printf()
output to a function will only work with a function that takes a single
parameter -- printf()  will call it once for each character in the
resulting output.  Doing this:

printf(lcd_putc,"value in memory is %02x",NUMBER);

should get you there, assuming you have a function lcd_putc() that takes a
character as a single parameter and spits it out to the LCD.
Alternatively, if the port_c=rs bit is impoprtant you could maybe do
something like this:

***WARNING*** untested code ahead!

char x = 0;
char buffer[25];
sprintf(buffer,"value in memory is %02x",NUMBER);
       // puts output string in buffer
while(buffer[x] lcd_send_byte(rs, buffer[x++]);
       // calls lcd_send_byte for each character in buffer

Dale

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@104815 by MATTHEWS, DEAN (D.)

picon face
Thanks, i shall give it a try.

Regards,
Dean Matthews
Fwd Planning Engineer - Cylinder heads.
Ford Engine Plant Bridgend
Waterton Industrial Estate
CF31 3PJ
South Wales, UK.
room. 25/117
TEL : 0044(1656)672331
FAX : 0044(1656)672558
EMAIL : dmatth14spamKILLspamford.com




{Original Message removed}

2002\03\19@111530 by Bob Ammerman

picon face
not knowing much about the C compiler being used, how about:

void my_lcd_putc(byte c)
{
   lcd_send_byte(rs,c);
}

int d;
void main()
{
   printf(my_lcd_putc, "Here is an integer: %d", d)

}

or some such....

Bob Ammerman
RAm Systems


{Original Message removed}

2002\03\19@125458 by Spehro Pefhany

picon face
At 08:09 AM 3/19/02 -0600, you wrote:
> > printf(lcd_putc,"value in memory is %02x",NUMBER);
>
>Now I'm confused.  Do you mean fprintf?  If so, what C compiler are you
>using where a FILE * is the same as a function pointer?  Or does your
>compiler have a "different" implementation of printf that can take an
>"optional" first argument specifying a putchar type routine to be used for
>the output?

Isn't this a good argument for more standardization in C compilers?

I've got nothing against them implementing a function like this, but
calling it printf is not right.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam.....interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
9/11 United we Stand

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@165008 by John Dammeyer

flavicon
face
I think it's important to keep code written in such a way so that others
looking at it a few years from now will easily understand what you were
trying to do.  In the C language environment putc refers to outputting a
character to the serial port or display device; as does putchar().  One
specifies the device and the other defaults to the stdout device.

So a putc(char ch); writes to stdout.

Inside putc() you'd perhaps do a putchar( stdout, ch );

In general you have several choices here.  You could,

stdout = LCD_DISPLAY;

Or

stdout = UART1;

Then just call putc().


Inside putchar you have the switch statement for how the stuff really
goes to the outside world.

void putchar( byte port, char ch ) {

 switch (port) {

   case LCD_DISPLAY :
       ...
   break;

   case UART1 :
     ...
   break;
}

Of course the PICs aren't really big stack devices or big RAM devices so
a putchar() for character out can be called directly instead of using
putc.

Correspondingly if you want to put out strings a puts(char * sptr) is a
better vehicle that again calls putc.  Add a function called putbuffer(
byte port, char * sptr) and you can forgo the puts.

In either case,  don't use putc for string output.  It just isn't
readable code.  In the Harvard architecture in the PIC keeping strings
in ROM is more efficient but needs totally different code to get at the
string.  So,  I use a putstring() for ROM strings and a putbuffer() for
arrays of characters.

BTW,  I've added to my library by also defining IntToDec(byte width),
IntToHex(byte width) that write into a global output buffer using a
global intarg variable.  The width parameter tells the functions how
wide to make the field and in the case of the Hex output fills in
leading zeros.

Code becomes:
       putstring("This is a string in ROM\n");
       intarg = <some expression>;
       IntToDec(4);
       putbuffer();
       putc(' ');
       intarg = <some expression>;
       IntToHex(2);
       putBuffer();
       putCRLF();

Now I know that's not really clean from a C perspective, but I'm using
Bytecraft C which allows 2 bytes of passed parameters.  And it turns out
this code is more efficient than the C compilers that allow lots of
passed parameters since ultimately the <expression> has to be saved to
some variable somewhere for use by the function.  I'm just doing it
externally first.

For example:

The same thing with a printf becomes:

   printf("This is a string in ROM\n%4d %2X\n", <expression 1>,
<expression 2>);

More readable and easier to type and uses a huge amount of RAM and ROM.
I use that when I'm working with 8051, C167 or PC size computers.

Regards,

John



> {Original Message removed}

2002\03\19@232632 by michael brown

flavicon
face
> At 08:09 AM 3/19/02 -0600, you wrote:
> > > printf(lcd_putc,"value in memory is %02x",NUMBER);
> >
> >Now I'm confused.  Do you mean fprintf?  If so, what C compiler are you
> >using where a FILE * is the same as a function pointer?  Or does your
> >compiler have a "different" implementation of printf that can take an
> >"optional" first argument specifying a putchar type routine to be used
for
> >the output?
>
> Isn't this a good argument for more standardization in C compilers?

> I've got nothing against them implementing a function like this, but
> calling it printf is not right.

Spehro,

I have to say that I must agree.  They should have created a new function
name, they absolutely positively should NOT have done what they did.  What C
compiler is this?  How many other things did they mess up?

michael

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\19@233031 by Barry Michels

flavicon
face
CCS C does it this way...

----- Original Message -----
From: "michael brown" <EraseMEn5qmgspam_OUTspamTakeThisOuTAMSAT.ORG>
To: <PICLISTspamspam_OUTMITVMA.MIT.EDU>
Sent: Tuesday, March 19, 2002 11:23 PM
Subject: Re: [PIC]: displaying a value on LCD


{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\03\20@133954 by Paul Hutchinson

flavicon
face
> -----Original Message-----
> From: pic microcontroller discussion list
> [@spam@PICLISTKILLspamspamMITVMA.MIT.EDU]On Behalf Of michael brown
> Sent: Tuesday, March 19, 2002 11:23 PM
<snip>
> I have to say that I must agree.  They should have created a new function
> name, they absolutely positively should NOT have done what they
> did.  What C compiler is this?  How many other things did they mess up?

I believe the compiler is CCS PIC C and, a lot of things are different than
standard C's. It is closer to K&R C than ANSI C but... As someone else on
the PICList said a while back (can't remember who) "it's a rapid development
language with a C like syntax". That pretty much sums up my feelings about
CCS C.

IMHO, CCS C is the worst compiler to use when learning C.

Paul

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\20@145317 by Peter L. Peres

picon face
>not knowing much about the C compiler being used, how about:
>
>void my_lcd_putc(byte c)
>{
>    lcd_send_byte(rs,c);
>}
>
>int d;
>void main()
>{
>    printf(my_lcd_putc, "Here is an integer: %d", d)
>}

Uhh, Bob, what compiler was this code for if Imay ask ?

Peter

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\03\20@172617 by John Dammeyer

flavicon
face
The function below isn't such a bad idea if your compiler supports
passed functions.  Instead of doing the C thing with stdin, stdou and
stderr as a number representing a structure in an array of structures,
the printf function just needs to call the single function.

If you are rolling your own you could also pass the number (similar to a
FILE handle), that indexes into a table of functions.  But remember,
we're talking about PICs here,  not Pentiums even though they both start
with a P.  Why waste code or data space if the function can be hard
coded and you can do indirect calls.

It's not C, but who cares.  I'd like to see someone translate a PIC ANSI
C project to a PENTIUM.  Like what do the TRIS registers do in a
PENTIUM.  Most embedded code isn't easily transportable and when it is,
then it's bloated.

John


> {Original Message removed}

2002\03\21@085724 by Bob Ammerman

picon face
----- Original Message -----
From: "Peter L. Peres" <KILLspamplpKILLspamspamACTCOM.CO.IL>
To: <RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU>
Sent: Wednesday, March 20, 2002 10:04 AM
Subject: Re: [PIC]: displaying a value on LCD


{Quote hidden}

I really don't know, but it had some strange way of passing a function as
the first parameter of printf to define a sink for the characters generated.
Wierd, huh?

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2002\03\21@143329 by Barry Gershenfeld

picon face
>> >    printf(my_lcd_putc, "Here is an integer: %d", d)
>> Uhh, Bob, what compiler was this code for if Imay ask ?
>I really don't know, but it had some strange way of passing a function as
>the first parameter of printf to define a sink for the characters generated.
>Wierd, huh?

I have a memory for weirdness.  That's CCS.  The description is:

"...fname is a function name to be used for outputting
(default is putc is none is specified)."

Apparently (from an example in the back) it will call the
supplied function once for each character generated by
printf.  I guess it's a cheap alternative for not
having sprintf.

Barry

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2002\03\21@224445 by Dale Botkin

flavicon
face
On Thu, 21 Mar 2002, Barry Gershenfeld wrote:

> >> >    printf(my_lcd_putc, "Here is an integer: %d", d)
> >> Uhh, Bob, what compiler was this code for if Imay ask ?
> >I really don't know, but it had some strange way of passing a function as
> >the first parameter of printf to define a sink for the characters generated.
> >Wierd, huh?
>
> I have a memory for weirdness.  That's CCS.  The description is:
>
> "...fname is a function name to be used for outputting
> (default is putc is none is specified)."
>
> Apparently (from an example in the back) it will call the
> supplied function once for each character generated by
> printf.  I guess it's a cheap alternative for not
> having sprintf.

Well, kinda.  There is now sprintf and fprintf, but sprintf outputs to a
string, not a function.  The fprintf function recently added only (I
think) supports output to a defined serial output stream, so if you need
to use it with another function you've got issues, as they say at work.
I kind of suspect they're working toward implementing a file-like IO where
you can use fprintf to direct output to another function, but they're not
there yet.  CCS seems to have a "release early and often" philosophy,
which has its good and bad points.  Mostly good, I've only been
inconvenienced by twitchy compiler releases once, and the fix is usually
pretty simple -- avoid the affected function, or go back a version.

Dale

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...