Friday, February 08, 2013

DS89C450 SDCC getchar() function

After the putchar() function you probably need the getchar() function.  The function is also quite simple. Just check the Receive Interrupt flag instead of Transmit Interrupt in the putchar().  I'm using mode 0 for the serial port, the RI_0 is set at the end of the 8th bit. When the flag is set, clear it then read and return the data:
char getchar(void) {
        char c;
        while (!RI_0)
        ;
        RI_0 = 0;
        c = SBUF0;
        return c;
}

If you want to read a line input you can use gets():
char line[100];

gets(line);

No comments: