Serout command
CraigR
Posts: 12
I am trying to use the serout command to accept a user input from the keyboard. The three options for the user are 1)pressing a pushbutton, 2)pressing 0, or 3)pressing any other key on the keyboard. If the user presses the pushbutton I want the program to go·to the Start subroutine. If the user presses 0 I want the program to go to the Quit·Subroutine. If the user·presses any other key on the keyboard I want the program to display "Incorrect Entry". My problem is that when I run the program·the keyboard entrys work, but the program does not·do anything when the pushbutton is pressed.·Can the Serout command work with the pushbutton?
BAUD CON 16468
PORT CON 16
DO
· SEROUT PORT, BAUD, [noparse][[/noparse]"To Play Press Blue Button or·0 to Quit", CR]
· SERIN PORT, BAUD, [noparse][[/noparse]keypressed]
·
· IF (IN0 = 1) THEN
········GOTO Start
· ELSEIF keypressed = "0" THEN
······· GOTO Quit
··ELSE
······· SEROUT PORT, BAUD, [noparse][[/noparse]CR, "Incorrect Entry", CR]
······· GOTO Start
· ENDIF
LOOP
Start:
Quit:
BAUD CON 16468
PORT CON 16
DO
· SEROUT PORT, BAUD, [noparse][[/noparse]"To Play Press Blue Button or·0 to Quit", CR]
· SERIN PORT, BAUD, [noparse][[/noparse]keypressed]
·
· IF (IN0 = 1) THEN
········GOTO Start
· ELSEIF keypressed = "0" THEN
······· GOTO Quit
··ELSE
······· SEROUT PORT, BAUD, [noparse][[/noparse]CR, "Incorrect Entry", CR]
······· GOTO Start
· ENDIF
LOOP
Start:
Quit:
Comments
The trick with RS-232 communication is that there is no point in waiting for more than one bit time because there is either a bit, or there is no bit. And if you run off to do something else (like, poll IN0) and can't get back in a bit time, you lose the framing bit anyway. So, shorten your polling routines (and testing IN0 is already pretty short) to avoid dropped bits, then run the polling routines more often.
It's a computer. It doesn't get tired. Might as well make it earn its keep.
Try this (I didn't -- I reserve the right to make syntax and other errors) --