serrxd problem

pilko

Senior Member
hi,

I am trying to cause my code to switch back and forth between two subroutines.
I can get it to go to sub_2 by sending a "7" via the serial terminal, but when I send a "2", it does not switch back to sub_1.

Code:
'serrxd test 

#picaxe 28X1   
                                          
main:
      if b0<3  then goto sub_1
      if b0>6  then goto sub_2

sub_1:
      pause 1000
      serrxd [1000,ss], b0      'b0 receive serial value >6,
ss:
      if b0>6  then goto sub_2
      b1=100
      sertxd (#b1,cr)
      goto main
      

sub_2:
      pause 1000
      serrxd [1000,jj], b0      'b0 receive serial value <3,
jj:
      if b0<3  then goto sub_1
      b2=50
      sertxd (#b2,cr)
      
      goto main
 

Technical

Technical Support
Staff member
Probably an ascii issue - are you sending the ascii character or a raw byte?

Try this, using ascii "6" instead:

if b0>"6" then
 

pilko

Senior Member
Thanks Technical, it works perfect using quotes in the code.
I don't understand why, (so much to learn). :eek:

regards
pilko
 

geoff07

Senior Member
ascii characters have a value and a meaning. When you enter a 6 that is the meaning. The value of "6" is the code value 54 and that is what is transmitted and received (and therefore, tested for). If you sent #, for example, that has the code value 35. Take a look at an ascii code table.

With picaxe (or any computer) you have to distinguish between the meaning and the code value of data. The "quotes" make that distinction in this case.
 

pilko

Senior Member
thanks geoff07
You've reminded me of what I think I used to know but I can't remember when I forgot it :eek:
 

lbenson

Senior Member
Note that if b0 is between 3 and 6, your code as shown will fall through into sub_1.

If that is your intent, then you could just omit the first "if" statement.
 

pilko

Senior Member
Note that if b0 is between 3 and 6, your code as shown will fall through into sub_1.

If that is your intent, then you could just omit the first "if" statement.
Good point lbenson,---- thanks
 
Top