I am developing a program using HSERIN in automatic mode. The basic idea of this application is to have a device attached serially to a computer running some specifit software. When this software sends a "1", "2", or "3", the device is to turn on a green, yellow, or red LED by itself (i.e. turn off any LEDs already on). On receipt of a "0" the leds are off.
I made a working program using regular serrxd which works fine... however, since there is to be a simple routine to flash the LED if a "F" is received from the computer, I went on to design code using HSERIN in background mode on a 40X2 so I don't lose any communications while the program is pausing for the flash modes.
It works... sort of.
0, 1, 2, and 3, the ASCII characters I expect per the program, don't work. Instead (and I found this out by accident), the characters that actually work are > : 6 and 2 (decimal 62, 58, 54, and 50).
There is a pattern here but I don't know what it means... I can't figure it out.
Any ideas?
Also (unrelated) I noticed it didn't matter if I used inverted mode or not on the hsersetup... is this important?
Code below.
I made a working program using regular serrxd which works fine... however, since there is to be a simple routine to flash the LED if a "F" is received from the computer, I went on to design code using HSERIN in background mode on a 40X2 so I don't lose any communications while the program is pausing for the flash modes.
It works... sort of.
0, 1, 2, and 3, the ASCII characters I expect per the program, don't work. Instead (and I found this out by accident), the characters that actually work are > : 6 and 2 (decimal 62, 58, 54, and 50).
There is a pattern here but I don't know what it means... I can't figure it out.
Any ideas?
Also (unrelated) I noticed it didn't matter if I used inverted mode or not on the hsersetup... is this important?
Code below.
Code:
' STACKLIGHT2.bas
' Test program for 40X2 development kit
' WITH HSERIN!!!
'
' OUTPUTS:
' B.0 GREEN LED
' B.1 YELLOW LED
' B.2 RED LED
'
' OPERATION: If serial data from attached computer = 1, 2, or 3, turn on
' green, yellow, or red LED by itself. If data is 0. turn off leds.
' If data is F, enable flash mode, if data is S, disable flash mode
'=== Constants ===
symbol STACK = outpinsB
symbol char = W3
symbol flash = B0
symbol GREEN = %00000001
symbol YELLOW = %00000010
symbol RED = %00000100
symbol BLANK = %00000000
symbol abit = 500
'=== Variables ===
' none
'=== DIRECTIVES ===
#com 7 ' SPECIFY SERIAL PORT
#picaxe 40X2 ' SPECIFIY PICAXE TYPE
#no_data ' SAVE DOWNLOAD TIME
'#terminal off ' ENABLE TERMINAL WINDOW
'=== MAIN PROGRAM ===
dirsB = %11111111 ' PORT B ALL OUTPUTS
hsersetup B9600_8, %11 ' baud 9600 at 8MHz, Invert, Background
HSerPtr = 0 ' Reset (background) write pointer
HSerInFlag = 0 ' Reset reception indicator
Ptr = 0 ' Reset read pointer
@Ptr = 0 ' Clear the first scratchpad location
'STACK=%00000100
main:
if hserinflag = 1 then gosub datain
if char="F" then let flash = 1 endif
if char="S" then let flash = 0 endif
if char="0" then let STACK=BLANK endif
if char="1" then let STACK=GREEN endif
if char="2" then let STACK=YELLOW endif
if char="3" then let STACK=RED endif
if flash = 0 then goto main
pause abit
if hserinflag = 1 then gosub datain
let STACK=BLANK
pause abit
goto main
datain:
ptr = 0
char = @ptr
hserptr = 0
hserinflag = 0
return
Last edited: