HT46R064D/065D/066D
Enhanced A/D Type 8-Bit OTP MCU with LED Driver
A/D Programming Example
The following two programming examples illustrate how to setup and implement an A/D conversion.
In the first example, the method of polling the EOCB bit in the ADCR register is used to detect when
the conversion cycle is complete, whereas in the second example, the A/D interrupt is used to
determine when the conversion is complete.
Example: using an EOCB polling method to detect the end of conversion
clr
mov
mov
mov
mov
mov
EADI
a,00000001B
ACSR,a
PCR, 00000001B
a,00000000B
ADCR,a
; disable ADC interrupt
; select fSYS/8 as A/D clock and ADONB=0
; setup ADCR register to configure Port as A/D inputs
; and select AN0 to be connected to the A/D converter
:
:
Start_conversion:
clr
set
clr
START
START
START
; reset A/D
; start A/D
Polling_EOC:
sz
EOCB
; poll the ADCR register EOCB bit to detect end
; of A/D conversion
; continue polling
; read low byte conversion result value
; save result to user defined register
; read high byte conversion result value
; save result to user defined register
jmp
mov
mov
mov
mov
polling_EOC
a,ADRL
adrl_buffer,a
a,ADRH
adrh_buffer,a
:
start_conversion ; start next A/D conversion
jmp
Note: To power off ADC module, it is necessary to set ADONB as ²1².
Example: using the interrupt method to detect the end of conversion
clr
mov
mov
mov
mov
mov
EADI
a,00000001B
ACSR,a
PCR,00000001B
a,00000000B
ADCR,a
; disable ADC interrupt
; select fSYS/8 as A/D clock and ADONB=0
setup ADCR register to configure Port as A/D inputs
; and select AN0 to be connected to the A/D
:
:
Start_conversion:
clr
set
clr
clr
set
set
START
START
START
ADF
EADI
EMI
:
; reset A/D
; start A/D
; clear ADC interrupt request flag
; enable ADC interrupt
; enable global interrupt
:
:
; ADC interrupt service routine
ADC_:
mov
mov
mov
acc_stack,a
a,STATUS
status_stack,a
:
; save ACC to user defined memory
; save STATUS to user defined memory
:
a,ADRL
adrl_buffer,a
a,ADRH
adrh_buffer,a
mov
mov
mov
mov
; read low byte conversion result value
; save result to user defined register
; read high byte conversion result value
; save result to user defined register
:
:
EXIT_ISR:
mov
mov
a,status_stack
STATUS,a
a,acc_stack
ADF
; restore STATUS from user defined memory
; restore ACC from user defined memory
; clear ADC interrupt flag
mov
clr
reti
Note: To power off ADC module, it is necessary to set ADONB as ²1².
Rev. 1.00
64
January 12, 2011