LIST	p=16F887
include	"P16F887.inc"

__CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG    _CONFIG2, _WRT_OFF & _BOR21V

		cblock		0x20 			;start of general purpose registers
				count1 			;used in delay routine
				counta 			;used in delay routine 
				countb 			;used in delay routine
		endc 					;end of general purpose registers


ORG 0x000

PortSettings	bsf		STATUS, RP0	; select Register Bank 1
		movlw		b'00000000'	
		movwf		TRISD
		movlw		b'00000001'
		movwf		TRISB
		bcf		STATUS, RP0	; back to Register Bank 0

Start		btfsc		PORTB, 0
		goto		Led_On
		goto		Led_Off
;		call		Delay250
goto		Start	

Led_On		movlw		b'11111111'
		movwf		PORTD
		goto		Start


Led_Off		movlw		b'00000000'
		movwf		PORTD
		goto		Start


;>>>>>>>>>>>>	DELAY ROUTINE    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<νν

Delay250		movlw	d'250'			;delay 250 mS
		goto	d0

Delay100		movlw	d'100'			;delay 100mS
		goto	d0

Delay50		movlw	d'50'			;delay 50mS
		goto	d0

Delay20		movlw	d'20'			;delay 20mS
		goto	d0

Delay5		movlw	d'5'			;delay 5.000 ms (4 MHz clock)

d0		movwf	count1

d1		movlw	d'199'			;delay 1mS
		movwf	counta
		movlw	d'1'
		movwf	countb

Delay_0		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

End
     
