??? 07/12/05 05:52 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#97120 - printf() to multiple devices Responding to: ???'s previous message |
Vinay said:
I just found this feature in SDCC and thought i could share it eith u people.SDCC has a printf() function similar to standard C .But since SDCC does not know what output device to print it to,SDCC requires the definition of putchar() function for its printf() command.What SDCC does is to parse the incoming data (of whatever datatype) to printf into single characters and call the putchar function for each of these characters.For example
int e=128; printf("%d",e); will call putchar as follows putchar('1'); putchar('2'); putchar('8'); thus the printf function can also be used to convert INT TO BCD by the use of the putchar function(though this is slow and occupies more space). Perhaps you mean an ASCII representation of the integer. Although it's true that printf() could be used in the way you suggest (the same applies for Keil), it seems that for most data conversion-only purposes, it would be easier to just use sprintf(), which places its output in a character buffer. In so doing, you avoid having to mess around with the implementation of putchar(). I'm guessing sprintf() is present in SDCC as well. Similarly, scanf() and sscanf() can be used in the reverse direction. scanf() reads using getchar(), which may also be customized, while sscanf(), as its name suggests, reads from a buffer instead. getchar(), of course, can be implemented to read from any device. You can also add other customizations to getchar(), such as the ability to turn on and off echo of the character received. Of course, in many cases, I'll be able to write special-purpose data conversion routines that are smaller and faster than these general purpose utilities. The uses of this are boundless.With some clever programming and use of switch() u can have multiple output devices LCD,EEPROM etc.By clever use of the putchar() function u can parse any data to bytes to store in the EEPROM. True. But you could probably fill your EEPROM with sprintf() and memcpy() as well. That said, if you truly have multiple display output devices, being able to retarget printf() could be useful and isn't hard. Keil has an application note describing how to do this. I cannot imagine it would be much different under SDCC. --Sasha Jevtic |
Topic | Author | Date |
ANY DATATYPE TO STRING/CHAR CONVERSION | 01/01/70 00:00 | |
Thanks for that | 01/01/70 00:00 | |
printf() to multiple devices | 01/01/70 00:00 | |
Yep! | 01/01/70 00:00 | |
Here's one I prepared earlier...![]() | 01/01/70 00:00 |