;********************************************************************
;
; Author        : ADI - Apps            www.analog.com/MicroConverter
;
; Date          : October 2003
;
; File          : ADCsingl.asm
;
; Hardware      : ADuC842/ADuC843
;
; Description   : Performs repeated single ADC conversions and moves
;                 results to UART. Sets the red LED on the eval
;                 board upon completion of each conversion.  A new
;                 conversion is innitiated every 200ms.
;                 All rate calculations assume an 2.097152MHz Mclk.
;		
;********************************************************************

$MOD842                       ; Use 8052&ADuC832 predefined symbols

LED     EQU     P3.4            ; P3.4 drives red LED on eval board
CHAN    EQU     0               ; convert this ADC input channel..
                                ; ..chan values can be 0 thru 6
;____________________________________________________________________
                                                  ; BEGINNING OF CODE
CSEG

ORG 0000h

        JMP     MAIN            ; jump to main program
;____________________________________________________________________
            

;====================================================================
                                                       ; MAIN PROGRAM
ORG 004Bh

MAIN:
	
; Set up UART
	MOV	T3CON,#083H
	MOV	T3FD,#02DH
        MOV     SCON,#52h

; PRECONFIGURE...

        MOV     ADCCON1,#0ACh   ; power up ADC
        MOV     ADCCON2,#CHAN   ; select channel to convert

; PERFORM REPEATED SINGLE CONVERSIONS...

AGAIN:  CPL     LED             ; turn the LED off
        MOV     A,#020		; Delay length
	CALL    DELAY           ; delay 200ms

        SETB    SCONV           ; innitiate single ADC conversion
        		        ; ADC ISR is called upon completion
	JNB     ADCI,$
	
	MOV     A,ADCDATAH
	CALL    SENDVAL
	MOV     A,ADCDATAL
	CALL    SENDVAL
	
        JMP     AGAIN           ; repeat

;____________________________________________________________________
                                                         ; SUBROUTINE
DELAY:					; Delays by 10ms * A
					; 25mSec based on 2.09MHZ 
					; Core Clock 
					; i.e. default ADuC842 Clock

		MOV	R1,A		; Acc holds delay variable (1 clock)
 DLY0:		MOV	R2,#01Bh	; Set up delay loop0 (2 clocks)
 DLY1:		MOV	R3,#0FFh	; Set up delay loop1 (2 clocks)
		DJNZ	R3,$		; Dec R3 & Jump here until R3 is 0 (3 clocks)
		DJNZ	R2,DLY1         ; Dec R2 & Jump DLY1 until R2 is 0 (3 clocks)
		DJNZ	R1,DLY0		; Dec R1 & Jump DLY0 until R1 is 0 (3 clocks)
		RET			; Return from subroutine


;____________________________________________________________________
		

$INCLUDE(UARTIO.ASM)		
END
