Problem reading a value from the scratch pad to use in branch command

BrendanP

Senior Member
Im TXing serial data to the scratch pad of a 40X1 via the hserin in auto mode. The program then looks through the scratch pad for a string of data in the correct sequence that indicates to it that this Rf tx is from one of its senders.

I then use one part of the string in the branch command to indicate where the program should go next.

Problem is that the program doesnt recognise the byte value in the branch command. It seems that the byte value is corrupted during the scratch pad write/read process.

Heres the code, Im a bit perplexed.

The branch comm works fine if I 'manually' set the b2 value with command " b2=7". I debug b2 after the 'get 101,b2' command and it shows b2 as holding 7 yet the branch command doesnt recognise the 7.

Any pointers anyone?

Code:
setfreq m4
hsersetup B1200_4,%11
setintflags %00100000,%00100000     
 
armed:
high 0 'flash led
pause 50
low 0
pause 50
if b20 = 1 then goto check_for_valid_data
goto armed
 
check_for_valid_data:
b20=0 'set b20 to zero so program knows it been here to check the scratch pad
ptr=0        
for b0 = 1 to 90
if @ptr="#" then goto next_check2
inc ptr
next b0
ptr=0    
setintflags %00100000,%00100000 
goto armed
 
next_check2:
put 100,@ptr
inc ptr
if @ptr="7" then goto next_check3
ptr=0    
 
setintflags %00100000,%00100000 
goto armed
 
next_check3:
put 101,@ptr
inc ptr
if @ptr="^" then goto valid_alarm
 
ptr=0    
setintflags %00100000,%00100000 
goto armed
 
valid_alarm:
put 102,@ptr
sertxd ("valid alarm")
 
 
get 101,b2
 
branch b2,(null,sensor1,sensor2,sensor3,sensor4,sensor5,sensor6,sensor7,sensor8,sensor9,sensor10) 'use the loaded b2 value with the branch comm to go to the right sensor learning subroutine
 
 
cont:
setintflags %00100000,%00100000 
goto armed
 
 
null:
goto cont
 
 
sensor1:
b1=1
write 1,b1
goto cont
 
sensor2:
b1=1
write 2,b1
goto cont
 
sensor3:
b1=1
write 3,b1
goto cont
 
sensor4:
b1=1
write 4,b1
goto cont
 
sensor5:
b1=1
write 5,b1
goto cont
 
sensor6:
b1=1
write 6,b1
pause 2000
goto cont
 
sensor7:
b1=1
write 7,b1
sertxd ("just wrote byte value to eeprom")
pause 2000
goto cont
 
sensor8:
b1=1
write 8,b1
pause 2000
goto cont
 
sensor9:
b1=1
write 9,b1
goto cont
 
sensor10:
b1=1
write 10,b1
goto cont
 
 
 
interrupt:
sertxd ("hserin triggered")
b20=1
return
 
Last edited by a moderator:

inglewoodpete

Senior Member
Please encapsulate you code in "code" tags (Advanced Editor), otherwise the webpages are enormous and formatting (indenting) is lost.
 

inglewoodpete

Senior Member
If you select the Advanced editor, select your code (Ie highlight it) and the click on the # button the editor's tool bar. The editor will add html-like tags around the selected text.

When revisiting a post, you can manually add the tags by putting the word {code} in square brackets (instead of curly ones) at the start of the code and {/code} in square brackets (instead of curly ones) at the end of the code block.
 
Last edited:

hippy

Ex-Staff (retired)
Inglewoodepete is refering to the Forum Editor.

I suspect that as it works when you use 'b2=7' and you say debugging the 'get 101,b2' shows 7 but doesn't work, what you are seeing in b2 after the 'get' is the ASCII character "7" not decimal value 7.

Try adding a 'b2=b2-$30' after the 'get' and see if that improves things.
 

BrendanP

Senior Member
Hippy.....'age cannot wither him, nor custom stale his infinite variety'

Ahhh Hippy........, 'age cannot wither him, nor custom stale his infinite variety' !

Once again you fixed the problem. Thank you. I'll do some more work and get back to you if I have more problems.
 

inglewoodpete

Senior Member
Sorry Brendan, I went off line leaving you in a bit of a pickle. I knew what I was referring to... and its easy to assume that others do too. Luckily we have people from all time zones on line at different times of the day.
 
Last edited:

BrendanP

Senior Member
No problem Pete, thanks for your help.

Hippy, I guessed (but wasnt sure) that your line of code is a formula that would convert the byte value (what ever its value) into a form the branch command could deal with. And yep it does, Ive set up a couple of TXer's txing different byte values which the branch command correctly processes. I didnt want to waste your time by asking a needless question until I had done my own' homework' on the problem.

I'm very gratefull for your help.
 
Last edited:

hippy

Ex-Staff (retired)
"B0=B0-$30" converts ASCII characters "0" to "9" to decimal value 0 to 9. One could also use "B0=B0 & $0F" or ...

B0=B0-"0"
 
Top