	TITLE	ADC ROUTINES
			

        CODE
* ADC initialization routine
IADC    BSET	OPTION,$80	;power up ADC (ADPU=1)
	BCLR	OPTION,$40	;select clock E (CSEL=0)
        LDAA    #$10            ;MULT=1, SCAN=0, lower group
	RTS		

* START CONVERSIONS AND READ ADC
READ_ADC JSR    RADL
         JSR    RADH
         RTS
***********************************************************
* RADL - read ADC lower channels
***********************************************************


RADL    LDAA	#$10	        ;MULT=1 - lower group
	STAA	ADCTL	        ;start conversion 
RADL05  LDAA	ADCTL	
	ANDA	#$80	        ;poll CCF until true
	BEQ	RADL05
	LDAA	ADR1	        ;get result in A for AN0
	STAA	AN0	        ;update variables
	LDAA	ADR2	
	STAA	AN1	
	LDAA	ADR3	
	STAA	AN2	
	LDAA	ADR4	
	STAA	AN3	
	RTS		

***********************************************************
* RADH - read ADC higher channels
***********************************************************

RADH    LDAA	#$14	        ;MULT=1, CC=1
	STAA	ADCTL	        ;start conversion 
RADH05  LDAA	ADCTL	
	ANDA	#$80	        ;poll CCF until true
	BEQ	RADH05
	LDAA	ADR1	        ;get result in A for AN4
	STAA	AN4	        ;update variables
	LDAA	ADR2	
	STAA	AN5	
	LDAA	ADR3	
	STAA	AN6	
	LDAA	ADR4	
	STAA	AN7	
	RTS		


	END		
