Hi,
Without looking at the code in detail it's possible that the two devices are getting out of sync due to the fact that sender is constantly sending either "A" or "B".
What if you, boil the code down to a bare minimum and instead of comparing with "B" compare with anytning but "A"?
Code:
SERIN PortC.7, 2, Char
IF Char = "A" THEN
  HPWM 1, 77, 5000
ELSE
 HPWM 1, 0, 5000
ENDIF
/Henrik.