hitusharpatil said: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
/*-----------------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 said: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 said: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.
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 am using Atmega32. Do I need to burn the cip and then see the output?
BeeBop said:Yes, you will have to do this in order for it to run (unless you are doing the project in simulation first.)
BeeBop said: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:
https://www.sparkfun.com/commerce/present.php?p=BEE-4-UART
There is another tutorial on using printf with the gcc compiler here:
https://www.sparkfun.com/commerce/present.php?p=BEE-5-Compiling
Hope this helps you get where you are going.
BeeBop said:Well, I haven't done much of anything with AVR, but can try...
What project are you working on?
I have a quick question regarding CodeVisionAVR. I have an electronic project going on and I need to program a certain hex-file to AT90S2313-chip by using **broken link removed**-board and CodeVisionAVR. I've programmed and practised with that same equipments and c-files, but now I'd need to program a hex-file, instead of c-file, to the chip with CodeVision and I have no idea how. I'm a total beginner at programming so any help would be highly appreciated. Thanks
I have EXB2313-board as a programmer like I said. I have already tried with PonyProg, and it worked with hex-files easily but somehow it wasn't able to put the hex-file to the chip, if I remember correctly it said something about device missing/unknown etc.I'm not an AVR expert, or a CodeVision one either. You will need a programmer of some sort... and programming software to run it. Do you have these?
If not you could try PonyProg. Look for a circuit diagram and the software download here:
I have EXB2313-board as a programmer like I said. I have already tried with PonyProg, and it worked with hex-files easily but somehow it wasn't able to put the hex-file to the chip, if I remember correctly it said something about device missing/unknown etc.
Indeed English isn't my native language.I didn't realize it was a programmer as well. Your link led to a photo of the board, not the place you got it, which would have included some useful information.
If that is your error message, then PonyProg didn't work. Then again, your text isn't very clear, I gather English is not your first language? How do you mean 'it worked with hex-files easily?' Probably it isn't configured correctly for your board. Can you post a link to the board, not to a photo of the board? There is no way to tell how that EXB2313 is made with a photo.
Never mind the link, I found the manual for your EXB2313. According to the manual, you should be able to download the hex file to the board directly from codeVision. Have you tried this?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?