getchar() / putchar() (Part 2)
We’ll add a 1-character buffer for both input and output
getchar()
- interrupt when a new character arrives
- if the buffer is empty, place character in buffer
- otherwise, set error flag (new function to check for errors)
- getchar() now looks at the buffer for a character
- otherwise the same as before
putchar()
- interrupt when a character has been sent
- if the buffer has a character, send it to the serial port
- putchar() now puts the character into the buffer
- otherwise the same as before
- what if the buffer is empty when interrupt occurs?
- new character to buffer will not be sent
Complication: one interrupt routine for both input and output