How to use printf and puts functions in IAR compiler for AVR

Status
Not open for further replies.

mike2002

Member level 2
Joined
Sep 16, 2002
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
c/c++ programming
Activity points
328
I*A*R FOR A*V*R

Hello,
Does anybody has experience with IAR Compiler for AVR?
I am having trouble, how to use printf and puts functions.
I did set BAUD rate and UART for MEGA8. Functions compiled fine but noting out on serial port?
Thanks,

 

printf

hi .. i am doing this other way ...

sprintf(buf, "\nTempC= %d degrees C\n", (int)temp_lsb ); // print temp. C
sends(buf)

where

void send(char TX_Char)
{//this sends TX_Char to UART
UDR = TX_Char;
while(!(USR&32)); //wait while tx buffer empty
}
void sends(char *string)
{
unsigned int n;
for(n=0;n<strlen(string);n++)
send(string[n]);
}

i have never used printf directly to seriel .. always via register ...

regards

cancel
 

I*A*R FOR A*V*R

printf calls the library function putchar, which must be adapted for the target hardware configuration.
The function is supplied in source format in the file putchar.c
Look in the HELP for detailed description.

Regards
 

Re: printf



What is the differece between using register and directly serial port commands?
 

puts & printf

Thanks to all of you,
I did revised putchar function and included to my code:
int putchar(int c)
{
if (c == '\n')
putchar('\r');
while ((UCSRA & (1<<UDRE)) == 0) // UDRE, data register empty
;
UDR = c;
return c;
}
Now all lib. functions related to serial I/O functioning.
I guess getchar() need to be revised also to get other way communication? :lol:
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…