	list      p=16F84A            ; list directive to define processor
	#include <p16F84A.inc>        ; processor specific variable definitions

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC

; This program turns one pin of Port A, namely bit 3, on and off as fast as possible.
; It does this only if Port B,  bit 4 is a HIGH input.  It stops doing it as long
; as that bit is LOW.

;***** VARIABLE DEFINITIONS

PortADirection	equ	B'00000000'	; Port A, bit 3 is an output.
PortAToggleFlag	equ	B'00001000'	; Permits easy toggling of bit 3.
PortBDirection	equ	B'00010000'	; Port B, bit 4 is an input.
					; HIGH permits Port A, bit 0 to flash.
					; LOW inhibits the flashing.
PortBSwitchMask	equ	B'00010000'	; Permits easy inspection of bit 4.

;**********************************************************************
		ORG     0x000             ; processor reset vector


main			; main is a label (address location)

; Initialize Port A and Port B.
; First, clear both Port registers.
	clrf	PORTA
	clrf	PORTB
	
; Now select Bank 1 to set the port direction bits in the TRIS registers.
	bsf	STATUS,RP0
	
	movlw	PortADirection	; Set the Port A direction bits.
	movwf	TRISA

	movlw	PortBDirection	; Set the Port B direction bits.
	movwf	TRISB
	
; Now revert to Bank 0 for further operations.

	bcf	STATUS,RP0

CheckFlashOK
	movlw	PortBSwitchMask	; Read Port B and discover the position of
				; the flash-control switch.

	andwf	PORTB,W		; Keep only the single bit for the switch.
	btfss	STATUS,Z	; Z=1 if the switch is LOW, Z=0 otherwise.
	goto	FlashOK		; We're here if the switch is HIGH.
	goto	CheckFlashOK	; We're here if the switch is LOW.
	
FlashOK
	movlw	PortAToggleFlag	; Get the word which makes it easy to toggle
				; the Port A output light.
	xorwf	PORTA,F		; Toggle the indicated bit of Port A.
	goto	CheckFlashOK	; Repeat the cycle indefinitely
	

	END                     ; directive 'end of program'

