Rev. 1.00
128
September 11, 2018
Rev. 1.00
129
September 11, 2018
HT45F4050
A/D NFC Flash MCU
HT45F4050
A/D NFC Flash MCU
A/D Converter Programming Examples
The following two programming examples illustrate how to setup and implement an A/D
conversion. In the first example, the method of polling the ADBZ bit in the SADC0 register is used
to detect when the conversion cycle is complete, whereas in the second example, the A/D converter
interrupt is used to determine when the conversion is complete.
Example: using an ADBZ polling method to detect the end of conversion
clr ADE ; disable ADC interrupt
mov a,03H ; select f
SYS
/8 as A/
D
clock and A/D input
signal comes from external
;
channel
mov
SADC1,a
mov a,00H ; select
AV
DD
as A
/D reference voltage source
mov
SADC
2,a
mov a,03h
;
setup
PCS0 to configure pin AN0
mov
PCS0
,a
mov a,20h ; enable
A/D converter
and
select AN0 external channel input
mov
SADC0,a
:
start_conversion:
clr
START ; high pulse on start bit to initiate conversion
set
START ; reset A/D converter
clr
START ; start A/D conversion
polling_EOC:
sz
ADBZ ; poll the SADC0 register ADBZ bit to detect end of A/D conversion
jmp polling_EOC ; continue polling
mov
a,SADOL
; read low byte conversion result value
mov
SADOL_buffer,a
; save result to user defined register
mov
a,SADOH
; read high byte conversion result value
mov
SADOH_buffer,a
; save result to user defined register
:
jmp
start_conversion
; start next A/D conversion