Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 21st January 2008, 04:55 PM   (permalink)
Default CodeVision AVR Help

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
hitusharpatil is offline   Reply With Quote
Old 21st January 2008, 05:38 PM   (permalink)
Default

Quote:
Originally Posted by hitusharpatil
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
I'm not sure about Codevisions printf function, but in general printf is formated printing. It uses putc, which directs the output stream to whatever you want. If your putc function is directed at an LCD, this is where it will show up. If it is directed at the serial port then sent to a PC, you can view the stream with a terminal program, etc.

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);
    }
BeeBop is offline   Reply With Quote
Old 21st January 2008, 06:11 PM   (permalink)
Default

Quote:
Originally Posted by BeeBop
I'm not sure about Codevisions printf function, but in general printf is formated printing. It uses putc, which directs the output stream to whatever you want. If your putc function is directed at an LCD, this is where it will show up. If it is directed at the serial port then sent to a PC, you can view the stream with a terminal program, etc.

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);
    }
Can you please tell me how can I see output of above program on PC?
What modifiactions should I do in the above code?
hitusharpatil is offline   Reply With Quote
Old 21st January 2008, 06:19 PM   (permalink)
Default

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.
BeeBop is offline   Reply With Quote
Old 21st January 2008, 06:27 PM   (permalink)
Default

Quote:
Originally Posted by BeeBop
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.
I am using Atmega32. Do I need to burn the cip and then see the output?
hitusharpatil is offline   Reply With Quote
Old 21st January 2008, 06:31 PM   (permalink)
Default

Looks like codevision has a wizard to set up a project to do this. I found this info on the IDE:
Quote:
Built-in CodeWizardAVR Automatic Program Generator, allows you to write in a matter of minutes all the code needed for implementing the following functions:

UART initialization and interrupt driven buffered serial communication with the following parameters: 7N2, 7E1, 7O1, 8N1, 8N2, 8E1 and 8O1
I downloaded the manual; I'll tell you more in a few minutes.
BeeBop is offline   Reply With Quote
Old 21st January 2008, 06:33 PM   (permalink)
Default

Quote:
I am using Atmega32. Do I need to burn the cip and then see the output?
Yes, you will have to do this in order for it to run (unless you are doing the project in simulation first.)
BeeBop is offline   Reply With Quote
Old 21st January 2008, 06:41 PM   (permalink)
Default

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/
BeeBop is offline   Reply With Quote
Old 21st January 2008, 06:48 PM   (permalink)
Default

Quote:
Originally Posted by BeeBop
Yes, you will have to do this in order for it to run (unless you are doing the project in simulation first.)
Suppose I burnt the program on chip now I want to see the output on PC.
So how can I interface Chip with PC to see output? What steps do i need to follow?
hitusharpatil is offline   Reply With Quote
Old 21st January 2008, 07:29 PM   (permalink)
Default

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.
BeeBop is offline   Reply With Quote
Old 21st January 2008, 08:05 PM   (permalink)
Default

Quote:
Originally Posted by BeeBop
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.
Now things are too much complicaetd for my Project. I have a project form net but thing is that it is very difficult for me to proceed. will you please guide me?
hitusharpatil is offline   Reply With Quote
Old 21st January 2008, 09:29 PM   (permalink)
Default

Well, I haven't done much of anything with AVR, but can try...

What project are you working on?
BeeBop is offline   Reply With Quote
Old 22nd January 2008, 04:09 AM   (permalink)
Default

Quote:
Originally Posted by BeeBop
Well, I haven't done much of anything with AVR, but can try...

What project are you working on?
I am working on "Voice command Recognition System" using Atmega32 to glow LED at output Port. I have similar project with code but as I am new in this field I cant proceed properly.

Last edited by hitusharpatil; 22nd January 2008 at 06:29 PM.
hitusharpatil is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
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



All times are GMT. The time now is 11:36 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.