Ok, I think I get it. Doesn't help me to explain it, but I get it.

I do not see anything in the code snippets to explain this so, I think it must be a hardware anomaly. Darrel once mentioned to me that output pins are first read before set and that setting individual pins(PORTA.1=1 : PORTA.2=1 : ...) is less desirable than the style of PORTA = %00000110, or that a brief PAUSE between may be necessary between statements to allow for this. I don't claim that this is happening in your code, only that their are some issues and limitations beyond the obvious. Sadly, I am not advanced enough in knowledge or equipment to troubleshoot at that level... Perhaps someone with more of one or the other will happen by.

Wish I'd been more help...