Note: 1. If the pin-shared pin functions have multiple outputs, the desired pin-shared function is determined by the
corresponding software control bits.
2. The OCDSDA and OCDSCK pins are supplied for the OCDS dedicated pins and as such only available
for the BS86DHV12C device which is the OCDS EV chip for the BS86DH12C device.
3. For less pin-count package types there will be unbonded pins which should be properly congured to
avoid unwanted current consumption resulting from floating input conditions. Refer to the “Standby
Current Considerations” and “Input/Output Ports” sections.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Pin NameFunctionOPTI/TO/T
PB4
PB4/CTP0/AN2/
KEY7
PB5/CTP0B/AN3/
KEY8
PB6/CTP1/AN4/
OCPAO
PB7/CTP1B/AN5/
OVPCOUT
PC0/PTP/OVPI0/
KEY11
PC1/INT/PTPB/
OVPI1/KEY12
PC2/CTP1/SCL/RX
PC3/CTP0/SDA/TX
PC4~PC5PC4~PC5PCPUSTCMOS General purpose I/O. Register enabled pull-up
PD0~PD5PD0~PD5—STCMOS High voltage I/O port
VDD/AVDD/VLDO
CTP0PBS1—CMOS CTM0 output
AN2PBS1AN—A/D converter external input channel
KEY7PBS1NSI—Touch key input
PB5
CTP0BPBS1—CMOS CTM0 inverted output
AN3PBS1AN—A/D converter external input channel
KEY8PBS1NSI—Touch key input
PB6
CTP1PBS1—CMOS CTM1 output
AN4PBS1AN—A/D converter external input channel
OCPAOPBS1AN—OCP operational amplier output
PB7
CTP1BPBS1—CMOS CTM1 inverted output
AN5PBS1AN—A/D converter external input channel
OVPCOUTPBS1—CMOS OVP comparator output
PC0
PTPPCS0—CMOS PTM output
OVPI0PCS0AN—OVP input 0
KEY11PCS0NSI—Touch key input
PC1
INT
PTPBPCS0—CMOS PTM inverted output
OVPI1PCS0AN—OVP input 1
KEY12PCS0NSI—Touch key input
PC2
CTP1PCS0—CMOS CTM1 output
SCL
RX
PC3
CTP0PCS0—CMOS CTM0 output
SDA
TXPCS0—CMOS UART data transmit pin
VDD—PWR—Digital positive power supply
AVDD—PWR—Analog positive power supply
VLDO——PWRLDO output voltage
PBPU
PBS1
PBPU
PBS1
PBPU
PBS1
PBPU
PBS1
PCPU
PCS0
PCPU
PCS0
PCS0
INTC0
INTEG
PCPU
PCS0
PCS0
IFS0
PCS0
IFS0
PCPU
PCS0
PCS0
IFS0
STCMOS General purpose I/O. Register enabled pull-up
STCMOS General purpose I/O. Register enabled pull-up
STCMOS General purpose I/O. Register enabled pull-up
STCMOS General purpose I/O. Register enabled pull-up
STCMOS General purpose I/O. Register enabled pull-up
STCMOS General purpose I/O. Register enabled pull-up
ST—External interrupt input
STCMOS General purpose I/O. Register enabled pull-up
STNMOS I2C clock line
ST—UART data receive pin
STCMOS General purpose I/O. Register enabled pull-up
STNMOS I2C data line
Description
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Pin NameFunctionOPTI/TO/T
VSS—PWR—Digital negative power supply, ground
VSS/AVSS/IOVSS/
HVSS
VCC1VCC1—PWR—
VCC2VCC2—PWR—
NCNC———Unused
AVSS—PWR—Analog negative power supply, ground
IOVSS—PWR—I/O port negative power supply, ground
HVSS—PWR—High voltage negative power supply, ground
Provides high voltage positive power supply for
LDO input
Provides high voltage positive power supply for
High Voltage I/O and Level Shifter
Legend: I/T: Input type; O/T: Output type;
OPT: Optional by register selection;
PWR: Power; ST: Schmitt Trigger input;
CMOS: CMOS output; NMOS: NMOS output;
AN: Analog signal; NSI: Non-standard input;
LXT: Low frequency crystal oscillator.
Absolute Maximum Ratings
Supply Voltage (VCC) ................................................................................................VSS-0.3V to 10.0V
Supply Voltage (VDD) .........................................................................................VSS-0.3V to VSS+6.0V
High Voltage Input Voltage ............................................................................... VSS-0.3V to VCC+0.3V
Input Voltage .....................................................................................................VSS-0.3V to VDD+0.3V
Storage Temperature .....................................................................................................-50°C to 125°C
Operating Temperature ................................................................................................... -40°C to 85°C
High Voltage IOH Total ..............................................................................................................-150mA
IOH Total ......................................................................................................................................-80mA
High Voltage IOL Total ............................................................................................................... 150mA
IOL Total ....................................................................................................................................... 80mA
Total Power Dissipation ........................................................................................................... 500mW
Description
Note: These are stress ratings only. Stresses exceeding the range specified under “Absolute
Maximum Ratings” may cause substantial damage to this device. Functional operation of
this device at other conditions beyond those listed in the specification is not implied and
prolonged exposure to extreme conditions may affect device reliability.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
3. The minimum and maximum tolerance values provided in the table are only for the frequency at which
the writer trims the HIRC oscillator. After trimming at this chosen specific frequency any change in
HIRC oscillator frequency using the oscillator register control bits by the application program will give a
frequency tolerance to within ±20%.
Quiescent Current10V No load—120200μA
Line Regulation—6V≤VIN≤10V, I
V
IN
TCTemperature Coefcient—Ta=-40°C~85°C, I
ΔV
OUT_RIPPLE
RRRipple Rejection
I
LIMIT
t
START
Output Voltage Ripple6VI
(3)
—
Current Limit6VΔV
LDO Start Up Time6VI
Test Conditions
Conditions
=1mA——0.2%/V
LOAD
=10mA—±1.5±2.0 mV/°C
LOAD
=10mA——40mV
LOAD
VIN=10VDC+2V
P-P(AC)
, I
LOAD
≤50mA,
f=120Hz
=-10%600800—mA
OUT
LOAD
=1mA, V
settle to ±5%——10ms
OUT
Min.Typ.Max.Unit
35——dB
Note: 1. Load regulation is measured at a constant junction temperature, using pulse testing with a low ON time
and is guaranteed up to the maximum power dissipation. Power dissipation is determined by the input/
output differential voltage and the output current. Guaranteed maximum power dissipation will not be
available over the full input/output range. The maximum allowable power dissipation at any ambient temperature is PD=(T
J(MAX)-Ta
)/θJA.
2. Dropout voltage is dened as the input voltage minus the output voltage that produces a 2% change in the
output voltage from the value at appointed VIN.
3. Ripple rejection ratio measurement circuit. RR=20×log(ΔVIN/ΔV
OUT
).
LDO
AC
0.33μF
V
IN
GND
V
OUT
2
10.1μF
R
Output
L
4. Application information for LDO load capacitor selection for stability:
Recommended Output Capacitor
SymbolParameter
C
LOAD
Output Load Capacitor—Capacitor4.710—μF
In common with most regulators, the LDO requires an external capacitor connected between V
and ground for regulator stability. If the ESR is less than 10Ω, capacitor values of 4.7μF or large
are acceptable. Any aluminum electrolytic capacitor meeting the requirements described above is
suitable.
For better load transient response purposes, use a combination of a C
0.1μF capacitor on V
. Note that the 0.1μF capacitor is always required on V
OUT
recommended to be a multi-layer ceramic capacitor. The internal regulator is designed to be stable
with an output lter capacitor C
and ESR as recommended.
LOAD
Test Conditions
V
DD
Conditions
Min.Typ.Max.
10μF and an extra
LOAD
and is strong
OUT
Ta=25°C
Unit
OUT
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
OCP Electrical Characteristics
Ta=25°C
SymbolParameter
I
V
V
V
V
V
V
OCP
Operating Current5V
Comparator Input Offset Voltage
OS_CMP
Hysteresis5V—104060mV
HYS
Comparator Common Mode Voltage
CM_CMP
Range
OPA Input Offset Voltage
OS_OPA
OPA Common Mode Voltage Range5V—V
CM_OPA
OPA Maximum Output Voltage Range 5V—VSS+0.1—VDD-0.1V
OR
GaPGA Gain Accuracy5V All gains-5—+5%
V
D/A Converter Reference Voltage5V OCPVRS=12—V
REF
DNLDifferential Non-linearity5V DAC V
INLIntegral Non-linearity5V DAC V
Test Conditions
V
DD
Conditions
OCPEN[1:0]=01B,
DAC V
Without calibration
5V
(OCPCOF[4:0]=10000B)
REF
=2.5V
Min.Typ.Max.Unit
—7301250μA
-15—15
5V With calibration-4—4
5V—V
Without calibration
5V
(OCPOOF[5:0]=100000B)
-15—15
—VDD-1.4V
SS
5V With calibration-4—4
—VDD-1.4V
SS
REF=VDD
REF=VDD
-1—+1LSB
-1.5—+1.5LSB
DD
mV
mV
V
OVP Electrical Characteristics
SymbolParameter
I
V
V
V
OVP
Operating Current5V OVPEN=1, DAC V
Input Offset Voltage5V With calibration-2—2mV
OS
Hysteresis5V
HYS
Common Mode Voltage Range5V—V
CM
DNLDifferential Non-linearity5V DAC V
INLIntegral Non-linearity5V DAC V
t
RP
OVP Response Time5V
V
DD
HYS[1:0]=00B005
HYS[1:0]=01B153045
HYS[1:0]=10B406080
HYS[1:0]=11B6080100
OVPDA[7:0]=10000000B,
OVPDEB[2:0]=000B,
DAC V
OVP input=2.1V~3.6V
The Program Memory is the location where the user code or program is stored. For this device the
Program Memory is Flash type, which means it can be programmed and re-programmed a large
number of times, allowing the user the convenience of code modication on the same device. By
using the appropriate programming tools, the Flash device offers users the exibility to conveniently
debug and develop their applications while also offering a means of eld programming and updating.
Structure
The Program Memory has a capacity of 8K×16 bits. The Program Memory is addressed by the
Program Counter and also contains data, table information and interrupt entries. Table data, which
can be configured in any location within the Program Memory, is addressed by a separate table
pointer register.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Special Vectors
Within the Program Memory, certain locations are reserved for the reset and interrupts. The location
0000H is reserved for use by the device reset for program initialisation. After a device reset is
initiated, the program will jump to this location and begin execution.
Look-up Table
Any location within the Program Memory can be dened as a look-up table where programmers
can store xed data. To use the look-up table, the table pointer must rst be congured by placing
the address of the look up data to be retrieved in the table pointer register, TBLP and TBHP. These
registers dene the total address of the look-up table.
After setting up the table pointer, the table data can be retrieved from the Program Memory using
the “TABRD [m]” or “TABRDL [m]” instructions respectively when the memory [m] is located in
sector 0. If the memory [m] is located in other sectors except sector 0, the data can be retrieved from
the program memory using the corresponding extended table read instruction such as “LTABRD [m]”
or “LTABRDL [m]” respectively. When the instruction is executed, the lower order table byte from
the Program Memory will be transferred to the user dened Data Memory register [m] as specied
sdz block ; check if last memory location has been cleared
jmp loop
continue:
The important point to note here is that in the example shown above, no reference is made to specic
Data Memory addresses.
Direct Addressing Program Example using extended instructions
data .section ´data´
temp db ?
code .section at 0 ´code´
org 00h
start:
lmov a, [m] ; move [m] data to acc
lsub a, [m +1] ; compare [m] and [m+1] data
snz c ; [m]>[m+1]?
jmp continue ; no
lmo v a, [m] ; y es, exchange [m] and [m +1] data
mov temp, a
lmov a, [m+1]
l m o v [ m ], a
mov a, temp
lmov [m+1], a
continue:
Note: here “m” is a data memory address located in any data memory sectors. For example,
m=1F0H, it indicates address 0F0H in Sector 1.
Accumulator – ACC
The Accumulator is central to the operation of any microcontroller and is closely related with
operations carried out by the ALU. The Accumulator is the place where all intermediate results
from the ALU are stored. Without the Accumulator it would be necessary to write the result of
each calculation or logical operation such as addition, subtraction, shift, etc., to the Data Memory
resulting in higher programming and timing overheads. Data transfer operations usually involve
the temporary storage function of the Accumulator; for example, when transferring data between
one user-defined register and another, it is necessary to do this by passing the data through the
Accumulator as no direct transfer between two registers is permitted.
High Voltage Touch A/D Flash MCU with HVIO
Program Counter Low Register – PCL
To provide additional program control functions, the low byte of the Program Counter is made
accessible to programmers by locating it within the Special Purpose area of the Data Memory. By
manipulating this register, direct jumps to other program locations are easily implemented. Loading
a value directly into this PCL register will cause a jump to the specied Program Memory location,
however, as the register is only 8-bit wide, only jumps within the current Program Memory page are
permitted. When such operations are used, note that a dummy cycle will be inserted.
Look-up Table Registers – TBLP, TBHP, TBLH
These three special function registers are used to control operation of the look-up table which is
stored in the Program Memory. TBLP and TBHP are the table pointers and indicate the location
where the table data is located. Their value must be set before any table read commands are
executed. Their value can be changed, for example using the “INC” or “DEC” instructions, allowing
for easy table data pointing and reading. TBLH is the location where the high order byte of the table
data is stored after a table read data instruction has been executed. Note that the lower order table
data byte is transferred to a user dened location.
Status Register – STATUS
This 8-bit register contains the SC ag, CZ ag, zero ag (Z), carry ag (C), auxiliary carry ag (AC),
overow ag (OV), power down ag (PDF), and watchdog time-out ag (TO). These arithmetic/
logical operation and system management ags are used to record the status and operation of the
microcontroller.
With the exception of the TO and PDF ags, bits in the status register can be altered by instructions
like most other registers. Any data written into the status register will not change the TO or PDF ag.
In addition, operations related to the status register may give different results due to the different
instruction operations. The TO ag can be affected only by a system power-up, a WDT time-out or
by executing the “CLR WDT” or “HALT” instruction. The PDF ag is affected only by executing
the “HALT” or “CLR WDT” instruction or during a system power-up.
The Z, OV, AC, C, SC and CZ ags generally reect the status of the latest operations.
• C is set if an operation results in a carry during an addition operation or if a borrow does not take
place during a subtraction operation; otherwise C is cleared. C is also affected by a rotate through
carry instruction.
• AC is set if an operation results in a carry out of the low nibbles in addition, or no borrow from
the high nibble into the low nibble in subtraction; otherwise AC is cleared.
• Z is set if the result of an arithmetic or logical operation is zero; otherwise Z is cleared.
• OV is set if an operation results in a carry into the highest-order bit but not a carry out of the
highest-order bit, or vice versa; otherwise OV is cleared.
• PDF is cleared by a system power-up or executing the “CLR WDT” instruction. PDF is set by
executing the “HALT” instruction.
• TO is cleared by a system power-up or executing the “CLR WDT” or “HALT” instruction. TO is
set by a WDT time-out.
• CZ is the operational result of different ags for different instructions. Refer to register denitions
for more details.
• SC is the result of the “XOR” operation which is performed by the OV ag and the MSB of the
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
• EED Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~0 D7~D0: Data EEPROM data bit 7 ~ bit 0
• EEC Register
Bit76543210
Name————WRENWRRDENRD
R/W————R/WR/WR/WR/W
POR————0000
Bit 7~4 Unimplemented, read as “0”
Bit 3 WREN: Data EEPROM Write Enable
0: Disable
1: Enable
This is the Data EEPROM Write Enable Bit which must be set high before Data
EEPROM write operations are carried out. Clearing this bit to zero will inhibit Data
EEPROM write operations.
Bit 2 WR: EEPROM Write Control
0: Write cycle has nished
1: Activate a write cycle
This is the Data EEPROM Write Control Bit and when set high by the application
program will activate a write cycle. This bit will be automatically reset to zero by the
hardware after the write cycle has nished. Setting this bit high will have no effect if
the WREN has not rst been set high.
Bit 1 RDEN: Data EEPROM Read Enable
0: Disable
1: Enable
This is the Data EEPROM Read Enable Bit which must be set high before Data
EEPROM read operations are carried out. Clearing this bit to zero will inhibit Data
EEPROM read operations.
Bit 0 RD: EEPROM Read Control
0: Read cycle has nished
1: Activate a read cycle
This is the Data EEPROM Read Control Bit and when set high by the application
program will activate a read cycle. This bit will be automatically reset to zero by the
hardware after the read cycle has nished. Setting this bit high will have no effect if
the RDEN has not rst been set high.
Note: 1. The WREN, WR, RDEN and RD bits cannot be set high at the same time in one instruction.
The WR and RD bits cannot be set high at the same time.
2. Ensure that the f
3. Ensure that the write operation is totally complete before changing the EEC register
content.
clock is stable before executing the write operation.
SUB
Reading Data from the EEPROM
To read data from the EEPROM, the EEPROM address of the data to be read must rst be placed in
the EEA register. The read enable bit, RDEN, in the EEC register must then be set high to enable the
read function. If the RD bit in the EEC register is now set high, a read cycle will be initiated. Setting
the RD bit high will not initiate a read operation if the RDEN bit has not been set. When the read cycle
terminates, the RD bit will be automatically cleared to zero, after which the data can be read from
the EED register. The data will remain in the EED register until another read or write operation is
executed. The application program can poll the RD bit to determine when the data is valid for reading.
Writing Data to the EEPROM
To write data to the EEPROM, the EEPROM address of the data to be written must rst be placed
in the EEA register and the data placed in the EED register. To initiate a write cycle the write enable
bit, WREN, in the EEC register must rst be set high to enable the write function. After this, the
WR bit in the EEC register must be immediately set high to initiate a write cycle successfully. These
two instructions must be executed in two consecutive instruction cycles. The global interrupt bit
EMI should also rst be cleared before implementing any write operations, and then set high again
after the write cycle has started. Note that setting the WR bit high will not initiate a write cycle if
the WREN bit has not been set. As the EEPROM write cycle is controlled using an internal timer
whose operation is asynchronous to microcontroller system clock, a certain time will elapse before
the data will have been written into the EEPROM. Detecting when the write cycle has finished
can be implemented either by polling the WR bit in the EEC register or by using the EEPROM
interrupt. When the write cycle terminates, the WR bit will be automatically cleared to zero by the
microcontroller, informing the user that the data has been written to the EEPROM. The application
program can therefore poll the WR bit to determine when the write cycle has ended.
Write Protection
Protection against inadvertent write operation is provided in several ways. After the device is
powered-on the Write Enable bit in the control register will be cleared preventing any write
operations. Also at power-on the Memory Pointer high byte register, MP1H or MP2H, will be reset
to zero, which means that Data Memory Sector 0 will be selected. As the EEPROM control register
is located in Sector 1, this adds a further measure of protection against spurious write operations.
During normal program operation, ensuring that the Write Enable bit in the control register is
cleared will safeguard against incorrect write operations.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
EEPROM Interrupt
The EEPROM write interrupt is generated when an EEPROM write cycle has ended. The EEPROM
interrupt must first be enabled by setting the DEE bit in the relevant interrupt register. When an
EEPROM write cycle ends, the DEF request ag will be set. If the global, EEPROM interrupts are
enabled and the stack is not full, a jump to the associated EEPROM Interrupt vector will take place.
When the interrupt is serviced, the EEPROM Interrupt ag, DEF, will be automatically cleared. The
EMI bit will also be automatically cleared to disable other interrupts. More details can be obtained
in the Interrupt section.
Programming Considerations
Care must be taken that data is not inadvertently written to the EEPROM. Protection can be
enhanced by ensuring that the Write Enable bit is normally cleared to zero when not writing. Also
the Memory Pointer high byte register, MP1H or MP2H, could be normally cleared to zero as this
would inhibit access to Sector 1 where the EEPROM control register exists. Although certainly not
necessary, consideration might be given in the application program to the checking of the validity of
new write data by a simple read back process.
When writing data the WR bit must be set high immediately after the WREN bit has been set high,
to ensure the write cycle executes correctly. The global interrupt bit EMI should also be cleared
before a write cycle is executed and then re-enabled after the write cycle starts. Note that the device
should not enter the IDLE or SLEEP mode until the EEPROM read or write operation is totally
complete. Otherwise, the EEPROM read or write operation will fail.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
f
H
High Speed
Oscillator
HIRCEN
HIRC
Low Speed
Oscillators
LXT
LIRC
IDLE0
SLEEP
IDLE2
SLEEP
FSS
System Clock Congurations
Internal High Speed RC Oscillator – HIRC
The internal RC oscillator is a fully integrated system oscillator requiring no external components.
The internal RC oscillator has three fixed frequencies of 8MHz, 12MHz and 16MHz, which is
selected using a conguration option. The HIRC1~HIRC0 bits in the HIRCC register must also be
congured to match the selected conguration option frequency. Setting up these bits is necessary to
ensure that the HIRC frequency accuracy specied in the A.C. Characteristics is achieved. Device
trimming during the manufacturing process and the inclusion of internal frequency compensation
circuits are used to ensure that the inuence of the power supply voltage, temperature and process
variations on the oscillation frequency are minimised. Note that this internal system clock option
requires no external pins for its operation.
Prescaler
fH/2
fH/4
fH/8
fH/16
fH/32
fH/64
f
SUB
CKS2~CKS0
f
SYS
f
SUB
f
LIRC
Internal 32kHz Oscillator – LIRC
The Internal 32 kHz System Oscillator is one of the low frequency oscillator choices, which is
selected by the FSS bit in the SCC register. It is a fully integrated RC oscillator with a typical
frequency of 32kHz, requiring no external components for its implementation. Device trimming
during the manufacturing process and the inclusion of internal frequency compensation circuits are
used to ensure that the inuence of the power supply voltage, temperature and process variations on
the oscillation frequency are minimised.
External 32.768 kHz Crystal Oscillator – LXT
The External 32.768 kHz Crystal System Oscillator is one of the low frequency oscillator choices,
which is selected by the FSS bit in the SCC register. This clock source has a xed frequency of
32.768 kHz and requires a 32.768 kHz crystal to be connected between pins XT1 and XT2. The
external resistor and capacitor components connected to the 32.768 kHz crystal are necessary to
provide oscillation. For applications where precise frequencies are essential, these components may
be required to provide frequency compensation due to different crystal manufacturing tolerances.
During power-up there is a time delay associated with the LXT oscillator waiting for it to start-up.
When the microcontroller enters the SLEEP or IDLE Mode, the system clock is switched off to stop
microcontroller activity and to conserve power. However, in many microcontroller applications it
may be necessary to keep the internal timers operational even when the microcontroller is in the
SLEEP or IDLE Mode. To do this, another clock, independent of the system clock, must be provided.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
However, for some crystals, to ensure oscillation and accurate frequency generation, it is necessary
to add two small value external capacitors, C1 and C2. The exact values of C1 and C2 should be
selected in consultation with the crystal or resonator manufacturer’s specification. The external
parallel feedback resistor, RP, is required.
The pin-shared function selection bits determine if the XT1/XT2 pins are used for the LXT oscillator
or as I/O or other pin-shared functions.
• If the LXT oscillator is not used for any clock source, the XT1/XT2 pins can be used as normal I/O
or other pin-shared functions.
• If the LXT oscillator is used for any clock source, the 32.768 kHz crystal should be connected to
the XT1/XT2 pins.
For oscillator stability and to minimise the effects of noise and crosstalk, it is important to ensure
that the crystal and any associated resistors and capacitors along with interconnecting lines are all
located as close to the MCU as possible.
C1
32.768kHz
C2
Note: 1. RP, C1 and C2 are required.
2. Although not shown pins have a parasitic capacitance of around 7pF.
External LXT Oscillator
LXT Oscillator C1 and C2 Values
Crystal FrequencyC1C2
32.768kHz10pF10pF
Note: 1. C1 and C2 values are for guidance only.
2. RP=5M~10MΩ is recommended.
32.768kHz Crystal Recommended Capacitor Values
XT1
R
P
XT2
Internal
Oscillator
Circuit
Internal RC
Oscillator
To internal
circuits
LXT Oscillator Low Power Function
The LXT oscillator can function in one of two modes, the Quick Start Mode and the Low Power
Mode. The mode selection is executed using the LXTSP bit in the LXTC register.
LXTSPLXT Operating Mode
0Low Power
1Quick Start
Setting the LXTSP bit high will enable the LXT Quick Start mode. In the Quick Start Mode the LXT
oscillator will power up and stabilise quickly. However, after the LXT oscillator has fully powered
up it can be placed into the Low power mode by clearing the LXTSP bit to zero. The oscillator will
continue to run but with reduced current consumption, as the higher current consumption is only
required during the LXT oscillator start-up. It is important to note that the LXT operating mode
switching must be properly controlled before the LXT oscillator clock is selected as the system
clock source. Once the LXT oscillator clock is selected as the system clock source using the CKS bit
eld and FSS bit in the SCC register, the LXT oscillator operating mode can not be changed.
It should be noted that, no matter what condition the LXTSP bit is set to, the LXT oscillator will
always function normally. The only difference is that it will take more time to start up if in the
These three bits are used to select which clock is used as the system clock source. In
addition to the system clock source directly derived from fH or f
, a divided version
SUB
of the high speed system oscillator can also be chosen as the system clock source.
Bit 4~3 Unimplemented, read as “0”
Bit 2 FSS: Low frequency clock selection
0: LIRC
1: LXT
Bit 1 FHIDEN: High frequency oscillator control when CPU is switched off
0: Disable
1: Enable
This bit is used to control whether the high speed oscillator is activated or stopped
when the CPU is switched off by executing an “HALT” instruction.
Bit 0 FSIDEN: Low frequency oscillator control when CPU is switched off
0: Disable
1: Enable
This bit is used to control whether the low speed oscillator is activated or stopped
when the CPU is switched off by executing an “HALT” instruction.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
• HIRCC Register
Bit76543210
Name————HIRC1HIRC0HIRCFHIRCEN
R/W————R/WR/WRR/W
POR————0001
Bit 7~4 Unimplemented, read as “0”
Bit 3~2 HIRC1~HIRC0: HIRC frequency selection
00: 8MHz
01: 12MHz
10: 16MHz
11: 8MHz
When the HIRC oscillator is enabled or the HIRC frequency selection is changed
by application program, the clock frequency will automatically be changed after the
HIRCF ag is set to 1.
It is recommended that the HIRC frequency selected by these two bits should be the
same with the frequency determined by the conguration option to achieve the HIRC
frequency accuracy specied in the A.C. Characteristics.
Bit 1 HIRCF: HIRC oscillator stable ag
0: Unstable
1: Stable
This bit is used to indicate whether the HIRC oscillator is stable or not. When the
HIRCEN bit is set to 1 to enable the HIRC oscillator, the HIRCF bit will first be
cleared to 0 and then set to 1 after the HIRC oscillator is stable.
Bit 0 HIRCEN: HIRC oscillator enable control
0: Disable
1: Enable
• LXTC Register
Bit76543210
Name—————LXTSPLXTFLXTEN
R/W—————R/WRR/W
POR—————000
Bit 7~3 Unimplemented, read as “0”
Bit 2 LXTSP: LXT oscillator quick start control
0: Disable – Low Power
1: Enable – Quick Start
This bit is used to control whether the LXT oscillator is operating in the low power
or quick start mode. When the LXTSP bit is set to 1, the LXT oscillator will oscillate
quickly but consume more power. If the LXTSP bit is cleared to 0, the LXT oscillator
will consume less power but take longer time to stablise. It is important to note that
this bit can not be changed after the LXT oscillator is selected as the system clock
source using the CKS2~CKS0 and FSS bits in the SCC register.
Bit 1 LXTF: LXT oscillator stable ag
0: Unstable
1: Stable
This bit is used to indicate whether the LXT oscillator is stable or not. When the
LXTEN bit is set to 1 to enable the LXT oscillator, the LXTF bit will rst be cleared
to 0 and then set to 1 after the LXT oscillator is stable.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Standby Current Considerations
As the main reason for entering the SLEEP or IDLE Mode is to keep the current consumption of the
device to as low a value as possible, perhaps only in the order of several micro-amps except in the
IDLE1 and IDLE2 Mode, there are other considerations which must also be taken into account by
the circuit designer if the power consumption is to be minimised. Special attention must be made to
the I/O pins on the device. All high-impedance input pins must be connected to either a xed high or
low level as any oating input pins could create internal oscillations and result in increased current
consumption. This also applies to the device which has different package types, as there may be
unbonded pins. These must either be set as outputs or if set as inputs must have pull-high resistors
connected.
Care must also be taken with the loads, which are connected to I/O pins, which are set as outputs.
These should be placed in a condition in which minimum current is drawn or connected only to
external circuits that do not draw current, such as other CMOS inputs. Also note that additional
standby current will also be required if the LXT or LIRC oscillator has enabled.
In the IDLE1 and IDLE2 Mode the high speed oscillator is on and if the system clock is from the
high speed system oscillator, the additional standby current will also be perhaps in the order of
several hundred micro-amps.
Wake-up
To minimise power consumption the device can enter the SLEEP or any IDLE Mode, where the
CPU will be switched off. However, when the device is woken up again, it will take a considerable
time for the original system oscillator to restart, stabilise and allow normal operation to resume.
After the system enters the SLEEP or IDLE Mode, it can be woken up from one of various sources
listed as follows:
• An external falling edge on Port A
• A system interrupt
• A WDT overow
When the device executes the “HALT” instruction, it will enter the SLEEP or IDLE mode and the
PDF flag will be set high. The PDF flag will be cleared to 0 if the device experiences a system
power-up or executes the clear Watchdog Timer instruction. If the system is woken up by a WDT
overow, a Watchdog Time-out hardware reset will be initiated and the TO ag will be set to 1. The
TO ag is set if a WDT time-out occurs and causes a wake-up that only resets the Program Counter
and Stack Pointer, other ags remain in their original status.
Each pin on Port A can be set using the PAWU register to permit a negative transition on the pin
to wake-up the system. When a pin wake-up occurs, the program will resume execution at the
instruction following the “HALT” instruction. If the system is woken up by an interrupt, then two
possible situations may occur. The first is where the related interrupt is disabled or the interrupt
is enabled but the stack is full, in which case the program will resume execution at the instruction
following the “HALT” instruction. In this situation, the interrupt which woke-up the device will not
be immediately serviced, but will rather be serviced later when the related interrupt is nally enabled
or when a stack level becomes free. The other situation is where the related interrupt is enabled and
the stack is not full, in which case the regular interrupt response takes place. If an interrupt request
flag is set high before entering the SLEEP or IDLE Mode, the wake-up function of the related
interrupt will be disabled.
Watchdog Timer
The Watchdog Timer is provided to prevent program malfunctions or sequences from jumping to
unknown locations, due to certain uncontrollable external events such as electrical noise.
Watchdog Timer Clock Source
The Watchdog Timer clock source is provided by the internal clock, f
the LIRC oscillator. The LIRC internal oscillator has an approximate frequency of 32kHz and this
specied internal clock period can vary with VDD, temperature and process variations. The Watchdog
Timer source clock is then subdivided by a ratio of 28 to 218 to give longer timeouts, the actual value
being chosen using the WS2~WS0 bits in the WDTC register.
Watchdog Timer Control Register
A single register, WDTC, controls the required time-out period as well as the enable and reset MCU
operation.
• WDTC Register
Bit76543210
NameWE4WE3WE2WE1WE0WS2WS1WS0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR01010011
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
which is sourced from
LIRC
Bit 7~3 WE4~WE0: WDT function control
10101 or 01010: Enable
Other values: Reset MCU
When these bits are changed to any other values due to environmental noise the
microcontroller will be reset; this reset operation will be activated after a delay time,
t
, and the WRF bit in the RSTFC register will be set high.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Bit 1 LRF: LVRC register software reset ag
Described elsewhere
Bit 0 WRF: WDTC register software reset ag
0: Not occurred
1: Occurred
This bit is set high by the WDTC register software reset and cleared to zero by the
application program. Note that this bit can only be cleared to zero by the application
program.
Watchdog Timer Operation
The Watchdog Timer operates by providing a device reset when its timer overows. This means
that in the application program and during normal operation the user has to strategically clear the
Watchdog Timer before it overows to prevent the Watchdog Timer from executing a reset. This is
done using the clear watchdog instruction. If the program malfunctions for whatever reason, jumps
to an unknown location, or enters an endless loop, the clear instruction will not be executed in the
correct manner, in which case the Watchdog Timer will overow and reset the device. There are ve
bits, WE4~WE0, in the WDTC register to offer the enable control and reset control of the Watchdog
Timer. The WDT function will be enabled if the WE4~WE0 bits are equal to 10101B or 01010B.
If the WE4~WE0 bits are set to any other values, other than 01010B and 10101B, it will reset the
device after a delay time, t
. After power on these bits will have a value of 01010B.
SRESET
WE4~WE0 BitsWDT Function
01010B or 10101BEnable
Any other valueReset MCU
Watchdog Timer Enable/Reset Control
Under normal program operation, a Watchdog Timer time-out will initialise a device reset and set
the status bit TO. However, if the system is in the SLEEP or IDLE Mode, when a Watchdog Timer
time-out occurs, the TO bit in the STATUS register will be set and only the Program Counter and
Stack Pointer will be reset. Three methods can be adopted to clear the contents of the Watchdog
Timer. The rst is a WDTC register software reset, which means a certain value except 01010B and
10101B written into the WE4~WE0 bits, the second is using the Watchdog Timer software clear
instruction and the third is via a HALT instruction.
There is only one method of using software instruction to clear the Watchdog Timer. That is to use
the single “CLR WDT” instruction to clear the WDT.
The maximum time-out period is when the 218 division ratio is selected. As an example, with a
32kHz LIRC oscillator as its source clock, this will give a maximum watchdog period of around 8s
for the 218 division ratio, and a minimum timeout of 8ms for the 28 division ration.
WE4~WE0 bitsWDTC RegisterReset MCU
“CLR WDT” Instruction
“HALT” Instruction
LIRC8-stage DividerWDT Prescaler
f
LIRC
CLR
f
LIRC
Watchdog Timer
8
/2
8-to-1 MUXWS2~WS0
WDT Time-out
8
/f
~ 218/f
(2
LIRC
LIRC
)
Reset and Initialisation
A reset function is a fundamental part of any microcontroller ensuring that the device can be set
to some predetermined condition irrespective of outside parameters. The most important reset
condition is after power is rst applied to the microcontroller. In this case, internal circuitry will
ensure that the microcontroller, after a short delay, will be in a well-defined state and ready to
execute the rst program instruction. After this power-on reset, certain important internal registers
will be set to dened states before the program commences. One of these registers is the Program
Counter, which will be reset to zero forcing the microcontroller to begin program execution from the
lowest Program Memory address.
In addition to the power-on reset, another reset exists in the form of a Low Voltage Reset, LVR,
where a full reset is implemented in situations where the power supply voltage falls below a
certain threshold. Another type of reset is when the Watchdog Timer overflows and resets the
microcontroller. All types of reset operations result in different register conditions being set.
Reset Functions
There are several ways in which a microcontroller reset can occur, through events occurring
internally.
Power-on Reset
The most fundamental and unavoidable reset is the one that occurs after power is rst applied to
the microcontroller. As well as ensuring that the Program Memory begins execution from the rst
memory address, a power-on reset also ensures that certain other registers are preset to known
conditions. All the I/O port and port control registers will power up in a high condition ensuring that
all pins will be rst set to inputs.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
V
DD
Power-on Reset
SST Time-out
Power-On Reset Timing Chart
t
RSTD
Internal Reset Control
There is an internal reset control register, RSTC, which is used to provide a reset when the device
operates abnormally due to the environmental noise interference. If the content of the RSTC register
is set to any value other than 01010101B or 10101010B, it will reset the device after a delay time,
t
. After power on the register will have a value of 01010101B.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
• RSTC Register
Bit76543210
NameRSTC7RSTC6RSTC5RSTC4RSTC3RSTC2RSTC1RSTC0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR01010101
Bit 7~0 RSTC7~RSTC0: Reset function control
01010101: No operation
10101010: No operation
Other values: Reset MCU
If these bits are changed due to adverse environmental conditions, the microcontroller
will be reset. The reset operation will be activated after a delay time, t
RSTF bit in the RSTFC register will be set to 1.
• RSTFC Register
Bit76543210
Name————RSTFLVRFLRFWRF
R/W————R/WR/WR/WR/W
POR————0x00
Bit 7~4 Unimplemented, read as “0”
Bit 3 RSTF: RSTC register software reset ag
0: Not occurred
1: Occurred
This bit is set to 1 by the RSTC control register software reset and cleared to zero
by the application program. Note that this bit can only be cleared to zero by the
application program.
Bit 2 LVRF: LVR function reset ag
Described elsewhere
Bit 1 LRF: LVRC register software reset ag
Described elsewhere
Bit 0 WRF: WDTC register software reset ag
Described elsewhere
, and the
SRESET
“x”: unknown
Low Voltage Reset – LVR
The microcontroller contains a low voltage reset circuit in order to monitor the supply voltage of
the device. The LVR function is always enabled in the FAST and SLOW modes with a specic LVR
voltage, V
. If the supply voltage of the device drops to within a range of 0.9V~V
LVR
such as might
LVR
occur when changing the battery, the LVR will automatically reset the device internally and the
LVRF bit in the RSTFC register will also be set to 1. For a valid LVR signal, a low supply voltage,
i.e., a voltage in the range between 0.9V~V
t
in the LVD/LVR Electrical Characteristics. If the low supply voltage state does not exceed this
LVR
must exist for a time greater than that specied by
LVR
value, the LVR will ignore the low supply voltage and will not perform a reset function. The actual
V
value can be selected by the LVS bits in the LVRC register. If the LVS7~LVS0 bits have any
LVR
other value, which may perhaps occur due to adverse environmental conditions such as noise, the
LVR will reset the device after a delay time, t
. When this happens, the LRF bit in the RSTFC
SRESET
register will be set to 1. Note that the LVR function will be automatically disabled when the device
enters the SLEEP/IDLE mode.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
LVR
t
+ t
RSTD
SST
Internal Reset
Low Voltage Reset Timing Chart
• LVRC Register
Bit76543210
NameLVS7LVS6LVS5LVS4LVS3LVS2LVS1LVS0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR01010101
Bit 7~0 LVS7~LVS0: LVR voltage selection
01010101: 2.1V
00110011: 2.55V
10011001: 3.15V
10101010: 3.8V
Other values: Generates a MCU reset – register is reset to POR value
When an actual low voltage condition occurs, as specied by the LVR voltage value
above, an MCU reset will be generated. The reset operation will be activated after the
low voltage condition keeps for greater than a t
contents will remain the same after such a reset occurs.
Any register value, other than the four dened register values above, will also result
in the generation of an MCU reset. The reset operation will be activated after a delay
time, t
. However in this situation the register contents will be reset to the POR
SRESET
value.
time. In this situation the register
LVR
• RSTFC Register
Bit76543210
Name————RSTFLVRFLRFWRF
R/W————R/WR/WR/WR/W
POR————0x00
Bit 7~4 Unimplemented, read as “0”
Bit 3 RSTF: RSTC register software reset ag
Described elsewhere
Bit 2 LVRF: LVR function reset ag
0: Not occurred
1: Occurred
This bit is set to 1 when a specic low voltage reset condition occurs. Note that this bit
can only be cleared to 0 by the application program.
Bit 1 LRF: LVR control register software reset ag
0: Not occurred
1: Occurred
This bit is set to 1 by the LVRC control register contains any undened LVR voltage
register values. This in effect acts like a software-reset function. Note that this bit can
only be cleared to 0 by the application program.
Bit 0 WRF: WDT control register software reset ag
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Input/Output Ports
Holtek microcontrollers offer considerable exibility on their I/O ports. With the input or output
designation of every pin fully under user program control, pull-high selections for all ports and
wake-up selections on certain pins, the user is provided with an I/O structure to meet the needs of a
wide range of application possibilities.
This device provides bidirectional input/output lines. These I/O ports are mapped to the RAM Data
Memory with specic addresses as shown in the Special Purpose Data Memory table. All of these
I/O ports can be used for input and output operations. For input operation, these ports are non-
latching, which means the inputs must be ready at the T2 rising edge of instruction “MOV A, [m]”,
where “m” denotes the port address. For output operation, all the data is latched and remains
unchanged until the output latch is rewritten.
Register
Name
PAPA 7PA6PA5PA 4PA3PA2PA 1PA0
PACPAC7PAC6PAC5PAC4PAC3PAC2PAC1PAC0
PAPUPAPU7PAPU6PAPU5PAPU4PAPU3PAPU2PAPU1PAPU0
PAWUPAWU7PAWU6PAWU5PAWU4PAWU3PAWU2PAWU1PAWU0
PBPB7PB6PB5PB4PB3PB2PB1PB0
PBCPBC7PBC6PBC5PBC4PBC3PBC2PBC1PBC0
PBPUPBPU7PBPU6PBPU5PBPU4PBPU3PBPU2PBPU1PBPU0
PC——PC5PC4PC3PC2PC1PC0
PCC——PCC5PCC4PCC3PCC2PCC1PCC0
PCPU——PCPU5PCPU4PCPU3PCPU2PCPU1PCPU0
76543210
I/O Logic Function Register List
Bit
“—”: Unimplemented, read as “0”
Pull-high Resistors
Many product applications require pull-high resistors for their switch inputs usually requiring
the use of an external resistor. To eliminate the need for these external resistors, all I/O pins,
when congured as a digital input have the capability of being connected to an internal pull-high
resistor. These pull-high resistors are selected using the relevant pull-high control registers and are
implemented using weak PMOS transistors.
Note that the pull-high resistor can be controlled by the relevant pull-high control register only when
the pin-shared functional pin is selected as a digital input or NMOS output. Otherwise, the pull-high
resistors cannot be enabled.
• PxPU Register
Bit76543210
NamePxPU7PxPU6PxPU5PxPU4PxPU3PxPU2PxPU1PxPU0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
PxPUn: I/O Port x Pin pull-high function control
0: Disable
1: Enable
The PxPUn bit is used to control the pin pull-high function. Here the “x” is the Port name
which can be A, B or C. However, the actual available bits for each I/O Port may be
different.
Port A Wake-up
The HALT instruction forces the microcontroller into the SLEEP or IDLE Mode which preserves
power, a feature that is important for battery and other low-power applications. Various methods
exist to wake-up the microcontroller, one of which is to change the logic condition on one of the Port
A pins from high to low. This function is especially suitable for applications that can be woken up
via external switches. Each pin on Port A can be selected individually to have this wake-up feature
using the PAWU register.
Note that the wake-up function can be controlled by the wake-up control registers only when the pin
is selected as a general purpose input and the MCU enters the IDLE or SLEEP mode.
• PAWU Register
Bit76543210
NamePAWU7PAWU6PAWU5PAWU4PAWU3PAWU2PAWU1PAWU0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~0 PAWU7~PAWU0: PA7~PA0 pin Wake-up function control
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
0: Disable
1: Enable
I/O Port Control Registers
Each I/O Port has its own control register which controls the input/output conguration. With this
control register, each I/O pin with or without pull-high resistors can be recongured dynamically
under software control. For the I/O pin to function as an input, the corresponding bit of the control
register must be written as a “1”. This will then allow the logic state of the input pin to be directly
read by instructions. When the corresponding bit of the control register is written as a “0”, the I/
O pin will be set as a CMOS output. If the pin is currently set as an output, instructions can still be
used to read the output register. However, it should be noted that the program will in fact only read
the status of the output data latch and not the actual logic status of the output pin.
• PxC Register
Bit76543210
NamePxC7PxC6PxC5PxC4PxC3PxC2PxC1PxC0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR11111111
PxCn: I/O Port x Pin type selection
0: Output
1: Input
The PxCn bit is used to control the pin type selection. Here the “x” is the Port name which
can be A, B or C. However, the actual available bits for each I/O Port may be different.
I/O Port Source Current Selection
The device supports different output source current driving capability for each I/O port. With the
selection register, SLEDCn, specic I/O port can support four levels of the source current driving
capability. These source current selection bits are available only when the corresponding pin is
configured as a CMOS output. Otherwise, these select bits have no effect. Users should refer to
the Input/Output Characteristics section to select the desired output source current for different
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
data registers are rst programmed. Selecting which pins are inputs and which are outputs can be
achieved byte-wide by loading the correct values into the appropriate port control register or by
programming individual bits in the port control register using the “SET [m].i” and “CLR [m].i”
instructions. Note that when using these bit control instructions, a read-modify-write operation takes
place. The microcontroller must rst read in the data on the entire port, modify it to the required new
bit values and then rewrite this data back to the output ports.
Port A has the additional capability of providing wake-up functions. When the device is in the SLEEP
or IDLE Mode, various methods are available to wake the device up. One of these is a high to low
transition of any of the Port A pins. Single or multiple pins on Port A can be set to have this function.
High Voltage I/O Port
The device provides several 10V high voltage input/output lines, known as PD0~PD5. These high
voltage I/O ports can convert 5V logic output signals to 10V voltage outputs to directly drive
TRIACs, relays, and buzzers.
PWRRDYF
PDn_DOUT_EN
PDOMn
PDn_DOUT
HVIO 0 ~ HVIO n
f
LIRC
5-stage
Divider
Comparator
f
/32
LIRC
f
/16
LIRC
M
U
X
PDn_DIN
VCC2VDD
Level
Shift
VCC2VDD
Level
Shift
Level
Shift
RB
2-bit Counter
VCC2VDD
PWRRDY
PDn_OE
EN
HV I/O Control
M
PDn
U
X
PDCn
VCC2
PDn
HVSS
Read Data Register
Data Bus
To high voltage short circuit interrupt
SFRTC
High Voltage I/O Block Diagram (n=0~5)
Note: 1. The structure contained in the dash line is identical for each PDn HVIO, and the structure contained in the
solid line is shared by all HVIO lines.
2. Each symbol name with a “_” sign in the figure is a circuit node name and not the Special Function
Register bit.
PDn_DOUT_EN: PDn data output enable signal
PDn_DOUT: PDn output data
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
PDn_OE: PDn output global enable signal
PDn_DIN: PDn input data
3. When the comparison result between PDn_DOUT and PDn_DIN is different, the LIRC oscillator will
be enabled by the hardware until the short circuit condition is released even if the CPU and LIRC are
both off. After the LIRC clock is stable, the f
functions. If the MCU is still in CPU off mode, the LIRC will be turned off after the short circuit
condition has been released.
4. The PDn_OE truth table is shown as follows:
PWRRDYPWRRDYFPDOMnPDn_DOUT_ENPDn_OE
00000
11000
11011
11100
11110
5. The PDn truth table is shown as follows:
PDn_OEPDn_DOUTPDnPDn Mode
00
01
10V
11V
Floating Input mode
SS
Output mode
(Short-circuit protection is enabled when PWRRDYF=1)
CC2
clock can be used as the clock source of the peripheral
LIRC
High Voltage I/O Registers
Overall operation of high voltage I/O port is controlled using a series of registers. The PD register
is the data register. The PDC register is used to select the input/output type. The PDOM register is
used for output mask control. The remaining register PWRDET is used to monitor the power supply
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Programming Considerations
The TM Counter Registers and the Capture/Compare CCRA and CCRP registers, all have a low
and high byte structure. The high bytes can be directly accessed, but as the low bytes can only be
accessed via an internal 8-bit buffer, reading or writing to these register pairs must be carried out in
a specic way. The important point to note is that data transfer to and from the 8-bit buffer and its
related low byte only takes place when a write or read operation to its corresponding high byte is
executed.
As the CCRA and CCRP registers are implemented in the way shown in the following diagram and
accessing these register pairs is carried out in a specic way as described above, it is recommended
to use the “MOV” instruction to access the CCRA and CCRP low byte registers, named xTMnAL
and PTMRPL, using the following access procedures. Accessing the CCRA or CCRP low byte
registers without following these access procedures will result in unpredictable values.
Clock input
CTMn
CCR output
CTCKn
CTPn
CTPnB
CTM Function Pin Block Diagram (n=0~1)
Clock/capture input
CCR capture input
PTM
CCR output
PTCK
PTPI
PTP
PTPB
PTM Function Pin Block Diagram
xTMn Counter Register (Read only)
xTMnDHxTMnDL
8-bit Buffer
xTMnAL
xTMn CCRA Register (Read/Write)
PTM CCRP Register (Read/Write)
xTMnAH
PTMRPHPTMRPL
The following steps show the read and write procedures:
• Writing Data to CCRA or CCRP
♦
Step 1. Write data to Low Byte xTMnAL or PTMRPL
– Note that here data is only written to the 8-bit buffer.
Data Bus
♦
Step 2. Write data to High Byte xTMnAH or PTMRPH
– Here data is written directly to the high byte registers and simultaneously data is latched
from the 8-bit buffer to the Low Byte registers.
• Reading Data from the Counter Registers and CCRA or CCRP
♦
Step 1. Read data from the High Byte xTMnDH, xTMnAH or PTMRPH
– Here data is read directly from the High Byte registers and simultaneously data is latched
from the Low Byte register into the 8-bit buffer.
♦
Step 2. Read data from the Low Byte xTMnDL, xTMnAL or PTMRPL
– This step reads data from the 8-bit buffer.
Compact Type TM – CTM
The Compact Type TM contains three operating modes, which are Compare Match Output, Timer/
Event Counter and PWM Output modes. The Compact TM can also be controlled with an external
input pin and can drive two external output pins.
(CTM0, CTM1)
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
CTM CoreCTM Input PinCTM Output Pin
10-bit CTM
CTCK0
CTCK1
CTP0, CTP0B
CTP1, CTP1B
CCRP
CTCKn
f
/4
000
SYS
001
f
SYS
010
fH/16
fH/64
011
f
100
SUB
f
101
SUB
110
111
CTnCK2~CTnCK0
CTnON
CTnPAU
3-bit Comparator P
b7~b9
10-bit Count-up Counter
b0~b9
10-bit Comparator A
CCRA
Comparator P Match
Counter Clear 0
CTnCCLR
Comparator A Match
1
CTMnPF Interrupt
CTnOC
Output
Control
CTnM1~CTnM0
CTnIO1~CTnIO0
CTMnAF Interrupt
Polarity
Control
CTnPOL
CTPn
CTPnB
Note: The CTMn external pins are pin-shared with other functions, so before using the CTMn function the relevant
pin-shared function registers must be set properly.
Compact Type TM Block Diagram (n=0~1)
Compact Type TM Operation
The size of Compact TM is 10-bit wide and its core is a 10-bit count-up counter which is driven by
a user selectable internal or external clock source. There are also two internal comparators with the
names, Comparator A and Comparator P. These comparators will compare the value in the counter
with CCRP and CCRA registers. The CCRP comparator is 3-bit wide whose value is compared with
the highest 3 bits in the counter while the CCRA is the 10 bits and therefore compares all counter bits.
The only way of changing the value of the 10-bit counter using the application program, is to
clear the counter by changing the CTnON bit from low to high. The counter will also be cleared
automatically by a counter overow or a compare match with one of its associated comparators.
When these conditions occur, a CTMn interrupt signal will also usually be generated. The Compact
Type TM can operate in a number of different operational modes, can be driven by different clock
sources including an input pin and can also control two output pins. All operating setup conditions
The counter can be paused by setting this bit high. Clearing the bit to zero restores
normal counter operation. When in a Pause condition the CTMn will remain powered
up and continue to consume power. The counter will retain its residual value when
this bit changes from low to high and resume counting from this value when the bit
changes to a low value again.
Bit 6~4 CTnCK2~CTnCK0: CTMn counter clock selection
These three bits are used to select the clock source for the CTMn. The external pin
clock source can be chosen to be active on the rising or falling edge. The clock source
f
is the system clock, while fH and f
SYS
are other internal clocks, the details of which
SUB
can be found in the oscillator section.
Bit 3 CTnON: CTMn counter on/off control
0: Off
1: On
This bit controls the overall on/off function of the CTMn. Setting the bit high enables
the counter to run while clearing the bit disables the CTMn. Clearing this bit to zero
will stop the counter from counting and turn off the CTMn which will reduce its power
consumption. When the bit changes state from low to high the internal counter value
will be reset to zero, however when the bit changes from high to low, the internal
counter will retain its residual value until the bit returns high again.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
If the CTMn is in the Compare Match Output Mode or the PWM Output Mode, then
the CTMn output pin will be reset to its initial condition, as specied by the CTnOC
bit, when the CTnON bit changes from low to high.
Bit 2~0 CTnRP2~CTnRP0: CTMn CCRP 3-bit register, compared with the CTMn counter
bit 9 ~ bit 7
Comparator P match period=
0: 1024 CTMn clocks
1~7: (1~7)×128 CTMn clocks
These three bits are used to set the value on the internal CCRP 3-bit register, which
are then compared with the internal counter’s highest three bits. The result of this
comparison can be selected to clear the internal counter if the CTnCCLR bit is set to
zero. Setting the CTnCCLR bit to zero ensures that a compare match with the CCRP
values will reset the internal counter. As the CCRP bits are only compared with the
highest three counter bits, the compare values exist in 128 clock cycle multiples.
Clearing all three bits to zero is in effect allowing the counter to overflow at its
maximum value.
Bit 7~6 CTnM1~CTnM0: CTMn operating mode selection
00: Compare Match Output Mode
01: Undened
10: PWM Output Mode
11: Timer/Counter Mode
These bits set the required operating mode for the CTMn. To ensure reliable operation
the CTMn should be switched off before any changes are made to the CTnM1 and
CTnM0 bits. In the Timer/Counter Mode, the CTMn output pin pin state is undened.
Bit 5~4 CTnIO1~CTnIO0: CTMn external pin CTPn function selection
Compare Match Output Mode
00: No change
01: Output low
10: Output high
11: Toggle output
PWM Output Mode
00: PWM output inactive state
01: PWM output active state
10: PWM output
11: Undened
Timer/Counter Mode
Unused
These two bits are used to determine how the CTMn external pin changes state when a
certain condition is reached. The function that these bits select depends upon in which
mode the CTMn is running.
In the Compare Match Output Mode, the CTnIO1 and CTnIO0 bits determine how the
CTMn output pin changes state when a compare match occurs from the Comparator A.
The CTMn output pin can be set to switch high, switch low or to toggle its present state
when a compare match occurs from the Comparator A. When the bits are both zero,
then no change will take place on the output. The initial value of the CTMn output pin
should be set using the CTnOC bit in the CTMnC1 register. Note that the output level
requested by the CTnIO1 and CTnIO0 bits must be different from the initial value
setup using the CTnOC bit otherwise no change will occur on the CTMn output pin
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
when a compare match occurs. After the CTMn output pin changes state, it can be reset
to its initial level by changing the level of the CTnON bit from low to high.
In the PWM Output Mode, the CTnIO1 and CTnIO0 bits determine how the CTMn
output pin changes state when a certain compare match condition occurs. The PWM
output function is modied by changing these two bits. It is necessary to only change
the values of the CTnIO1 and CTnIO0 bits only after the CTMn has been switched off.
Unpredictable PWM outputs will occur if the CTnIO1 and CTnIO0 bits are changed
when the CTMn is running.
Bit 3 CTnOC: CTMn CTPn output control
Compare Match Output Mode
0: Initial low
1: Initial high
PWM Output Mode/Single Pulse Output Mode
0: Active low
1: Active high
This is the output control bit for the CTMn output pin. Its operation depends upon
whether CTMn is being used in the Compare Match Output Mode or in the PWM
Output Mode. It has no effect if the CTMn is in the Timer/Counter Mode. In the
Compare Match Output Mode it determines the logic level of the CTMn output pin
before a compare match occurs. In the PWM Output Mode it determines if the PWM
signal is active high or active low.
Bit 2 CTnPOL: CTMn CTPn output polarity control
0: Non-invert
1: Invert
This bit controls the polarity of the CTPn output pin. When the bit is set high the
CTMn output pin will be inverted and not inverted when the bit is zero. It has no effect
if the CTMn is in the Timer/Counter Mode.
This bit determines which of the CCRA and CCRP registers are used for period and
duty control of the PWM waveform.
Bit 0 CTnCCLR: CTMn counter clear condition selection
0: Comparator P match
1: Comparator A match
This bit is used to select the method which clears the counter. Remember that the
CTMn contains two comparators, Comparator A and Comparator P, either of which
can be selected to clear the internal counter. With the CTnCCLR bit set high, the
counter will be cleared when a compare match occurs from the Comparator A. When
the bit is low, the counter will be cleared when a compare match occurs from the
Comparator P or with a counter overflow. A counter overflow clearing method can
only be implemented if the CCRP bits are all cleared to zero. The CTnCCLR bit is not
used in the PWM Output mode.
• CTMnDL Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WRRRRRRRR
POR00000000
Bit 7~0 D7~D0: CTMn Counter Low Byte Register bit 7 ~ bit 0
CTMn 10-bit Counter bit 7 ~ bit 0
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
• CTMnDH Register
Bit76543210
Name——————D9D8
R/W——————RR
POR——————00
Bit 7~2 Unimplemented, read as “0”
Bit 1~0 D9~D8: CTMn Counter High Byte Register bit 1 ~ bit 0
CTMn 10-bit Counter bit 9 ~ bit 8
• CTMnAL Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~0 D7~D0: CTMn CCRA Low Byte Register bit 7 ~ bit 0
CTMn 10-bit CCRA bit 7 ~ bit 0
• CTMnAH Register
Bit76543210
Name——————D9D8
R/W——————R/WR/W
POR——————00
Bit 7~2 Unimplemented, read as “0”
Bit 1~0 D9~D8: CTMn CCRA High Byte Register bit 7 ~ bit 0
CTMn 10-bit CCRA bit 9 ~ bit 8
Compact Type TM Operation Modes
The Compact Type TM can operate in one of three operating modes, Compare Match Output Mode,
PWM Output Mode or Timer/Counter Mode. The operating mode is selected using the CTnM1 and
CTnM0 bits in the CTMnC1 register.
Compare Match Output Mode
To select this mode, bits CTnM1 and CTnM0 in the CTMnC1 register, should be set to “00”
respectively. In this mode once the counter is enabled and running it can be cleared by three
methods. These are a counter overow, a compare match from Comparator A and a compare match
from Comparator P. When the CTnCCLR bit is low, there are two ways in which the counter can be
cleared. One is when a compare match from Comparator P, the other is when the CCRP bits are all
zero which allows the counter to overow. Here both CTMnAF and CTMnPF interrupt request ags
for Comparator A and Comparator P respectively, will both be generated.
If the CTnCCLR bit in the CTMnC1 register is high then the counter will be cleared when a compare
match occurs from Comparator A. However, here only the CTMnAF interrupt request ag will be
generated even if the value of the CCRP bits is less than that of the CCRA registers. Therefore when
CTnCCLR is high no CTMnPF interrupt request ag will be generated. If the CCRA bits are all
zero, the counter will overow when it reaches its maximum 10-bit, 3FF Hex, value. However, here
the CTMnAF interrupt request ag will not be generated.
As the name of the mode suggests, after a comparison is made, the CTMn output pin, will change
state. The CTMn output pin condition however only changes state when a CTMnAF interrupt
request ag is generated after a compare match occurs from Comparator A. The CTMnPF interrupt
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Register
Name
PTMC0PTPAUPTCK2PTCK1PTCK0PTON———
PTMC1PTM1PTM0PTIO1PTIO0PTOCPTPOL PTCAPTS PTCCLR
PTMDLD7D6D5D4D3D2D1D0
PTMDH——————D9D8
PTMALD7D6D5D4D3D2D1D0
PTMAH——————D9D8
PTMRPLPTRP7PTRP6PTRP5PTRP4PTRP3PTRP2PTRP1PTRP0
PTMRPH——————PTRP9PTRP8
76543210
10-bit Periodic TM Register List
Bit
• PTMC0 Register
Bit76543210
NamePTPAUPTCK2PTCK1PTCK0PTON———
R/WR/WR/WR/WR/WR/W———
POR00000———
Bit 7 PTPAU: PTM counter pause control
0: Run
1: Pause
The counter can be paused by setting this bit high. Clearing the bit to zero restores
normal counter operation. When in a Pause condition the PTM will remain powered up
and continue to consume power. The counter will retain its residual value when this bit
changes from low to high and resume counting from this value when the bit changes to
a low value again.
These three bits are used to select the clock source for the PTM. The external pin clock
source can be chosen to be active on the rising or falling edge. The clock source f
the system clock, while fH and f
are other internal clocks, the details of which can
SUB
be found in the oscillator section.
Bit 3 PTON: PTM counter on/off control
0: Off
1: On
This bit controls the overall on/off function of the PTM. Setting the bit high enables
the counter to run while clearing the bit disables the PTM. Clearing this bit to zero
will stop the counter from counting and turn off the PTM which will reduce its power
consumption. When the bit changes state from low to high the internal counter value
will be reset to zero, however when the bit changes from high to low, the internal
counter will retain its residual value until the bit returns high again. If the PTM is in
the Compare Match Output Mode, PWM output Mode or Single Pulse Output Mode
then the PTM output pin will be reset to its initial condition, as specied by the PTOC
bit, when the PTON bit changes from low to high.
Bit 2~0 Unimplemented, read as “0”
SYS
is
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
• PTMC1 Register
Bit76543210
NamePTM1PTM0PTIO1PTIO0PTOCPTPOL PTCAPTS PTCCLR
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~6 PTM1~PTM0: Select PTM Operating Mode
00: Compare Match Output Mode
01: Capture Input Mode
10: PWM Output Mode or Single Pulse Output Mode
11: Timer/Counter Mode
These bits set the required operating mode for the PTM. To ensure reliable operation
the PTM should be switched off before any changes are made to the PTM1 and PTM0
bits. In the Timer/Counter Mode, the PTM output pin state is undened.
Bit 5~4 PTIO1~PTIO0: PTM external pin PTP, PTPI or PTCK function selection
Compare Match Output Mode
00: No change
01: Output low
10: Output high
11: Toggle output
PWM Output Mode/Single Pulse Output Mode
00: PWM output inactive state
01: PWM output active state
10: PWM output
11: Single Pulse Output
Capture Input Mode
00: Input capture at rising edge of PTPI or PTCK
01: Input capture at falling edge of PTPI or PTCK
10: Input capture at rising/falling edge of PTPI or PTCK
11: Input capture disabled
Timer/Counter Mode
Unused
These two bits are used to determine how the PTM external pin changes state when a
certain condition is reached. The function that these bits select depends upon in which
mode the PTM is running.
In the Compare Match Output Mode, the PTIO1 and PTIO0 bits determine how the
PTM output pin changes state when a compare match occurs from the Comparator A.
The PTM output pin can be set to switch high, switch low or to toggle its present state
when a compare match occurs from the Comparator A. When the bits are both zero,
then no change will take place on the output. The initial value of the PTM output pin
should be set using the PTOC bit in the PTMC1 register. Note that the output level
requested by the PTIO1 and PTIO0 bits must be different from the initial value setup
using the PTOC bit otherwise no change will occur on the PTM output pin when a
compare match occurs. After the PTM output pin changes state, it can be reset to its
initial level by changing the level of the PTON bit from low to high.
In the PWM Output Mode, the PTIO1 and PTIO0 bits determine how the TM output
pin changes state when a certain compare match condition occurs. The PTM output
function is modified by changing these two bits. It is necessary to only change the
values of the PTIO1 and PTIO0 bits only after the PTM has been switched off.
Unpredictable PWM outputs will occur if the PTIO1 and PTIO0 bits are changed
when the PTM is running.
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Bit 3 PTOC: PTM PTP output control
Compare Match Output Mode
0: Initial low
1: Initial high
PWM Output Mode/Single Pulse Output Mode
0: Active low
1: Active high
This is the output control bit for the PTM output pin. Its operation depends upon
whether PTM is being used in the Compare Match Output Mode or in the PWM
Output Mode/Single Pulse Output Mode. It has no effect if the PTM is in the Timer/
Counter Mode. In the Compare Match Output Mode it determines the logic level of
the PTM output pin before a compare match occurs. In the PWM Output Mode it
determines if the PWM signal is active high or active low. In the Single Pulse Output
Mode it determines the logic level of the PTM output pin when the PTON bit changes
from low to high.
Bit 2 PTPOL: PTM PTP output polarity control
0: Non-invert
1: Invert
This bit controls the polarity of the PTP output pin. When the bit is set high the PTM
output pin will be inverted and not inverted when the bit is zero. It has no effect if the
PTM is in the Timer/Counter Mode.
Bit 1 PTCAPTS: PTM capture trigger source selection
0: From PTPI pin
1: From PTCK pin
Bit 0 PTCCLR: PTM counter clear condition selection
0: Comparator P match
1: Comparator A match
This bit is used to select the method which clears the counter. Remember that the
Periodic TM contains two comparators, Comparator A and Comparator P, either of
which can be selected to clear the internal counter. With the PTCCLR bit set high,
the counter will be cleared when a compare match occurs from the Comparator A.
When the bit is low, the counter will be cleared when a compare match occurs from
the Comparator P or with a counter overow. A counter overow clearing method can
only be implemented if the CCRP bits are all cleared to zero. The PTCCLR bit is not
used in the PWM Output, Single Pulse Output or Capture Input Mode.
• PTMDL Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WRRRRRRRR
POR00000000
Bit 7~0 D7~D0: PTM Counter Low Byte Register bit 7 ~ bit 0
PTM 10-bit Counter bit 7 ~ bit 0
• PTMDH Register
Bit76543210
Name——————D9D8
R/W——————RR
POR——————00
Bit 7~2 Unimplemented, read as “0”
Bit 1~0 D9~D8: PTM Counter High Byte Register bit 1 ~ bit 0
PTM 10-bit Counter bit 9 ~ bit 8
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
• PTMAL Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~0 D7~D0: PTM CCRA Low Byte Register bit 7 ~ bit 0
PTM 10-bit CCRA bit 7 ~ bit 0
• PTMAH Register
Bit76543210
Name——————D9D8
R/W——————R/WR/W
POR——————00
Bit 7~2 Unimplemented, read as “0”
Bit 1~0 D9~D8: PTM CCRA High Byte Register bit 1 ~ bit 0
PTM 10-bit CCRA bit 9 ~ bit 8
• PTMRPL Register
Bit76543210
NamePTRP7PTRP6PTRP5PTRP4PTRP3PTRP2PTRP1PTRP0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~0 PTRP7~PTRP0: PTM CCRP Low Byte Register bit 7 ~ bit 0
PTM 10-bit CCRP bit 7 ~ bit 0
• PTMRPH Register
Bit76543210
Name——————PTRP9PTRP8
R/W——————R/WR/W
POR——————00
Bit 7~2 Unimplemented, read as “0”
Bit 1~0 PTRP9~PTRP8: PTM CCRP High Byte Register bit 1 ~ bit 0