HT66F016/HT66F017/HT68F016/HT68F017
HT66F016R/HT66F017R/HT68F016R/HT68F017R
Example: using an EOCB polling method to detect the end of conversion
clr ADE
; disable ADC interrupt
mov a,03H
mov ADCR1,a
; select fSYS/8 as A/D clock and switch off 1.25V
clr ADOFF
mov a,0Fh
; setup ACERL to configure pins AN0~AN3
mov ACERL,a
mov a,00h
mov ADCR0,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 EOCB
; poll the ADCR0 register EOCB bit to detect end
; of A/D conversion
jmp polling_EOC
; continue polling
mov a,ADRL
; read low byte conversion result value
mov ADRL_buffer,a
; save result to user defined register
mov a,ADRH
; read high byte conversion result value
mov ADRH_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 ADCR1,a
Clr ADOFF
; select fSYS/8 as A/D clock and switch off 1.25V
mov a,0Fh
; setup ACERL to configure pins AN0~AN3
mov ACERL,a
mov a,00h
mov ADCR0,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 interrupt service routine
ADC_ISR:
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,ADRL
; read low byte conversion result value
mov adrl_buffer,a
; save result to user defined register
mov a,ADRH
; read high byte conversion result value
mov adrh_buffer,a
; save result to user defined register
:
:
EXIT_INT_ISR:
mov a,status_stack
mov STATUS,a
; restore STATUS from user defined memory
mov a,acc_stack
; restore ACC from user defined memory
reti
Rev. 1.40
81
November 22, 2016