;##################################################################################
;# TITLE   "OVERSAMPLING General Purpose Library Test Software"
;#
;#
;#      Program:        OVER.ASM
;#      Version:        1.0
;#      Revision Date:
;#      Author:         CG
;#
;#
;# Program demonstrates use of A/D Oversampling general purpose library module.
;##################################################################################

#define        	PIC18					;set the test to use PIC16

#ifdef          PIC18
        list p=18C252
        include <P18C252.INC>
#endif
      
        include "ADOver.inc"

;##################################################################################
;##############################  Definitions ######################################
;##################################################################################


#define	DELAY50USEC		.12
#define	DELAY1300MS		.7		;Value to get about 1.3seconds Long Delay
#define SETLINGDELAY            .1              ;D/A long .2sec delay


;##################################################################################
;###################### Test Related Variables ####################################
;##################################################################################


_ADOVERTESTDATA		UDATA

delayCounter	        RES		1	;delay counter used in SPI transmission and Reception
testdata		RES		1	;

DirUpper		res		1	;Data input Register - Upper (mirrors internal reg.)
DirHigh			res		1	;Data input Register - High (mirrors internal reg.)
DirLow			res		1	;Data input Register - Low (mirrors internal reg.)

t0			res		1	;Long delay timing
t1			res		1	;Long delay timing
t2			res		1	;Long delay timing

ascLow			res		1	;
ascHigh			res		1	;


;##################################################################################
;############################# Test Code Start ####################################
;##################################################################################


_ADOverTestStartHere         CODE    0x000

        goto        Main

_ADOverTestMainCode          CODE

;*********************** MAIN *************************************

Main
    	call        CpuInit			;CPU Registers Initialization
	call        ADOverInit                  ;oversampling initialization
	call	    SetlingDelay	        ;initial setling time
mainLoop
	call	    ADOverGetData		;New data obtained from A/D with Oversampling
	goto	    mainLoop			;Loop

;******************************************************************

CpuInit:
	bcf	    ADCON1,PCFG0		;Use AN0(RA0) Analog Input
	bsf	    ADCON1,PCFG1
	bsf	    ADCON1,PCFG2
	bsf	    ADCON1,PCFG3

        bcf	    ADCON0,CHS0		        ;choose channel 0
	bcf	    ADCON0,CHS1
	bcf	    ADCON0,CHS2
        return

SetlingDelay:
        movlw   SETLINGDELAY
        goto    PutDelay
        
LongDelay:
	movlw	    DELAY1300MS
PutDelay
	movwf	    t2
	clrf	    t1
	clrf	    t0
LlD
	decfsz	    t0,f
	goto	    LlD
	decfsz	    t1,f
	goto	    LlD
	decfsz	    t2,f
	goto	    LlD
	return


	END
