SN8P2711A
8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD
Page 111
Version 0.1
¾
Example : To set AIN1 for ADC input and executing 12-bit ADC. VREFH is external input voltage from
VREFH pin (P4.0/AIN0). ADC clock source is Fcpu. Using ADC interrupt.
; Enable ADC function and delay 100us for conversion.
ADC0:
B0BSET
FADENB
; Enable ADC circuit
CALL
Delay100uS
; Delay 100uS to wait ADC circuit ready for conversion.
; Set Port 4 I/O mode.
MOV
A,
#0FDH
B0MOV
P4UR, A
; Disable P4.1 pull-up resistor.
B0BCLR
FP41M
; Set P4.1 as input pin.
; or
MOV
A,
#02H
B0MOV
P4CON, A
; Set P4.1 as pure analog input.
; Set VREFH is external input voltage.
B0BSET
EVHENB
; Enable external VREFH input.
; Set ADC clock source = Fcpu.
MOV
A,
#40H
B0MOV
ADR, A
; To set ADC clock = Fcpu.
; Enable AIN0 (P4.1).
MOV
A,
#91H
B0MOV
ADM,A
; To enable ADC and set AIN1 input
; Set ADC interrupt.
B0BCLR
FADCIRQ
; Clear ADC interrupt request flag.
B0BSET
FADCIEN
; Enable ADC interrupt function.
B0BSET
FGIE
; Enable Global interrupt function.
; Start AD conversion.
B0BSET
FADS
; To start conversion
…
…
…
ADC_INT_SR:
PUSH
B0BTS1
FADCIRQ
; Check ADC interrupt flag.
JMP
ADC_INT_EXIT
B0BCLR
FADCIRQ
; Clear ADC interrupt request flag.
B0MOV
A, ADB
; To get AIN0 input data bit11 ~ bit4
B0MOV
Adc_Buf_Hi,
A
B0MOV
A, ADR
; To get AIN0 input data bit3 ~ bit0
AND
A,
0FH
B0MOV
Adc_Buf_Low,
A
B0BCLR
FADENB
; Disable ADC circuit
ADC_INT_EXIT: .
POP
RETI