Hi,
perhaps you drive your pin to one level and your external too heavy load drives it to the opposite level?
If the pin has no excess load, then perhaps part is damaged. Isn't chip hot?
BTW I see problems in your code. You should fix your way to clear flags, or they will bite you later when you add more features to your code.
This is correct:
TFLG1 = 0xff; // 清除各IC/OC中断标志位
TFLG2 = 0xff; // 清除自由定时器中断标志位
to clear single bit 2 flag your would do
TFLG1 = (1<<2);
or
TFLG1 = 4;
This is wrong:
PIFJ |= 0x10; //对PIFJ的每一位写1来清除标志位;
flags register is not regular register or memory cell. Flag is cleared writing one to particular bit. If more flags bits are set, then you will rewrite with 1 and thus clear all flags which are set! Above code line is clearing all PIFJ flags!
You need to either
PIFJ = 0x10;
or
PIFJ &= 0x10; // please notice the difference, not ~0x10 but 0x10
This is wrong as well:
CPMUFLG &=~(0x80);
it clears all flags except what you expect to clear. You think bit 7 should be cleared, but instead bit6..0 flags are cleared.
should be
CPMUFLG &= 0x80;
or
CPMUFLG = 0x80;
or even better self commented
CPMUFLG &= CPMUFLG_RTIF_MASK;
or
CPMUFLG = CPMUFLG_RTIF_MASK;
Regards,
Edward