
Rev. 1.20
160
November 20, 2019
Rev. 1.20
161
November 20, 2019
HT66F2740
12V High Current Flash MCU
HT66F2740
12V High Current Flash MCU
A/D Conversion 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 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
mov SADC1,a ; select f
SYS
/8 as A/D clock
set ADCEN
mov a,08H ; setup PAS0 to configure pin AN0
mov PAS0,a
mov a,20H
mov SADC0,a ; enable and connect AN0 channel to A/D Converter
:
start_conversion:
clr START ; high pulse on start bit to initiate conversion
set START ; reset A/D
clr START ; start A/D
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
Example: using the interrupt method to detect the end of conversion
clr
ADE
;
disable
ADC
interrupt
mov a,03H
mov SADC1,a ; select f
SYS
/8 as A/D clock
set ADCEN
mov a,08H ; setup PAS0 to configure pin AN0
mov PAS0,a
mov a,20H
mov SADC0,a ; enable and connect AN0 channel to A/D Converter
Start_conversion:
clr START ; high pulse on START bit to initiate conversion
set START ; reset A/D
clr START ; start A/D
clr ADF ; clear ADC interrupt request flag
set
ADE
;
enable
ADC
interrupt
set EMI ; enable global interrupt
:
:
ADC_ISR: ; ADC interrupt service routine
mov acc_stack,a ; save ACC to user defined memory
mov a,STATUS
mov status_stack,a ; save STATUS to user defined memory
:
:
mov a,SADOL ; read low byte conversion result value