Rev. 1.10
140
October 23, 2020
Rev. 1.10
141
October 23, 2020
BC66F5652
2.4GHz RF Transceiver A/D Flash MCU
BC66F5652
2.4GHz RF Transceiver A/D 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
mov SADC1,a ; select f
SYS
/8 as ADC clock
set ADCEN
mov a,02h ; setup PBS0 to configure pin AN0
mov PBS0,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
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
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 ADC clock
set ADCEN
mov a,02h ; setup PBS0 to configure pin AN0
mov PBS0,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
converter
clr START ; start A/D
conversion
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
:
: