Everything about my daily life as a programmer/Electrical Engineer!

Getting printf to work in avr-gcc \ winavr

Printf wiring in avr-gcc is fairly easy. First, make sure you add libm.a and printf_flt.a in avrstudio. See project options for help on this. Otherwise the lines below will get you started.

int main(void)

Init(); //init the system
fdevopen(&sys_putchar,NULL);//wire in stdout to sys_putchar
return 0;

//simple function that receive chars from stdout
int sys_putchar(char val,FILE* fle)
//write out to the LCD for now
//Put code here to pump a char to the uart port!
//TODO: uart_putchar
return 0;

Let me know if this doenst work! I wish I would have known about this earlier!

No comments: