In: Electrical Engineering
For the PIC16F887, using the execution delay of instructions, write assembly language commands to implement a delay of 3 seconds
LIST p=16F877A
INCLUDE <P16F877A.inc>
X EQU 0x20
Y EQU 0x21
ORG 0x00
BANKSEL TRISD
BCF TRISD,7
BSF TRISD,2
BANKSEL PORTD
state btfss PORTD,2
GOTO main
GOTO ledoff
main
CALL setval
BSF PORTD,7
CALL delay
CALL setval
BCF PORTD,7
CALL delay
btfss PORTD,2
GOTO main
GOTO ledoff
ledoff BCF PORTD,7
GOTO state
delay movlw 0xF9
nop
loop addlw 0xFF
btfss STATUS,Z
goto loop
decfsz X
goto delay
decfsz Y
goto delay
return
setval MOVLW 0xFF
MOVWF X
MOVLW 0x04
MOVWF Y
return
END
delay
movlw 0xF9
nop
loop addlw 0xFF
btfss STATUS,Z
goto loop
decfsz X
goto delay