I knew there'd be a way to do this, since there are files for most PICs with all this stuff in - just didn't bother to look! Ta :)
Cool :-)
What I meant, was that if I need to change 2 bits (say, turn two motors on, but leave the other bits as they are), is it possible in one instruction, or would I need to have two conditional jumps, which would then require "buffering" the input, to make sure both conditions execute the same, even if an input changes between instructions
Danny
Didn't find your answer? Ask the community — no account required.
R
Rheilly Phoull
Dare we ask for a circuit ??
-- Regards ..... Rheilly Phoull
A
Anthony Fremont
should be
why
PICs
not
motors
would
execute
AND is the way. For example, let's say we have a port value of b'100101' on the port and we wanted to turn off the first and last bits. We would AND the port value with b'011110'. This would let bits 1-4 pass thru unscathed, but bits 0 and 5 would be forced off. The code to do that would be:
movlw b'011110' andwf GPIO, F
If we wanted to turn them both on at the same time, we could OR (inclusive OR) the port value with b'100001'. This will turn on bits 0 and 5, but leave the rest unchanged. The code would be:
movlw b'100001' iorwf GPIO, F
XOR (exclusive OR) is how you 'flip' bits without knowing their current state. To toggle the first an last bits of the port, you could do something like this:
movlw b'100001' xorwf GPIO, F
It's still probably a good idea to use a shadow register (like your TMPOUT) instead of ANDing and ORing directly to the port.
D
Danny T
Of course!
Ta :)
Danny
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.