; list p=pic18f452 ; list p=pic18f252 ; ***************************************************************************** #ifdef __18F452 #include p18f452.inc #endif #ifdef __18F252 #include p18f252.inc #endif temp equ 0x00 ; RAM file variable delay equ 0x01 ; delay work area org 0x200 ; reset vector goto start org 0x208 ; interrupt vector goto $ org 0x218 ; interrupt vector goto $ org 0x220 start: movlw 0xfe movwf TRISA ; PORTA, bit 0 is now an output movlw 0x06 movwf ADCON1 ; define PORTA mode (analog/digital) clrf temp ; initialize toggle variable loop: movlw 0x01 xorwf temp, f movf temp, w movwf PORTA ; toggle pin call _1s_delay ; delay goto loop ; ; 3.6864-MHz clock ; ; 271-ns clock period, 1.08-us machine cycle ; ; approximate 1-second delay ; _1s_delay: movlw .100 movwf delay dloop: call _10ms_delay decfsz delay, F goto dloop return ; 9221-instruction cycles => approximately 10-ms ; (9216 is ideal) ; _10ms_delay: ; (2) to get here movlw .96 ; (1) _dloop: call _100us_delay ; (92) addlw -1 ; (1) btfss STATUS, Z ; (1/2) goto _dloop ; (2) nop ; (1) return ; (2) to get back ; 92-instruction cycles => 99.8 us ; _100us_delay: ; (2) to get here call _20us_delay ; (18) call _20us_delay ; (18) call _20us_delay ; (18) call _20us_delay ; (18) call _20us_delay+2 ; (16) return ; (2) to get back ; 18-instruction cycles => 19.5-us ; _20us_delay: ; (2) to get here goto $+2 ; (2) goto $+2 ; (2) goto $+2 ; (2) goto $+2 ; (2) goto $+2 ; (2) goto $+2 ; (2) goto $+2 ; (2) return ; (2) to get back ; 9-instruction cycles => 9.76-us ; _10us_delay: ; (2) to get here goto $+2 ; (2) goto $+2 ; (2) nop ; (1) return ; (2) to get back end