IV. STDIO

stdio is a good example of the way C can make embedded programming more palatable. Though an operating system with streams is not generally possible on an 8 bit microprocessor, programmers can call some of the familiar functions to perform input and output operations to the predictable devices.

stdio relies upon the library functions getch() and putch(), which must be available elsewhere. Possible definitions for getch()/putch() are:

  • keypad_getch() in keypad.c

  • lcd_getch()/lcd_putch() in lcd.c

  • uart_getch()/uart_putch() in uart.c

A typical application defines the required functions as macros.

        #include <lcd.h>
        #include <uart.h>
        #include <stdio.h>

        #define getch() uart_getch()
        #define putch(CH) lcd_putch(CH)

        char str[16];

        void main(void)
        {
                while(1)
                {
                        gets(str,sizeof(str));
                        puts(str);
                }
        }
      

Table of Contents
gets — stores input characters to a buffer
puts — outputs characters from a buffer