;############################################################################
;# TITLE   "ADCPol General Purpose Library Checking Software"
;#
;#
;#      Program:        testpol.ASM
;#      Version:        1.0
;#      Revision Date:
;#      Author:         B.K. Anantha Ramu
;#
;#
;# Program demonstrates use of ADC general purpose library module for polling mode.
;############################################################################


;       list    p=18f452       
        list    p=18f6620
;       #include    <P18f452.INC>
        #include   <P18f6620.INC>
        #include <adcpol.inc>           ;This file contains macros of ADC library
                      

    UDATA_ACS 
;------------------------------------------------------------------------------
adcRSLThigh RES 1                       ;ADC high byte result is read to this location
adcRSLTlow  RES 1                       ;ADC low byte result is read to this location
;------------------------------------------------------------------------------

STARThere   CODE 0x0
            goto    Start

MAIN        CODE
Start    
            nop                         ;User may have his code here
;------------------------------------------------------------------------------
;ADC is configured using macro mADCPolInit. This macro takes one or two arguments
;depending upon the processor used.  
;For processors PIC18C242,PIC18C252,PIC18C442,PIC18C452,PIC18F242,PIC18F252
; PIC18F442,PIC18F452 ADC port configuration name only is required. Depending
;upon the port configuration used, select the port configuration name from
;Table 1 of file ADCPol.ReadMe.pdf
;For processors PIC18F6620,PIC18F6720,PIC18F8620 & PIC18F8720 select port
;configuration name from Table 2 & ADC reference voltage configuration name
;from Table 3 of file ADCPol.ReadMe.pdf.
; 
           mADCPolInit ADCPORTCONFIG14,ADCREFERENCECONFIG2     
;            mADCPolInit ADCPORTCONFIG9    ;ADC configured as per compile time options

;mADCPolInit sets channel 0 as default ADC channel.
;If user wants to use a different channel, he can select
;the required channel by invoking macro mADCPolChannelSelect. The ADC channel being
;used is stored in location vADCPolChannelNumber_A. User can read this location  
;and use this for channel dependent processing.                
;------------------------------------------------------------------------------
            nop                         ;User may have his code here.     
            nop            

;------------------------------------------------------------------------------
            mADCPolChannelSelect D'11'  ;ADC channel 11 is selected.
 
            nop
            call ADCPolAcquisitionTime  ;Before starting AD conversion a delay
                                        ;of acquisition time is provided. 
                                        ;This function provides this delay.
                                        ;User enters the required delay with
                                        ;in MpAM
;------------------------------------------------------------------------------
            mADCPolStart                ;This starts AD conversion

;-----------------------------------------------------------------------------
Check       mADCPolIsBusy               ;Tests whether AD conversion is over.
                                        ;If over WREG contains 0, otherwise 1
            btfsc  WREG,0    
            goto Check        
;-----------------------------------------------------------------------------
     
            mADCPolReadHigh             ;High byte of ADC result is available in W reg
            movwf adcRSLThigh
;------------------------------------------------------------------------------
                        
            mADCPolReadLow              ;Low byte of ADC result is available in W reg
            movwf adcRSLTlow
;------------------------------------------------------------------------------
            mADCPolDisable              ;Switches off ADC
;------------------------------------------------------------------------------
            goto $

    END            
