![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Can anyone tell me how "printf" statement works in CodeVision AVR and after compling Where Can I see output
OR please tell me Why "printf" is use in Codevision AVR |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Here is a simple example of a printf function with no strings and no floating point: Code:
/*-----------------28.08.99 22:49-------------------
* Simple printf function (no fp, and strings)
*--------------------------------------------------*/
int printf(const char *format, ...) {
static const char hex[] = "0123456789ABCDEF";
char format_flag;
unsigned int u_val, div_val, base;
char *ptr;
va_list ap;
va_start (ap, format);
for (;;) {
while ((format_flag = *format++) != '%') { // Until '%' or '\0'
if (!format_flag) {
va_end (ap);
return (0);
}
lcd_putch (format_flag);
}
switch (format_flag = *format++) {
case 'c': format_flag = va_arg(ap,int);
default: lcd_putch(format_flag); continue;
case 'd': base = 10; div_val = 10000; goto CONVERSION_LOOP;
case 'x': base = 16; div_val = 0x10;
CONVERSION_LOOP:
u_val = va_arg(ap,int);
if (format_flag == 'd') {
if (((int)u_val) < 0) {
u_val = - u_val;
lcd_putch ('-');
}
while (div_val > 1 && div_val > u_val) div_val /= 10;
}
do {
lcd_putch (hex[u_val / div_val]);
u_val %= div_val;
div_val /= base;
} while (div_val);
}
|
||
|
|
|
|
|
(permalink) | |
|
Quote:
What modifiactions should I do in the above code? |
||
|
|
|
|
|
(permalink) |
|
You don't need to add the function to your code; it is an example of how printf works. To direct your output to a PC, then write yourself a PC_putc() function which will direct its output to a serial stream using a UART if you have one on your chip. Which chip are you using?
I will try to find out more about codevision, if I can. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) | |
|
Looks like codevision has a wizard to set up a project to do this. I found this info on the IDE:
Quote:
|
||
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
Hi again,
Get the manual here: http://www.hpinfotech.ro/html/cvavr_doc.htm and turn to page 113, which gives you details on using printf and the UART. Do you know about AVR Freaks website? http://www.avrfreaks.net/ |
|
|
|
|
|
|
(permalink) | |
|
Quote:
So how can I interface Chip with PC to see output? What steps do i need to follow? |
||
|
|
|
|
|
(permalink) |
|
You will need some kind of level converter, such as Max 232, hooked up to your micro rx and tx pins. This tutorial should help:
http://www.sparkfun.com/commerce/pre...p?p=BEE-4-UART There is another tutorial on using printf with the gcc compiler here: http://www.sparkfun.com/commerce/pre...EE-5-Compiling Hope this helps you get where you are going. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
Well, I haven't done much of anything with AVR, but can try...
What project are you working on? |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Last edited by hitusharpatil; 22nd January 2008 at 06:29 PM. |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| AVR (tiny85) differing output on pins... | magician13134 | Electronic Projects Design/Ideas/Reviews | 7 | 24th January 2008 11:13 PM |
| pic or avr | umar karim | Micro Controllers | 11 | 21st January 2008 06:30 PM |
| AVR DDS ~ RS232 problem... | krazatchu | Micro Controllers | 15 | 13th December 2007 04:44 AM |
| How does the AVR do one clock per instruction? | blueroomelectronics | Micro Controllers | 5 | 9th December 2007 01:29 AM |
| Eclipse IDE for ARM, AVR, and PIC? | linuxguy | Micro Controllers | 9 | 29th September 2007 05:13 PM |