Appropriate or inappropriate, I've never been surprised by the way CW does bit-level hardware manipulation and I've used C exclusively for years. That's why I'm surprised to find someone claiming that it is, perhaps, unreliable.
You know, I see a lot of people doing bit setting/clearing in C like this:
PTBD_PTBD7 = 1;
which is fine, but I was taught to do it with the whole byte and a bitmask like this:
PTBD |= 0x80;
In the case of the exclusive or, with a single bit, does the bitwise XOR even make sense when applied to a single bit? The_andie originally stated that the entire port was sometimes flipping its state.
My question is, how did the other bits get flipped if CW was using BRSET, BSET, and BCLR?
It seems like CW must be doing something like:
PTB ^= 1;
instead of applying the XOR to just 1 bit like:
PTBD_PTBD7 ^=1;
I've never looked into how the bit structures are laid out in the really long header file where they are defined... Maybe the answer lies in there somewhere.
I've always toggled bits like this:
if (PTB & 0x80) {
PTB &= ~0x80;
} else {
PTB |= 0x80;
}
This compiles to BRCLR, BRSET and BCLR - which should never mess with other bits in the port. But still I would disable interrupts before starting this segment.