Since you're using PORTA (Analog pins) as digital ...
I might suggest ...

ALLDIGITAL.pbp
http://www.picbasic.co.uk/forum/showthread.php?t=11100
<br>