PropBASIC Simple terminal I/O
Rsadeika
Posts: 3,837
Below is my version of showing a key press on a terminal screen. What I would like to do is expand this so it can respond to some simple commands, maybe ledon(16), ledoff(16), and quit. I am having a hard time trying to figure out how to do string input, and output, TX and RX of course.
The way I have my board setup is, I have an RS232 breakout board, and I use Tera Term as the terminal program. You could use pins 31, and 30, but its a pain because you cannot start the terminal program until PropBASIC has released the com port.
Thanks
Ray
The way I have my board setup is, I have an RS232 breakout board, and I use Tera Term as the terminal program. You could use pins 31, and 30, but its a pain because you cannot start the terminal program until PropBASIC has released the com port.
Thanks
Ray
'********** '**** Master.pbas '**** Simple terminal I/O '**** Enter a keypress, and it displays on terminal screen '********** '** Device Settings '********** DEVICE P8X32A, XTAL1, PLL16X XIN 5_000_000 '********** '** Constants '********** Baud CON "T115200" '********** '** I/O Pins '********** TX PIN 24 high RX PIN 25 input '*********** '** Variables '*********** alpha VAR long '********** '** Subroutine / Fuction Declarations '********** TX_BYTE SUB 2 RX_BYTE FUNC 1 DELAY_MS SUB 1 '********** PROGRAM Start '********** Start: DELAY_MS 10 Main: TX_BYTE TX, "A" 'Print A on startup TX_BYTE TX, 10 'Newline TX_BYTE TX, 13 'CR 'Do simple console I/O 'Start an endless loop do alpha = RX_BYTE RX 'Get keypress IF alpha = 13 THEN 'Check if CR was pressed TX_BYTE TX, 10 'Newline TX_BYTE TX, 13 'CR ELSE TX_BYTE TX, alpha 'Print the keypress ENDIF loop 'Stops program,just in case it ever breaks out of loop END '********** '** Subroutine / Function Code '********** SUB TX_BYTE SEROUT __param1, Baud, __param2 ENDSUB SUB DELAY_MS PAUSE __param1 ENDSUB FUNC RX_BYTE __param2 = __param1 SERIN __param2, Baud, __param1 return __param1 ENDFUNC
Comments
Fairly sure Bean had an example included in the PropBasic demo files (probably in the first post of the original Propbasic thread if not in the more recent PropBasic zip).
From memory it echo'd back stuff typed in the terminal... it might explain what you need.
-Mike
It is MUCH easy to use single letter commands like:
H# = Make pin "#" high
L# = Make pin "#" low
I# = Make pin "#" an input
And so on...
Bean
If I used this as the basis for Prop-to-Prop comms, I assume I can crank-up the Baud to multiples of what you have above, right?
I love this compiler and hope you never abandon further development....Great Job!!!
Regards,
Mickster
Bean
If I change it to, help DATA "Just anything",0, then it works without an error. In your documentation I got the impression that using the HUB is the preferred way, but that does not to work for me, or how/when to use HUB maybe needs some more explanation. So, if you could set me straight ...
Ray
I'll check into it.
It looks like it should work.
I use DATA instead of HUB for static strings.
Bean
P.S. I check it, you can't declare strings with HUB. DATA does what you want.
In the above snippet, when it runs, TX_STR TX, help, all I get is a blank line. Do I have to use something other than __param1, to deal with the string?
Ray
I assume you are trying to do this...
When you pass a HUB string as a parameter it is passed as the ADDRESS of the string in HUB ram.
The SEROUT command "assumes" that __param2 is a character value that you want to send. To let it know that it is a string address you need to use the virtual __STRING() array.
I hope this helps...
Bean
Right now the program uses GetChar FUNC, I would still like to figure out how to do a GetString FUNC, so I could have a larger Command choice than just the letters of the alphabet. I guess I could try implementing an XBee driver, a very stripped down driver, and try to do something with one letter commands. Any suggestions for improvements or short cuts will be greatly appreciated.
Ray
Ray
You cannot compare strings with "=", strings are special HUB byte arrays.
I almost never use VAR arrays, because they require self-modifying-code on the propeller. I just use HUB arrays, which save COG space too.
Are you trying to do something like this...
Bean
Ray
Bean