demo
demo
#include <P16F887.INC>
START:
BSF STATUS, RP0 ; Bank 1
CLRF TRISB ; Set PORTB as output
BANKSEL PORTB
BCF STATUS, RP0 ; Bank 0
MAIN_LOOP:
BSF PORTB, RB0 ; Turn on LED on RB0
CALL DELAY ; Call delay subroutine
BCF PORTB, RB0 ; Turn off LED on RB0
CALL DELAY
GOTO MAIN_LOOP ; Repeat the loop
DELAY:
MOVLW 0x9 ; Load W with 9 --> Count from 0-->9 (10)
MOVWF 0x20 ; Load register 0x20 with 9
DELAY_LOOP_1:
MOVLW 0xC5 ; Load W with 197 (count 0--> 198)
MOVWF 0x21 ; Load register 0x20 with 197
DELAY_LOOP_1:
MOVLW 0xC3 ; Load W with 195 (count 0--> 196)
MOVWF 0x22 ; Load register 0x20 with 195
DELAY_LOOP_3:
DECFSZ 0x22, F ; Decrement register 0x20, skip if zero
GOTO DELAY_LOOP_3 ; Repeat until register 0x20 is zero
DECFSZ 0x21, F ; Decrement register 0x21, skip if zero
GOTO DELAY_LOOP_2 ; Repeat until register 0x20 is zero
DECFSZ 0x20, F ; Decrement register 0x21, skip if zero
GOTO DELAY_LOOP_2 ; Repeat until register 0x20 is zero
; f=4MHz --> Cycle=1MHz --> T=1usec
; estimate delay time (10*(198+2)*(196+4)=1000)
RETURN ; return from subroutine
END