View previous topic :: View next topic |
Author |
Message |
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Wed Apr 02, 2014 10:31 pm Post subject: UART Input |
|
|
Hello,
I would like to make a simple configuration menu. Could you help me what i can use instead of command INPUT ? The INPUT waits for ENTER and it halts my program.
If i use INKEY then i don't see what i write to terminal.
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Wed Apr 02, 2014 11:10 pm Post subject: |
|
|
The idea is to only respond to a character when there are characters in the input buffer. When no characters, just bypass the input statement.
Look up the terms "buffered serial input" and "ischarwaiting" in the Bascom help file and serial examples. That might give you some clues.
There was a bit of discussion also on
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12174
about this type of thing, although not quite what you want. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Apr 03, 2014 2:43 am Post subject: |
|
|
Hello bibibo
In my ENC28J60 webserver program in the blog section there is the code for a terminal input to the server so that you can change all the settings like IP number , MAC address , gateway IP and many others it also sends back a help file when you send ? or Help to it.
Regards Paul |
|
Back to top |
|
|
DoctorBob
Joined: 05 Jul 2006 Posts: 12 Location: Nederland
|
Posted: Fri Apr 04, 2014 5:38 pm Post subject: |
|
|
As I prefer IRQ's as I do not like to check inputs for activity here some simple way of RxD by interrupt example
Int IRQ for UART here used as RS485
Code: |
' UART
RS485DIR alias PORTD.5
const _RxD_BUSY = 0 ' RxD still loading
const CMD_START_MASTER = &H4D ' 'M' &H3A = ":" start of frame
const CMD_START_SLAVE = &H53 ' 'S'
const CMD_STOP = &H0D ' <cr> stop of frame
dim RxD as byte ' RxD read data
dim RxD_data as string * 16 ' Rx/Tx databuffer (max. 8 bytes)
dim RxD_pointer as byte ' point position in dataframe
dim RxD_status as byte ' package building
'---- RS485 --------------------------------------------------------------------
config print = PORTD.5 , mode = set ' Auto control RS485 direction pin
config RS485DIR = output ' control direction for RS485 bus
RS485DIR = 0 ' set to receive mode
on URXC ISR_UART ' On RxD data collect package
enable URXC
|
The IRQ code for handling the RxD from UART when RxD input detected
Code: |
ISR_UART:
RxD = UDR
if RxD = CMD_START_MASTER then ' Start data capture
RxD_pointer = 0 ' reset data input counter
RxD_data = "" ' clear data buffer
RxD_status = _RxD_BUSY
elseif rxd = CMD_STOP then ' Stop data capture
RxD_status = _RxD_OK ' tell MOS we are done
elseif RxD_status = _RxD_BUSY then
incr RxD_pointer
RxD_data = RxD_data + chr(RxD) ' store character in data buffer
endif
return
|
|
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sat Apr 05, 2014 12:59 am Post subject: |
|
|
That is exactly what using Bascom serial buffered input and ischarwaiting does for you.
After all, at some point in your main program, you have to check that you have some characters in your buffer, and handle that input. So let Bascom handle the tricky stuff of getting the chars into a buffer ( and checking for overflows, and all the other details to keep it running ). _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Mon Apr 07, 2014 7:33 am Post subject: |
|
|
Hi all,
thank you for your tips. Super |
|
Back to top |
|
|
|