; FILE: count.asm
; AUTH: P.Oh
; DATE: 04/13/02 17:00
; DESC: Count to 255 at 1 second intervals and display on LED in 
;	binary. pause subroutine takes apx. 0.2 sec, pause repeated 5 times
; NOTE: Tested on PIC16F84-04/P.  
;       Page numbers in code are in Easy Pic'n book
; REFs: Easy Pic'n p. 81

	list	p=16F84
	radix	hex

;----------------------------------------------------------------------
;	cpu equates (memory map)
portB	equ	0x06		; (p. 10 defines port address)
count	equ	0x0c
nCount	equ	0x0d
mCount	equ	0x0e
;----------------------------------------------------------------------

	org	0x000

start	movlw	0x00		; load W with 0x00 make port B output (p. 45)
	tris	portB		; copy W tristate, port B outputs (p. 58)
	clrf	portB		; clear all lines low
	clrf	count		; initialize counter to 0
get_cnt	movf	count, w	; move count to W
	movwf	portB		; move W to port B
	call	pause		; delay by subroutine
	call	pause		
	call	pause
	call	pause
	call	pause		; five pause executions equals ~ 1 second
	incf	count, f	; increment counter
	goto	get_cnt		; repeat forever

pause	movlw	0xff		; set w = 255 decimal
	movwf	mCount		; mCount = w
loadN	movlw	0xff		; set w = 255 decimal
	movwf	nCount		; nCount = w
decN	decfsz	nCount, f	; nCount--
	goto	decN		; if nCount != 0 then repeat nCount--
	decfsz	mCount, f	; else decrement Count
	goto	loadN		; if mCount != 0 then 
				;   reload nCount to 255 and decrement
	return			; else exit subroutine

	end

;----------------------------------------------------------------------
; at blast time, select:
;	memory uprotected
;	watchdog timer disabled
;	standard crystal (4 MHz)
;	power-up timer on

