#include <SERIAL.bas> ' PBASIC library, these routines were written for ARMexpress, and included for general reference,UART functions should be used instead of these.
Library sources are in the BASIClib directory.
This library has some initialization code that can either be copied into your program or the code can be run inline as in the following-
code without a main:
... user code
code with a main:
INcnt is the number of bytes that will be received. If INcnt is 0, then the string will be filled with bytes until a 0, CR or LF character is received. Note that no bounds checking is performed on the input, and if a 0, CR, or LF is never received then this routine will hang. As there is no bounds checking its possible to overwrite other variables, if less than 256 bytes have been allocated for the InputList string.
SERIN will timeout after 0.5 seconds and return -1 and place 255 in the next item in the INlist before the timeout. These routines are "bit-banged" by the processor, so the processor is consumed during these operations. Interrupts are also disabled during each byte for these operations. The hardware UART0 can be used see RXD0 or DEBUGIN . The timeout can be changed with SERINtimeout.
Baudrates can be up to 115.2 Kbaud for all pins on transmit. Receive rates to 57Kb
DIM choice(10) as STRING
SERIN(1,9600,0, choice) ' read a UserCode CR/LF terminated
SELECT VAL (choice)
CASE 123 ...
SEROUT sends a string of characters out on pin as an asynchronous data stream. baud and posTrue set the parameters for the transmission. OUTcnt is the number of bytes that will be transmitted. If OUTcnt is 0, then OUTlist will be sent until a 0 is encountered (the 0 is not sent).