modified for xc8 compiler and external clock