Is this possible?
GC4130
Posts: 13
I have some code in SX/B that works very well for a particular sensor. I need to address multiple sensors of the same type and I am trying to figure out a way to make the original code more dynamic, all I need to do is change the I/O pin definition. Any help would be greatly appreciated. Thanks
'example
A var rb.1
B·var rb.2
temp var·byte
Test sub
Test:
...............
......
return
main:
··· temp=A
··· Test
··· temp=B
··· Test
goto main
·
'example
A var rb.1
B·var rb.2
temp var·byte
Test sub
Test:
...............
......
return
main:
··· temp=A
··· Test
··· temp=B
··· Test
goto main
·
Comments
SX/B does not have anything like PIN variables. That is because the compiler "hard codes" the pin into the assembly instructions. A different pin requires different instructions.
Depending on what you are doing in your TEST routine you might be able to pass a bit mask to the routine.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"It's not getting what you want, it's wanting what you've got."
·
Could you explain a "bit mask rountine". My "Test" rountine is not complicated at all, it just allows me to measure the pulse width from an accelerometer. Problem is I have 4 of them and I want to·save code space by dynamically changing·the pin through the temp variable. If this is not possible, I guess I just have to have·4 individual "Test" rountines for·my 4 sensors with the specific pin designations in each.
thanks
George
Can you post your program ? Or at least the "test" subroutine. It's easier to show you the code, than to explain how to do it.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"It's not getting what you want, it's wanting what you've got."
·
Bit masking is essentially performing an AND function to determine the state of one bit.
There are other ways to address a single bit of a byte
"This is what I would like to have"
A var rb.1
B·var rb.2
temp var·byte
Test sub
Test:
···· if temp=1 then check1
···· if temp=0 then check2
·····check1:
········· ...........
···· return
···· check2:
··········...........
···· return
main:
··· temp=A
··· Test
··· temp=B
··· Test
goto main
"This is what I Think I will be forced to do"
A var rb.1
B·var rb.2
Test1 sub
Test2 sub
Test1:
···· if A=1 then check1
···· if A=0 then check2
·····check1:
········· ...........
···· return
···· check2:
··········...........
···· return
Test2:
···· if B=1 then check3
···· if B=0 then check4
·····check3:
········· ...........
···· return
···· check4:
··········...........
·····return
main:
··· Test1
··· Test2
goto main
I need to know what is inside the "check" routine.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"It's not getting what you want, it's wanting what you've got."
·
"This is what I would like to have"
A var rb.1
B·var rb.2
temp var·byte
Test sub
Test:
···· if temp=1 then check1
···· if temp=0 then check2
·····check1:
········· ...........
···· return
···· check2:
··········...........
···· return
main:
··· temp=A
··· Test
··· temp=B
··· Test
goto main
To answer your original question with what you have provided...
Yes it is possible.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"It's not getting what you want, it's wanting what you've got."
·
Post Edited (Paul Baker) : 5/31/2005 5:53:15 PM GMT
You can use variables for the shift count.
Instead of your loop in fetch you can do:
TempVar = __PARAM1
TempVar = TempVar·* 2
TwoBit = ByteVar >> TempVar
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"It's not getting what you want, it's wanting what you've got."
Post Edited (Bean (Hitt Consulting)) : 5/31/2005 6:47:01 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
To read:
Figure out which position you need (0-3) (we'll call it P)
make a copy of the variable you want the two bits from (this can be a port register)
Right shift the copy 2*P times.
AND the result with the constant 3
what's left is the two bits you wanted in the lowest two bits of your copy of the data.
To write:
Figure out which position you need (0-3) (we'll call it P)
Make a copy of the bits that you want store (or use the original if you do not care if its destroyed)
Create a variable and store $FC into it (this is your mask which is the inverse of the above mask)
Left shift the data to be store and the mask 2*P times.
AND the mask with the location the data is to be stored
OR the data to be stored with the location it is to be stored.
Now those two bits are inserted into the location without messing with the other bits.
Either create a subroutine as I did above or just embed it into your code.
Thanks for the explaination I think I get it now. I'll try to implement it in my code.
George
·