Pin Masks?
tom90
Posts: 55
I have been told on this forum a couple of times to set up a pin mask to define my pins
something like this:
mov mask, #1
shl mask, pin
What is the advantage between doing this and defining a pin by:
pin6 long |<6
Also, when I setup a pin mask like the first example, on the second line "shl mask, pin"
where it says "pin" do i put the actual pin number there (#8), or how exactly do I define
that pin number?
Thanks,
Tom
something like this:
mov mask, #1
shl mask, pin
What is the advantage between doing this and defining a pin by:
pin6 long |<6
Also, when I setup a pin mask like the first example, on the second line "shl mask, pin"
where it says "pin" do i put the actual pin number there (#8), or how exactly do I define
that pin number?
Thanks,
Tom
Comments
mov mask,#1
shl mask,pin
mov mask,# |<n ' for n == 0..8
mov mask,pinMask
:
pinMask long |< n
The main disadvantage is that the first is a tad slower than the second and third, and 'pin' also needs to be loaded from somewhere. The main advantage is that the first can use a run-time supplied pin number, the second and third require the pin number to be known in advance.
Without conditional compilation it's not easy to switch between the second or third if pin number can be changed by the user, which forces the third case to be the default choice.
A handy use of the first is that it's easy to modify to make an output pin 'not used' by making it negative, eg, outPinNumber can be 0..31 or -1 ...
The rest of the code can carry on as if the pin were an output but it will have no actual effect on the I/O pin.
Spin doesn't quite have the same problem, but the coding habit persists.
pin is a register (named cog location) whose contents are used to shift mask. The code you show assumes that it has been set by a mistake free program[noparse][[/noparse]mer].
And mask is another named register, whose contents were set to 1 in the first line.
mask long 1
pin long 8
pin6 long %1000000 'initialized data aka named registers can obviously have any bit of the 32 set, requiring no shifts at·all..
Post Edited (Fred Hawkins) : 11/19/2007 6:25:17 PM GMT