TOGGLE should ONLY be used on PIN's!
Yes, it does toggle the bit of any Register.Bit combination that you pass to it.
What's not so obvious is that it also attempts to set the TRIS register associated with that PIN.
On a 16F, it adds 80h to the specified PORT's register.
On an 18F, it adds 12h, and in both cases it clears the matching bit to insure the PIN is set to output.
It doesn't care if it's not really a TRIS register. It clears it anyway.
If you aren't actually toggling a PIN, the results can be RANDOM because it's overwriting BIT's in other variables.
A better method of toggling a BIT in any register is to use the Bitwise NOT operator (~) or the Logical NOT (! or NOT).
The PIN numbers are a Basic Stamp compatibility issue.So what does the 'variable that contains a number 0-15 (e.g. B0)' mean ?
On some PIC's 0 = PORTB.0, on other PIC's it's PORTA.0, on 12F's It's GPIO.0.
<br>




just the answer I was looking for. I was about to start TOGGLING variable bits !!!


Bookmarks