printf

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi freaks,

I'm using codevisionavr and defined _ALTERNATE_PUTCHAR_ to write data to a LCD using printf.

This works great but I also want to use sprintf with the default putchar function.

Does anybody know how to do this?

Thanks for your help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You want to select which device to write to on the fly... so you have a flag that you set for uart, clear it for lcd, and rig up the putchar to look at the flag and call one or the other device putchars. So now printf works with either device, sprintf still works with strings, everyone is happy?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I assume that you want to printf() to your LCD and to use sprintf() to send stuff to your UART.

Since you have made putchar() use the LCD, you need to write your own uart_putchar() and call this to output the strings from sprintf().

Alternatively make your putchar() call lcd_putchar() or uart_putchar() according to a global flag. ie just as bob has advised. This way you just change your output device whenever you like.