DELAY1 EQU H'20' ; 3, 1 byte RAM locations Used for delay routine
DELAY2 EQU H'21' ; General purpose ram begins at H'20'
DELAY3 EQU H'22'
; SET UP DELAY FUNCTION clocks to call delay 2
DELAY CLRF DELAY1 ; 1 clock cycle delay1 = 0 so will decrement 256 times until 0 1
CLRF DELAY2 ; 1 clock cycle delay2 = 0 so will decrement 256 times untii 0 1
MOVLW D'12' ; 1 clock cycle 1
MOVWF DELAY3 ; 1 clock cycle delay3 = 12 so will derement 12 times until 0 1
; total 6 clock cycles
; DELAY LOOP
; This section runs 'delay1' x 'delay2' x 'delay3' times = 786432
LOOP DECFSZ DELAY1,1 ; 1 or 2 clocks - runs 255 times x 1 clock + 1 times 2 clocks = 257
GOTO LOOP ; 2 clocks - runs 256 times x 2 clock3 = 512
; total 769
; 769 X 256 X 12 = 2,362,368 clock cycles
; This section runs 'delay2' x 'delay3' times = 3072
DECFSZ DELAY2,1 ; 1 or 2 clocks - runs 255 times x 1 clock + 1 times 2 clocks = 257
GOTO LOOP ; 2 clocks - runs 256 times x 2 clocks = 512
; total 769
; 769 X 12 = 9228 clock cycles
; This section runs 'delay3' times = 12
DECFSZ DELAY3,1 ; 1 or 2 clocks - runs 12 times x 1 clock + 1 times 2 clocks = 13
GOTO LOOP ; 2 clocks - runs 12 times x 2 clocks = 24
; total 37 = 37 clock cycles
RETLW 0 ; 2 clock cycles 2 clock cycles
; grand total 2,371,641 clock cycles
; formula: clock cycles x instruction time = delay time
; 2,371,641 x (1 / 5,000,000) = .4743282 second delay
; On a PICC16F877A the oscillator frequency is divided by 4 for the instruction clock
; a 20mhz crystal gives a 5mhz instruction clock