;Xtal = 4MHz, 1 instruction = 1uS
;
;    
        LIST    p=16F84A
	#include <p16F84A.inc>
	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_OFF & _XT_OSC
;
;
TEMP1   EQU     0x0C            ;User file (RAM) registers
TEMP2   EQU     0x0D
TEMP3   EQU     0x0E
;
LED	EQU	0		;LED ON RB0	- PORTB
;
        ORG     0x000           ;Reset vector
        GOTO    INIT
        ORG     0x004           ;Interrupt vector
        GOTO    INIT
;
;===============Subroutines===============
;
	ORG     0x005		;Start of program ROM
;
;---------------Initilaise---------------
;
INIT    MOVLW   0x00            ;Set PORT direction
	BSF	STATUS,RP0	;Set Bank1
	MOVWF   TRISA		;All outputs
	MOVWF   TRISB
	BCF	STATUS,RP0	;Set Bank0
	CLRF    PORTA           ;Clear outputs
	CLRF    PORTB
	MOVLW   0x07            ;Pull-up, clkout, RTCC/256 
	BSF	STATUS,RP0	;Set Bank1
	MOVWF	OPTION_REG
	BCF	STATUS,RP0	;Set Bank0
	CLRF	INTCON		;Disable all interrupts
	GOTO	MAIN
;
;---------------Delays---------------
;
DELAY   MOVLW	0x1		;200 mSec delay
	MOVWF	TEMP3
	CLRF	TEMP2
	CLRF	TEMP1
DEL1	DECFSZ	TEMP1		;1 * (256 * (256 * 3)) = 196608uS, approx 200mS
	GOTO	DEL1
	DECFSZ	TEMP2
	GOTO	DEL1
	DECFSZ	TEMP3
	GOTO	DEL1
	RETURN
;
;===============Main Program===============
;
MAIN    MOVLW	0x01
	MOVWF	PORTB
	CALL	DELAY
LEFT	RLF	PORTB,1
	CALL	DELAY
	BTFSS	PORTB,7
	GOTO	LEFT
	NOP
RIGHT	RRF	PORTB,1
	CALL	DELAY
	BTFSS	PORTB,0
        GOTO    RIGHT
	GOTO	LEFT
;        
        END

