Induction Cooker Flash MCU: Revision: V1.30 Date: February 07, 2022
Induction Cooker Flash MCU: Revision: V1.30 Date: February 07, 2022
Induction Cooker Flash MCU: Revision: V1.30 Date: February 07, 2022
HT45F0058
Table of Contents
Features.................................................................................................................. 6
CPU Features................................................................................................................................6
Peripheral Features........................................................................................................................6
General Description............................................................................................... 7
Block Diagram........................................................................................................ 7
Pin Assignment...................................................................................................... 8
Pin Description...................................................................................................... 8
Absolute Maximum Ratings................................................................................ 10
D.C. Characteristics............................................................................................. 10
Operating Voltage Characteristics................................................................................................10
Operating Current Characteristics................................................................................................10
Standby Current Characteristics..................................................................................................10
A.C. Characteristics............................................................................................. 11
High Speed Internal Oscillator – HIRC – Frequency Accuracy.................................................... 11
Low Speed Internal Oscillator Characteristics – LIRC................................................................. 11
Operating Frequency Characteristic Curve.................................................................................. 11
System Start Up Time Characteristics.........................................................................................12
Input/Output Characteristics.............................................................................. 12
A/D Converter Electrical Characteristics........................................................... 13
Memory Characteristics...................................................................................... 13
LVD & LVR Electrical Characteristics................................................................ 13
Reference Voltage Characteristics..................................................................... 14
Over Voltage Protection Electrical Characteristics.......................................... 15
Operational Amplifier Electrical Characteristics.............................................. 15
Comparator Electrical Characteristics.............................................................. 16
PPG Electrical Characteristics........................................................................... 17
Power-on Reset Characteristics......................................................................... 17
System Architecture............................................................................................ 18
Clocking and Pipelining................................................................................................................18
Program Counter..........................................................................................................................19
Stack............................................................................................................................................19
Arithmetic and Logic Unit – ALU..................................................................................................20
Data Memory........................................................................................................ 24
Structure.......................................................................................................................................24
Data Memory Addressing.............................................................................................................25
General Purpose Data Memory...................................................................................................25
Special Purpose Data Memory....................................................................................................25
Oscillators............................................................................................................ 36
Oscillator Overview......................................................................................................................36
System Clock Configurations.......................................................................................................36
Internal High Speed RC Oscillator – HIRC..................................................................................37
Internal 32kHz Oscillator – LIRC..................................................................................................37
Watchdog Timer................................................................................................... 45
Watchdog Timer Clock Source.....................................................................................................45
Watchdog Timer Control Register................................................................................................45
Watchdog Timer Operation..........................................................................................................46
Input/Output Ports............................................................................................... 53
Pull-high Resistors.......................................................................................................................53
Port A Wake-up............................................................................................................................54
I/O Port Control Registers............................................................................................................54
Pin-shared Functions...................................................................................................................54
I/O Pin Structures.........................................................................................................................57
Programming Considerations.......................................................................................................57
Timer/Event Counters......................................................................................... 58
Configuring the Timer/Event Counter Input Clock Source........................................................... 59
Timer/Event Counter Registers – TMR0, TMR1, TMR2............................................................... 60
Timer/Event Counter Control Registers – TMR0C, TMR1C, TMR2C..........................................60
Timer/Event Counter Operating Modes.......................................................................................62
I/O Interfacing...............................................................................................................................64
Programming Considerations.......................................................................................................65
Timer Program Example..............................................................................................................66
LVD Operation............................................................................................................................107
LVD Operation............................................................................................................................107
Interrupts............................................................................................................ 108
Interrupt Registers......................................................................................................................108
Interrupt Operation..................................................................................................................... 111
OVP Interrupt............................................................................................................................. 112
Comparator Interrupts................................................................................................................ 112
A/D Converter Interrupt.............................................................................................................. 113
EEPROM Interrupt..................................................................................................................... 113
LVD Interrupt.............................................................................................................................. 113
Timer/Event Counter Interrupts.................................................................................................. 113
PPGINT Interrupt....................................................................................................................... 113
PPGTIMER Interrupt.................................................................................................................. 114
PPGATCD Interrupt.................................................................................................................... 114
Interrupt Wake-up Function........................................................................................................ 114
Programming Considerations..................................................................................................... 114
Features
CPU Features
• Operating voltage
♦ fSYS=16MHz: 3.3V~5.5V
• Up to 0.25μs instruction cycle with 16MHz system clock at VDD=5V
• Power down and wake-up functions to reduce power consumption
• Oscillator types
♦ Internal High Speed 16MHz RC – HIRC
♦ Internal Low Speed 32kHz RC– LIRC
• Multi-mode operation: FAST, SLOW, IDLE and SLEEP
• Fully integrated internal oscillators require no external components
• All instructions executed in 1~3 instruction cycles
• Table read instructions
• 115 powerful instructions
• 8-level subroutine nesting
• Bit manipulation instruction
Peripheral Features
• Flash Program Memory: 4K×16
• Data Memory: 256×8
• True EEPROM Memory: 32×8
• Watchdog Timer function
• 13 bidirectional I/O lines
• 10 external channel 12-bit resolution A/D converter with Internal Reference Voltage VBG
• 9-bit programmable pulse generator
♦ Pulse width limit function
♦ Two sets of 9-bit PPG preload registers and two sets of 9-bit timer approach registers
♦ Non-retriggered control from 8-bit Timer/Event Counter 1
♦ Active high pulse, active low pulse, force low or force high output
• Three 8-bit programmable timer/event counters
♦ Timer/Event Counter 0 can be configured to count synchronism pulse number or measure
synchronism pulse high or low period
♦ Timer/Event Counter 1 can be configured to implement PPG non-retriggered function
• Four comparators
• Single Operational Amplifier – OPAMP
• Single Over Voltage Protection – OVP
• Peripheral clock output
• Low voltage reset function
• Low voltage detect function
• Package types: 16-pin NSOP
General Description
The HT45F0058 is a Flash Memory type 8-bit high performance RISC architecture microcontroller
especially designed for induction cooker applications.
For memory features, the Flash Memory offers users the convenience of multi-programming
features. Other memory includes an area of RAM Data Memory as well as an area of true EEPROM
memory for storage of non-volatile data such as serial numbers, calibration data etc.
Analog features include a multi-channel 12-bit A/D converter, an OPAMP and multiple comparators
functions. Protective features such as an internal Watchdog Timer, Low Voltage Reset and Low
Voltage Detector coupled with excellent noise immunity and ESD protection ensure that reliable
operation is maintained in hostile electrical environments.
The device also includes fully integrated high and low speed oscillators which require no external
components for their implementation. The ability to operate and switch dynamically between a range
of operating modes using different clock sources gives users the ability to optimise microcontroller
operation and minimise power consumption.
The inclusion of flexible I/O programming features, Timers, a Programmable Pulse Generator, an
Over Voltage Protection, a Peripheral Clock Output along with many other features ensure that the
device will find excellent use in induction cooker applications.
Block Diagram
12-bit AN0~AN9
LIRC
32kHz ADC
Bus
1.04V
MUX
MUX
Pin-Shared
Analog Digital OPOUT
HIRC With Port A & B
Converter OPROUT
16MHz
AVSS
VDD/AVDD VDD/AVDD Clock System
OPINN/OPINP
VSS/AVSS VSS/AVSS OPAMP
OPOUT
OPROUT
+ OVPI1
PPG Reload
_
Pin-Shared
Timer Ctrl OVP 8-bit With Port A & B
DAC
CP1N
C1VOD _
RLBF Ctrl Debounce
+ VR1
CMP1
C1VO
PPG Start OPOUT
C3VOD _
Debounce
+ VR4
CMP3
PPG Stop C3VO
+ CP0P
PPG Output CP0N
Trigger
_
MUX
CP2N
C2VOD _ VR3
Debounce
+ CP2P
CMP2
VR2
C2VO
Analog Peripherals
Pin-Shared
With Port A & B
PPG
: Pin-Shared Node
Pin Assignment
PPG 1 16 PB0/OPINN/OPINP
PB3/PPGIN/CP0N/AN0 2 15 PA1/OPOUT/AN8
PA3/TC0/CP0P/AN9 3 14 PA4/C2VO/AN4/VREF
PA6/CP2N/AN6 4 13 PB4/C0VO/AN3
PA7/CP2P/AN5 5 12 PA0/ICPDA/OCDSDA
PA5/CP1N/AN7 6 11 PB1/PCK/C1VO/C3VO
PB2/OVPI1/AN1 7 10 PA2/OPROUT/AN2/ICPCK/OCDSCK
VSS/AVSS 8 9 VDD/AVDD
HT45F0058/HT45V0058
16 NSOP-A
Note: 1. If the pin-shared pin functions have multiple outputs simultaneously, 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 HT45V0058 device which is the OCDS EV chip for the HT45F0058 device.
Pin Description
With the exception of the power pins and the PPG output pin, all pins on the device can be
referenced by their Port name, e.g. PA0, PA1 etc., which refer to the digital I/O function of the pins.
However these Port pins are also shared with other function such as the Analog to Digital Converter
etc. The function of each pin is listed in the following table, however the details behind how each
pin is configured is contained in other sections of the datasheet.
Pin Name Function OPT I/T O/T Descriptions
PAPU General purpose I/O. Register enabled pull-up
PA0 ST CMOS
PA0/ICPDA/ PAWU and wake-up
OCDSDA ICPDA — ST CMOS ICP data/address
OCDSDA — ST CMOS OCDS data/address pin, for EV chip only
PAPU
General purpose I/O. Register enabled pull-up
PA1 PAWU ST CMOS
and wake-up
PA1/OPOUT/AN8 PAS0
OPOUT PAS0 — AN OPAMP output pin
AN8 PAS0 AN — A/D converter external input 8
PAPU
General purpose I/O. Register enabled pull-up
PA2 PAWU ST CMOS
and wake-up
PAS0
PA2/OPROUT/
AN2/ICPCK/ OPROUT PAS0 — AN OPAMP output pin
OCDSCK AN2 PAS0 AN — A/D converter external input 2
ICPCK — ST — ICP clock pin
OCDSCK — ST — OCDS clock pin, for EV chip only
PAPU
General purpose I/O. Register enabled pull-up
PA3 PAWU ST CMOS
and wake-up
PA3/TC0/CP0P/ PAS0
AN9 TC0 PAS0 ST — Timer/Event Counter 0clock input
CP0P PAS0 AN — Comparator 0 non-inverting input
AN9 PAS0 AN — A/D converter external input 9
PAPU
General purpose I/O. Register enabled pull-up
PA4 PAWU ST CMOS
and wake-up
PA4/C2VO/AN4/ PAS1
VREF C2VO PAS1 — CMOS Comparator 2 output
AN4 PAS1 AN — A/D converter external input 4
VREF PAS1 AN — A/D converter external reference voltage input
Note: These are stress ratings only. Stresses exceeding the range specified under “Absolute Maximum
Ratings” may cause substantial damage to the device. Functional operation of the device at
other conditions beyond those listed in the specification is not implied and prolonged exposure
to extreme conditions may affect device reliability.
D.C. Characteristics
For data in the following tables, note that factors such as oscillator type, operating voltage, operating
frequency, pin load conditions, temperature and program instruction type, etc., can all exert an
influence on the measured values.
Note: When using the characteristic table data, the following notes should be taken into consideration:
1. Any digital inputs are setup in a non-floating condition.
2. All measurements are taken under conditions of no load and with all peripherals in an off state.
3. There are no DC current paths.
4. All Operating Current values are measured using a continuous NOP instruction program loop.
Note: When using the characteristic table data, the following notes should be taken into consideration:
A.C. Characteristics
For data in the following tables, note that factors such as oscillator type, operating voltage, operating
frequency and temperature etc., can all exert an influence on the measured values.
Note: 1. The 5V values for VDD are provided as this is the fixed voltage at which the HIRC frequency is trimmed by
the writer.
2. The row below the 5V trim voltage row is provided to show the values for the specific VDD range operating
voltage.
16MHz
~
~
~
~
~
~
3.3V 5.5V
Operating Voltage
Note: 1. For the System Start-up time values, whether fSYS is on or off depends upon the mode type and the chosen
fSYS system oscillator. Details are provided in the System Operating Modes section.
2. The time units, shown by the symbols tHIRC, tSYS etc. are the inverse of the corresponding frequency values
as provided in the above tables. For example tHIRC=1/fHIRC, tSYS=1/fSYS etc.
3. If the LIRC is used as the system clock, then an additional LIRC start up time, tSTART, as provided in the
LIRC frequency table, must be added to the tSST time in the table above.
4. The System Speed Switch Time is effectively the time taken for the newly activated oscillator to start up.
Input/Output Characteristics
Ta=25°C
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
5V 0 — 1.5
VIL Input Low Voltage for I/O Ports or Input Pins — V
— 0 — 0.2VDD
5V 3.5 — 5.0
VIH Input High Voltage for I/O Ports or Input Pins — V
— 0.8VDD — VDD
IOL Sink Current for I/O Ports 5V VOL=0.1VDD 32 65 — mA
IOH Source Current for I/O Ports 5V VOH=0.9VDD -8 -16 — mA
RPH Pull-High Resistance for I/O Ports (Note) 5V — 10 30 50 kΩ
tTC TC0 Input Pin Minimum Pulse Width — — 25 — — ns
Note: The RPH internal pull high resistance value is calculated by connecting to ground and enabling the input pin
with a pull-high resistor and then measuring the pin current at the specified supply voltage level. Dividing
the voltage by this measured current provides the RPH value.
Memory Characteristics
Ta=25°C
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
VRW VDD for Read / Write — — VDDmin — VDDmax V
Flash Program Memory / Data EEPROM Memory
tDEW Write Cycle Time – Data EEPROM Memory — — — 4 6 ms
Cell Endurance – Flash Program Memory — — 10K — —
EP E/W
Cell Endurance – Data EEPROM Memory — — 100K — —
tRETD ROM Data Retention Time — — — 40 — Year
RAM Data Memory
VDR RAM Data Retention Voltage — Device in SLEEP Mode 1.0 — — V
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
LVD enable, voltage select 2.0V
— 2.0
Ta=-40°C~85°C
LVD enable, voltage select 2.2V
— 2.2
Ta=-40°C~85°C
LVD enable, voltage select 2.4V
— 2.4
Ta=-40°C~85°C
LVD enable, voltage select 2.7V
— 2.7
Ta=-40°C~85°C
VLVD Low Voltage Detection Voltage -5% +5% V
LVD enable, voltage select 3.0V
— 3.0
Ta=-40°C~85°C
LVD enable, voltage select 3.3V
— 3.3
Ta=-40°C~85°C
LVD enable, voltage select 3.6V
— 3.6
Ta=-40°C~85°C
LVD enable, voltage select 4.0V
— 4.0
Ta=-40°C~85°C
LVD enable, LVR enable,
5V — 20 25 μA
VBGEN=0
ILVRLVDBG Operating Current
LVD enable, LVR enable,
5V — 180 200 μA
VBGEN=1
For LVR enable, VBGEN=0,
tLVDS LVDO Stable Time — — — 20 μs
LVD off → on, Ta=-40°C~85°C
TLVR[1:0]=00B 120 240 480 μs
Minimum Low Voltage Width to TLVR[1:0]=01B 0.5 1.0 2.0 ms
tLVR —
Reset TLVR[1:0]=10B 1 2 4 ms
TLVR[1:0]=11B 2 4 8 ms
Minimum Low Voltage Width to
tLVD — — 60 120 240 μs
Interrupt
Note: The VBG voltage is used as the A/D converter internal signal input.
Note: 1. If the OPAMP is configured as an over resistance form, it will measure using the unit gain.
2. If the OPAMP is configured as a PGA form, it will measure using the internal gain. The PGA current
consumption includes the amplifying resistance current consumption.
3. The PGA gain accuracy is guaranteed only when the PGA output voltage meets the VOR specification.
4. If VIN is negative, it should not be lower than -0.2V to avoid leakage current.
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
0.600
0.625
0.650
Reference Voltage for 0.675
VR4 5V — -5% +5% VDD
Comparator 3 0.700
0.725
0.750
0.775
VDD
tPOR RRPOR
VPOR
Time
System Architecture
A key factor in the high-performance features of the Holtek range of microcontrollers is attributed to
their internal system architecture. The range of the device take advantage of the usual features found
within RISC microcontrollers providing increased speed of operation and enhanced performance.
The pipelining scheme is implemented in such a way that instruction fetching and instruction
execution are overlapped, hence instructions are effectively executed in one or two cycles for
most of the standard or extended instructions respectively, with the exception of branch or call
instructions which need one more cycle. An 8-bit wide ALU is used in practically all instruction set
operations, which carries out arithmetic operations, logic operations, rotation, increment, decrement,
branch decisions, etc. The internal data path is simplified by moving data through the Accumulator
and the ALU. Certain internal registers are implemented in the Data Memory and can be directly
or indirectly addressed. The simple addressing methods of these registers along with additional
architectural features ensure that a minimum of external components is required to provide a
functional I/O and A/D control system with maximum reliability and flexibility. This makes the
device suitable for low-cost, high-volume production for controller applications.
fSYS
(System Clock)
Phase Clock T1
Phase Clock T2
Phase Clock T3
Phase Clock T4
Instruction Fetching
Program Counter
During program execution, the Program Counter is used to keep track of the address of the next
instruction to be executed. It is automatically incremented by one each time an instruction is executed
except for instructions, such as “JMP” or “CALL” that demand a jump to a non-consecutive Program
Memory address. Only the lower 8 bits, known as the Program Counter Low Register, are directly
addressable by the application program.
When executing instructions requiring jumps to non-consecutive addresses such as a jump instruction,
a subroutine call, interrupt or reset, etc., the microcontroller manages program control by loading
the required address into the Program Counter. For conditional skip instructions, once the condition
has been met, the next instruction, which has already been fetched during the present instruction
execution, is discarded and a dummy cycle takes its place while the correct instruction is obtained.
Program Counter
Program Counter High Byte PCL Register
PC11~PC8 PCL7~PCL0
Program Counter
The lower byte of the Program Counter, known as the Program Counter Low register or PCL, is
available for program control and is a readable and writeable register. By transferring data directly
into this register, a short program jump can be executed directly; however, as only this low byte
is available for manipulation, the jumps are limited to the present page of memory that is 256
locations. When such program jumps are executed it should also be noted that a dummy cycle
will be inserted. Manipulating the PCL register may cause program branching, so an extra cycle is
needed to pre-fetch.
Stack
This is a special part of the memory which is used to save the contents of the Program Counter
only. The stack is organized into 8 levels and neither part of the data nor part of the program space,
and is neither readable nor writeable. The activated level is indexed by the Stack Pointer, and is
neither readable nor writeable. At a subroutine call or interrupt acknowledge signal, the contents of
the Program Counter are pushed onto the stack. At the end of a subroutine or an interrupt routine,
signaled by a return instruction, RET or RETI, the Program Counter is restored to its previous value
from the stack. After a device reset, the Stack Pointer will point to the top of the stack.
If the stack is full and an enabled interrupt takes place, the interrupt request flag will be recorded but
the acknowledge signal will be inhibited. When the Stack Pointer is decremented, by RET or RETI,
the interrupt will be serviced. This feature prevents stack overflow allowing the programmer to use
the structure more easily. However, when the stack is full, a CALL subroutine instruction can still
be executed which will result in a stack overflow. Precautions should be taken to avoid such cases
which might cause unpredictable program branching.
If the stack is overflow, the first Program Counter save in the stack will be lost.
Program Counter
Stack Level 2
Stack
Stack Level 3
Pointer Program Memory
:
:
:
Bottom of Stack Stack Level 8
Structure
The Program Memory has a capacity of 4K×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 setup in any location within the Program Memory, is addressed by a separate table pointer register.
000H
Initialisation Vector
004H
Interrupt Vectors
034H
n00H
Look-up Table
nFFH
FFFH 16 bits
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 defined as a look-up table where programmers can
store fixed data. To use the look-up table, the table pointer must first be setup by placing the address
of the look up data to be retrieved in the table pointer register, TBLP and TBHP. These registers
define 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 corresponding table read instruction such as “TABRD [m]” or “TABRDL [m]” 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
defined Data Memory register [m] as specified in the instruction. The higher order table data byte
from the Program Memory will be transferred to the TBLH special register. Any unused bits in this
transferred higher order byte will be read as “0”.
The accompanying diagram illustrates the addressing data flow of the look-up table.
Program Memory
Last Page or
Address
TBHP Register Data
16 bits
TBLP Register
User Selected
Register TBLH Register
High Byte Low Byte
The Program Memory can be programmed serially in-circuit using this 4-wire interface. Data
is downloaded and uploaded serially on a single pin with an additional line for the clock. Two
additional lines are required for the power supply and one line for the reset. The technical details
regarding the in-circuit programming of the device is beyond the scope of this document and will be
supplied in supplementary literature.
During the programming process, the user must take care of the ICPDA and ICPCK pins for data
and clock programming purposes to ensure that no other outputs are connected to these two pins.
Writer_VDD VDD/AVDD
ICPDA PA0
ICPCK PA2
Writer_VSS VSS/AVSS
* *
To other Circuit
Note: * may be resistor or capacitor. The resistance of * must be greater than 1kΩ or the capacitance
of * must be less than 1nF.
shared with the OCDSDA and OCDSCK pins in the device will have no effect in the EV chip.
However, the two OCDS pins which are pin-shared with the ICP programming pins are still used
as the Flash Memory programming pins for ICP. For more detailed OCDS information, refer to the
corresponding document named “Holtek e-Link for 8-bit MCU OCDS User’s Guide”.
Holtek e-Link Pins EV Chip Pins Pin Description
OCDSDA OCDSDA On-Chip Debug Support Data/Address input/output
OCDSCK OCDSCK On-Chip Debug Support Clock input
VDD VDD/AVDD Power Supply
VSS VSS/AVSS Ground
Data Memory
The Data Memory is a volatile area of 8-bit wide RAM internal memory and is the location where
temporary information is stored.
Categorized into two types, the first of these is an area of RAM, known as the Special Function Data
Memory. These registers have fixed locations and are necessary for correct operation of the device.
Many of these registers can be read from and written to directly under program control, however,
some remain protected from user manipulation. The second area of Data Memory is known as the
General Purpose Data Memory, which is reserved for general purpose use. All locations within this
area are read and write accessible under program control.
Structure
The Data Memory is subdivided into two sectors, all of which are implemented in 8-bit wide RAM.
Each of the Data Memory Sector is categorized into two types, the special Purpose Data Memory and
the General Purpose Data Memory. Switching between the different Data Memory sectors is achieved
by setting the Memory Pointers to the correct value if using the indirectly accessing method.
The address range of the Special Purpose Data Memory for the device is from 00H to 7FH while the
General Purpose Data Memory address range is from 80H to FFH.
Special Purpose Data Memory General Purpose Data Memory
Located Sectors Capacity Sector: Address
0: 80H~FFH
0~1 256×8
1: 80H~FFH
Data Memory Summary
00H
Special Purpose
Data Memory
7FH
80H
General Purpose
Data Memory
FFH Sector 0
Sector 1
Example 1
data .section ´data´
adres1 db ?
adres2 db ?
adres3 db ?
adres4 db ?
block db ?
code .section at 0 ´code´
org 00h
start:
mov a, 04h ; setup size of block
mov block, a
mov a, offset adres1 ; Accumulator loaded with first RAM address
mov mp0, a ; setup memory pointer with first RAM address
loop:
clr IAR0 ; clear the data at address defined by MP0
inc mp0 ; increase memory pointer
sdz block ; check if last memory location has been cleared
jmp loop
continue:
Example 2
rambank 1 data1
data1 .section at 080H ‘data’
adres1 db ?
adres2 db ?
adres3 db ?
adres4 db ?
data .section ‘data’
block db ?
code .section at 0 ´code´
org 00h
start:
mov a, 04h ; setup size of block
mov block, a
mov a, 01h ; setup the memory sector
mov mp1h, a
mov a, offset adres1 ; Accumulator loaded with first RAM address
mov mp1l, a ; setup memory pointer with first RAM address
loop:
clr IAR1 ; clear the data at address defined by MP1L
inc mp1l ; increment memory pointer MP1L
sdz block ; check if last memory location has been cleared
jmp loop
continue:
The important point to note here is that in the examples shown above, no reference is made to
specific Data Memory addresses.
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.
• ORMC Register
Bit 7 6 5 4 3 2 1 0
Name ORMC7 ORMC6 ORMC5 ORMC4 ORMC3 ORMC2 ORMC1 ORMC0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• STATUS Register
Bit 7 6 5 4 3 2 1 0
Name SC CZ TO PDF OV Z AC C
R/W R/W R/W R R R/W R/W R/W R/W
POR x x 0 0 x x x x
“x”: Unknown
Bit 7 SC: The result of the “XOR” operation which is performed by the OV flag and the
MSB of the instruction operation result
Bit 6 CZ: The operational result of different flags for different instructions
For SUB/SUBM/LSUB/LSUBM instructions, the CZ flag is equal to the Z flag.
For SBC/SBCM/LSBC/LSBCM instructions, the CZ flag is the “AND” operation result
which is performed by the previous operation CZ flag and current operation zero flag.
For other instructions, the CZ flag will not be affected.
Bit 5 TO: Watchdog Time-out flag
0: After power up or executing the “CLR WDT” or “HALT” instruction
1: A watchdog time-out occurred
Bit 4 PDF: Power down flag
0: After power up or executing the “CLR WDT” instruction
1: By executing the “HALT” instruction
Bit 3 OV: Overflow flag
0: No overflow
1: An operation results in a carry into the highest-order bit but not a carry out of the
highest-order bit or vice versa
Bit 2 Z: Zero flag
0: The result of an arithmetic or logical operation is not zero
1: The result of an arithmetic or logical operation is zero
Bit 1 AC: Auxiliary flag
0: No auxiliary carry
1: 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
Bit 0 C: Carry flag
0: No carry-out
1: An operation results in a carry during an addition operation or if a borrow does
not take place during a subtraction operation
The “C” flag is also affected by a rotate through carry instruction.
EEPROM Registers
Three registers control the overall operation of the internal EEPROM Data Memory. These are the
address register, EEA, the data register, EED and a single control register, EEC. As both the EEA
and EED registers are located in Sector 0, they can be directly accessed in the same way as any other
Special Function Register. The EEC register however, being located in Sector 1, can only read from
or written to indirectly using the MP1L/MP1H or MP2L/MP2H Memory Pointer pairs and Indirect
Addressing Register, IAR1/IAR2. Because the EEC control register is located at address 40H in
Sector 1, the MP1L or MP2L Memory Pointer must first be set to the value 40H and the MP1H or
MP2H Memory Pointer high byte set to the value, 01H, before any operations on the EEC register
are executed.
Register Bit
Name 7 6 5 4 3 2 1 0
EEA — — — EEA4 EEA3 EEA2 EEA1 EEA0
EED D7 D6 D5 D4 D3 D2 D1 D0
EEC — — — — WREN WR RDEN RD
EEPROM Register List
• EEA Register
Bit 7 6 5 4 3 2 1 0
Name — — — EEA4 EEA3 EEA2 EEA1 EEA0
R/W — — — R/W R/W R/W R/W R/W
POR — — — 0 0 0 0 0
• EED Register
Bit 7 6 5 4 3 2 1 0
Name D7 D6 D5 D4 D3 D2 D1 D0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• EEC Register
Bit 7 6 5 4 3 2 1 0
Name — — — — WREN WR RDEN RD
R/W — — — — R/W R/W R/W R/W
POR — — — — 0 0 0 0
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.
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 interrupt request flag will be set. If the global and EEPROM
are enabled and the stack is not full, a jump to the EEPROM interrupt vector will take place. When
the EEPROM Interrupt is serviced, the EEPROM Interrupt request flag, 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.
Programming Examples
Oscillators
Various oscillator options offer the user a wide range of functions according to their various
application requirements. The flexible features of the oscillator functions ensure that the best
optimisation can be achieved in terms of speed and power saving. Oscillator selections and operation
are selected only through the application program by using some control registers.
Oscillator Overview
In addition to being the source of the main system clock the oscillators also provide clock sources
for the Watchdog Timer and Time Base Interrupts. Fully integrated internal oscillators, requiring no
external components, are provided to form a wide range of both fast and slow system oscillators.
The higher frequency oscillators provide higher performance but carry with it the disadvantage of
higher power requirements, while the opposite is of course true for the lower frequency oscillators.
With the capability of dynamically switching between fast and slow system clock, the device has the
flexibility to optimize the performance/power ratio, a feature especially important in power sensitive
portable applications.
Type Name Frequency
Internal High Speed RC HIRC 16MHz
Internal Low Speed RC LIRC 32kHz
Oscillator Types
fH
fSUB
Low Speed
Oscillator
CKS2~CKS0
LIRC
IDLE2 fSUB
SLEEP
fLIRC
System Clock Configurations
System Clocks
The device has many different clock sources for both the CPU and peripheral function operation. By
providing the user with a wide range of clock options using register programming, a clock system
can be configured to obtain maximum application performance.
The main system clock, can come from a high frequency, fH, or low frequency, fSUB, source, and is
selected using the CKS2~CKS0 bits in the SCC register. The high frequency clock is sourced from
the HIRC oscillator, while the low frequency clock source is sourced from the internal clock fSUB
which is sourced by the LIRC oscillator. The other choice, which is a divided version of the high
speed system oscillator has a range of fH/2~fH/64.
fSUB
Low Speed
Oscillator
CKS2~CKS0
LIRC
IDLE2 fSUB
SLEEP
fSYS
fSYS/4 fPSC
fSUB Prescaler Timer n
fLIRC
WDT
TnPSC[2:0]
CLKSEL[1:0]
Note: When the system clock source fSYS is switched to fSUB from fH, the high speed oscillator will
stop to conserve the power or continue to oscillate to provide the clock source, fH~fH/64, for
peripheral circuit to use, which is determined by configuring the corresponding high speed
oscillator enable control bit.
FAST Mode
This is one of the main operating modes where the microcontroller has all of its functions
operational and where the system clock is provided the high speed oscillator. This mode operates
allowing the microcontroller to operate normally with a clock source from the HIRC high speed
oscillator. The high speed oscillator will however first be divided by a ratio ranging from 1 to 64,
the actual ratio being selected by the CKS2~CKS0 bits in the SCC register. Although a high speed
oscillator is used, running the microcontroller at a divided clock ratio reduces the operating current.
SLOW Mode
This is also a mode where the microcontroller operates normally although now with a slower speed
clock source. The clock source used will be from fSUB. The fSUB clock is derived from the LIRC
oscillator.
SLEEP Mode
The SLEEP Mode is entered when a HALT instruction is executed and when the FHIDEN and
FSIDEN bit both are low. In the SLEEP mode the CPU will be stopped. The fSUB clock provided to
the peripheral function will also be stopped. However the fLIRC clock still continues to operate since
the WDT function is enabled.
IDLE0 Mode
The IDLE0 Mode is entered when a HALT instruction is executed and when the FHIDEN bit in
the SCC register is low and the FSIDEN bit in the SCC register is high. In the IDLE0 Mode the
CPU will be switched off but the low speed oscillator will be turned on to drive some peripheral
functions.
IDLE1 Mode
The IDLE1 Mode is entered when a HALT instruction is executed and when the FHIDEN bit in the
SCC register is high and the FSIDEN bit in the SCC register is high. In the IDLE1 Mode the CPU
will be switched off but both the high and low speed oscillators will be turned on to provide a clock
source to keep some peripheral functions operational.
IDLE2 Mode
The IDLE2 Mode is entered when a HALT instruction is executed and when the FHIDEN bit in the
SCC register is high and the FSIDEN bit in the SCC register is low. In the IDLE2 Mode the CPU
will be switched off but the high speed oscillator will be turned on to provide a clock source to keep
some peripheral functions operational.
Control Registers
The SCC and HIRCC registers are used to control the system clock and the HIRC oscillator
configurations.
Register Bit
Name 7 6 5 4 3 2 1 0
SCC CKS2 CKS1 CKS0 — — — FHIDEN FSIDEN
HIRCC — — — — — — HIRCF HIRCEN
System Operating Mode Control Register List
• SCC Register
Bit 7 6 5 4 3 2 1 0
Name CKS2 CKS1 CKS0 — — — FHIDEN FSIDEN
R/W R/W R/W R/W — — — R/W R/W
POR 0 0 1 — — — 0 0
• HIRCC Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — HIRCF HIRCEN
R/W — — — — — — R R/W
POR — — — — — — 0 1
FAST SLOW
fSYS=fH~fH/64 fSYS=fSUB
fH on fSUB on
CPU run CPU run
fSYS on fSYS on
fSUB on fH on/off
SLEEP IDLE0
HALT instruction executed HALT instruction executed
CPU stop CPU stop
FHIDEN=0 FHIDEN=0
FSIDEN=0 FSIDEN=1
fH off fH off
fSUB off fSUB on
IDLE2 IDLE1
HALT instruction executed HALT instruction executed
CPU stop CPU stop
FHIDEN=1 FHIDEN=1
FSIDEN=0 FSIDEN=1
fH on fH on
fSUB off fSUB on
FAST Mode
CKS2~CKS0=111
SLOW Mode
FHIDEN=0, FSIDEN=0
HALT instruction is executed
SLEEP Mode
FHIDEN=0, FSIDEN=1
HALT instruction is executed
IDLE0 Mode
FHIDEN=1, FSIDEN=1
HALT instruction is executed
IDLE1 Mode
FHIDEN=1, FSIDEN=0
HALT instruction is executed
IDLE2 Mode
SLOW Mode
CKS2~CKS0=000~110
FAST Mode
FHIDEN=0, FSIDEN=0
HALT instruction is executed
SLEEP Mode
FHIDEN=0, FSIDEN=1
HALT instruction is executed
IDLE0 Mode
FHIDEN=1, FSIDEN=1
HALT instruction is executed
IDLE1 Mode
FHIDEN=1, FSIDEN=0
HALT instruction is executed
IDLE2 Mode
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 overflow
When the device executes the “HALT” instruction, 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 overflow, a Watchdot Timer reset will be initiated
and the TO flag will be set high. The TO flag is set if a WDT time-out occurs and causes a wake-up
that only resets the Program Counter and Stack Pointer, other flags 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 finally 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.
• WDTC Register
Bit 7 6 5 4 3 2 1 0
Name WE4 WE3 WE2 WE1 WE0 WS2 WS1 WS0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 1 0 1 0 0 1 1
• RSTFC Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — LVRF LRF WRF
R/W — — — — — R/W R/W R/W
POR — — — — — x 0 0
“x”: Unknown
Bit 7~3 Unimplemented, read as “0”
Bit 2 LVRF: LVR function reset flag
Refer to the Low Voltage Reset section.
Bit 1 LRF: LVR control register software reset flag
Refer to the Low Voltage Reset section.
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 first is a WDTC software reset, which means a certain value except 01010B and 10101B written
into the WE4~WE0 bit filed, 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 8
seconds for the 218 division ratio, and a minimum timeout of 8ms for the 28 division ration.
fLIRC fLIRC/28
LIRC 8-stage Divider WDT Prescaler
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 first applied to
the microcontroller. As well as ensuring that the Program Memory begins execution from the first
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 first set to inputs.
VDD
Power-on Reset
tRSTD
SST Time-out
LVR
tRSTD + tSST
Internal Reset
Register Bit
Name 7 6 5 4 3 2 1 0
LVRC LVS7 LVS6 LVS5 LVS4 LVS3 LVS2 LVS1 LVS0
TLVRC — — — — — — TLVR1 TLVR0
Low Voltage Reset Register List
• LVRC Register
Bit 7 6 5 4 3 2 1 0
Name LVS7 LVS6 LVS5 LVS4 LVS3 LVS2 LVS1 LVS0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 1 0 1 0 1 0 1
• TLVRC Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — TLVR1 TLVR0
R/W — — — — — — R/W R/W
POR — — — — — — 0 0
• RSTFC Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — LVRF LRF WRF
R/W — — — — — R/W R/W R/W
POR — — — — — x 0 0
“x”: Unknown
Bit 7~3 Unimplemented, read as “0”
Bit 2 LVRF: LVR function reset flag
0: Not occurred
1: Occurred
This bit is set high when a specific Low Voltage Reset situation condition occurs. This
bit can only be cleared to zero by the application program.
Bit 1 LRF: LVR control register software reset flag
0: Not occurred
1: Occurred
This bit is set high if the LVRC register contains any non-defined LVRC register
values. This in effect acts like a software-reset function. This bit can only be cleared to
zero by the application program.
Bit 0 WRF: WDT control register software reset flag
Refer to the Watchdog Timer Control Register section.
WDT Time-out
tRSTD
Internal Reset
WDT Time-out
tSST
Internal Reset
The different kinds of resets all affect the internal registers of the microcontroller in different ways.
To ensure reliable continuation of normal program execution after a reset occurs, it is important to
know what condition the microcontroller is in after a particular reset occurs. The following table
describes how each type of reset affects each of the microcontroller internal registers.
Power On WDT Time-out WDT Time-out
Register
Reset (Normal Operation) (IDLE/SLEEP)
IAR0 0000 0000 0000 0000 uuuu uuuu
MP0 0000 0000 0000 0000 uuuu uuuu
IAR1 0000 0000 0000 0000 uuuu uuuu
MP1L 0000 0000 0000 0000 uuuu uuuu
MP1H 0000 0000 0000 0000 uuuu uuuu
ACC xxxx xxxx uuuu uuuu uuuu uuuu
PCL 0000 0000 0000 0000 0000 0000
TBLP xxxx xxxx uuuu uuuu uuuu uuuu
TBLH xxxx xxxx uuuu uuuu uuuu uuuu
TBHP ---- xxxx ---- uuuu ---- uuuu
STATUS xx00 xxxx uu1u uuuu u u 11 u u u u
IAR2 0000 0000 0000 0000 uuuu uuuu
MP2L 0000 0000 0000 0000 uuuu uuuu
MP2H 0000 0000 0000 0000 uuuu uuuu
RSTFC ---- -x00 ---- -uuu ---- -uuu
SCC 001- --00 001- --00 uuu- --uu
HIRCC ---- --01 ---- --01 ---- --uu
LVRC 0101 0101 0101 0101 uuuu uuuu
LVDC --00 0000 --00 0000 --uu uuuu
PA 1111 1111 1111 1111 uuuu uuuu
PAC 1111 1111 1111 1111 uuuu uuuu
Input/Output Ports
Holtek microcontrollers offer considerable flexibility 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.
The device provides bidirectional input/output lines labeled with port names PA~PB. These I/O
ports are mapped to the RAM Data Memory with specific 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 Bit
Name 7 6 5 4 3 2 1 0
PA PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0
PAC PAC7 PAC6 PAC5 PAC4 PAC3 PAC2 PAC1 PAC0
PAPU PAPU7 PAPU6 PAPU5 PAPU4 PAPU3 PAPU2 PAPU1 PAPU0
PAWU PAWU7 PAWU6 PAWU5 PAWU4 PAWU3 PAWU2 PAWU1 PAWU0
PB — — — PB4 PB3 PB2 PB1 PB0
PBC — — — PBC4 PBC3 PBC2 PBC1 PBC0
PBPU — — — PBPU4 PBPU3 PBPU2 PBPU1 PBPU0
“—”: Unimplemented, read as “0”
I/O Logic Function Register List
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
configured as an input have the capability of being connected to an internal pull-high resistor. These
pull-high resistors are selected using the PAPU~PBPU 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 output. Otherwise, the pull-high resistors
cannot be enabled.
• PxPU Register
Bit 7 6 5 4 3 2 1 0
Name PxPU7 PxPU6 PxPU5 PxPU4 PxPU3 PxPU2 PxPU1 PxPU0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
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
Bit 7 6 5 4 3 2 1 0
Name PAWU7 PAWU6 PAWU5 PAWU4 PAWU3 PAWU2 PAWU1 PAWU0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• PxC Register
Bit 7 6 5 4 3 2 1 0
Name PxC7 PxC6 PxC5 PxC4 PxC3 PxC2 PxC1 PxC0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 1 1 1 1 1 1 1 1
Pin-shared Functions
The flexibility of the microcontroller range is greatly enhanced by the use of pins that have more
than one function. Limited numbers of pins can force serious design constraints on designers but by
supplying pins with multi-functions, many of these difficulties can be overcome. For these pins, the
desired function of the multi-function I/O pins is selected by a series of registers via the application
program control.
Register Bit
Name 7 6 5 4 3 2 1 0
PAS0 PAS07 PAS06 PAS05 PAS04 PAS03 PAS02 — —
PAS1 PAS17 PAS16 PAS15 PAS14 PAS13 PAS12 PAS11 PAS10
PBS0 PBS07 PBS06 PBS05 PBS04 PBS03 PBS02 PBS01 PBS00
PBS1 — — — — — — PBS11 PBS10
Pin-shared Function Selection Register List
• PAS0 Register
Bit 7 6 5 4 3 2 1 0
Name PAS07 PAS06 PAS05 PAS04 PAS03 PAS02 — —
R/W R/W R/W R/W R/W R/W R/W — —
POR 0 0 0 0 0 0 — —
• PAS1 Register
Bit 7 6 5 4 3 2 1 0
Name PAS17 PAS16 PAS15 PAS14 PAS13 PAS12 PAS11 PAS10
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• PBS0 Register
Bit 7 6 5 4 3 2 1 0
Name PBS07 PBS06 PBS05 PBS04 PBS03 PBS02 PBS01 PBS00
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• PBS1 Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — PBS11 PBS10
R/W — — — — — — R/W R/W
POR — — — — — — 0 0
Pull-high
Control Bit Register Weak
Select Pull-up
Data Bus D Q
Programming Considerations
Within the user program, one of the first things to consider is port initialisation. After a reset, all of
the I/O data and port control registers will be set high. This means that all I/O pins will default to
an input state, the level of which depends on the other connected circuitry and whether pull-high
selections have been chosen. If the port control registers are then programmed to setup some pins
as outputs, these output pins will have an initial high output value unless the associated port data
registers are first 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 first 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 function. 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 setup to have this function.
Timer/Event Counters
The provision of timers form an important part of any microcontroller, giving the designer a means
of carrying out time related functions. The device contains three count-up timer of 8-bit capacity. The
Timer/Event Counter 0 has three different operating modes, it can be configured to operate as a general
timer, an external event counter or as a pulse width capture device. The Timer/Event Counter 1 has two
different operating modes, it can be configured to operate as a general timer or operate in the mode 0
for the PPG non-retriggered function. The Timer Counter 2 has only one operating mode – timer mode,
thus the Timer Counter 2 there is no “/Event”, the mode selection bits and the related descriptions. The
provision of an internal prescaler to the clock circuitry on gives added range to the timers.
There are two types of registers related to the Timer/Event Counters. The first are the registers that
contain the actual value of the timer and into which an initial value can be preloaded. Reading from
these registers retrieves the contents of the Timer/Event Counter. The second type of associated
registers is the Timer Control Registers which define the timer options and determines how the
timers are to be used.
CLKSEL[1:0]
T0PSC2~T0PSC0
fSYS M Data bus
fSYS/4 U fPSC
X
Prescaler
fSUB
T0M1
0 8-bit Timer / Event Counter Reload
TC0 T0M0 Preload Register
PPGINTO 1
T0EG
T0ECS
fT0
Pulse Width 8-bit Timer / Event Counter Overflow to
T0M1~T0M0 Mesurement (TMR0) Interrupt
T0ON Mode Control
Note: PPGINTO is inverted or non-inverted debounce signal from PPGIN pin or comparator 0 output "C0VO" by software option.
8-bit Timer/Event Counter 0
T1PSC2~T1PSC0
fSYS M Data bus
fSYS/4 U fPSC Prescaler
fSUB X 8-bit Timer/Event
Counter Preload Register
Reload
CLKSEL[1:0]
Timer fT1
T1M1~T1M0 8-bit Timer/Event
Overflow to Interrupt
Control Counter (TMR1)
T1ON Circuit
INH
T1M1
T1M0
R Q
PPGOUT One shot SET_T1ON
T1ON S
Note: The INH output signal is used to inhibit further PPG trigger.
8-bit Timer/Event Counter 1
Data bus
fSYS M
fSYS/4 U fPSC 7-stage prescaler
fSUB X
CLKSEL[1:0]
T0PSC2~T0PSC0 8-1 MUX fT0
Prescaler
• PSCR Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — CLKSEL1 CLKSEL0
R/W — — — — — — R/W R/W
POR — — — — — — 0 0
• TMR0C Register
Bit 7 6 5 4 3 2 1 0
Name T0M1 T0M0 T0ECS T0ON T0EG T0PSC2 T0PSC1 T0PSC0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 1 0 0 0
• TMR1C Register
Bit 7 6 5 4 3 2 1 0
Name T1M1 T1M0 — T1ON — T1PSC2 T1PSC1 T1PSC0
R/W R/W R/W — R/W — R/W R/W R/W
POR 0 0 — 0 — 0 0 0
• TMR2C Register
Bit 7 6 5 4 3 2 1 0
Name — — — T2ON — T2PSC2 T2PSC1 T2PSC0
R/W — — — R/W — R/W R/W R/W
POR — — — 0 — 0 0 0
Timer Mode
In this mode, the Timer/Event Counter n can be utilised to measure fixed time intervals, providing
an internal interrupt signal each time the Timer/Event Counter n overflows. To operate in this mode,
the TnM1~TnM0 bits in the TMRnC register must be set to 10 respectively.
In this mode the internal clock is used as the timer clock. The Timer/Event Counter n clock is clock
source, fTn, which is sourced from the internal clock fPSC. The fPSC originates from the internal clock
source fSYS, fSYS/4 or fSUB, which is selected using the CLKSEL[1:0] bits in the PSCR register,
and then passes through a divider, the division ratio of which is selected by programming the
TnPSC2~TnPSC0 bits in the TMRnC register. The timer-on bit, TnON must be set high to enable
the timer to run. Each time an internal clock high to low transition occurs, the timer increments by
one. When the timer is full and overflows, an interrupt sigal is generated and the timer will reload
the value already loaded into the preload register and continue counting. A timer overflow condition
and corresponding internal interrupts are two of the wake-up sources. However, the internal
interrupts can be disabled by ensuring that the Timer/Event Counter n Interrupt Enable bits in the
Interrupt control registers are reset to zero.
Internal clock
source output
Increase
Timer + 1 Timer + 2 Timer + N Timer + N + 1
Timer Counter
Timer Mode Timing Chart
Event
reset to zero and the Timer/Event Counter will stop counting. It is important to note that in the pulse
width measurement mode, the enable bit is automatically reset to zero when the TC0 pin or the
PPGINTO signal returns to its original level, whereas in the other modes the enable bit can only be
reset to zero under program control.
The residual value in the Timer/Event Counter, which can now be read by the program, therefore
represents the length of the pulse received on the TC0 pin or PPGINTO signal. As the enable bit has
now been reset, any further transitions on the TC0 pin or the PPGINTO signal will be ignored. The
timer cannot begin further pulse width capture until the enable bit is set high again by the program.
In this way, single shot pulse measurements can be easily made.
It should be noted that in this mode the Timer/Event Counter is controlled by logical transitions on
the TC0 pin or the PPGINTO signal and not by the logic level. When the Timer/Event Counter is full
and overflows, an interrupt signal is generated and the Timer/Event Counter will reload the value
already loaded into the preload register and continue counting. The interrupt can be disabled by
ensuring that the Timer/Event Counter 0 Interrupt Enable bit in the corresponding Interrupt Control
Register, it is reset to zero.
As the TC0 pin is shared with an I/O pin, to ensure that the pin is configured to operate as a pulse
width capture pin, two things have to be implemented. The first is to ensure that the Operating
Mode Select bits in the Timer Control Register place the Timer/Event Counter in the pulse width
measurement mode, the second is to ensure that the port control register configure the pin as an input.
TC0 pin or
PPGINTO signal input
T0ON–with T0EG=0
Prescaler Output
Increment Timer +1 +2 +3 +4
Timer Counter
Pulse Width Measurement Mode Timing Chart (T0EG=0)
Mode 0
The Timer/Event Counter 1 has a mode 0 for PPG usage. This mode is used to implement the PPG
non-retriggered function. To operate in this mode, the T1M1~T1M0 bits in the TMR1C register
must be set to 00 respectively.
In this mode, the Timer/Event Counter 1 starts counting when PPG is stopped and stops when
overflow. That means the T1ON will be set once PPG stopped and cleared when overflow. Once
an overflow occurs, the counter is reloaded from t the Timer/Event Counter 1 preload register, and
generates an interrupt request flag. The interrupt can be disabled by ensuring that the Timer/Event
Counter 1 Interrupt Enable bit in the corresponding Interrupt Control Register, it is reset to zero.
I/O Interfacing
The Timer/Event Counter 0, when configured to run in the event counter or pulse width measurement
mode, it can use an external timer pin for its operation. The external timer pin TC0 is used as the
Timer/Event Counter 0 clock source by clearing the T0ECS bit to zero. As TC0 pin is a shared pin
it must be configured correctly to ensure that it is setup for use as a Timer/Event Counter input pin.
This is achieved by ensuring that the mode selects bits in the Timer/Event Counter control register,
either the event counter or pulse width measurement mode. Additionally the corresponding Port
Control Register bit must be set high to ensure that the pin is setup as an input. Any pull-high resistor
connected to this pin will remain valid even if the pin is used as a Timer/Event Counter input.
Programming Considerations
When configured to run in the timer mode, the internal system clock is used as the timer clock
source and is therefore synchronised with the overall operation of the microcontroller. In this mode
when the appropriate timer register is full, the microcontroller will generate an internal interrupt
signal directing the program flow to the respective internal interrupt vector. For the pulse width
measurement mode, the internal system clock is also used as the timer clock source but the timer
will only run when the correct logic condition appears on the TC0 pin or the PPGINTO signal. As
this is an event and not synchronised with the internal timer clock, the microcontroller will only see
this event when the next timer clock pulse arrives. As a result, there may be small differences in
measured values requiring programmers to take this into account during programming. The same
applies if the timer is configured to be in the event counting mode, which again is an event and not
synchronised with the internal system or timer clock.
When the Timer/Event Counter n is read, or if data is written to the preload register, the clock is
inhibited to avoid errors, however as this may result in a counting error, this should be taken into
account by the programmer. Care must be taken to ensure that the timers are properly initialised
before using them for the first time. The associated timer enable bits in the interrupt control
register must be properly set otherwise the internal interrupt associated with the timer will remain
inactive. The edge select, timer mode and clock source control bits in timer control register must
also be correctly set to ensure the timer is properly configured for the required application. It is
also important to ensure that an initial value is first loaded into the timer registers before the timer
is switched on; this is because after power-on the initial values of the timer registers are unknown.
After the timer has been initialized the timer can be turned on and off by controlling the enable bit in
the timer control register.
When the Timer/Event Counter overflows, its corresponding interrupt request flag in the interrupt
control register will be set. If the Timer/Event Counter interrupt is enabled this will in turn generate
an interrupt signal. However irrespective of whether the interrupts are enabled or not, a Timer/Event
Counter overflow will also generate a wake-up signal if the device is in the SLEEP or IDLE mode.
This situation may occur if the Timer/Event Counter is in the Event Counting Mode and if the TC0
pin or the PPGINTO signal continues to change state. In such a case, the Timer/Event Counter will
continue to count these external events and if an overflow occurs the device will be woken up from
its Power-down condition. To prevent such a wake-up from occurring, the timer interrupt request
flag should first be set high before issuing the “HALT” instruction to enter the SLEEP or IDLE
Mode.
The accompanying block diagram shows the overall internal structure of the A/D converter, together
with its associated registers.
fSYS AVDD
Pin-shared
Selection
SACKS2~ ÷ 2N ADCEN
SACKS0 (N=0~7)
AN0 AVSS ADRFS
A/D Clock
AN1
SADOL A/D Data
A/D Converter
SADOH Registers
AN9
A/D Reference Voltage
SACS3~SACS0
START ADBZ ADCEN
VREF
VBG
OPOUT Pin-shared
SAVRS1~SAVRS0 Selection
OPROUT
AVSS AVDD
SAINS2~SAINS0
A/D Converter Structure
Register Bit
Name 7 6 5 4 3 2 1 0
SADOL
D3 D2 D1 D0 — — — —
(ADRFS=0)
SADOL
D7 D6 D5 D4 D3 D2 D1 D0
(ADRFS=1)
SADOH
D11 D10 D9 D8 D7 D6 D5 D4
(ADRFS=0)
SADOH
— — — — D11 D10 D9 D8
(ADRFS=1)
SADC0 START ADBZ ADCEN ADRFS SACS3 SACS2 SACS1 SACS0
SADC1 SAINS2 SAINS1 SAINS0 SAVRS1 SAVRS0 SACKS2 SACKS1 SACKS0
A/D Converter Register List
• SADC0 Register
Bit 7 6 5 4 3 2 1 0
Name START ADBZ ADCEN ADRFS SACS3 SACS2 SACS1 SACS0
R/W R/W R R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• SADC1 Register
Bit 7 6 5 4 3 2 1 0
Name SAINS2 SAINS1 SAINS0 SAVRS1 SAVRS0 SACKS2 SACKS1 SACKS0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
The clock source for the A/D converter, which originates from the system clock f SYS, can be
chosen to be either fSYS or a subdivided version of fSYS. The division ratio value is determined by
the SACKS2~SACKS0 bits in the SADC1 register. Although the A/D clock source is determined
by the system clock fSYS and by bits SACKS2~SACKS0, there are some limitations on the A/D
clock source speed range that can be selected. As the recommended range of permissible A/D clock
period, tADCK, is from 0.5μs to 10μs, care must be taken for system clock frequencies. For example,
as the system clock operates at a frequency of 8MHz, the SACKS2~SACKS0 bits should not be set
to 000, 001 or 111. Doing so will give A/D clock periods that are less than the minimum or larger
than the maximum A/D clock period which may result in inaccurate A/D conversion values. Refer to
the following table for examples, where values marked with an asterisk * show where special care
must be taken, as the values may be out of the specified A/D clock period range.
A/D Clock Period (tADCK)
Controlling the power on/off function of the A/D converter circuitry is implemented using the
ADCEN bit in the SADC0 register. This bit must be set high to power on the A/D converter. When
the ADCEN bit is set high to power on the A/D converter internal circuitry a certain delay, as
indicated in the timing diagram, must be allowed before an A/D conversion is initiated. Even if
no pins are selected for use as A/D inputs, if the ADCEN bit is high, then some power will still be
consumed. In power conscious applications it is therefore recommended that the ADCEN is set low
to reduce power consumption when the A/D converter function is not being used.
register programming, will be automatically disconnected if the pins are setup as A/D inputs. Note
that it is not necessary to first setup the A/D pin as an input in the port control register to enable the
A/D input as when the pin-shared function control bits enable an A/D input, the status of the port
control register will be overridden.
There are four internal analog signals derived from the Bandgap reference voltage, the operational
amplifier output, OPOUT , the operational amplifier output, OPROUT, or A/D converter negative
power supply, AVSS, which can be connected to the A/D converter as the analog input signal by
configuring the SAINS2~SAINS0 bits. If the external channel input is selected to be converted, the
SAINS2~SAINS0 bits should be set to “000, 101~111” and the SACS3~SACS0 bits can determine
which external channel is selected. If the internal analog signal is selected to be converted, the
SACS3~SACS0 bits must be configured with a value from 1010 to 1111 to switch off the external
analog channel input. Otherwise, the internal analog signal will be connected together with the
external channel input. This will result in unpredictable situations.
SAINS[2:0] SACS[3:0] Input Signals Description
000, 0000~1001 AN0~AN9 External pin analog input
101~111 1010~1111 — Non-existed channel, input is floating
001 1010~1111 VBG Internal Bandgap reference voltage
010 1010~1111 OPOUT Operational amplifier output
011 1010~1111 OPROUT Operational amplifier output
100 1010~1111 AVSS A/D converter negative power supply
A/D Converter Input Signal Selection
tON2ST
ADCEN off on off on
A/D sampling time A/D sampling time
tADS tADS
START
Start of A/D conversion Start of A/D conversion Start of A/D conversion
ADBZ
End of A/D End of A/D
conversion conversion
Programming Considerations
During microcontroller operations where the A/D converter is not being used, the A/D internal
circuitry can be switched off to reduce power consumption, by clearing bit ADCEN to 0 in the
SADC0 register. When this happens, the internal A/D converter circuits will not consume power
irrespective of what analog voltage is applied to their input lines. If the A/D converter input lines are
used as normal I/Os, then care must be taken as if the input voltage is not at a valid logic level, then
this may lead to some increase in power consumption.
1.5 LSB
FFFH
FFEH
FFDH
A/D Conversion
Result
0.5 LSB
03H
02H
01H
VREF
4096
0 1 2 3 4093 4094 4095 4096
Analog Input Voltage
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
b0~b7
b0~b7 b0~b7
PPGTPSC[1:0]
fH/128 PPGTMMD[1:0]
fH /128
fH/256
/256 M
U
fH/512 Reload
/512 X
fH /1024 Reload Counter
/1024
PPGTRG PPG
PPGASA[1:0] PPGACNT[1:0] PPGTIMES[2:0] PPG Control Circuit PPG Counter
C2VOD PPG Output Control
C3VOD PPGOUT
PPGADJF
PPGOUT
Over Voltage Protection Circuit
PCSD
INH
PPGIN
C0COFM C0CRS S0 S1 S2
0 x ON ON OFF
1 0 OFF ON ON
1 1 ON OFF ON PPGTRG
x: Dont care
CP0P C0HYSON C0DBC[5:0] TRGMOD PPGDL[5:0]
S0
C0CMP0P M
+ INT0 INT0S INT00
U Debounce Polarity Triger mode Triger delay PPGINT
C0VO
S2 CMP0 X
-
INTINV PPGINTO
S1 INTS
CP0N C0EN
fSYS M fPPGDCK
C1COFM C1CRS S3 S4 S5 U
0 x ON ON OFF fSYS/2 X
1 0 OFF ON ON
CVREF1[2:0]
1 1 ON OFF ON
FPPGDC
x: Dont care C0VO
VR1 C1HYSON
C1DBEN
S3
C1CMP0P
+
C1VOD
S5 CMP1 Debounce CMP1INT
-
S4 fPPGDCK
C1EN C1VO
CP1N
C1CTL
C2COFM C2CRS S6 S7 S8
0 x ON ON OFF
CVREF2[2:0] 1 0 OFF ON ON
1 1 ON OFF ON
VR2 x: Dont care
C2HYSON
CP2P C2DBEN
S6
C2CMP0P
+
C2VOD
S8 CMP2 Polarity Debounce CMP2INT
CVREF3[2:0]
-
S7 C2VOINV fPPGDCK
VR3
C2EN
CP2N C2VO
C2CTL[1:0]
C3COFM C3CRS S9 S10 S11
0 x ON ON OFF
1 0 OFF ON ON
CVREF4[2:0]
1 1 ON OFF ON
x: Dont care
VR4 C3HYSON
C3DBEN
S9
C3CMP0P
+
C3VOD
C3CTL[1:0] CMP3 Polarity Debounce
S11 CMP3INT
-
S10 C3VOINV fPPGDCK
C3EN
C3VO
OPS2
OPG[1:0]
OPS0
SW2
OPINN
OPAR3 SW0 OPAR1 OPOFM
SW3 OPS3 OPO
-
OPAMP OPOUT
+
OPINP OPROUT
OPEN OPAR4
SW1 OPS4 SW4
OPS1
OPAR2
Note: The CMPn interrupt is triggered by the CMPnINT falling edge. (n=1~3)
b0~b7
b0~b7 b0~b7
PPGTPSC[1:0]
fH/128
fH /128
PPGTMMD[1:0]
fH/256
/256 M
U
fH/512
/512 X
fH/1024 Reload
/1024
Reload Counter
fSYS
PPG
PPGTRG
PPGASA[1:0] PPGACNT[1:0] PPGTIMES[2:0] PPG Control PPG Output
C2VOD PPG Counter
Circuit Control
C3VOD PPGADJF
PPGOUT
fSYS/2
fSYS /2
M fPPG
U /2
fSYS X
PCSD
The PPG detects a trigger input and outputs a single pulse. The trigger source may come from the
INT00 trigger input or from a software trigger bit, which can be configured by software. The PPG
pin can output an active low pulse, active high pulse, force low or force high by setting the PPGPC
register. An external pull-high or pull-low resistor is required if the PPG output is defined as an
active low pulse output or an active high pulse output.
The PPG module consists of a PPG control circuit, a PPGTIMER counter, a PPG counter and a PPG
output control. The PPG counter consists of a 9-bit up-counter timer, two sets of 9-bit preload data
registers and two sets of 9-bit timer approach registers. The programmable pulse generator, PPG,
starts counting at the current value in the preload registers and ends at “1FFH → 000H”. A “000H”
data write to the PPGTA[8:0] and PPGTB[8:0] bits yields a pulse width of 512×T output. Once an
overflow occurs, the counter is reloaded from the PPG timer counter preload register, and generates
a signal to stop the PPG timer. The software trigger bit, PST, will be cleared when the PPG timer
overflow occurs.
The PPG counter will be reloaded by one of following conditions:
1. A PPG counter overflow
2. When the PPG is off
3. Any action causing the PPG to stop
Normally, if RLBF=0, the PPG timer is reloaded from the preload register A. If C1RLEN=1 and a
C1VOD falling edge occurs, the PPG timer reloads from preload register B and RLBF will be set to
“1” until RLBF is cleared by software.
The PRSEN is the PPG restarting enable or disable bit using the INT00 trigger input. If this bit is
enabled, the PPG module output can be restarted by an INT00 trigger or by software control by
setting the PST bit to “1”. Once an INT00 falling edge occurs, the PPG counter will start counting.
The PRSEN bit will be cleared to zero by a C2VOD or C3VOD falling edge, no matter whether the
PPG is in an active period or not. This will prevent the PPG module output from being restarted by
an INT00 falling edge occurring again, it can only be restarted by software when PRSEN is set again
by software.
The PST is a software trigger bit, if this bit is set to “1” the PPG timer will start counting and this bit
will be cleared to zero when a PPG timer overflow occurs or when the PPG timer stop counting. If
this bit is cleared to “0”, the PPG timer will stop counting.
When the PPG timer is counting and if an INT00 falling edge trigger input occurs or if a software
control bit PST is set, the PPG timer counter will not be affected, that is a trigger from INT00 or
PST will have no effect. PST can also be used as a status bit for the PPG timer output.
The PPG output is determined by the PPGPC register setting. If the PPGPC[7:0] bits are set to
“01010101B”, the PPG output will be defined as an active low pulse output. If the PPGPC[7:0]
bits are set to “10101010B”, the PPG output will be defined as an active high pulse output. If the
PPGPC[7:0] bits are set to “00110010B”, this will force the PPG output low. If the PPGPC[7:0] bits
are set to “00110011B”, this will force the PPG output high. If the PPGPC[7:0] bits are set to any
other values, other than the four defined values above, the PPG output will be floating.
When the PPG timer starts counting and whether it is synchronised with the clock or not is
determined by the PTSYN bit in the PPGC0 register.
When using the PPG function, the most important point to note is to ensure that the CMP1 settings
and C1VOD signal set high before setting the PPGC2 register. Since the C1VOD signal state is
unknown, if PPGDEC[3:0]≠0000, the PPGTA[8:0] value will be automatically incremented by a
specific value every 64/fSYS until it is incremented to 1FFH. The incremented value depends on the
PPGDEC[3:0] bits.
• PPG Registers
The overall operation of the PPG function is controlled using a series of registers. The following
table considerations must be taken into account when modifying the relevant bits.
C1VOD PPGTMMD PPGDEC
PPGSAMD PPGSAEN Unchangeable Bits
Signal [1:0] [3:0]
0000 —
0 x x xx
0001~1111 PPGTA[8:0]
0 0 xx —
0 1 xx PPGTA[8:0], PPGCNT[1:0], PPGSA[2:0]
1 xxxx
1 x 01/10 PPGTA[8:0], PPGCNT[1:0], PPGSA[2:0]
1 x 00/11 —
“x”: Don’t care
Register Bit
Name 7 6 5 4 3 2 1 0
PPGC0 PST PRSEN PSPEN RLBF PTSYN PCSD TRGMOD C1RLEN
PPGC1 INTS FPPGDC PPGDL5 PPGDL4 PPGDL3 PPGDL2 PPGDL1 PPGDL0
PPGC2 — — — DVS PPGDEC3 PPGDEC2 PPGDEC1 PPGDEC0
PPGTA PPGTA7 PPGTA6 PPGTA5 PPGTA4 PPGTA3 PPGTA2 PPGTA1 PPGTA0
PPGTB PPGTB7 PPGTB6 PPGTB5 PPGTB4 PPGTB3 PPGTB2 PPGTB1 PPGTB0
PPGTC PPGTC7 PPGTC6 PPGTC5 PPGTC4 PPGTC3 PPGTC2 PPGTC1 PPGTC0
PPGTD PPGTD7 PPGTD6 PPGTD5 PPGTD4 PPGTD3 PPGTD2 PPGTD1 PPGTD0
PPGTEX — PPGTD8 — PPGTB8 — PPGTC8 — PPGTA8
PWLT D7 D6 D5 D4 D3 D2 D1 D0
PPGPC PPGPC7 PPGPC6 PPGPC5 PPGPC4 PPGPC3 PPGPC2 PPGPC1 PPGPC0
PPGATC0 PPGSAEN PPGSAMD PPGSCD PPGADJF PPGTMMD1 PPGTMMD0 PPGACF PPGADF
PPGATC1 PPGHTMD — — PPGCNT1 PPGCNT0 PPGSA2 PPGSA1 PPGSA0
PPGATC2 — PPGTIMES2 PPGTIMES1 PPGTIMES0 PPGACNT1 PPGACNT0 PPGASA1 PPGASA0
PPGTMC — — — PPGTON PPGTEG — PPGTPSC1 PPGTPSC0
PPGTMR1 D7 D6 D5 D4 D3 D2 D1 D0
PPGTMR2 D7 D6 D5 D4 D3 D2 D1 D0
PPGTMR3 D7 D6 D5 D4 D3 D2 D1 D0
PPGTMRD D7 D6 D5 D4 D3 D2 D1 D0
Programmable Pulse Generator Register List
• PPGC0 Register
Bit 7 6 5 4 3 2 1 0
Name PST PRSEN PSPEN RLBF PTSYN PCSD TRGMOD C1RLEN
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
Bit 2 PCSD: PPG counter and pulse width limiter timer clock source, fPPG, selection
0: fSYS
1: fSYS/2
Bit 1 TRGMOD: Select single edge or double falling edges of INT0 as the input of the
trigger delay circuit which produce INT00
0: Single falling edge
1: Double falling edges
Bit 0 C1RLEN: Enable or disable to set RLBF when a C1VOD falling edge occurs
0: Disable
1: Enable
If this bit is set to “1”, the PPG timer reloads from the preload register B and RLBF
will be set to “1” when a C1VOD falling edge occurs.
• PPGC1 Register
Bit 7 6 5 4 3 2 1 0
Name INTS FPPGDC PPGDL5 PPGDL4 PPGDL3 PPGDL2 PPGDL1 PPGDL0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 1 0 0 0 0 0 0 0
• PPGC2 Register
Bit 7 6 5 4 3 2 1 0
Name — — — DVS PPGDEC3 PPGDEC2 PPGDEC1 PPGDEC0
R/W — — — R/W R/W R/W R/W R/W
POR — — — 0 0 0 0 0
• PPGTA Register
Bit 7 6 5 4 3 2 1 0
Name PPGTA7 PPGTA6 PPGTA5 PPGTA4 PPGTA3 PPGTA2 PPGTA1 PPGTA0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR x x x x x x x x
“x”: Unknown
Bit 7~0 PPGTA7~PPGTA0: PPG timer preload register A bit 7 ~ bit 0
• PPGTB Register
Bit 7 6 5 4 3 2 1 0
Name PPGTB7 PPGTB6 PPGTB5 PPGTB4 PPGTB3 PPGTB2 PPGTB1 PPGTB0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR x x x x x x x x
“x”: Unknown
Bit 7~0 PPGTB7~PPGTB0: PPG timer preload register B bit 7 ~ bit 0
• PPGTC Register
Bit 7 6 5 4 3 2 1 0
Name PPGTC7 PPGTC6 PPGTC5 PPGTC4 PPGTC3 PPGTC2 PPGTC1 PPGTC0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR x x x x x x x x
“x”: Unknown
Bit 7~0 PPGTC7~PPGTC0: PPG timer approach register C bit 7 ~ bit 0
• PPGTD Register
Bit 7 6 5 4 3 2 1 0
Name PPGTD7 PPGTD6 PPGTD5 PPGTD4 PPGTD3 PPGTD2 PPGTD1 PPGTD0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR x x x x x x x x
• PPGTEX Register
Bit 7 6 5 4 3 2 1 0
Name — PPGTD8 — PPGTB8 — PPGTC8 — PPGTA8
R/W — R/W — R/W — R/W — R/W
POR — x — x — x — x
“x”: Unknown
Bit 7 Unimplemented, read as “0”
Bit 6 PPGTD8: PPG timer approach register D bit 8
Bit 5 Unimplemented, read as “0”
Bit 4 PPGTB8: PPG timer preload register B bit 8
Bit 3 Unimplemented, read as “0”
Bit 2 PPGTC8: PPG timer approach register C bit 8
Bit 1 Unimplemented, read as “0”
Bit 0 PPGTA8: PPG timer preload register A bit 8
• PWTL Register
Bit 7 6 5 4 3 2 1 0
Name D7 D6 D5 D4 D3 D2 D1 D0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR x x x x x x x x
“x”: Unknown
Bit 7~0 D7~D0: PPG pulse width limit timer bit 7 ~ bit 0
The pulse width limit is (256-PWLT)/(fPPG/2)
• PPGPC Register
Bit 7 6 5 4 3 2 1 0
Name PPGPC7 PPGPC6 PPGPC5 PPGPC4 PPGPC3 PPGPC2 PPGPC1 PPGPC0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• PPGATC0 Register
Bit 7 6 5 4 3 2 1 0
Name PPGSAEN PPGSAMD PPGSCD PPGADJF PPGTMMD1 PPGTMMD0 PPGACF PPGADF
R/W R/W R/W R/W R R R R/W R/W
POR 0 0 0 0 0 0 0 0
This bit is only valid when PPGSAMD=0. Since the pulse width approach operation is
controlled by hardware when PPGSAMD=1, a software write is invalid.
PPGSAEN
PPGSAMD
Software Write Hardware Write Read
0 0
0 x
1 1
0 0 0
0 1 1
1
1 0 0
1 1 1
“x”: Don’t care
Bit 6 PPGSAMD: PPGTA approach mode selection
0: S/W approach mode
1: H/W approach mode
The PPGTON bit will be cleared to zero and the PPGTIMER counter will reload the
PPGTMR1 register value if this bit changes from 0 to 1.
Bit 5 PPGSCD: PPGTA approach bits selection
0: PPGTC[8:0]
1: PPGTD[8:0]
This bit is only valid when PPGSAMD=0.
Bit 4 PPGADJF: PPG register modification flag
0: PPG related registers can be changed
1: PPG related registers cannot be changed
If this bit set to high, the contents of the PPGTA register, the PPGCNT[1:0] bits in the
PPGATC1 register and the PPGSA[2:0] bits in the PPGATC1 register cannot be changed
by software.
Bit 3~2 PPGTMMD1~PPGTMMD0: PPG timer mode
00: PPGTA floating mode (t0~t1 interval)
01: PPGTA approach PPGTC mode (t1~t2 interval)
10: PPGTA approach PPGTD mode (t2~t3 interval)
11: PPGTA floating mode (t3~t0 interval)
These bits are only valid when PPGSAMD=1.
Bit 1 PPGACF: PPGTA approach PPGTC operation complete flag
0: PPGTA approach PPGTC operation has not completed
1: PPGTA approach PPGTC operation is completed
This bit can be cleared to zero by software, but it cannot be set high by the software.
If this bit is high, it also can be automatically cleared to zero by the hardware when
PPGSAMD=0 and PPGSAEN bit changes from 0 to 1; or if PPGSAMD=1 and
PPGHTMD=0, the OVPINT trigger occurs; or if PPGSAMD=1 and PPGHTMD=0
when the PPGTON bit changes from 0 to 1.
Bit 0 PPGADF: PPGTA approach PPGTD completed operation complete flag
0: PPGTA approach PPGTD operation has not completed
1: PPGTA approach PPGTD operation is completed
This bit can be cleared to zero by software, but it cannot be set high by software. If this
bit is high, it can be also automatically cleared to zero by a hardware when PPGSAMD=0
and PPGSAEN bit changes from 0 to 1; or if PPGSAMD=1 and PPGHTMD=0, when
an OVPINT trigger occurs; or if PPGSAMD=1 and PPGHTMD=0, the PPGTON bit
changes from 0 to 1.
• PPGATC1 Register
Bit 7 6 5 4 3 2 1 0
Name PPGHTMD — — PPGCNT1 PPGCNT0 PPGSA2 PPGSA1 PPGSA0
R/W R/W — — R/W R/W R/W R/W R/W
POR 0 — — 0 0 0 0 0
Bit 7 PPGHTMD: PPGTIMER counter trigger source selection in the H/W approach mode
0: OVPINT
1: PPGTON (0→1)
Bit 6~5 Unimplemented, read as “0”
Bit 4~3 PPGCNT1~PPGCNT0: PPG trigger times selection (Variable: M)
00: 1
01: 2
10: 3
11: 4
Bit 2~0 PPGSA2~PPGSA0: PPGTA approach value selection (Variable: N)
000: ±1
001: ±2
010: ±3
011: ±4
100: ±5
101: ±6
110: ±7
111: ±8
• PPGATC2 Register
Bit 7 6 5 4 3 2 1 0
Name — PPGTIMES2 PPGTIMES1 PPGTIMES0 PPGACNT1 PPGACNT0 PPGASA1 PPGASA0
R/W — R/W R/W R/W R/W R/W R/W R/W
POR — 0 0 0 0 0 0 0
Bit 1~0 PPGASA1~PPGASA0: PPGTA approach value change selection – change N value
00: Unchange
01: Unchange
10: +1
11: -1
Note: 1. When the PPGSA[2:0] bits increase or decrease to a maximum value of 111 or
a minimum value of 000, the PPGSA[2:0] bits are fixed to a maximum value
of 111 or a minimum value of 000.
2. In the H/W approach mode, when PPGASA[1:0]=10, it increases by 1 in the
t1~t2 interval and decreases by 1 in the t2~t3 interval. When PPGASA[1:0]=11,
it is decreased by 1 in the t1~t2 interval and increased by 1 in the t2~t3 interval.
• PPGTMC Register
Bit 7 6 5 4 3 2 1 0
Name — — — PPGTON PPGTEG — PPGTPSC1 PPGTPSC0
R/W — — — R/W R/W — R/W R/W
POR — — — 0 0 — 0 0
Bit 7~0 D7~D0: The PPGTIMER counter pre-load register Tn bit 7 ~ bit 0
• PPGTMRD Register
Bit 7 6 5 4 3 2 1 0
Name D7 D6 D5 D4 D3 D2 D1 D0
R/W R R R R R R R R
POR 0 0 0 0 0 0 0 0
Non-retriggered Function
The PPG unit has non-retriggered function to inhibit further PPG triggers. The PPG will be non-triggered
by one of following conditions:
• PPG is active
• During the non-retriggered period which starts counting once the PPG has stopped. Only
available when used with mode 0 of the Timer/Event counter 1, the non-trigger period is
determined by the Timer/Event counter 1 which will start to count when the PPG output active to
inactive transition occurs.
Non-retrigger period
PPGOUT
PPG active PPG inactive
Note: 1. If T1ON=1, when the INH signal is high, the PPG non-retriggered mode will be enabled to
inhibit further PPG triggers until the counter overflow or the T1ON bit is cleared to zero, the
INH signal will be low, the PPG can be triggered again and the signal can be output normally.
2. During the non-retriggered period, the PPG module cannot be triggered by the INT00
trigger signal, but the PPG module can be triggered by the software control bit PST.
PPG clock
Start trigger
PPG pulse
Example 2: Since the first trigger type is a rising edge after the PPG starts, the PPG timer is triggered by
a rising edge until the PPG stops.
tPPG
PPG clock
Start trigger
PPG pulse
• Determine whether to use the non-retriggered period function or not using mode 0 of Timer/Event
Counter 1
• Set the pulse width limit timer for the pulse width limit function using the PWLT register.
When the PPG input is triggered by an INT00 falling edge or triggered by a software bit, PST, being
set to “1”, the PPG will start counting from the current values of the preload register. If a PPG timer
overflow occurs, a pulse width limit condition occurs, the PPG input is trigged by a software bit,
PST, being cleared to zero or the PPG input is triggered by a C2VOD/C3VOD falling edge, the PPG
will stop counting.
In the S/W approach mode, the PPGTIMER counter operates in the general timer mode and the
counting value is loaded by PPGTMR1 register. When PPGTON=1, the PPGTIMER counter counts
from the PPGTMR1 register, if the counter overflow will trigger the PPGTMINT signal.
The following summarises the individual steps that should be executed in order to implement a
PPGTA approach process in the S/W approach mode.
• Step 1
Write the initial value to the PPGTA[8:0] and PPGTD[8:0] bits. Note that the high byte needs to
written first after which the low byte can be written to ensure the PPGTA[8:0] and PPGTD[8:0]
bits will be correctly written.
• Step 2
Set the PPG trigger times and the approach value by configuring the PPGATC1 register.
• Step 3
Select adjusting the PPG trigger times and approach value after several approached times by
setting the PPGTIMES[2:0] bits in PPGATC2 register.
• Step 4
Select how to change the PPG trigger times by setting the PPGACNT[1:0] bits in the PPGATC2
register.
• Step 5
How to change the approach value by setting the PPGASA[1:0] bits in PPGATC2 register.
• Step 6
Clear the PPGSAMD bit in the PPGATC0 register to zero.
• Step 7
Select the PPGTA approach registers by setting the PPGSCD bit in the PPGATC0 register.
• Step 8
Setup other PPG related registers. Refer to the PPG Registers for details.
• Step 9
Set the PPGSAEN bit in the PPGATC0 register to 1.
• Step 10
Read the PPGACF and PPGADF bits to determine whether PPGTA is equal to PPGTC or PPGTD.
Note that before t1 occurs, the PPG related registers must be setup. Otherwise, the PPGTA[8:0],
PPGCNT[1:0] and PPGSA[2:0] bits cannot be changed in the t1~t2 interval. These bits cannot be
changed until t3 occurs.
In the t1~t2 interval, when PPGTA is equal to PPGTC, the PPGACF bit will be set to 1 by the
hardware. Note that the PPGACF bit can be cleared by the software, but it cannot set high by the
software. When PPGACF=1, the software does not clear this bit to zero, it also can be automatically
clear to zero by the hardware when the next OVPINT falling edge or PPGTON bit changes from 0
to 1 occurs.
In the t2~t3 interval, when PPGTA is equal to PPGTD, the PPGADF bit will be set to 1 by the
hardware. Note that the PPGADF bit can be cleared by the software, but it cannot set high by the
software. When PPGADF=1, the software does not clear this bit, it also can be automatically clear
to zero by the hardware when the next OVPINT falling edge occurs or when the PPGTON changes
from 0 to 1.
In the H/W approach mode, if users want to stop the related function, the PPG can be changed to the
S/W approach mode by clearing the PPGSAMD bit to zero.
C1VOD PPGTMMD
PPGSAMD PPGSAEN PPGSCD Description
Signal [1:0]
1 0 0 x x The PPGTA[8:0] value does not update automatically.
The PPGTA[8:0] approaches the PPGTC[8:0] times ac-
1 0 1 0 x cording to the PPGCNT[1:0] bits, the approach value is
determined by the PPGSA[2:0] bits.
The PPGTA[8:0] approache the PPGTD[8:0] times ac-
1 0 1 1 x cording to the PPGCNT[1:0] bits, the approach value is
determined by the PPGSA[2:0] bits.
1 1 0 x 00B The PPGTA[8:0] value does not update automatically.
The PPGTA[8:0] approache the PPGTC[8:0] times ac-
1 (by
1 1 x 01B cording to the PPGCNT[1:0] bits, the approach value is
hardware)
determined by the PPGSA[2:0] bits.
The PPGTA[8:0] approache the PPGTD[8:0] times ac-
1 (by
1 1 x 10B cording to the PPGCNT[1:0] bits, the approach value is
hardware)
determined by the PPGSA[2:0] bits.
1 1 0 x 11B The PPGTA[8:0] value does not update automatically.
“x”: Don’t care
The following summarises the individual steps that should be executed in order to implement a
PPGTA approaching process in the H/W approach mode.
• Step 1
Write the initial value to the PPGTA[8:0] and PPGTD[8:0] bits. Note that the high byte needs
to be written first after which the low byte can be written to ensure the PPGTA[8:0] and
PPGTD[8:0] bits will be correctly written.
• Step 2
Set the PPG trigger times and the approach value by configuring the PPGACNT[1:0] and
PPGASA[2:0] bits in the PPGATC1 register.
• Step 3
Select the hardware trigger source by setting the PPGHTMD bit in the PPGATC1 register.
• Step 4
Select adjusting the PPG trigger times and the approach value after several times by setting the
PPGTIMES[2:0] bits in the PPGATC2 register.
• Step 5
Select the PPG trigger times by setting the PPGACNT[1:0] bits in the PPGATC2 register.
• Step 6
Select the approach value by setting the PPGASA[1:0] bits in the PPGATC2 register.
• Step 7
Set the PPGTM1, PPGTM2 and PPGTM3 counter values.
• Step 8
Select the polarity of the OVPINT trigger source in the hardware proximity function by setting
the PPGTEG bit in the PPGTMC0 register.
• Step 9
Select the timer clock source by setting the PPGTPSC bit in the PPGTMC0 register.
• Step 10
Setup the other PPG related registers. Refter to the PPG Registers for details.
• Step 11
Set the PPGSAMD bit in the PPGATC0 register to 1. Note that the PPGTON bit will be cleared
to zero by the hardware. If the PPGHTMD bit is 0, once an active OVPINT edge trigger source
is occurred will trigger a hardware action, it is important to ensure that other relevant settings are
completed before setting this bit to avoid unpredictable errors.
• Step 12
Determine whether PPGTA is equal to PPGTC/PPGTD by reading the PPGACF and PPGADF
bits.
• Step 13
Read the PPGTMMD[1:0] bits to determine the PPG timer current operating mode.
Example
1. PPGSAMD=1; PPGTEG=1; PPGTPSC0=1; PPGHTMD=0
2. PPGCNT[1:0]=10B; PPGSA[2:0]=011B; this means that PPGTA increases by 4 for every 3 PPG
triggers
3. PPGTIMES[2:0]=001B; PPGACNT[1:0]=10B; PPGASA[1:0]=00B; this means that the PPG
triggers times increases by one and the increased value remains for every 2 PPG triggers. Thus
PPGTA increases by 4 for every 4 PPG triggers
4. PPGTA=400; PPGTC=420; PPGTD=410
Note: 1. If the PPGTC/PPGTD is larger than PPGTA, the PPGTA increases to approach PPGTC/PPGTD. When
the PPGTC/PPGTD minus PPGTA is less than PPGSA, the PPGTA will add the PPGSA value after PPG
triggering. At this point the PPGTA value will be greater than PPGTC/PPGTD, the PPGTA is equal to
PPGTC/PPGTD at the next PPGTA trigger.
2. If the PPGTC/PPGTD is less than PPGTA, the PPGTA decreases to approach PPGTC/PPGTD. When the
PPGTA minus the PPGTC/PPGTD is less than PPGSA, PPGTA decreases the PPGSA value after PPG
triggering, at this point the PPGTC/PPGTD is larger than the PPGTA, the PPGTA is equal to PPGTC/PPGTD
after the next PPG triggering.
3. If PPGTA + PPGSA is larger than 511 or PPGTA – PPGSA is less than 0, the extreme value 511 or 0 will be
written to PPGTA directly.
OVPDA Code
t0 t1 t2 t3 t0 t1 t2 t3 t0
OVP INT
PPGTON
PPGADJF
PPGTMMD[1:0] 11B 00B 01B 10B 11B 00B 01B 10B 11B
PPGTC (New)
PPGTC
PPGTD (New)
PPGTA
PPGTD
PPGTA (New)
PPGACF
Software clearing Hardware clearing
C0COFM C0CRS S0 S1 S2
0 x ON ON OFF PPGOUT
1 0 OFF ON ON PPGTRG
1 1 ON OFF ON INH
x: Dont care
CP0P C0HYSON C0DBC[5:0] TRGMOD PPGDL[5:0]
S0
C0CMP0P M
+ INT0 INT0S INT00
U Debounce Polarity Triger mode Triger delay PPGINT
C0VO
S2 CMP0 X
- PPGINTO
INTINV
S1 INTS
CP0N C0EN
fSYS M fPPGDCK
C1COFM C1CRS S3 S4 S5
U
0 x ON ON OFF fSYS/2 X
1 0 OFF ON ON
CVREF1[2:0]
1 1 ON OFF ON
FPPGDC
x: Dont care C0VO
VR1 C1HYSON
C1DBEN
S3
C1CMP0P
+
C1VOD
S5 CMP1 Debounce CMP1INT
-
S4 fPPGDCK
C1EN
C1VO
CP1N
C1CTL
C2COFM C2CRS S6 S7 S8
0 x ON ON OFF
CVREF2[2:0] 1 0 OFF ON ON
1 1 ON OFF ON
VR2 x: Dont care
C2HYSON
CP2P C2DBEN
S6
C2CMP0P
+
C2VOD
S8 CMP2 Polarity Debounce CMP2INT
CVREF3[2:0]
-
S7 C2VOINV fPPGDCK
VR3
C2EN
CP2N C2VO
C2CTL[1:0]
C3COFM C3CRS S9 S10 S11
0 x ON ON OFF
1 0 OFF ON ON
CVREF4[2:0]
1 1 ON OFF ON
x: Dont care
VR4 C3HYSON
C3DBEN
S9
C3CMP0P
+
C3VOD
C3CTL[1:0] CMP3 Polarity Debounce CMP3INT
S11
-
S10 C3VOINV fPPGDCK
C3EN
C3VO
OPS2
OPG[1:0]
OPS0
SW2
OPINN
OPAR3 SW0 OPAR1 OPOFM
SW3 OPO
OPS3
-
OPAMP OPOUT
+
OPINP OPROUT
SW4 OPEN OPAR4
SW1 OPS4
OPS1
OPAR2
Comparators
There are four comparators which are used for the synchronous signal detection, inverting voltage
protection, SUG voltage detection and over current detection. As the comparator inputs are pin share
with I/Os, as well as configuring their respective function.
Comparator Registers
The overall operation of the internal comparators is controlled using a series of registers.
Register Bit
Name 7 6 5 4 3 2 1 0
CMP0C C0COFM C0CRS C0COF5 C0COF4 C0COF3 C0COF2 C0COF1 C0COF0
CMPnC
CnCMPOP CnCOFM CnCRS CnCOF4 CnCOF3 CnCOF2 CnCOF1 CnCOF0
(n=1~3)
CMPVREF0 — CVREF22 CVREF21 CVREF20 — CVREF12 CVREF11 CVREF10
Register Bit
Name 7 6 5 4 3 2 1 0
CMPVREF1 — CVREF42 CVREF41 CVREF40 — CVREF32 CVREF31 CVREF30
CMPCTL0 C3VOINV C2VOINV — INTINV C3EN C2EN C1EN C0EN
CMPCTL1 C0CMPOP C3CTL0 C2CTL1 C2CTL0 — C1CTL — C3CTL1
CMPDBC0 — — C0DBC5 C0DBC4 C0DBC3 C0DBC2 C0DBC1 C0DBC0
CMPDBC1 C3DBEN C2DBEN C1DBEN — — — — —
CMPHYS — — — — C3HYSON C2HYSON C1HYSON C0HYSON
Comparator Register List
• CMP0C Register
Bit 7 6 5 4 3 2 1 0
Name C0COFM C0CRS C0COF5 C0COF4 C0COF3 C0COF2 C0COF1 C0COF0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 1 0 0 0 0 0
Bit 7 C0COFM: Comparator 0 input offset voltage calibration mode and comparator mode
selection
0: Comparator mode
1: Input offset voltage calibration mode
Bit 6 C0CRS: Comparator 0 input offset voltage calibration reference selection bit
0: Select internal 0V as the reference input
1: Select positive input as the reference input
Bit 5~0 C0COF5~C0COF0: Comparator 0 input offset voltage calibration control bits
• CMPVREF0 Register
Bit 7 6 5 4 3 2 1 0
Name — CVREF22 CVREF21 CVREF20 — CVREF12 CVREF11 CVREF10
R/W — R/W R/W R/W — R/W R/W R/W
POR — 0 0 0 — 0 0 0
Bit 6~4 CVREF22~CVREF20: Internal reference voltage VR2 for comparator 2 selection
000: 0.600VDD
001: 0.625VDD
010: 0.650VDD
011: 0.675VDD
100: 0.700VDD
101: 0.725VDD
110: 0.750VDD
111: 0.775VDD
Bit 3 Unimplemented, read as “0”
Bit 2~0 CVREF12~CVREF10: Internal reference voltage VR1 for comparator 1 selection
000: 0.600VDD
001: 0.625VDD
010: 0.650VDD
011: 0.675VDD
100: 0.700VDD
101: 0.725VDD
110: 0.750VDD
111: 0.775VDD
• CMPVREF1 Register
Bit 7 6 5 4 3 2 1 0
Name — CVREF42 CVREF41 CVREF40 — CVREF32 CVREF31 CVREF30
R/W — R/W R/W R/W — R/W R/W R/W
POR — 0 0 0 — 0 0 0
• CMPCTL0 Register
Bit 7 6 5 4 3 2 1 0
Name C3VOINV C2VOINV — INTINV C3EN C2EN C1EN C0EN
R/W R/W R/W — R/W R/W R/W R/W R/W
POR 0 0 — 0 0 0 0 0
• CMPCTL1 Register
Bit 7 6 5 4 3 2 1 0
Name C0CMPOP C3CTL0 C2CTL1 C2CTL0 — C1CTL — C3CTL1
R/W R R/W R/W R/W — R/W — R/W
POR 0 0 0 0 — 0 — 0
• CMPDBC0 Register
Bit 7 6 5 4 3 2 1 0
Name — — C0DBC5 C0DBC4 C0DBC3 C0DBC2 C0DBC1 C0DBC0
R/W — — R/W R/W R/W R/W R/W R/W
POR — — 0 0 0 0 0 0
• CMPDBC1 Register
Bit 7 6 5 4 3 2 1 0
Name C3DBEN C2DBEN C1DBEN — — — — —
R/W R/W R/W R/W — — — — —
POR 0 0 0 — — — — —
• CMPHYS Register
Bit 7 6 5 4 3 2 1 0
Name — — — — C3HYSON C2HYSON C1HYSON C0HYSON
R/W — — — — R/W R/W R/W R/W
POR — — — — 0 0 0 0
Operational Amplifier
The device includes an integrated operational amplifier which is used to amplify small analog input
signals. OPINP is the OPAMP non-inverting input and OPINN is the OPAMP inverting input. OPOUT
and OPROUT are the OPAMP analog voltage output pins. OPEN is used to enable or disable OPAMP.
As the OPAMP inputs are pin-shared with I/Os, as well as selecting their respective function.
Register Bit
Name 7 6 5 4 3 2 1 0
OPC OPO OPEN — — OPG1 OPG0 — —
OPVOS OOFM ORSP OOF5 OOF4 OOF3 OOF2 OOF1 OOF0
OPS — — — OPS4 OPS3 OPS2 OPS1 OPS0
Operational Amplifier Register List
• OPC Register
Bit 7 6 5 4 3 2 1 0
Name OPO OPEN — — OPG1 OPG0 — —
R/W R R/W — — R/W R/W — —
POR 0 0 — — 0 0 — —
Bit 7 OPO: OPAMP digital output for input offset voltage calibration mode
0: Positive input voltage < negative input voltage
1: Positive input voltage > negative input voltage
Bit 6 OPEN: OPAMP enable or disable selection bit
0: Disable
1: Enable
Bit 5~4 Unimplemented, read as “0”
Bit 3~2 OPG1~OPG0: R2/R1 ratio selection
00: R2/R1=20
01: R2/R1=30
10: R2/R1=40
11: R2/R1=60
Note that the internal R1 and R2 resistors should be used when the gain is determined
by these bits. This means the OPINN pin should be selected and the SW switch should
be on. Otherwise, the gain accuracy will not be guaranteed. (R2=OPAR1; R1=OPAR3)
Bit 1~0 Unimplemented, read as “0”
• OPVOS Register
Bit 7 6 5 4 3 2 1 0
Name OOFM ORSP OOF5 OOF4 OOF3 OOF2 OOF1 OOF0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 1 0 0 0 0 0
Bit 7 OOFM: OPAMP normal operation or input offset voltage calibration mode selection
0: Normal operation mode
1: Offset calibration mode
Bit 6 ORSP: OPAMP input offset voltage calibration reference selection
0: Select inverting input as the reference input
1: Select non-inverting input as the reference input
Bit 5~0 OOF5~OOF0: OPAMP input offset voltage calibration control bits
• OPS Register
Bit 7 6 5 4 3 2 1 0
Name — — — OPS4 OPS3 OPS2 OPS1 OPS0
R/W — — — R/W R/W R/W R/W R/W
POR — — — 0 0 0 0 0
OVPEN
OVPDA[7:0]
8-bit
AVDD fSYS
DAC S1
OVPCOUT OVPO
-
S2 CMP Debounce
OVPS[1:0] OVPINT
+
S0 (to induction cooker)
OVPI0 OVPDEB[2:0] OVPSPOL
HYS[1:0]
OVPI1
OVPCOFM OVPCRS
Over Voltage Protection Circuit
Note: 1. If the input source is supplied on OVPI1 pin, as the OVPI1 pin is pin-shared with I/O or other pin
functions, before turning on the OVP function, make sure the OVPI1 pin function is selected using the
corresponding Pin-shared Function Selection Registers.
2. The OVPI0 input sources from the CP1N pin.
3. The on/off control for the switches S0, S1 and S2 is summarised below.
OVPCOFM OVPCRS S0 S1 S2
0 x ON ON OFF
1 0 OFF ON ON
1 1 ON OFF ON
“x”: Don’t care
Register Bit
Name 7 6 5 4 3 2 1 0
OVPC0 OVPO OVPSPOL OVPEN — — OVPDEB2 OVPDEB1 OVPDEB0
OVPC1 OVPCOUT OVPCOFM OVPCRS OVPCOF4 OVPCOF3 OVPCOF2 OVPCOF1 OVPCOF0
OVPC2 — — — — HYS1 HYS0 OVPS1 OVPS0
OVPDA D7 D6 D5 D4 D3 D2 D1 D0
OVP Register List
• OVPC0 Register
Bit 7 6 5 4 3 2 1 0
Name OVPO OVPSPOL OVPEN — — OVPDEB2 OVPDEB1 OVPDEB0
R/W R R/W R/W — — R/W R/W R/W
POR 0 0 0 — — 0 0 0
• OVPC1 Register
Bit 7 6 5 4 3 2 1 0
Name OVPCOUT OVPCOFM OVPCRS OVPCOF4 OVPCOF3 OVPCOF2 OVPCOF1 OVPCOF0
R/W R R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 1 0 0 0 0
• OVPC2 Register
Bit 7 6 5 4 3 2 1 0
Name — — — — HYS1 HYS0 OVPS1 OVPS0
R/W — — — — R/W R/W R/W R/W
POR — — — — 0 0 0 0
• OVPDA Register
Bit 7 6 5 4 3 2 1 0
Name D7 D6 D5 D4 D3 D2 D1 D0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
Bit 7~0 D7~D0: OVP D/A converter output voltage control bits
D/A converter Output: D/A converter VOUT=(D/A converter reference voltage/256)×
OVPDA[7:0]
• Step 5
Let OVPCOF[4:0]=OVPCOF[4:0]-1 then read the OVPCOUT bit status after a certain delay.
If the OVPCOUT bit state has not changed, then repeat Step 5 until the OVPCOUT bit state changes.
If the OVPCOUT bit state has changed, record the OVPCOF[4:0] value as VCS2 and then go to Step 6.
• Step 6
Restore VCS=(VCS1+VCS2)/2 to the OVPCOF[4:0] bits. The calibration is finished.
If (VCS1+VCS2)/2 is not an integral, discard the decimal.
PCKEN
fH/4096 0
fH Prescaler
M Output
U Polarity PCK
fH/8192 Control
1 X
• PCKC Register
Bit 7 6 5 4 3 2 1 0
Name — PCKD PCKPOL PCKEN — — — PCKPSC
R/W — R/W R/W R/W — — — R/W
POR — 0 0 0 — — — 0
LVD Register
The Low Voltage Detector function is controlled using a single register with the name LVDC. Three
bits in this register, VLVD2~VLVD0, are used to select one of eight fixed voltages below which a low
voltage condition will be determined. A low voltage condition is indicated when the LVDO bit is
set. If the LVDO bit is low, this indicates that the VDD voltage is above the preset low voltage value.
The LVDEN bit is used to control the overall on/off function of the low voltage detector. Setting the
bit high will enable the low voltage detector. Clearing the bit to zero will switch off the internal low
voltage detector circuits. As the low voltage detector will consume a certain amount of power, it may
be desirable to switch off the circuit when not in use, an important consideration in power sensitive
battery powered applications.
• LVDC Register
Bit 7 6 5 4 3 2 1 0
Name — — LVDO LVDEN VBGEN VLVD2 VLVD1 VLVD0
R/W — — R R/W R/W R/W R/W R/W
POR — — 0 0 0 0 0 0
VDD
VLVD
LVDEN
LVDO
tLVDS
LVD Operation
The Low Voltage Detector also has its own interrupt, providing an alternative means of low voltage
detection, in addition to polling the LVDO bit. The interrupt will only be generated after a delay of
tLVD after the LVDO bit has been set high by a low voltage condition. In this case, the LVF interrupt
request flag will be set, causing an interrupt to be generated if V DD falls below the preset LVD
voltage. This will cause the device to wake-up from the IDLE Mode, however if the Low Voltage
Detector wake up function is not required then the LVF flag should be first set high before the device
enters the IDLE Mode.
Interrupts
Interrupts are an important part of any microcontroller system. When an internal function such as a
Timer or an A/D converter requires microcontroller attention, their corresponding interrupt will enforce
a temporary suspension of the main program allowing the microcontroller to direct attention to their
respective needs. The device contains several internal interrupt functions, which are generated by
various internal functions such as the Timers, Comparators, LVD, EEPROM and the A/D converter, etc.
Interrupt Registers
Overall interrupt control, which basically means the setting of request flags when certain
microcontroller conditions occur and the setting of interrupt enable bits by the application program,
is controlled by the INTC0~INTC3 registers, located in the Special Purpose Data Memory, as shown
in the accompanying table.
Each register contains a number of enable bits to enable or disable individual registers as well as
interrupt flags to indicate the presence of an interrupt request. The naming convention of these
follows a specific pattern. First is listed an abbreviated interrupt type, then the (optional) number of
that interrupt followed by either an “E” for enable/disable bit or “F” for request flag.
Function Enable Bit Request Flag Notes
Global EMI — —
OVP OVPE OVPF —
Comparator CPnE CPnF n=1~3
PPGINT interrupt PPGINTF PPGINTE —
PPG PPGTIMER interrupt PPGTMF PPGTME —
PPGATCD interrupt PPGATCDF PPGATCDE —
A/D Converter ADE ADF —
EEPROM DEE DEF —
LVD LVE LVF —
Timer/Event Counter TnE TnF n=0~2
Interrupt Register Bit Naming Conventions
Register Bit
Name 7 6 5 4 3 2 1 0
INTC0 — PPGINTF CP1F OVPF PPGINTE CP1E OVPE EMI
INTC1 CP3F CP2F ADF T0F CP3E CP2E ADE T0E
INTC2 DEF T2F T1F LVF DEE T2E T1E LVE
INTC3 — — PPGATCDF PPGTMF — — PPGATCDE PPGTME
Interrupt Register List
• INTC0 Register
Bit 7 6 5 4 3 2 1 0
Name — PPGINTF CP1F OVPF PPGINTE CP1E OVPE EMI
R/W — R/W R/W R/W R/W R/W R/W R/W
POR — 0 0 0 0 0 0 0
• INTC1 Register
Bit 7 6 5 4 3 2 1 0
Name CP3F CP2F ADF T0F CP3E CP2E ADE T0E
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• INTC2 Register
Bit 7 6 5 4 3 2 1 0
Name DEF T2F T1F LVF DEE T2E T1E LVE
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 0 0 0 0 0 0
• INTC3 Register
Bit 7 6 5 4 3 2 1 0
Name — — PPGATCDF PPGTMF — — PPGATCDE PPGTME
R/W — — R/W R/W — — R/W R/W
POR — — 0 0 — — 0 0
Interrupt Operation
When the conditions for an interrupt event occur, such as a Timer/Event Counter n overflow or A/D
conversion completion etc., the relevant interrupt request flag will be set. Whether the request flag
actually generates a program jump to the relevant interrupt vector is determined by the condition of
the interrupt enable bit. If the enable bit is set high then the program will jump to its relevant vector;
if the enable bit is zero then although the interrupt request flag is set an actual interrupt will not be
generated and the program will not jump to the relevant interrupt vector. The global interrupt enable
bit, if cleared to zero, will disable all interrupts.
When an interrupt is generated, the Program Counter, which stores the address of the next instruction
to be executed, will be transferred onto the stack. The Program Counter will then be loaded with a
new address which will be the value of the corresponding interrupt vector. The microcontroller will
then fetch its next instruction from this interrupt vector. The instruction at this vector will usually
be a “JMP” which will jump to another section of program which is known as the interrupt service
routine. Here is located the code to control the appropriate interrupt. The interrupt service routine
must be terminated with a “RETI”, which retrieves the original Program Counter address from
the stack and allows the microcontroller to continue with normal execution at the point where the
interrupt occurred.
The various interrupt enable bits, together with their associated request flags, are shown in the
accompanying diagrams with their order of priority. All interrupt sources have their own individual
vector. Once an interrupt subroutine is serviced, all the other interrupts will be blocked, as the global
interrupt enable bit, EMI bit will be cleared automatically. This will prevent any further interrupt
nesting from occurring. However, if other interrupt requests occur during this interval, although the
interrupt will not be immediately serviced, the request flag will still be recorded.
If an interrupt requires immediate servicing while the program is already in another interrupt service
routine, the EMI bit should be set after entering the routine, to allow interrupt nesting. If the stack
is full, the interrupt request will not be acknowledged, even if the related interrupt is enabled, until
the Stack Pointer is decremented. If immediate service is desired, the stack must be prevented from
becoming full. In case of simultaneous requests, the accompanying diagram shows the priority that
is applied. All of the interrupt request flags when set will wake-up the device if it is in SLEEP or
IDLE Mode, however to prevent a wake-up from occurring the corresponding flag should be set
before the device is in SLEEP or IDLE Mode.
Legend
EMI auto disabled in ISR
xxF Request Flag, auto reset in ISR
xxE Enable Bits
Interrupt Structure
OVP Interrupt
The OVP Interrupt is controlled by the Over voltage protection function. An OVP interrupt request
will take place when the OVP interrupt request flag, OVPF, is set, a situation that will occur when
an OVP input voltage is larger than a preset voltage. To allow the program to branch to its respective
interrupt vector address, the global interrupt enable bit, EMI, and OVP interrupt enable bit, OVPE,
must first be set. When the interrupt is enabled, the stack is not full and a larger voltage than the
preset reference value is input, a subroutine call to the OVP interrupt vector will take place. When
the interrupt is serviced, the OVP interrupt request flag will be automatically reset and the EMI bit
will be automatically cleared to disable other interrupts.
Comparator Interrupts
The device has three comparator interrupts, controlled by the internal comparators, CMP1~CMP3.
The comparator n interrupt request will take place when the comparator n interrupt request flag,
CPnF, is set, a situation that will occur when the comparator output bit changes state. To allow the
program to branch to its respective interrupt vector address, the global interrupt enable bit, EMI, and
comparator interrupt enable bits, CPnE, must first be set. When the interrupt is enabled, the stack is
not full and the comparator inputs generate a comparator output falling edge since any of the above
described situations occurs, a subroutine call to the comparator interrupt vector, will take place.
When the interrupt is serviced, the comparator interrupt request flag, CPnF, will be automatically
reset and the EMI bit will be automatically cleared to disable other interrupts.
EEPROM Interrupt
An EEPROM Interrupt request will take place when the EEPROM Interrupt request flag, DEF, is set,
which occurs when an EEPROM Write cycle ends. To allow the program to branch to its respective
interrupt vector address, the global interrupt enable bit, EMI, and EEPROM Interrupt enable bit,
DEE, must first be set. When the interrupt is enabled, the stack is not full and an EEPROM Write
cycle ends, a subroutine call to the EEPROM Interrupt vector will take place. When the EEPROM
Interrupt is serviced, the EEPROM Interrupt request flag, DEF, will be automatically cleared. The
EMI bit will also be automatically cleared to disable other interrupts.
LVD Interrupt
A LVD Interrupt request will take place when the LVD Interrupt request flag, LVF, is set, which
occurs when the Low Voltage Detector function detects a low power supply voltage. To allow the
program to branch to its respective interrupt vector address, the global interrupt enable bit, EMI and
Low Voltage Interrupt enable bit, LVE, must first be set. When the interrupt is enabled, the stack is
not full and a low voltage condition occurs, a subroutine call to the LVD interrupt vector, will take
place. When the Low Voltage Interrupt is serviced, the LVD Interrupt request flag, LVF, will be
automatically cleared. The EMI bit will also be automatically cleared to disable other interrupts.
PPGINT Interrupt
A PPGINT Interrupt request will take place when the PPGINT Interrupt request flag, PPGINTF, is set,
a situation that will occur when a PPG INT00 signal falling edge is generated. To allow the program
to branch to its respective interrupt vector address, the global interrupt enable bit, EMI, and PPGINT
Interrupt enable bit, PPGINTE, must first be set. When the interrupt is enabled, the stack is not full
and the INT00 signal falling edge is produced, a subroutine call to the PPGINT Interrupt vector, will
take place. When the PPGINT Interrupt is serviced, the PPGINT Interrupt flag, PPGINTF, will be
automatically cleared. The EMI bit will also be automatically cleared to disable other interrupts.
PPGTIMER Interrupt
A PPGTIMER Interrupt request will take place when the PPGTIMER Interrupt request flag,
PPGTMF, is set, a situation that will occur when the PPGTIMER overflows. To allow the program
to branch to its respective interrupt vector address, the global interrupt enable bit, EMI, and
PPGTIMER Interrupt enable bit, PPGTME, must first be set. When the interrupt is enabled, the
stack is not full and the PPGTIMER overflow occurs, a subroutine call to the PPGTIMER Interrupt
vector, will take place. When the PPGTIMER Interrupt is serviced, the PPGTIMER Interrupt flag,
PPGTMF, will be automatically cleared. The EMI bit will also be automatically cleared to disable
other interrupts.
PPGATCD Interrupt
A PPGATCD interrupt request will take place when the PPGATCD Interrupt request flag,
PPGATCDF, is set, a situation that will occur when the PPGTA approaches PPGTC/PPGTD has
completed. To allow the program to branch to its respective interrupt vector address, the global
interrupt enable bit, EMI, and PPGATCD Interrupt enable bit, PPGATCDE, must first be set. When
the interrupt is enabled, the stack is not full and the PPG Timer overflow occurs, a subroutine call
to the PPGATCD Interrupt vector, will take place. When the PPGATCD Interrupt is serviced, the
PPGATCD Interrupt flag, PPGATCDF, will be automatically cleared. The EMI bit will also be
automatically cleared to disable other interrupts.
Programming Considerations
By disabling the relevant interrupt enable bits, a requested interrupt can be prevented from being
serviced, however, once an interrupt request flag is set, it will remain in this condition in the
interrupt register until the corresponding interrupt is serviced or until the request flag is cleared by
the application program.
It is recommended that programs do not use the “CALL” instruction within the interrupt service
subroutine. Interrupts often occur in an unpredictable manner or need to be serviced immediately.
If only one stack is left and the interrupt is not well controlled, the original control sequence will be
damaged once a CALL subroutine is executed in the interrupt subroutine.
Every interrupt has the capability of waking up the microcontroller when it is in the SLEEP or IDLE
Mode, the wake up being generated when the interrupt request flag changes from low to high. If it is
required to prevent a certain interrupt from waking up the microcontroller then its respective request
flag should be first set high before enter SLEEP or IDLE Mode.
As only the Program Counter is pushed onto the stack, then when the interrupt is serviced, if the
contents of the accumulator, status register or other registers are altered by the interrupt service
program, their contents should be saved to the memory at the beginning of the interrupt service
routine.
To return from an interrupt subroutine, either a RET or RETI instruction may be executed. The RETI
instruction in addition to executing a return to the main program also automatically sets the EMI
bit high to allow further interrupts. The RET instruction however only executes a return to the main
program leaving the EMI bit in its present zero state and therefore disabling the execution of further
interrupts.
Application Circuits
+5V
9 +5V
VDD/AVDD
VDD
8
VSS/AVSS
GND
13
PB4/C0VO/AN3 SDA
7
PB2/OVP0I1/AN1 SCL
18V_1
+5V
+18V
1
PPG
11
PB1/PCK/C1VO/C3VO
+5V
3
PA3/TC0/CP0P/AN9
2 5
PB3/PPGIN/CP0N/AN0 PA7/CP2P/AN5
16
PB0/OPINN/OPINP
T
15
PA1/OPOUT/AN8
14
PA4/C2VO/AN4/VREF
+5V +5V
+5V
VDD
12
PA0/ICPDA/OCDSDA PA0
GND
PA2
4
PA6/CP2N/AN6
10
PA2/OPROUT/AN2/ICPCK/OCDSCK
T
6
PA5/CP1N/AN7
+5V
Vin Vout
+18V 18V_1 GND
5 4
DVDD
6
D
7 3
D FB
8
D
2
S
1
S
Instruction Set
Introduction
Central to the successful operation of any microcontroller is its instruction set, which is a set of
program instruction codes that directs the microcontroller to perform certain operations. In the case
of Holtek microcontroller, a comprehensive and flexible set of over 60 instructions is provided to
enable programmers to implement their application with the minimum of programming overheads.
For easier understanding of the various instruction codes, they have been subdivided into several
functional groupings.
Instruction Timing
Most instructions are implemented within one instruction cycle. The exceptions to this are branch,
call, or table read instructions where two instruction cycles are required. One instruction cycle is
equal to 4 system clock cycles, therefore in the case of an 8MHz system oscillator, most instructions
would be implemented within 0.5μs and branch or call instructions would be implemented within
1μs. Although instructions which require one more cycle to implement are generally limited to
the JMP, CALL, RET, RETI and table read instructions, it is important to realize that any other
instructions which involve manipulation of the Program Counter Low register or PCL will also take
one more cycle to implement. As instructions which change the contents of the PCL will imply a
direct jump to that new address, one more cycle will be required. Examples of such instructions
would be “CLR PCL” or “MOV PCL, A”. For the case of skip instructions, it must be noted that if
the result of the comparison involves a skip operation then this will also take one more cycle, if no
skip is involved then only one cycle is required.
Arithmetic Operations
The ability to perform certain arithmetic operations and data manipulation is a necessary feature of
most microcontroller applications. Within the Holtek microcontroller instruction set are a range of
add and subtract instruction mnemonics to enable the necessary arithmetic to be carried out. Care
must be taken to ensure correct handling of carry and borrow data when results exceed 255 for
addition and less than 0 for subtraction. The increment and decrement instructions such as INC,
INCA, DEC and DECA provide a simple means of increasing or decreasing by a value of one of the
values in the destination specified.
Bit Operations
The ability to provide single bit operations on Data Memory is an extremely flexible feature of all
Holtek microcontrollers. This feature is especially useful for output port bit programming where
individual bits or port pins can be directly set high or low using either the “SET [m].i” or “CLR [m].i”
instructions respectively. The feature removes the need for programmers to first read the 8-bit output
port, manipulate the input data to ensure that other bits are not changed and then output the port with
the correct new data. This read-modify-write process is taken care of automatically when these bit
operation instructions are used.
Other Operations
In addition to the above functional instructions, a range of other instructions also exist such as
the “HALT” instruction for Power-down operations and instructions to control the operation of
the Watchdog Timer for reliable program operations under extreme electric or electromagnetic
environments. For their relevant operations, refer to the functional related sections.
Table Conventions
x: Bits immediate data
m: Data Memory address
A: Accumulator
i: 0~7 number of bits
addr: Program memory address
Mnemonic Description Cycles Flag Affected
Arithmetic
ADD A,[m] Add Data Memory to ACC 1 Z, C, AC, OV, SC
ADDM A,[m] Add ACC to Data Memory 1Note Z, C, AC, OV, SC
ADD A,x Add immediate data to ACC 1 Z, C, AC, OV, SC
ADC A,[m] Add Data Memory to ACC with Carry 1 Z, C, AC, OV, SC
ADCM A,[m] Add ACC to Data memory with Carry 1Note Z, C, AC, OV, SC
SUB A,x Subtract immediate data from the ACC 1 Z, C, AC, OV, SC, CZ
SUB A,[m] Subtract Data Memory from ACC 1 Z, C, AC, OV, SC, CZ
SUBM A,[m] Subtract Data Memory from ACC with result in Data Memory 1Note Z, C, AC, OV, SC, CZ
SBC A,x Subtract immediate data from ACC with Carry 1 Z, C, AC, OV, SC, CZ
SBC A,[m] Subtract Data Memory from ACC with Carry 1 Z, C, AC, OV, SC, CZ
SBCM A,[m] Subtract Data Memory from ACC with Carry, result in Data Memory 1Note Z, C, AC, OV, SC, CZ
DAA [m] Decimal adjust ACC for Addition with result in Data Memory 1Note C
Logic Operation
AND A,[m] Logical AND Data Memory to ACC 1 Z
OR A,[m] Logical OR Data Memory to ACC 1 Z
XOR A,[m] Logical XOR Data Memory to ACC 1 Z
ANDM A,[m] Logical AND ACC to Data Memory 1Note Z
ORM A,[m] Logical OR ACC to Data Memory 1Note Z
XORM A,[m] Logical XOR ACC to Data Memory 1Note Z
AND A,x Logical AND immediate Data to ACC 1 Z
OR A,x Logical OR immediate Data to ACC 1 Z
XOR A,x Logical XOR immediate Data to ACC 1 Z
CPL [m] Complement Data Memory 1Note Z
CPLA [m] Complement Data Memory with result in ACC 1 Z
Increment & Decrement
INCA [m] Increment Data Memory with result in ACC 1 Z
INC [m] Increment Data Memory 1Note Z
DECA [m] Decrement Data Memory with result in ACC 1 Z
DEC [m] Decrement Data Memory 1Note Z
Rotate
RRA [m] Rotate Data Memory right with result in ACC 1 None
RR [m] Rotate Data Memory right 1Note None
RRCA [m] Rotate Data Memory right through Carry with result in ACC 1 C
RRC [m] Rotate Data Memory right through Carry 1Note C
RLA [m] Rotate Data Memory left with result in ACC 1 None
RL [m] Rotate Data Memory left 1Note None
RLCA [m] Rotate Data Memory left through Carry with result in ACC 1 C
RLC [m] Rotate Data Memory left through Carry 1Note C
Note: 1. For skip instructions, if the result of the comparison involves a skip then two cycles are required, if no
skip takes place only one cycle is required.
2. Any instruction which changes the contents of the PCL will also require 2 cycles for execution.
Note: 1. For these extended skip instructions, if the result of the comparison involves a skip then three cycles are
required, if no skip takes place two cycles is required.
2. Any extended instruction which changes the contents of the PCL register will also require three cycles for
execution.
Instruction Definition
DAA [m] Decimal-Adjust ACC for addition with result in Data Memory
Description Convert the contents of the Accumulator value to a BCD (Binary Coded Decimal) value
resulting from the previous addition of two BCD variables. If the low nibble is greater than 9
or if AC flag is set, then a value of 6 will be added to the low nibble. Otherwise the low nibble
remains unchanged. If the high nibble is greater than 9 or if the C flag is set, then a value of 6
will be added to the high nibble. Essentially, the decimal conversion is performed by adding
00H, 06H, 60H or 66H depending on the Accumulator and flag conditions. Only the C flag
may be affected by this instruction which indicates that if the original BCD sum is greater than
100, it allows multiple precision decimal addition.
Operation [m] ← ACC + 00H or
[m] ← ACC + 06H or
[m] ← ACC + 60H or
[m] ← ACC + 66H
Affected flag(s) C
NOP No operation
Description No operation is performed. Execution continues with the next instruction.
Operation No operation
Affected flag(s) None
RET A,x Return from subroutine and load immediate data to ACC
Description The Program Counter is restored from the stack and the Accumulator loaded with the specified
immediate data. Program execution continues at the restored address.
Operation Program Counter ← Stack
ACC ← x
Affected flag(s) None
RLCA [m] Rotate Data Memory left through Carry with result in ACC
Description Data in the specified Data Memory and the carry flag are rotated left by 1 bit. Bit 7 replaces the
Carry bit and the original carry flag is rotated into the bit 0. The rotated result is stored in the
Accumulator and the contents of the Data Memory remain unchanged.
Operation ACC.(i+1) ← [m].i; (i=0~6)
ACC.0 ← C
C ← [m].7
Affected flag(s) C
RRCA [m] Rotate Data Memory right through Carry with result in ACC
Description Data in the specified Data Memory and the carry flag are rotated right by 1 bit. Bit 0 replaces
the Carry bit and the original carry flag is rotated into bit 7. The rotated result is stored in the
Accumulator and the contents of the Data Memory remain unchanged.
Operation ACC.i ← [m].(i+1); (i=0~6)
ACC.7 ← C
C ← [m].0
Affected flag(s) C
SBCM A,[m] Subtract Data Memory from ACC with Carry and result in Data Memory
Description The contents of the specified Data Memory and the complement of the carry flag are
subtracted from the Accumulator. The result is stored in the Data Memory. Note that if the
result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is
positive or zero, the C flag will be set to 1.
Operation [m] ← ACC − [m] − C
Affected flag(s) OV, Z, AC, C, SC, CZ
SDZA [m] Skip if decrement Data Memory is zero with result in ACC
Description The contents of the specified Data Memory are first decremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy
instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0,
the program proceeds with the following instruction.
Operation ACC ← [m] − 1
Skip if ACC=0
Affected flag(s) None
SIZA [m] Skip if increment Data Memory is zero with result in ACC
Description The contents of the specified Data Memory are first incremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy
instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not
0 the program proceeds with the following instruction.
Operation ACC ← [m] + 1
Skip if ACC=0
Affected flag(s) None
SUBM A,[m] Subtract Data Memory from ACC with result in Data Memory
Description The specified Data Memory is subtracted from the contents of the Accumulator. The result is
stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will be
cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1.
Operation [m] ← ACC − [m]
Affected flag(s) OV, Z, AC, C, SC, CZ
TABRD [m] Read table (specific page) to TBLH and Data Memory
Description The low byte of the program code (specific page) addressed by the table pointer (TBLP and
TBHP) is moved to the specified Data Memory and the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
TABRDL [m] Read table (last page) to TBLH and Data Memory
Description The low byte of the program code (last page) addressed by the table pointer (TBLP) is moved
to the specified Data Memory and the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
ITABRD [m] Increment table pointer low byte first and read table (specific page) to TBLH and Data
Memory
Description Increment table pointer low byte, TBLP, first and then the program code (specific page)
addressed by the table pointer (TBHP and TBLP) is moved to the specified Data Memory and
the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
ITABRDL [m] Increment table pointer low byte first and read table (last page) to TBLH and Data Memory
Description Increment table pointer low byte, TBLP, first and then the low byte of the program code
(last page) addressed by the table pointer (TBLP) is moved to the specified Data Memory and
the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
LDAA [m] Decimal-Adjust ACC for addition with result in Data Memory
Description Convert the contents of the Accumulator value to a BCD (Binary Coded Decimal) value
resulting from the previous addition of two BCD variables. If the low nibble is greater than 9
or if AC flag is set, then a value of 6 will be added to the low nibble. Otherwise the low nibble
remains unchanged. If the high nibble is greater than 9 or if the C flag is set, then a value of 6
will be added to the high nibble. Essentially, the decimal conversion is performed by adding
00H, 06H, 60H or 66H depending on the Accumulator and flag conditions. Only the C flag
may be affected by this instruction which indicates that if the original BCD sum is greater than
100, it allows multiple precision decimal addition.
Operation [m] ← ACC + 00H or
[m] ← ACC + 06H or
[m] ← ACC + 60H or
[m] ← ACC + 66H
Affected flag(s) C
LRLCA [m] Rotate Data Memory left through Carry with result in ACC
Description Data in the specified Data Memory and the carry flag are rotated left by 1 bit. Bit 7 replaces the
Carry bit and the original carry flag is rotated into the bit 0. The rotated result is stored in the
Accumulator and the contents of the Data Memory remain unchanged.
Operation ACC.(i+1) ← [m].i; (i=0~6)
ACC.0 ← C
C ← [m].7
Affected flag(s) C
LRRCA [m] Rotate Data Memory right through Carry with result in ACC
Description Data in the specified Data Memory and the carry flag are rotated right by 1 bit. Bit 0 replaces
the Carry bit and the original carry flag is rotated into bit 7. The rotated result is stored in the
Accumulator and the contents of the Data Memory remain unchanged.
Operation ACC.i ← [m].(i+1); (i=0~6)
ACC.7 ← C
C ← [m].0
Affected flag(s) C
LSBCM A,[m] Subtract Data Memory from ACC with Carry and result in Data Memory
Description The contents of the specified Data Memory and the complement of the carry flag are
subtracted from the Accumulator. The result is stored in the Data Memory. Note that if the
result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is
positive or zero, the C flag will be set to 1.
Operation [m] ← ACC − [m] − C
Affected flag(s) OV, Z, AC, C, SC, CZ
LSDZA [m] Skip if decrement Data Memory is zero with result in ACC
Description The contents of the specified Data Memory are first decremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy
instruction while the next instruction is fetched, it is a three cycle instruction. If the result is
not 0, the program proceeds with the following instruction.
Operation ACC ← [m] − 1
Skip if ACC=0
Affected flag(s) None
LSIZA [m] Skip if increment Data Memory is zero with result in ACC
Description The contents of the specified Data Memory are first incremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy
instruction while the next instruction is fetched, it is a three cycle instruction. If the result is
not 0 the program proceeds with the following instruction.
Operation ACC ← [m] + 1
Skip if ACC=0
Affected flag(s) None
LSUBM A,[m] Subtract Data Memory from ACC with result in Data Memory
Description The specified Data Memory is subtracted from the contents of the Accumulator. The result is
stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will be
cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1.
Operation [m] ← ACC − [m]
Affected flag(s) OV, Z, AC, C, SC, CZ
LTABRD [m] Read table (specific page) to TBLH and Data Memory
Description The low byte of the program code (specific page) addressed by the table pointer (TBHP and
TBLP) is moved to the specified Data Memory and the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
LTABRDL [m] Read table (last page) to TBLH and Data Memory
Description The low byte of the program code (last page) addressed by the table pointer (TBLP) is moved
to the specified Data Memory and the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
LITABRD [m] Increment table pointer low byte first and read table (specific page) to TBLH and Data
Memory
Description Increment table pointer low byte, TBLP, first and then the program code (specific page)
addressed by the table pointer (TBHP and TBLP) is moved to the specified Data Memory and
the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
LITABRDL [m] Increment table pointer low byte first and read table (last page) to TBLH and Data Memory
Description Increment table pointer low byte, TBLP, first and then the low byte of the program code
(last page) addressed by the table pointer (TBLP) is moved to the specified Data Memory and
the high byte moved to TBLH.
Operation [m] ← program code (low byte)
TBLH ← program code (high byte)
Affected flag(s) None
Package Information
Note that the package information provided here is for consultation purposes only. As this
information may be updated at regular intervals users are reminded to consult the Holtek website for
the latest version of the Package/Carton Information.
Additional supplementary information with regard to packaging is listed below. Click on the relevant
section to be transferred to the relevant website page.
• Package Information (include Outline Dimensions, Product Tape and Reel Specifications)
• Carton information
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.236 BSC —
B — 0.154 BSC —
C 0.012 — 0.020
C' — 0.390 BSC —
D — — 0.069
E — 0.050 BSC —
F 0.004 — 0.010
G 0.016 — 0.050
H 0.004 — 0.010
α 0° ― 8°
Dimensions in mm
Symbol
Min. Nom. Max.
A — 6.00 BSC —
B — 3.90 BSC —
C 0.31 — 0.51
C' — 9.90 BSC —
D — — 1.75
E — 1.27 BSC —
F 0.10 — 0.25
G 0.40 — 1.27
H 0.10 — 0.25
α 0° ― 8°