English
Language : 

BS87B12A-3 Datasheet, PDF (123/224 Pages) Holtek Semiconductor Inc – Touch A/D Flash MCU with OCVP
BS87B12A-3/BS87C16A-3/BS87D20A-3
Touch A/D Flash MCU with OCVP
A/D 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 ; select fSYS/8 as A/D clock and A/D input
mov SADC1,a ; signal comes from external channel
mov a,00H ; select VREF pin voltage as A/D reference voltage source
mov SADC0,a ; and AN0 is selected as the external channel input
set ADCEN ; enable the A/D converter
mov a,01H ; setup ACERL to configure pin AN0 as analog input
mov ACERL,a
:
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
Rev. 1.20
123
December 05, 2016