;**********************************************************************
;                                                                     *
;    Filename: e00.asm                                                *
;    Date: 19/09/2007                                                 *
;    File Version: 1.0                                                *
;    Web: www.eeng.biz                                                *
;                                                                     *
;    Assembler: MPASMWIN v5.11                                        *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes: template for the PIC16F887 experimental board.            *
;    Visit http://www.eeng.biz/887.htm                                *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************


	list		p=16f887	; list directive to define processor
	#include	<p16f887.inc>	; processor specific variable definitions


	; '__CONFIG' directive is used to embed configuration data within .asm file.

	__CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO & _DEBUG_OFF 
	__CONFIG    _CONFIG2, _WRT_OFF 


;***** DEFINITIONS
	
	#define	LED1 PORTB,5		; LED1
	#define LED2 PORTB,4		; LED2

	#define SWITCH PORTB,2		; switch

	; LCD
	#define LCD PORTC		; data PORT (4-bit interface)
	#define RS PORTA,7		; Register Select
	#define EN PORTA,6		; Enable


;***** VARIABLE DEFINITIONS

	cblock	0x020
	
		; define variables here
		
	endc


;**********************************************************************


	ORG     0x000			; processor reset vector
	nop
  	goto    init			; go to beginning of program



	ORG     0x004			; interrupt vector location

	movwf   w_temp			; save off current W register contents
	movf	STATUS, w		; move status register into W register
	movwf	status_temp		; save off contents of STATUS register
	movf	PCLATH, w		; move pclath register into w register
	movwf	pclath_temp		; save off contents of PCLATH register



	; isr code can go here or be located as a call subroutine elsewhere



	movf	pclath_temp, w		; retrieve copy of PCLATH register
	movwf	PCLATH			; restore pre-isr PCLATH register contents
	movf    status_temp, w		; retrieve copy of STATUS register
	movwf	STATUS			; restore pre-isr STATUS register contents
	swapf   w_temp, f
	swapf   w_temp, w		; restore pre-isr W register contents
	retfie 



	ORG     0x100              
init
	bcf	STATUS, RP0 		 
	bcf	STATUS, RP1 		 

	banksel	OSCCON
	; internal oscillator frequency = 4 MHz (default)
osctest 
  	btfss 	OSCCON, HTS 		; oscillator stable?
  	goto  	osctest	
	

	banksel PORTA			
	
	clrf	PORTA
	clrf	PORTB
	clrf 	PORTC
	clrf	PORTD
	clrf	PORTE
	
	banksel ANSEL;
	clrf	ANSELH  		; configure RB0/5 for digital I/O 
	movlw	b'00001101'		
	movwf	ANSEL			; configure RA0, RA2, RA3 as analog inputs

	banksel	TRISA
	mowlw	b'00111111'
	movwf	TRISA			; set RA6, RA7 as outputs
	mowlw	b'11001111'
	movwf	TRISB			; set RB4, RB5 as outputs
	mowlw	b'11110000'
	movwf	TRISC			; set RC0/3 as outputs

	banksel	PORTA


main

	; remaining code goes here





	END                       	; directive 'end of program'


