Sigh. Lengthy reply wiped out by web page ![]()
- please provide example code that compiles and runs.
- use separate code for each possible value with special actions. Right now, j=576 gets tested for 3 times, and executes 3 code segments.
- check if "bit-banding" can speed up IO.
if (((Tdata[767 - a] >> count) & 0x1)) {
REG_PIOD_SODR = 0x1 << 8;
} else {
REG_PIOD_CODR = 0x1 << 8;
}
Might become:
PIOBANDEDBITS[8] = Tdata[767 - a] >> count;
with associated less masking and loading of bitshifted constants. I haven't actually ever used bit-banding, because I've never quite seen a case where it would obviously work better, but your code where you're trying to manipulate multiple bits in one Port might be such a case...