HT46R01B-1/HT46R01N-1
HT48R01B-1/HT48R01N-1
A/D Programming Example
The following two programming examples illustrate how to setup and implement an A/D conversion. In the first exam-
ple, 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 ADE
; disable ADC interrupt
mov a,00000001B
mov ACSR,a
; select fSYS/8 as A/D clock and ADONB=0
mov a,00000100B
; setup ADCR register to configure Port as A/D inputs
mov ADCR,a
; and select AN0 to be connected to the A/D converter
:
:
Start_conversion:
clr START
set START
; reset A/D
clr START
; start A/D
Polling_EOC:
sz EOCB
; poll the ADCR 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
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 ADE
; disable ADC interrupt
mov a,00000001B
mov ACSR,a
; select fSYS/8 as A/D clock and ADONB=0
mov a,00000100B
; setup ADCR register to configure Port as A/D inputs
mov ADCR,a
; and select AN0 to be connected to the A/D
:
:
Start_conversion:
clr START
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_:
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_ISR:
mov a,status_stack
mov STATUS,a
; restore STATUS from user defined memory
mov a,acc_stack
; restore ACC from user defined memory
clr ADF
; clear ADC interrupt flag
reti
Note: To power off ADC module, it is necessary to set ADONB as ²1².
Rev.1.00
48
June 9, 2011