We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I write function, which recieve 4 characters from serial port with _getkey() function. It waits until all characters does not come. I need to exit from recieving if characters does not come for long time (about 1 sec.). Please write example. Thanks Martin Pokorny
You just need to check a timer overflow flag along with the serial interrupt flag in your loop. _getkey() blocks until a character is received, so you need a different loop polling both possible event sources. Something like:
// set up timer 0 // start timer 0 for 1 second charsRx = 0; while (!TF0 && (charsRx < 4)) { if (RI) { // got a character, fetch it buffer[charsRx++] = _getkey(); } }