HA.. Got it. You got me looking in the right direction with the itoa. Found example code at http://en.wikipedia.org/wiki/Itoa and now its working as desired without the added bloat. Again I owe ya. Thanks guys ----- Original Message ----- From: "Don Kinzer" <dkinzer@easystreet.com> To: <AVR-Chat@yahoogroups.com> Sent: Wednesday, January 23, 2008 8:19 PM Subject: [AVR-Chat] Re: Simple casting winavr --- In AVR-Chat@yahoogroups.com, "Bryan Martin" <registration@...> wrote: > I need to print the decimal value to UART so I want to see 10. This issue has nothing to do with casting, by the way. That aside, the C run-time library has a function to convert a value to a string and the one that you mentioned is close but not the right one. You need sprintf() or, alternately, itoa(). uint8_t byte_in; uint8_t buf[5]; sprintf(buf, "%u", byte_in); That will get you a null-terminated sequence of digits in the buffer. Note that I used the %u format specifier which is for unsigned decimal conversion. The %d that you used if for signed decimal conversion. Next, you need to output those characters via the UART. For this, you need a different function, one that is not part of the C run-time library. The reason that this is so is because there is no "standard" way to implement a UART interface. You might be using an interrupt- driven output routine with a fancy queue arrangement while I might be using a simple polled output techinique. You can find examples of both interrupt-driven and polled I/O drivers for AVR UARTs in many places. If you search for "procyon" or "stang" and "UART" you'll find but one example written by Pascal Stang. You'll find that C has significantly more power and flexibility than Bascom but the price that you pay is a steeper learning curve and having to search to find code you can use or write your own for many things that Bascom provides for you. Don Kinzer ZBasic Microcontrollers http://www.zbasic.net -------------------------------------------------------------------------------- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.9/1238 - Release Date: 1/22/2008 8:12 PM
Message
Re: [AVR-Chat] Re: Simple casting winavr
2008-01-24 by Bryan Martin
Attachments
- No local attachments were found for this message.