Searching \ for '[PIC]: Serial Output with Hi Tec C' 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/microchip/ios.htm?key=serial
Search entire site for: 'Serial Output with Hi Tec C'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Serial Output with Hi Tec C'
2002\08\03@152555 by ian.forse

flavicon
face
I am using an F877 to produce a 10 bit A/D reading.  This is combined into a
single variable.  This is then passed to a binary to bcd routine which gives
me a single variable xxxx (i.e. 1023, 0963, 0053, 0007).  I now want to sent
this to the terminal in the following format x.xxx (i.e. 1.023, 0.963,
0.053, 0.007). The serial comms is OK but I am not sure which is the best
method method to produce this output.

Any suggestions please?

Ian Forse
------------------------------------------------------------------
http://mdm1.bravepages.com
Technical support for the Multifunction Display Module
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.380 / Virus Database: 213 - Release Date: 24/07/02

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


2002\08\03@171700 by Spehro Pefhany

picon face
At 07:45 PM 8/3/02 +0100, you wrote:
>I am using an F877 to produce a 10 bit A/D reading.  This is combined into a
>single variable.  This is then passed to a binary to bcd routine which gives
>me a single variable xxxx (i.e. 1023, 0963, 0053, 0007).  I now want to sent
>this to the terminal in the following format x.xxx (i.e. 1.023, 0.963,
>0.053, 0.007). The serial comms is OK but I am not sure which is the best
>method method to produce this output.
>
>Any suggestions please?

So you have printf directed to the serial port?

Best to avoid floating point numbers, they will probably add a lot of
space to your program. How about this (untested)

  unsigned int x;               // holds the ADC value from 0..1023
  unsigned char y;              // scratch variable for printing

  y = x/1000;                   //  0 <= x <= 65535
  printf("%d.%3.3d", y, x-(y*1000));

Note that this compiler does not recognize the "0n" width specifier.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@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#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2002\08\03@174914 by Bill & Pookie

picon face
Hummmm.....

The ascii for '0' is 30 hex,  and for '1' is 31
hex.
What is the bcd for '0' and '1'?

Hummmm.......

Bill

{Original Message removed}

2002\08\03@191123 by Brent Brown

picon face
Doh! It just occurred to me that your 4 digit BCD number is probably
"packed" into 16 bits (4 x 4 bit digits).

In that case this should work:

SendByte(((number >>   0) & 0x000f) + '0');
SendByte('0');
SendByte(((number >>   4) & 0x000f) + '0');
SendByte(((number >>   8) & 0x000f) + '0');
SendByte(((number >> 12) & 0x000f) + '0');

The shift right by 0 places for the first digit is obviously
redundant, as is the AND by 0x000f for the 4th digit, but I like to
keep things looking consistent so it's easier to see what it is
intended.

This should optimise quite nicely in Hi-Tech C, perhaps you can get
away without some of the extra brackets too.

--
Brent Brown, Electronic Design Solutions
16 English Street, Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/txt: 025 334 069
eMail:  .....brent.brownKILLspamspam.....clear.net.nz

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


2002\08\04@065758 by ian.forse

flavicon
face
Yes it was packed 16bits.  And 3 days ago I was almost there but did it the
otherway round i.e. AND 0xf000, 0x0f00 etc followed by the shift.  My error
was && instead of & (Double Doh!!).  It works perfectly now thanks.

Ian

------------------------------------------------------
http://mdm1.bravepages.com
Technical support for the Multifunction Display Module
------------------------------------------------------

> {Original Message removed}

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