; LED_1.ASM
;
; Shows how to flash an LED on PortB, Bit 0.  Logic 0 turns LED on.
;
; Timing is done with a simple loop.  Nominally 250 ms on and 250 ms off.
; This assumes an oscillator of 4.0 MHz or 1 usec per instruction.
;
; Peter H. Anderson, MSU, June 1, '97
;

	LIST p=16c84
#include <p16c84.inc>	; this is where all registers and bits are defined
	__CONFIG 11h

LOOP1	EQU 10H		;note that general purpose registers begin at 0CH
LOOP2	EQU 11H

	ORG 000H	;program code to start at 000H

	BCF STATUS, RP1
	BSF STATUS, RP0		; switch to bank 1 and
				; make all bits on Portb outputs

	CLRF TRISB		; make all PortB bits outputs

	BCF STATUS, RP0		; back to data bank 0

TOP
	BCF	PORTB, 0	; bit 0 to logic 0
	CALL	DELAY
	BSF	PORTB, 0	; turn LED off
	CALL	DELAY
	GOTO	TOP

DELAY	; when running set LOOP1 to .250 and LOOP2 to .110.
	; this will result in 250 ms delay.
	MOVLW	.250
	MOVWF 	LOOP1
OUTTER
	MOVLW	.110	; close to 1.0 msec delay when set to .110
	MOVWF 	LOOP2
INNER
	NOP
	NOP
	DECFSZ	LOOP2, F	; decrement and leave result in LOOP2 
				; skip next statement if zero
	GOTO INNER
	DECFSZ 	LOOP1, F
	GOTO OUTTER
	RETURN

	END