Thank you for your comment, I will try your suggestion. Just a note: the code works fine on an 16F688 using the same I/O pin GP4.(with minors modifications: TRISIO replaced by TRISA, ANSEL replaced by ADCON1, CMCON line removed)