; --- WARNING:  DO NOT APPLY MORE THAN 5 VOLTS TO ANY OF THE A/D INPUTS

        $MOD51GB

        ORG     8000H

START:  CALL   CIN
;        MOV     P1,#000h
        CJNE    A,#'s',START


;                       AIF            A/D Interrupt Flag
;                       |ACE           A/D Conversion Enable
;                       ||ACS1         A/D Channel Select 1
;                       |||ACS0        A/D Channel Select 0
;                       ||||AIM        A/D Input Mode
;                       |||||ATM       A/D Triger Mode
;                       ||||||
;                       ||||||
        MOV     ACON,#00010000B   ; ENABLE A/D OPERATION

WAIT:
        
        MOV     A,#1
        ACALL   COUT          ; THROUGH THE SERIAL PORT
;        MOV     P1,AD0        ; PLACE THE CONTERNTS OF AD0 AT PORT 1
        MOV     A,AD3         ; ALSO SEND THE READING
        ACALL   COUT          ; THROUGH THE SERIAL PORT
        CALL    DELAY
        SJMP    WAIT

DELAY:  DJNZ    R2,$
        DJNZ    R3,DELAY
        RET

CIN:
        JNB     RI,$            ; WAIT FOR THE TI FLAG TO SET
        CLR     RI               ; CLEAR THE TI FLAG ONCE SENT
        MOV     A,SBUF           ; SEND THE CONTENTS OF REGISTER A
        RET                      ; RETURN
COUT:
        JNB     TI,$            ; WAIT FOR THE TI FLAG TO SET
        CLR     TI               ; CLEAR THE TI FLAG ONCE SENT
        MOV     SBUF,A           ; SEND THE CONTENTS OF REGISTER A
        RET                      ; RETURN

        END
