How come?

tmack

Member
How come when I run either of the below listed programs: pin0 sends out a "1"
pin1 sends out a "2"
pin2 sends out a "4"
pin6 sends out a "64"
pin7 sends out a "128" on the serial line?
Is there a way to do it so that when pin2 goes high it sends out a 3 , then pin6 sends a 4 and pin7 going high sends out a 5?


Do: if pin0= 1 then SEROUT 2,N2400,(1)
else SEROUT 2,N2400,(0) endif
if pin1= 1 then serout 2,n2400, (2)
else serout 2,n2400, (0) endif
if pin2= 1 then serout 2,n2400, (3)
else serout 2,n2400, (0) endif
if pin6= 1 then serout 2,n2400, (4)
else serout 2,n2400, (0) endif
if pin7= 1 then serout 2,n2400, (5)
else serout 2,n2400, (0) endif
Loop


----------OR--------------------------

#Picaxe 18x
do
b0=pins & %00010010
if b0<>b1 then
serout 2,n2400,(b0)
b1=b0
end if
loop
 
I dont know if this is the problem but try:

Do: if pin0= 1 then SEROUT 2,N2400,("1")
else SEROUT 2,N2400,("0") endif
if pin1= 1 then serout 2,n2400, ("2")
else serout 2,n2400, ("0") endif
if pin2= 1 then serout 2,n2400, ("3")
else serout 2,n2400, ("0") endif
if pin6= 1 then serout 2,n2400, ("4")
else serout 2,n2400, ("0") endif
if pin7= 1 then serout 2,n2400, ("5")
else serout 2,n2400, ("0") endif
Loop
 
Still the same

I should have mentioned that these are the results I get when running the code on the simulator.
 
SO.....

So if I use that code for my transmitter, I have to set my reciever up so that it decodes 0,1,2,4,64 and 128? Since I want it to be only number for each pin. Thanks alot for teaching me this. I have wanted to learn about it for so long but reading just confused me I learn way better by doing.
 
You are confusing byte values with characters with serout. When simulating, because you are using non-ascii byte values (very low values), when you look at the simulated serial output it is shown in brackets. This is because it is a non-printing character.

sevs3 has already given you a program that will work as you want, by putting the digit 1-7 character in " " speech marks you get a correct ascii character sente.g. "2" not 2

so your receiver can now also make decisions based upon the ascii code received, so you can forget about 1,2,4,8,16,etc.

Code:
serin 1,n2400,b1
if b1 = "1" then

else if b1 = "2" then 
etc..
 
So Im clear

Just so Im clear, Even though the simulator is showing it recieved the 1,2,4,8,64, etc .,when used in hardware it will really be putting out "1","2","3","4"? If I use the code sevs3 gave me? Thanks , sorry for being kinda slow But I just REALLY want to understand this.
 
This might help.
When you put something in " " it's a ASCII character, leave them out and it's a decimal.
So "0" would = 48 (%00110000) and "A" would = 65 (%01000001).
 
Back
Top