;*******************************************************************
;            AN IDEAL STARTING POINT FOR PIC PROGRAMMING   
; This code blinks an LED connected to pin 2 every 5 seconds.
; 
; The code contains typical timing routines when the PIC16F84 is
; used with a 4 Mhz crystal. Assembly is done with MPLAB.
;
;*******************************************************************
	LIST    P=16C84,f=inhx8m
_CP_OFF         equ     H'3FFF'                 ;code protect off
_PWRTE_ON       equ     H'3FFF'                 ;Power on timer on
_WDT_OFF        equ     H'3FFB'                 ;watch dog timer off
_XT_OSC         equ     H'3FFD'                 ;crystal oscillator
	__CONFIG       _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
						;configure programmer directive
w       equ     0       ; register destination numbers.
f       equ     1       
same    equ     1
z       equ     2       ; status flags
zero    equ     2
c       equ     0
carry   equ     0
	
count1  equ     0C      ; wait counter ls digit file register C
count2  equ     0D      ; wait counter ms digit file register D
portb   equ     06      ; port b I/O register f6
porta   equ     05      ; port a I/O register f5
status  equ     03      ; status register f3
;
;
;
	org     0       ; origin
;
init   
	movlw   0
	tris    porta                   ; set porta as outputs
	movwf   porta                   ; set porta levels all low
;-----------------------------------------------------------------------
; Start usermodificable code :
;-----------------------------------------------------------------------
start
	bsf     porta,3                 ; set porta bit 3 high / pin 2 / LED
	call    wait_sec_5              ; Wait approx. 5 Sec                    
	bcf     porta,3                 ; Set porta bit 3 low  / pin 2 / LED
	call    wait_sec_5              ; Wait approx. 5 Sec
	goto    start
	
;      
; ----------------------------
; wait subroutines 
; ----------------------------
wait_min
	call    wait_sec_30
	call    wait_sec_30
	return
wait_sec_30
	call    wait_sec_10
	call    wait_sec_10
	call    wait_sec_10
	return
wait_sec_10
	call    wait_sec_5
	call    wait_sec_5
	return
wait_sec_5
	call    wait_sec
	call    wait_sec
	call    wait_sec
	call    wait_sec
	call    wait_sec
	return
wait_sec
	call    wait1
	call    wait1
	return
wait1
	call    wait0
	call    wait0
	call    wait0
	call    wait0
	return
wait0    
	movlw   .200            ; load count1 with decimal 200
	movwf   count1
d1      movlw   .200            ; load count2 with decimal 200
	movwf   count2  
			      
	
d2      decfsz  count2,same     ; decrement and skip next line if zero
	goto    d2              ; if not zero           
	decfsz  count1,same     ; decrement count1 if count2 is zero
	goto    d1              ; do inside loop again if count2 nz
	return
; ----------------------------        
	END