Owen's First PIC Program



        list P=16F84
	include 

; Interdig.asm
; Interdigitate
;    Program to alternately flash
;    LEDs in this sequence: 13243546576867564534231
; April 14, 2001
; Owen Lawrence
;
; 


tmpw		EQU	0CH
portb   	EQU     6
trisb   	EQU     86H
optreg  	EQU     81H
status  	EQU     3
RP0     	EQU     5
leftmost	EQU	7	; Bit position of leftmost LED
rightmost	EQU	0	; Bit position of rightmost LED

	__config	_RC_OSC	& _WDT_ON	; RC oscillator with watch-dog timer

	org	0		; program starts at address 0

	bsf	status,RP0	; Select register bank 1
	clrf	trisb^80H	; Set PORTB to all outputs
	movlw	0DH		; Assign prescaler (1:32) to WDT
	movwf	optreg^80H
	bcf	status,RP0	; Select register bank 0
	movlw	B'10000000'	; Prepare initial value--leftmost LED on
	movwf	portb		; and place it in PORTB
	clrf	tmpw
RIGHT	movf	portb,0		; We want to shift right by 2, but we do it in tmpw
	movwf	tmpw		; so the intermediate shift by 1 doesn't appear
	rrf	tmpw,1		; Shift tmpw to the right by 1, result in tmpw
	rrf	tmpw,0		; Shift tmpw to the right by another 1, result in W
	movwf	portb		; Move results (W) into portb
	sleep			; Wait for WDT timeout
	btfsc	portb,rightmost	; If the rightmost bit is set
	goto	LEFT		;	Switch direction
	rlf	portb,1		; Else shift to the left by 1
	sleep
	goto	RIGHT		; Start new cycle
LEFT	movf	portb,0
	movwf	tmpw
	rlf	tmpw,1
	rlf	tmpw,0
	movwf	portb		; Shift to the left by 2
	sleep
	btfsc	portb,leftmost	; If the leftmost bit is set
	goto	RIGHT		; 	Switch direction back
	rrf	portb,1		; Else shift to the right by 1
	sleep
	goto	LEFT		; Start new cycle
	end

Home