This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

customization of putchar function

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.

Parents
  • 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");
    

    But in Keil, you can't really do it this way, because neither fopen() nor fprintf() exist.

    You could implement them yourself, though, and with the plan of keeping the main body of the code as close to ANSI C as possible, that may even be the best idea available.

Reply
  • 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");
    

    But in Keil, you can't really do it this way, because neither fopen() nor fprintf() exist.

    You could implement them yourself, though, and with the plan of keeping the main body of the code as close to ANSI C as possible, that may even be the best idea available.

Children
No data