I have made the new function putchar for redirect the output to LCD already. But by default, I also want to use this as output to serial port on the same program. I do not understand how to use both output function in parallel or other way to switch between each other. Please tell me if possible. With my thanks.
"So I can not switch between output function (e.g. lcd_putchar and putchar)" That's ANSI 'C' for you! "which I can do in PIC-C(C compiler for PIC Microcontroller) very flexible as: - printf("......",.....);//default serial port - printf(lcd_putc,"......",.....);//redirect to LCD" Well, who cares about standards anyway - let's just make up the rules as we go along! You could create an fprintf (or whatever) that sets up your port selection, then calls the standard printf. Maybe you could do it as a Macro?
That's ANSI 'C' for you! In all fairness, ANSI C has nothing to do with this. What we're seeing here is a direct consequence of a design decision made by Keil: they decided to support printf(), but not fprintf() and fopen(), which would be the brutally obvious way a job like this would be done in actual ANSI C. I.e. the code at hand should be writable like this:
FILE *lcdout = fopen("mylcd_pseudofile", "w"); fprintf(lcdout, "this goes to the screen"); FILE *serialout = fopen("serial_pseudofile", "w"); printf("this goes to default output device");