HT66F0175 185v170
HT66F0175 185v170
HT66F0175 185v170
HT66F0175/HT66F0185
Table of Contents
Features................................................................................................................. 7
CPU Features...............................................................................................................................7
Peripheral Features.......................................................................................................................7
Development Tools............................................................................................... 8
General Description.............................................................................................. 8
Selection Table...................................................................................................... 8
Block Diagram....................................................................................................... 9
Pin Assignment..................................................................................................... 9
Pin Descriptions................................................................................................. 11
Absolute Maximum Ratings............................................................................... 17
D.C. Characteristics............................................................................................ 17
A.C. Characteristics............................................................................................ 19
HIRC Electrical Characteristics......................................................................... 20
A/D Converter Electrical Characteristics.......................................................... 21
LVD/LVR Electrical Characteristics................................................................... 22
Comparator Electrical Characteristics............................................................. 22
Software Controlled LCD Driver Electrical Characteristics............................ 23
Power-on Reset Characteristics........................................................................ 23
System Architecture........................................................................................... 24
Clocking and Pipelining...............................................................................................................24
Program Counter.........................................................................................................................25
Stack...........................................................................................................................................26
Arithmetic and Logic Unit – ALU.................................................................................................26
Data Memory....................................................................................................... 31
Structure......................................................................................................................................31
Oscillator............................................................................................................. 41
Oscillator Overview.....................................................................................................................41
System Clock Configurations......................................................................................................41
External Crystal/Ceramic Oscillator – HXT.................................................................................42
Internal High Speed RC Oscillator – HIRC.................................................................................43
External 32.768 kHz Crystal Oscillator – LXT.............................................................................43
Internal 32kHz Oscillator – LIRC.................................................................................................44
Supplementary Oscillators..........................................................................................................44
Watchdog Timer.................................................................................................. 55
Watchdog Timer Clock Source....................................................................................................55
Watchdog Timer Control Register...............................................................................................55
Watchdog Timer Operation.........................................................................................................57
Input/Output Ports.............................................................................................. 64
Pull-high Resistors......................................................................................................................65
Port A Wake-up...........................................................................................................................65
I/O Port Control Registers...........................................................................................................66
I/O Port Source Current Control..................................................................................................66
Pin-remapping Functions............................................................................................................68
I/O Pin Structures........................................................................................................................69
Programming Considerations......................................................................................................70
Introduction.................................................................................................................................71
TM Operation..............................................................................................................................71
TM Clock Source.........................................................................................................................72
TM Interrupts...............................................................................................................................72
TM External Pins.........................................................................................................................72
TM Input/Output Pin Control Register.........................................................................................73
Programming Considerations......................................................................................................75
Comparators..................................................................................................... 146
Comparator Operation..............................................................................................................146
Comparator Interrupt.................................................................................................................146
Programming Considerations....................................................................................................146
LCD Operation..........................................................................................................................148
LCD Control Registers..............................................................................................................150
Interrupts........................................................................................................... 172
Interrupt Registers.....................................................................................................................172
Interrupt Operation....................................................................................................................179
External Interrupt.......................................................................................................................181
Comparator Interrupt – HT66F0185..........................................................................................181
Multi-function Interrupt..............................................................................................................181
A/D Converter Interrupt.............................................................................................................182
Time Base Interrupt...................................................................................................................182
Serial Interface Module Interrupt...............................................................................................183
UART Transfer Interrupt – HT66F0185.....................................................................................183
LVD Interrupt.............................................................................................................................184
EEPROM Interrupt....................................................................................................................184
TM Interrupt...............................................................................................................................184
Interrupt Wake-up Function.......................................................................................................185
Programming Considerations....................................................................................................185
Features
CPU Features
• Operating voltage
♦ fSYS= 8MHz: 2.2V~5.5V
♦ fSYS=12MHz: 2.7V~5.5V
♦ fSYS=20MHz: 4.5V~5.5V
Peripheral Features
• Program Memory: Up to 4K×16
• Data Memory: Up to 256×8
• True EEPROM Memory: Up to 128×8
• Watchdog Timer function
• Up to 26 bidirectional I/O lines
• Two external interrupt lines shared with I/O pins
• Multiple Timer Modules for time measure, input capture, compare match output, PWM output
function or single pulse output function
• Serial Interfaces Module – SIM for SPI or I2C
• Software controlled 6-SCOM/SSEG and 18-SSEG lines LCD driver with 1/3 bias
• Programmable I/O port source current for LED applications
• Dual Time-Base functions for generation of fixed time interrupt signals
• 8-channel 12-bit resolution A/D converter
• One Comparator function – available in HT66F0185
• Fully-duplex Universal Asynchronous Receiver and Transmitter Interface – UART, available in
HT66F0185
• Low voltage reset function
• Low voltage detect function
• Flash program memory can be re-programmed up to 10,000 times
• Flash program memory data retention > 10 years
• True EEPROM data memory can be re-programmed up to 100,000 times
• True EEPROM data memory data retention > 10 years
• Wide range of available package types
Development Tools
For rapid product development and to simplify device parameter setting, Holtek has provided
relevant development tools which users can download from the following link:
https://www.holtek.com/esk-tds-100 (HT66F0185 only)
General Description
The series of devices are Flash Memory A/D type 8-bit high performance RISC architecture
microcontroller. Offering users the convenience of Flash Memory multi-programming features, these
devices also include a wide range of functions and 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, calibratuib data, etc.
Analog features include a multi-channel 12-bit A/D converter and a comparator functions. Multiple
and extremely flexible Timer Modules provide timing, pulse generation and PWM generation
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. A full choice of HXT, LXT, HIRC and
LIRC oscillator functions are provided including a fully integrated system oscillator which requires
no external components for its 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 minimize power consumption.
The inclusion of flexible I/O programming features, Time-Base functions along with many other
features ensure that the devices will find excellent use in applications such as electronic metering,
environmental monitoring, handheld instruments, household appliances, electronically controlled
tools, motor driving in addition to many others.
Selection Table
Most features are common to all devices. The main features distinguishing them are Memory
capacity, I/O count, Timer Module features, SSEG count, LED count, UART and package types. The
following table summarises the main features of each device.
Time SCOM/
Part No. SIM UART CMP SSEG LED Stack Package
Base SSEG
HT66F0175 2 √ — — 6 14 22 8 20SOP/SSOP, 24SSOP
HT66F0185 2 √ √ √ 6 18 26 8 24/28SOP/SSOP
Note: As devices exist in more than one package format, the table reflects the situation for the package with
the most pins.
Block Diagram
Internal
Watchdog
HIRC/LIRC
Timer Reset
Oscillators
Circuit
Flash/EEPROM
Programming Circuitry 8-bit
RISC Interrupt
Low Low Controller
Voltage Voltage MCU
Detect Reset Core
External
HXT/LXT
EEPROM Flash Oscillators
RAM Data Time
Data Program
Memory Base
Memory Memory
12-bit A/D
Converter
Comparator
SSEG/ Timer SIM +
I/O UART
SCOM Modules (SPI/I2C) ─
For HT66F0185
For HT66F0185
Pin Assignment
VSS&AVSS 1 20 VDD&AVDD
PC0/SSEG17/OSC1 2 19 PB0/INT0/SSEG16/AN0/XT1
PC1/SSEG18/OSC2 3 18 PB1/INT1/SSEG15/AN1/XT2
PC2/SDO/SSEG0/SCOM0 4 17 PB2/TCK0/SSEG14/AN2
PA0/TP0/ICPDA/OCDSDA 5 16 PA4/TCK1/SSEG13/AN3
PA1/[SDO]/SCS/SSEG2/SCOM2 6 15 PA5/SSEG10/AN4/VREFI
PA2/ICPCK/OCDSCK 7 14 PA6/SSEG9/AN5/VREF
PA3/[SDI/SDA]/SSEG3/SCOM3 8 13 PA7/TP1/SSEG8/AN6
PB6/[SCK/SCL]/SSEG4/SCOM4 9 12 PB3/SSEG7/AN7
PB5/[SCS]/SSEG5/SCOM5 10 11 PB4/CLO/SSEG6
HT66F0175/HT66V0175
20 SOP-A/SSOP-A
VSS&AVSS 1 24 VDD&AVDD
PC0/SSEG17/OSC1 2 23 PB0/INT0/SSEG16/AN0/XT1
PC1/SSEG18/OSC2 3 22 PB1/INT1/SSEG15/AN1/XT2
PC2/SDO/SSEG0/SCOM0 4 21 PB2/TCK0/SSEG14/AN2
PA0/TP0/ICPDA/OCDSDA 5 20 PA4/TCK1/SSEG13/AN3
PC3/SDI/SDA/SSEG19 6 19 PC6/[INT0]/SSEG12
PC4/SCK/SCL/SSEG1/SCOM1 7 18 PC5/[INT1]/SSEG11
PA1/[SDO]/SCS/SSEG2/SCOM2 8 17 PA5/SSEG10/AN4/VREFI
PA2/ICPCK/OCDSCK 9 16 PA6/SSEG9/AN5/VREF
PA3/[SDI/SDA]/SSEG3/SCOM3 10 15 PA7/TP1/SSEG8/AN6
PB6/[SCK/SCL]/SSEG4/SCOM4 11 14 PB3/SSEG7/AN7
PB5/[SCS]/SSEG5/SCOM5 12 13 PB4/CLO/SSEG6
HT66F0175/HT66V0175
24 SSOP-A
VSS&AVSS 1 24 VDD&AVDD
PC0/SSEG19/OSC1 2 23 PB0/INT0/SSEG18/AN0/XT1
PC1/SSEG20/OSC2 3 22 PB1/INT1/SSEG17/AN1/XT2
PC2/[SDO]/SSEG0/SCOM0 4 21 PB2/TCK0/SSEG16/AN2
PA0/TP0/ICPDA/OCDSDA 5 20 PA4/TCK1/SSEG15/AN3
PC4/SDI/SDA/SSEG22 6 19 PD2/TX/SSEG13
PC5/SCK/SCL/SSEG1/SCOM1 7 18 PD1/RX/SSEG12
PA1/[SDO]/SSEG2/SCOM2 8 17 PA5/SSEG10/AN4/VREFI
PA2/ICPCK/OCDSCK 9 16 PA6/TCK2/SSEG9/AN5/VREF
PA3/[SDI/SDA]/CX/SSEG3/SCOM3 10 15 PA7/TP1/SSEG8/AN6
PB6/[SCK/SCL]/C+/SSEG4/SCOM4 11 14 PB3/[TX]/TP2/SSEG7/AN7
PB5/[SCS]/C-/SSEG5/SCOM5 12 13 PB4/[RX]/CLO/SSEG6
HT66F0185/HT66V0185
24 SOP-A/SSOP-A
VSS&AVSS 1 28 VDD&AVDD
PC0/SSEG19/OSC1 2 27 PB0/INT0/SSEG18/AN0/XT1
PC1/SSEG20/OSC2 3 26 PB1/INT1/SSEG17/AN1/XT2
PC2/[SDO]/SSEG0/SCOM0 4 25 PB2/TCK0/SSEG16/AN2
PA0/TP0/ICPDA/OCDSDA 5 24 PA4/TCK1/SSEG15/AN3
PC3/SDO/SSEG21 6 23 PD3/SSEG14
PC4/SDI/SDA/SSEG22 7 22 PD2/TX/SSEG13
PC5/SCK/SCL/SSEG1/SCOM1 8 21 PD1/RX/SSEG12
PC6/SCS/SSEG23 9 20 PD0/SSEG11
PA1/[SDO]/SSEG2/SCOM2 10 19 PA5/SSEG10/AN4/VREFI
PA2/ICPCK/OCDSCK 11 18 PA6/TCK2/SSEG9/AN5/VREF
PA3/[SDI/SDA]/CX/SSEG3/SCOM3 12 17 PA7/TP1/SSEG8/AN6
PB6/[SCK/SCL]/C+/SSEG4/SCOM4 13 16 PB3/[TX]/TP2/SSEG7/AN7
PB5/[SCS]/C-/SSEG5/SCOM5 14 15 PB4/[RX]/CLO/SSEG6
HT66F0185/HT66V0185
28 SOP-A/SSOP-A
Note: 1. If the pin-shared pin functions have multiple outputs simultaneously, its pin names at the right side of the “/”
sign can be used for higher priority.
2. VDD&AVDD means the VDD and AVDD are the double bonding.
3. VSS&AVSS means the VSS and AVSS are the double bonding.
4. The OCDSDA and OCDSCK pins are the OCDS dedicated pins and only available for the HT66V01x5
device which is the OCDS EV chip for the HT66F01x5 device.
Pin Descriptions
With the exception of the power pins, all pins on these devices 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, Timer Module pins, 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.
HT66F0175
Pad Name Function OPT I/T O/T Description
PAWU General purpose I/O. Register enabled pull-up and
PA0 ST CMOS
PAPU wake-up.
PA0/TP0/ICPDA/ TP0 TMPC ST CMOS TM0 input/output
OCDSDA
ICPDA — ST CMOS ICP Data/Address pin
OCDSDA — ST CMOS OCDS Data/Address pin, for EV chip only.
PAWU General purpose I/O. Register enabled pull-up and
PA1 ST CMOS
PAPU wake-up.
SLCDC0
[SDO] SIMC0 — CMOS SPI data output
IFS
PA1/[SDO]/SCS/
SLCDC0
SSEG2/SCOM2 SCS ST CMOS SPI slave select
SIMC0 IFS
SLCDC0
SSEG2 — SSEG Software controlled LCD segment output
SLCDC1
SLCDC0
SCOM2 — SCOM Software controlled LCD common output
SLCDC1
PAWU General purpose I/O. Register enabled pull-up and
PA2 ST CMOS
PAPU wake-up.
PA2/ICPCK/
OCDSCK ICPCK — ST CMOS ICP Clock pin
OCDSCK — ST — OCDS Clock pin, for EV chip only.
PAWU General purpose I/O. Register enabled pull-up and
PA3 ST CMOS
PAPU wake-up.
SLCDC0
[SDI] SIMC0 ST — SPI data input
IFS
PA3/[SDI/SDA]/ SLCDC0
SSEG3/SCOM3 [SDA] SIMC0 ST NMOS I2C address/data line
IFS
SLCDC0
SSEG3 — SSEG Software controlled LCD segment output
SLCDC1
SLCDC0
SCOM3 — SCOM Software controlled LCD common output
SLCDC1
PAWU General purpose I/O. Register enabled pull-up and
PA4 ST CMOS
PAPU wake-up.
PA4/TCK1/ TCK1 TM1C0 ST — TM1 input
SSEG13/AN3
SSEG13 SLCDC2 — SSEG Software controlled LCD segment output
AN3 ACERL AN — A/D Converter analog input
PAWU General purpose I/O. Register enabled pull-up and
PA5 ST CMOS
PAPU wake-up.
PA5/SSEG10/ SSEG10 SLCDC2 — SSEG Software controlled LCD segment output
AN4/VREFI
AN4 ACERL AN — A/D Converter analog input
VREFI SADC2 AN — A/D Converter PGA voltage input
HT66F0185
Pad Name Function OPT I/T O/T Description
PAWU General purpose I/O. Register enabled pull-up and
PA0 ST CMOS
PAPU wake-up.
PA0/TP0/ICPDA/ TP0 TMPC ST CMOS TM0 input/output
OCDSDA
ICPDA — ST CMOS ICP Data/Address pin
OCDSDA — ST CMOS OCDS Data/Address pin, for EV chip only.
Note: These are stress ratings only. Stresses exceeding the range specified under “Absolute
Maximum Ratings” may cause substantial damage to these devices. Functional operation of
these devices at other conditions beyond those listed in the specification is not implied and
prolonged exposure to extreme conditions may affect devices reliability.
D.C. Characteristics
Ta=25°C
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
fSYS= fHXT=8MHz 2.2 — 5.5 V
fSYS= fHXT=12MHz 2.7 — 5.5 V
Operating Voltage (HXT) —
fSYS= fHXT=16MHz 4.5 — 5.5 V
VDD fSYS= fHXT=20MHz 4.5 — 5.5 V
fSYS= fHIRC=8MHz 2.2 — 5.5 V
Operating Voltage (HIRC) — fSYS= fHIRC=12MHz 2.7 — 5.5 V
fSYS= fHIRC=16MHz 4.5 — 5.5 V
3V fSYS=fH= fHXT=8MHz — 1.0 1.5 mA
5V No load, all peripherals off — 2.5 4.0 mA
3V fSYS=fH= fHXT=12MHz — 1.5 2.5 mA
Operating Current (HXT) 5V No load, all peripherals off — 3.5 5.5 mA
fSYS=fH= fHXT=16MHz, no load,
5V — 4.5 7.0 mA
all peripherals off
fSYS=fH= fHXT=20MHz, no load,
5V — 5.5 8.5 mA
all peripherals off
3V fSYS=fH= fHIRC=8MHz — 2.0 2.8 mA
IDD
5V No load, all peripherals off — 3.0 4.5 mA
3V fSYS=fH= fHIRC=12MHz — 3.0 4.2 mA
Operating Current (HIRC)
5V No load, all peripherals off — 4.5 6.7 mA
fSYS=fH= fHIRC=16MHz
5V — 6.0 9.0 mA
No load, all peripherals off
3V fSYS=fSUB=fLXT=32.768kHz — 10 20 μA
Operating Current (LXT)
5V No load, all peripherals off — 30 50 μA
3V fSYS=fSUB=fLIRC=32kHz — 10 20 μA
Operating Current (LIRC)
5V No load, all peripherals off — 30 50 μA
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
3V No load, all peripherals off, — 3 5 μA
Standby Current (IDLE0 Mode)
5V fSUB on — 5 10 μA
3V fSYS=fHXT=8MHz on, fSUB on — 0.5 1.0 mA
5V No load, all peripherals off — 1.0 2.0 mA
3V fSYS=fHXT=12MHz on, fSUB on — 0.6 1.2 mA
5V No load, all peripherals off — 1.2 2.4 mA
fSYS=fHXT=16MHz on, fSUB on
5V — 2.0 4.0 mA
No load, all peripherals off
fSYS=fHXT=20MHz on, fSUB on
Standby Current (IDLE1 Mode) 5V — 2.5 5.0 mA
No load, all peripherals off
ISTB
3V fSYS=fHIRC=8MHz on, fSUB on — 0.8 1.6 mA
5V No load, all peripherals off — 1.0 2.0 mA
3V fSYS=fHIRC=12MHz on, fSUB on — 1.2 2.4 mA
5V No load, all peripherals off — 1.5 3.0 mA
fSYS=fHIRC=16MHz on, fSUB on
5V — 2.0 4.0 mA
No load, all peripherals off
3V fSUB off, WDT disable — — 1.0 μA
Standby Current (SLEEP0 Mode)
5V No load, all peripherals off — — 2.0 μA
3V fSUB on, WDT enable — — 3.0 μA
Standby Current (SLEEP1 Mode)
5V No load, all peripherals off — — 5.0 μA
Input Low Voltage for I/O Ports 5V — 0 — 1.5 V
VIL
or Input Pins — — 0 — 0.2VDD V
Input High Voltage for I/O Ports 5V — 3.5 — 5.0 V
VIH
or Input Pins — — 0.8VDD — VDD V
3V VOL = 0.1VDD 16 32 — mA
IOL Sink Current for I/O Port
5V VOL = 0.1VDD 32 64 — mA
3V VOH = 0.9VDD, -1.0 -2.0 — mA
SLEDCn [m+1, m] = 00
5V n = 0 or 1; m = 0, 2, 4 or 6 -2.0 -4.0 — mA
A.C. Characteristics
Ta=25°C
Test Condition
Symbol Parameter Min. Typ. Max. Unit
VDD Condition
2.2V~5.5V fSYS=fHXT=8MHz — 8 — MHz
2.7V~5.5V fSYS=fHXT=12MHz — 12 — MHz
System Clock (HXT)
4.5V~5.5V fSYS=fHXT=16MHz — 16 — MHz
4.5V~5.5V fSYS=fHXT=20MHz — 20 — MHz
fSYS 2.4V~5.5V fSYS=fHIRC=8MHz — 8 — MHz
System Clock (HIRC) 2.7V~5.5V fSYS=fHIRC=12MHz — 12 — MHz
4.5V~5.5V fSYS=fHIRC=16MHz — 16 — MHz
System Clock (LXT) 2.2V~5.5V fSYS=fLXT=32.768kHz — 32.768 — kHz
System Clock (LIRC) 2.2V~5.5V fSYS=fLIRC=32kHz — 32 — kHz
5V Ta=25°C -10% 32 +10% kHz
fLIRC Low Speed Internal RC oscillator (LIRC)
2.2V~5.5V Ta=-40°C to 85°C -50% 32 +60% kHz
tTCK TCKn pin Minimum Input Pulse Width — — 0.3 — — μs
tINT Interrupt Pin Minimum Input Pulse Width — — 10 — — μs
— fSYS=fHXT off 128 — — tHXT
System Start-up Timer Period — fSYS=fHIRC off 16 — — tHIRC
(Wake-up from power down mode and
fSYS off) — fSYS=fLXT off 128 — — tLXT
tSST
— fSYS=fLIRC off 2 — — tLIRC
System Start-up Timer Period
— fSYS on 2 — — tSYS
(Wake-up from power down mode)
System reset delay time
(Power-on reset, LVR hardware reset, — — 25 50 100 ms
tRSTD LVRC/WDTC software reset)
System reset delay time
— — 8.3 16.7 33.3 ms
(WDT hardware reset)
tEERD EEPROM Read Time — — — — 4 tSYS
tEEWR EEPROM Write Time — — — 2 4 ms
Note: tSYS= 1/fSYS
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 devices 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 cycle, with the
exception of branch or call instructions. 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 these
devices suitable for low-cost, high-volume production for controller applications.
For instructions involving branches, such as jump or call instructions, two machine cycles are
required to complete instruction execution. An extra cycle is required as the program takes one
cycle to first obtain the actual jump or call address and then another cycle to actually execute the
branch. The requirement for this extra cycle should be taken into account by programmers in timing
sensitive applications.
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
Device
High Byte Low Byte (PCL)
HT66F0175 PC10~PC8 PC7~PC0
HT66F0185 PC11~PC8 PC7~PC0
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 has multiple levels and is 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 2K×16 to 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 registers.
HT66F0175 HT66F0185
000H
Initialisation Vector Initialisation Vector
004H
024H
028H
n00H
Look-up Table Look-up Table
nFFH
7FFH 16 bits
FFFH 16 bits
Special Vectors
Within the Program Memory, certain locations are reserved for the reset and interrupts. The location
000H is reserved for use by these devices 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 “TABRD [m]” or “TABRDL [m]” instructions 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.
L a s t p a g e o r
A d d re s s
T B H P R e g is te r D a ta
T B L P R e g is te r 1 6 b its
U s e r S e le c te d
R e g is te r T B L H
R e g is te r
H ig h B y te L o w B y te
The Program Memory and EEPROM data 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. The technical details regarding
the in-circuit programming of the device are 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.
W r ite r C o n n e c to r M C U P r o g r a m m in g
S ig n a ls P in s
W r ite r _ V D D V D D
IC P D A P A 0
IC P C K P A 2
W r ite r _ V S S V S S
* *
T o o th e r C ir c u it
Note: * may be resistor or capacitor. The resistance of * must be greater than 1kΩ or the capacitance
of * must be less than 1nF.
Data Memory
The Data Memory is an 8-bit wide RAM internal memory and is the location where temporary
information is stored.
Structure
Divided into two banks, the first of these is an area of RAM, known as the Special Function Data
Memory. Here are located registers which 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.
The overall Data Memory is subdivided into two banks. The Special Purpose Data Memory registers
are accessible in all banks, with the exception of the EEC register at address 40H, which is only
accessible in Bank 1. Switching between the different Data Memory banks is achieved by setting the
Bank Pointer to the correct value. The start address of the Data Memory for the device is the address
00H.
The address range of the Special Purpose Data Memory for the device is from 00H to 7FH while the
address range of the General Purpose Data Memory is from 80H to FFH.
Device Capacity Banks
HT66F0175 128 × 8 0: 80H~FFH
0: 80H~FFH
HT66F0185 256 × 8
1: 80H~FFH
00H 00H
Special Special
Purpose Data Purpose Data
40H: EEC Memory 40H:EEC
Memory
(Bank 1) (Bank 1)
7FH 7FH
80H 80H
General
General Purpose Data
Purpose Data Memory
Memory
FFH Bank 0
FFH Bank 0 Bank 1
HT66F0175 HT66F0185
HT66F0175 HT66F0185
Bank Pointer – BP
For the HT66F0185 device, the Data Memory is divided into two banks, Bank0 and Bank1.
Selecting the required Data Memory area is achieved using the Bank Pointer. Bit 0 of the Bank
Pointer is used to select Data Memory Banks 0~1. The Data Memory is initialised to Bank 0 after a
reset, except for a WDT time-out reset in the Power Down Mode, in which case, the Data Memory
bank remains unaffected. It should be noted that the Special Function Data Memory is not affected
by the bank selection, which means that the Special Function Registers can be accessed from
within any bank. Directly addressing the Data Memory will always result in Bank 0 being accessed
irrespective of the value of the Bank Pointer. Accessing data from Bank1 must be implemented
using Indirect Addressing.
BP Register – HT66F0185
Bit 7 6 5 4 3 2 1 0
Name — — — — — — — DMBP0
R/W — — — — — — — R/W
POR — — — — — — — 0
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.
STATUS Register
Bit 7 6 5 4 3 2 1 0
Name — — TO PDF OV Z AC C
R/W — — R R R/W R/W R/W R/W
POR — — 0 0 x x x x
“x”: unknown
Bit 7~6 Unimplemented, read as “0”
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” instructin
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 substraction
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 bank 0, they can be directly accessed in the same was as any other
Special Function Register. The EEC register, however, being located in bank 1, can be read from
or written to indirectly using the MP1 Memory Pointer and Indirect Addressing Register, IAR1.
Because the EEC control register is located at address 40H in bank 1, the MP1Memory Pointer
register must first be set to the value 40H and the Bank Pointer register, BP, set to the value, 01H,
before any operations on the EEC register are executed.
Bit
Register Name
7 6 5 4 3 2 1 0
EEA (HT66F0175) — — EEA5 EEA4 EEA3 EEA2 EEA1 EEA0
EEA (HT66F0185) — EEA6 EEA5 EEA4 EEA3 EEA2 EEA1 EEA0
EED D7 D6 D5 D4 D3 D2 D1 D0
EEC — — — — WREN WR RDEN RD
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 Bank Pointer register, BP, will be reset to zero, which means that
Data Memory bank 0 will be selected. As the EEPROM control register is located in bank 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. However, as
the EEPROM is contained within a Multi-function Interrupt, the associated multi-function interrupt
enable bit must also be set. When an EEPROM write cycle ends, the DEF request flag and its
associated multi-function interrupt request flag will both be set. If the global, EEPROM and Multi-
function interrupts are enabled and the stack is not full, a jump to the associated Multi-function
Interrupt vector will take place. When the interrupt is serviced only the Multi-function interrupt flag
will be automatically reset, the EEPROM interrupt flag must be manually reset by the application
program.
Programming Considerations
Care must be taken that data is not inadvertently written to the EEPROM. Protection can be Periodic
by ensuring that the Write Enable bit is normally cleared to zero when not writing. Also the Bank
Pointer register could be normally cleared to zero as this would inhibit access to bank 1 where the
EEPROM control register exist. 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 Example
Oscillator
Various oscillator types 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
through a combination of configuration options and relevant 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. External oscillators requiring some external
components as well as fully integrated internal oscillators, requiring no external components, are
provided to form a wide range of both fast and slow system oscillators. All oscillator options are
selected through configuration options. 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 Pins
High Speed External Crystal HXT 400 kHz~20 MHz OSC1/OSC2
High Speed Internal RC HIRC 8/12/16 MHz —
Low Speed External Crystal LXT 32.768 kHz XT1/XT2
Low Speed Internal RC LIRC 32 kHz —
Oscillator Types
fH
High Speed
Oscillator fH/2
fH/4
HXT
fH/8
Prescaler fH/16
HIRC fH
fH/32 fSYS
fH/64
High Speed Oscillator
Low Speed Configuration Option
Oscillator Fast Wake-up from IDLE
or SLEEP Mode Control
HLCLK, (for HXT only )
LXT CKS2~CKS0
fSUB
fSUB
LIRC
C1
OSC1
RP
OSC2
C2
Crystal/Resonator Oscillator
C1
XT1
RP
32.768kHz
XT2
C2
Note: 1. RP, C1 and C2 are required.
2. Although not shown XT1/XT2 pins have a parasitic
capacitance of around 7pF.
After power on, the LXTLP bit will be automatically cleared to zero ensuring that the LXT oscillator
is in the Quick Start operating mode. In the Quick Start Mode the LXT oscillator will power up
and stabilise quickly. However, after the LXT oscillator has fully powered up it can be placed
into the Low-power mode by setting the LXTLP bit high. The oscillator will continue to run but
with reduced current consumption, as the higher current consumption is only required during the
LXT oscillator start-up. In power sensitive applications, such as battery applications, where power
consumption must be kept to a minimum, it is therefore recommended that the application program
sets the LXTLP bit high about 2 seconds after power-on. It should be noted that, no matter what
condition the LXTLP bit is set to, the LXT oscillator will always function normally and the only
difference is that it will take more time to start up if in the Low-power mode.
Supplementary Oscillators
The low speed oscillators, in addition to providing a system clock source are also used to provide
a clock source to two other device functions. These are the Watchdog Timer and the Time Base
Interrupts.
System Clocks
The devices have many different clock sources for both the CPU and peripheral function operation.
By providing the user with a wide range of clock options using configuration options and register
programming, a clock system can be configured to obtain maximum application performance.
The main system clock, can come from either a high frequency fH or low frequency fSUB source, and
is selected using the HLCLK bit and CKS2~CKS0 bits in the SMOD register. The high speed system
clock can be sourced from either an HXT or HIRC oscillator, selected via a configuration option.
The low speed system clock source can be sourced from internal clock fSUB. If fSUB is selected then it
can be sourced by either the LXT or LIRC oscillator, selected via a configuration option. The other
choice, which is a divided version of the high speed system oscillator has a range of fH/2~ fH/64.
There are two additional internal clocks for the peripheral circuits, the substitute clock, fSUB, and
the Time Base clock, fTBC. Each of these internal clocks is sourced by either the LXT or LIRC
oscillators, selected via configuration options. The fSUB clock is used to provide a substitute clock for
the microcontroller just after a wake-up has occurred to enable faster wake-up times.
fH
High Speed
Oscillator fH/2
fH/4
HXT
fH/8
Prescaler fH/16
HIRC fH
fH/32 fSYS
fH/64
High Speed Oscillator
Low Speed Configuration Option
Oscillator Fast Wake-up from IDLE
or SLEEP Mode Control
HLCLK, (for HXT only )
LXT CKS2~CKS0
fSUB
fSUB
LIRC fSUB
WDT
TBCK
NORMAL Mode
As the name suggests this is one of the main operating modes where the microcontroller has all of
its functions operational and where the system clock is provided by one of the high speed oscillators.
This mode operates allowing the microcontroller to operate normally with a clock source will come
from one of the high speed oscillators, either the HXT or HIRC oscillators. 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 and HLCLK bits in the SMOD 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 one of the low speed oscillators, either the LXT
or the LIRC. Running the microcontroller in this mode allows it to run with much lower operating
currents. In the SLOW Mode, the fH is off.
SLEEP0 Mode
The SLEEP0 Mode is entered when an HALT instruction is executed and when the IDLEN bit in
the SMOD register is low. In the SLEEP0 mode the CPU will be stopped, the fSUB clock will also be
stopped and the Watchdog Timer function is disabled. In this mode, the LVDEN must be set to “0”.
If the LVDEN is set to “1”, it won’t enter the SLEEP0 Mode.
SLEEP1 Mode
The SLEEP1 Mode is entered when an HALT instruction is executed and when the IDLEN bit in the
SMOD register is low. In the SLEEP1 mode the CPU will be stopped. However the fSUB clock will
continue to operate if the Watchdog Timer function is enabled.
IDLE0 Mode
The IDLE0 Mode is entered when a HALT instruction is executed and when the IDLEN bit in the
SMOD register is high and the FSYSON bit in the CTRL register is low. In the IDLE0 Mode the
system oscillator will be inhibited from driving the CPU but some peripheral functions will remain
operational such as the Watchdog Timer and TMs. In the IDLE0 Mode, the system oscillator will be
stopped.
IDLE1 Mode
The IDLE1 Mode is entered when an HALT instruction is executed and when the IDLEN bit in the
SMOD register is high and the FSYSON bit in the CTRL register is high. In the IDLE1 Mode the
system oscillator will be inhibited from driving the CPU but may continue to provide a clock source
to keep some peripheral functions operational such as the Watchdog Timer and TMs. In the IDLE1
Mode, the system oscillator will continue to run, and this system oscillator may be high speed or low
speed system oscillator.
Control Registers
A single register, SMOD, is used for overall control of the internal clocks within the devices.
SMOD Register
Bit 7 6 5 4 3 2 1 0
Name CKS2 CKS1 CKS0 FSTEN LTO HTO IDLEN HLCLK
R/W R/W R/W R/W R/W R R R/W R/W
POR 0 0 0 0 0 0 1 1
CTRL Register
Bit 7 6 5 4 3 2 1 0
Name FSYSON — — — — LVRF LRF WRF
R/W R/W — — — — R/W R/W R/W
POR 0 — — — — x 0 0
“x”: unknown
Bit 7 FSYSON: fSYS Control in IDLE Mode
0: Disable
1: Enable
This bit is used to control whether the system clock is switched on or not in the IDLE
Mode. If this bit is set to “0”, the system clock will be switched off in the IDLE Mode.
However, the system clock will be switched on in the IDLE Mode when the FSYSON
bit is set to “1”.
Bit 6~3 Unimplemented, read as “0”
Bit 2 LVRF: LVR function reset flag
Described elsewhere.
Bit 1 LRF: LVR control register software reset flag
Described elsewhere.
Bit 0 WRF: WDT control register software reset flag
Described elsewhere.
Fast Wake-up
To minimise power consumption the device can enter the SLEEP or IDLE0 Mode, where the system
clock source to the devices will be stopped. However when the devices are woken up again, it can
take a considerable time for the original system oscillator to restart, stabilise and allow normal
operation to resume. To ensure the devices are up and running as fast as possible a Fast Wake-
up function is provided, which allows fSUB, namely either the LXT or LIRC oscillator, to act as a
temporary clock to first drive the system until the original system oscillator has stabilised. As the
clock source for the Fast Wake-up function is fSUB, the Fast Wake-up function is only available in
the SLEEP1 and IDLE0 modes. When the devices are woken up from the SLEEP0 mode, the Fast
Wake-up function has no effect because the fSUB clock is stopped. The Fast Wake-up enable/disable
function is controlled using the FSTEN bit in the SMOD register.
If the HXT oscillator is selected as the NORMAL Mode system clock, and if the Fast Wake-up
function is enabled, then it will take one to two tSUB clock cycles of the LIRC or LXT oscillator for
the system to wake-up. The system will then initially run under the fSUB clock source until 512 HXT
clock cycles have elapsed, at which point the HTO flag will switch high and the system will switch
over to operating from the HXT oscillator.
If the HIRC oscillator or LIRC oscillator is used as the system oscillator then it will take 15~16
clock cycles of the HIRC or 1~2 cycles of the LIRC to wake up the system from the SLEEP or
IDLE0 Mode. The Fast Wake-up bit, FSTEN will have no effect in these cases.
System FSTEN Wake-up Time Wake-up Time Wake-up Time Wake-up Time
Oscillator Bit (SLEEP0 Mode) (SLEEP1 Mode) (IDLE0 Mode) (IDLE1 Mode)
0 128 HXT cycles 128 HXT cycles 1~2 HXT cycles
HXT 1~2 fSUB cycles
1 128 HXT cycles (System runs with fSUB first for 512 HXT cycles and 1~2 HXT cycles
then switches over to run with the HXT clock)
HIRC x 15~16 HIRC cycles 15~16 HIRC cycles 1~2 HIRC cycles
LIRC x 1~2 LIRC cycles 1~2 LIRC cycles 1~2 LIRC cycles
LXT x 128 HXT cycles 1~2 LXT cycles 1~2 LXT cycles
“x”: don’t care
Wake-up Times
Note that if the Watchdog Timer is disabled, which means that the LXT and LIRC are all both off,
then there will be no Fast Wake-up function available when the devices wake-up from the SLEEP0
Mode.
NORMAL SLOW
fSYS=fH~fH/64 fSYS=fSUB
fH on fSUB on
CPU run CPU run
fSYS on fSYS on
fSUB on fH off
fTBC on fTBC on
SLEEP0 IDLE0
HALT instruction executed HALT instruction executed
CPU stop CPU stop
IDLEN=0 IDLEN=1
fSYS off FSYSON=0
fSUB off fSYS off
fTBC off fSUB on
WDT & LVD off fTBC on
SLEEP1 IDLE1
HALT instruction executed HALT instruction executed
CPU stop CPU stop
IDLEN=0 IDLEN=1
fSYS off FSYSON=1
fSUB on fSYS on
fTBC off fSUB on
WDT on fTBC on
NORMAL Mode
SLEEP0 Mode
WDT is on
IDLEN=0
HALT instruction is executed
SLEEP1 Mode
IDLEN=1, FSYSON=0
HALT instruction is executed
IDLE0 Mode
IDLEN=1, FSYSON=1
HALT instruction is executed
IDLE1 Mode
SLOW Mode
SLEEP0 Mode
WDT is on
IDLEN=0
HALT instruction is executed
SLEEP1 Mode
IDLEN=1, FSYSON=0
HALT instruction is executed
IDLE0 Mode
IDLEN=1, FSYSON=1
HALT instruction is executed
IDLE1 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, stablise 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 devices execute the “HALT” instruction, it will enter the Power down mode and the PDF
flag will be set to 1. The PDF flag will be cleared to 0 if the devices experience a system power-up
or executes the clear Watchdog Timer instruction. If the system is woken up by a WDT overflow, a
Watchdog Timer reset will be initiated and the TO flag will be set to 1. 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 setup using the PAWU register to permit a negative transition on the pin
to wake up the system. When a Port 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 devices 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.
Programming Considerations
The high speed and low speed oscillators both use the same SST counter. For example, if the system
is woken up from the SLEEP0 Mode and both the HIRC and LXT oscillators need to start-up from
an off state. The LXT oscillator uses the SST counter after the HIRC oscillator has finished its SST
period.
• If the devices are woken up from the SLEEP0 Mode to the NORMAL Mode, the high speed
system oscillator needs an SST period. The devices will execute first instruction after HTO is
“1”. At this time, the LXT oscillator may not be stability if fSUB is from LXT oscillator. The
same situation occurs in the power-on state. The LXT oscillator is not ready yet when the first
instruction is executed.
• If the devices are woken up from the SLEEP1 Mode to NORMAL Mode, and the system clock
source is from the HXT oscillator and FSTEN is “1”, the system clock can be switched to the
LIRC oscillator after wake up.
• There are peripheral functions, such as WDT and TMs, for which the fSYS is used. If the system
clock source is switched from fH to fSUB, the clock source to the peripheral functions mentioned
above will change accordingly.
• The on/off condition of fSUB and fS depends upon whether the WDT is enabled or disabled as the
WDT clock source is selected from fSUB.
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
CTRL Register
Bit 7 6 5 4 3 2 1 0
Name FSYSON — — — — LVRF LRF WRF
R/W R/W — — — — R/W R/W R/W
POR 0 — — — — x 0 0
“x”: unknown
Bit 7 FSYSON: fSYS Control in IDLE Mode
Described elsewhere.
Bit 6~3 Unimplemented, read as “0”
Bit 2 LVRF: LVR function reset flag
Described elsewhere.
Bit 1 LRF: LVR control register software reset flag
Described elsewhere.
Bit 0 WRF: WDT control register software reset flag
0: Not occurred
1: Occurred
This bit is set to 1 by the WDT control register software reset and cleared by the
application program. Note that this bit can only be cleared to 0 by the application
program.
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 WDT reset, which means a certain value except 01010B and 10101B written into the
WE4~WE0 field, 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 contents.
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
second for the 218 division ratio and a minimum timeout of 7.8ms for the 28 division ration.
“HALT”Instruction CLR
“CLR WDT”Instruction
fSUB/28
fSUB 8-stage Divider WDT Prescaler
Watchdog timer
Reset Functions
There are five ways in which a microcontroller reset can occur, through events occurring both
internally and externally.
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
• 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
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 the microcontroller internal registers. Note that where more
than one package type exists the table will reflect the situation for the larger package type.
HT66F0175
HT66F0185
Reset LVR Reset WDT Time-out WDT Time-out
Register
(Power On) (Normal Operation) (Normal Operation) (IDLE or SLEEP)*
HT66F0175
HT66F0185
Reset LVR Reset WDT Time-out WDT Time-out
Register
(Power On) (Normal Operation) (Normal Operation) (IDLE or SLEEP)*
HT66F0175
HT66F0185
Reset LVR Reset WDT Time-out WDT Time-out
Register
(Power On) (Normal Operation) (Normal Operation) (IDLE or SLEEP)*
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.
These devices provide bidirectional input/output lines labeled with port names PA~PD. 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
PAWU PAWU7 PAWU6 PAWU5 PAWU4 PAWU3 PAWU2 PAWU1 PAWU0
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
PB — PB6 PB5 PB4 PB3 PB2 PB1 PB0
PBC — PBC6 PBC5 PBC4 PBC3 PBC2 PBC1 PBC0
PBPU — PBPU6 PBPU5 PBPU4 PBPU3 PBPU2 PBPU1 PBPU0
PC — PC6 PC5 PC4 PC3 PC2 PC1 PC0
PCC — PCC6 PCC5 PCC4 PCC3 PCC2 PCC1 PCC0
PCPU — PCPU6 PCPU5 PCPU4 PCPU3 PCPU2 PCPU1 PCPU0
Register Bit
Name 7 6 5 4 3 2 1 0
PAWU PAWU7 PAWU6 PAWU5 PAWU4 PAWU3 PAWU2 PAWU1 PAWU0
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
PB — PB6 PB5 PB4 PB3 PB2 PB1 PB0
PBC — PBC6 PBC5 PBC4 PBC3 PBC2 PBC1 PBC0
PBPU — PBPU6 PBPU5 PBPU4 PBPU3 PBPU2 PBPU1 PBPU0
PC — PC6 PC5 PC4 PC3 PC2 PC1 PC0
PCC — PCC6 PCC5 PCC4 PCC3 PCC2 PCC1 PCC0
PCPU — PCPU6 PCPU5 PCPU4 PCPU3 PCPU2 PCPU1 PCPU0
PD — — — — PD3 PD2 PD1 PD0
PDC — — — — PDC3 PDC2 PDC1 PDC0
PDPU — — — — PDPU3 PDPU2 PDPU1 PDPU0
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 relevant pull-high control registers and are implemented
using weak PMOS transistors.
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.
Register Bit
Name 7 6 5 4 3 2 1 0
SLEDC0 PBPS3 PBPS2 PBPS1 PBPS0 PAPS3 PAPS2 PAPS1 PAPS0
SLEDC1
— — — — PCPS3 PCPS2 PCPS1 PCPS0
(HT66F0175)
SLEDC1
— — PDPS1 PDPS0 PCPS3 PCPS2 PCPS1 PCPS0
(HT66F0185)
SLEDC0 Register
Bit 7 6 5 4 3 2 1 0
Name PBPS3 PBPS2 PBPS1 PBPS0 PAPS3 PAPS2 PAPS1 PAPS0
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
Pin-remapping 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. The way in
which the pin function of each pin is selected is different for each function and a priority order is
established where more than one pin function is selected simultaneously. Additionally there is a
register, IFS, to establish certain pin functions.
The limited number of supplied pins in a package can impose restrictions on the amount of functions
a certain device can contain. However by allowing the same pins to share several different functions
and providing a means of function selection, a wide range of different functions can be incorporated
into even relatively small package sizes. If the pin-shared pin function have multiple outputs
simultaneously, its pin names at the right side of the “/” sign can be used for higher priority.
Register Bit
Name 7 6 5 4 3 2 1 0
IFS
— — SDOPS SDI_SDAPS SCK_SCLPS SCSBPS INT1PS INT0PS
(HT66F0175)
IFS
— SDOPS1 SDOPS0 SDI_SDAPS SCK_SCLPS SCSBPS TXPS RXPS
(HT66F0185)
A/D Input/Output Structure
Programming Considerations
Within the user program, one of the things first to consider is port initialisation. After a reset, all
of the I/O data and port control registers will be set to high. This means that all I/O pins will be
defaulted 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.
The power-on reset condition of the A/D converter control registers ensures that any A/D input
pins, which are always shared with other I/O functions, will be setup as analog inputs after a reset.
Although these pins will be configured as A/D inputs after a reset, the A/D converter will not be
switched on. It is therefore important to note that if it is required to use these pins as I/O digital
input pins or as other functions, the A/D converter control registers must be correctly programmed
to remove the A/D function. Note also that as the A/D channel is enabled, any internal pull-high
resistor connections will be removed.
Port A has the additional capability of providing wake-up functions. When the devices are in the
SLEEP or IDLE Mode, various methods are available to wake the devices 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 Modules – TM
One of the most fundamental functions in any microcontroller devices is the ability to control and
measure time. To implement time related functions each device includes several Timer Modules,
generally abbreviated to the name TM. The TMs are multi-purpose timing units and serve to provide
operations such as Timer/Counter, Input Capture, Compare Match Output and Single Pulse Output
as well as being the functional unit for the generation of PWM signals. Each of the TMs has two
interrupts. The addition of input and output pins for each TM ensures that users are provided with
timing units with a wide and flexible range of features.
The common features of the different TM types are described here with more detailed information
provided in the individual Compact, Standard and Periodic TM sections.
Introduction
The devices contain two or three TMs depending upon which device is selected with each TM
having a reference name of TM0, TM1, and TM2. Each individual TM can be categorised as a
certain type, namely Compact Type TM, Standard Type TM or Periodic Type TM. Although similar
in nature, the different TM types vary in their feature complexity. The common features to all of the
Compact, Standard and Periodic TMs will be described in this section and the detailed operation
regarding each of the TM types will be described in separate sections. The main features and
differences between the three types of TMs are summarised in the accompanying table.
TM Function CTM STM PTM
Timer/Counter √ √ √
Input Capture — √ √
Compare Match Output √ √ √
PWM Channels 1 1 1
Single Pulse Output — 1 1
PWM Alignment Edge Edge Edge
PWM Adjustment Period & Duty Duty or Period Duty or Period Duty or Period
TM Function Summary
Each device in the series contains a specific number of either Compact Type, Standard Type and
Periodic Type TM units which are shown in the table together with their individual reference name,
TM0~TM2.
Device TM0 TM1 TM2
HT66F0175 10-bit PTM 10-bit PTM —
HT66F0185 16-bit STM 10-bit PTM 16-bit CTM
TM Name/Type Reference
TM Operation
The different types of TM offer a diverse range of functions, from simple timing operations to PWM
signal generation. The key to understanding how the TM operates is to see it in terms of a free
running count-up counter whose value is then compared with the value of pre-programmed internal
comparators. When the free running count-up counter has the same value as the pre-programmed
comparator, known as a compare match situation, a TM interrupt signal will be generated which
can clear the counter and perhaps also change the condition of the TM output pin. The internal TM
counter is driven by a user selectable clock source, which can be an internal clock or an external pin.
TM Clock Source
The clock source which drives the main counter in each TM can originate from various sources.
The selection of the required clock source is implemented using the TnCK2~TnCK0 bits in the TM
control registers. The clock source can be a ratio of the system clock, fSYS, or the internal high clock,
fH, the fTBC clock source or the external TCKn pin. The TCKn pin clock source is used to allow an
external signal to drive the TM as an external clock source for event counting.
TM Interrupts
The Compact, Standard or Periodic type TM has two internal interrupts, one for each of the internal
comparator A or comparator P, which generate a TM interrupt when a compare match condition
occurs. When a TM interrupt is generated, it can be used to clear the counter and also to change the
state of the TM output pin.
TM External Pins
Each of the TMs, irrespective of what type, has one TM input pin, with the label TCKn. The TM
input pin is essentially a clock source for the TM and is selected using the TnCK2~TnCK0 bits in
the TMnC0 register. This external TM input pin allows an external clock source to drive the internal
TM. This external TM input pin is shared with other functions but will be connected to the internal
TM if selected using the TnCK2~TnCK0 bits. The TM input pin can be chosen to have either a
rising or falling active edge. The TCKn pin is also used as the external trigger input pin in single
pulse output mode for the STM and PTM respectively.
The TMs each have one output pin with the label TPn. When the TM is in the Compare Match
Output Mode, these pins can be controlled by the TM to switch to a high or low level or to toggle
when a compare match situation occurs. The external TPn output pin is also the pin where the
TM generates the PWM output waveform. The TPn pin acts as an input when the TM is setup to
operate in the Capture Input Mode. As the TPn pins are pin-shared with other functions, the TPn
pin function is enabled or disabled according to the internal TM on/off control, operation mode and
output control settings. When the corresponding TM configuration selects the TPn pin to be used as
an output pin, the associated pin will be setup as an external TM output pin. If the TM configuration
selects the TPn pin to be setup as an input pin, the input signal supplied on the associated pin can
be derived from an external signal and other pin-shared output function. If the TM configuration
determines that the TPn pin function is not used, the associated pin will be controlled by other
pin-shared functions. The details of the TPn pin for each TM type and device are provided in the
accompanying table.
Device STM PTM CTM Register
TCK0; TP0
HT66F0175 — — TMPC
TCK1; TP1
HT66F0185 TCK0; TP0 TCK1; TP1 TCK2; TP2 TMPC
TM External Pins
0
Output
1
T0CP
PA0
TM0
(PTM)
1
Capture Input 0
0
1
T0CAPTS
TCK Input
PB2/TCK0
0
Output
1
T0CP
TM0
PA0
(STM)
Capture Input 1
0
TCK Input
PB2/TCK0
0
Output
1
T1CP
PA7
TM1
(PTM)
1
Capture Input 0
0
1
T1CAPTS
TCK Input
PA4/TCK1
TM2 0
(CTM) Output
1
T2CP
PB3
TCK Input
PA6/TCK2
Note: 1. The I/O register data bits shown are used for TM output inversion control.
2. In the Capture Input Mode, the TM pin control register must never enable more than one
TM input.
Programming Considerations
The TM Counter Registers and the Capture/Compare CCRA and CCRP registers, being either 10-
bit or 16-bit, all have a low and high byte structure. The high bytes can be directly accessed, but as
the low bytes can only be accessed via an internal 8-bit buffer, reading or writing to these register
pairs must be carried out in a specific way. The important point to note is that data transfer to and
from the 8-bit buffer and its related low byte only takes place when a write or read operation to its
corresponding high byte is executed.
As the CCRA and CCRP registers are implemented in the way shown in the following diagram and
accessing these register pairs is carried out in a specific way as described above, it is recommended
to use the “MOV” instruction to access the CCRA and CCRP low byte registers, named TMnAL and
TMnRPL, using the following access procedures. Accessing the CCRA or CCRP low byte registers
without following these access procedures will result in unpredictable values.
TMnDL TMnDH
8-bit Buffer
TMnAL TMnAH
TMn CCRA Register (Read/Write)
TMnRPL TMnRPH
PTM CCRP Register (Read/Write)
Data Bus
CCRP
Comparator P Match
8-bit Comparator P TnPF Interrupt
fSYS/4 000
fSYS 001 TnOC
b8~b15
fH/16 010
fH/64 011 Counter Clear 0 Output Polarity Pin
16-bit Count-up Counter TPn
fTBC 100 1 Control Control Control
fH/8 101
TnON TnCCLR
110 b0~b15 TnM1, TnM0
TnPAU TnPOL TnCP
TCKn 111 TnIO1, TnIO0
Comparator A Match
16-bit Comparator A TnAF Interrupt
TnCK2~TnCK0
CCRA
Compact TM Operation
The Compact TM core is a 16-bit count-up counter which is driven by a user selectable internal or
external clock source. There are also two internal comparators with the names, Comparator A and
Comparator P. These comparators will compare the value in the counter with CCRP and CCRA
registers. The CCRP is eight-bit wide whose value is compared with the highest eight bits in the
counter while the CCRA is sixteen-bit wide and therefore compares with all counter bits.
The only way of changing the value of the 16-bit counter using the application program, is to
clear the counter by changing the TnON bit from low to high. The counter will also be cleared
automatically by a counter overflow or a compare match with one of its associated comparators.
When these conditions occur, a TM interrupt signal will also usually be generated. The Compact
Type TM can operate in a number of different operational modes, can be driven by different clock
sources including an input pin and can also control an output pin. All operating setup conditions are
selected using relevant internal registers.
TMnDL 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
TMnDH Register
Bit 7 6 5 4 3 2 1 0
Name D15 D14 D13 D12 D11 D10 D9 D8
R/W R R R R R R R R
POR 0 0 0 0 0 0 0 0
TMnAL 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
TMnAH Register
Bit 7 6 5 4 3 2 1 0
Name D15 D14 D13 D12 D11 D10 D9 D8
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
TMnC0 Register
Bit 7 6 5 4 3 2 1 0
Name TnPAU TnCK2 TnCK1 TnCK0 TnON — — —
R/W R/W R/W R/W R/W R/W — — —
POR 0 0 0 0 0 — — —
TMnC1 Register
Bit 7 6 5 4 3 2 1 0
Name TnM1 TnM0 TnIO1 TnIO0 TnOC TnPOL TnDPX TnCCLR
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
TMnRP Register
Bit 7 6 5 4 3 2 1 0
Name TnRP7 TnRP6 TnRP5 TnRP4 TnRP3 TnRP2 TnRP1 TnRP0
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 TnRP7~TnRP0: TMn CCRP 8-bit register, compared with the TMn Counter bit 15~bit 8
Comprartor P Match Period
0: 65535 TMn clocks
1~255: 256 × (1~255) TMn clocks
These eight bits are used to setup the value on the internal CCRP 8-bit register, which
are then compared with the internal counter’s highest eight bits. The result of this
comparison can be selected to clear the internal counter if the TnCCLR bit is set to
zero. Setting the TnCCLR bit to zero ensures that a compare match with the CCRP
values will reset the internal counter. As the CCRP bits are only compared with the
highest eight counter bits, the compare values exist in 256 clock cycle multiples.
Clearing all three bits to zero is in effect allowing the counter to overflow at its
maximum value.
Time
TnON
TnPAU
TnPOL
CCRP
Time
TnON
TnPAU
TnPOL
No TnAF flag
generated on
CCRA Int. flag CCRA overflow
TnAF
Timer/Counter Mode
To select this mode, bits TnM1 and TnM0 in the TMnC1 register should be set to 11 respectively.
The Timer/Counter Mode operates in an identical way to the Compare Match Output Mode
generating the same interrupt flags. The exception is that in the Timer/Counter Mode the TMn output
pin is not used. Therefore the above description and Timing Diagrams for the Compare Match
Output Mode can be used to understand its function. As the TMn output pin is not used in this mode,
the pin can be used as a normal I/O pin or other pin-shared function.
If fSYS = 16MHz, TMn clock source is fSYS/4, CCRP = 2 and CCRA = 128,
The TMn PWM output frequency = (fSYS/4) / (2×256) = fSYS/2048 = 7.8125 kHz, duty = 128/(2×256)=
25%.
If the Duty value defined by the CCRA register is equal to or greater than the Period value, then the
PWM output duty is 100%.
The PWM output period is determined by the CCRA register value together with the TMn clock
while the PWM duty cycle is defined by the (CCRP×256) value except when the CCRP value is
equal to 0.
Time
TnON
TnPAU
TnPOL
Time
TnON
TnPAU
TnPOL
CCRP Int.
flag TnPF
CCRA Int.
flag TnAF
CCRP
Comparator P Match
8-bit Comparator P TnPF Interrupt
fSYS/4 000
fSYS 001 TnOC
b8~b15
fH/16 010
fH/64 011 Counter Clear 0 Output Polarity Pin
16-bit Count-up Counter Control TPn
fTBC 100 1 Control Control
fH/8 101
TnON TnCCLR
110 TnPAU b0~b15 TnM1, TnM0 TnPOL TnCP
TCKn 111 TnIO1, TnIO0
Comparator A Match
TnCK2~TnCK0 16-bit Comparator A TnAF Interrupt
TnIO1, TnIO0
Edge
CCRA
Detector
Standard TM Operation
The size of Standard TM is 16-bit wide and its core is a 16-bit count-up counter which is driven by
a user selectable internal or external clock source. There are also two internal comparators with the
names, Comparator A and Comparator P. These comparators will compare the value in the counter
with CCRP and CCRA registers. The CCRP comparator is 8-bit wide whose value is compared the
with highest eight bits in the counter while the CCRA is the sixteen bits and therefore compares all
counter bits.
The only way of changing the value of the 16-bit counter using the application program, is to
clear the counter by changing the TnON bit from low to high. The counter will also be cleared
automatically by a counter overflow or a compare match with one of its associated comparators.
When these conditions occur, a TM interrupt signal will also usually be generated. The Standard
Type TM can operate in a number of different operational modes, can be driven by different clock
sources including an input pin and can also control an output pin. All operating setup conditions are
selected using relevant internal registers.
Register Bit
Name 7 6 5 4 3 2 1 0
TMnC0 TnPAU TnCK2 TnCK1 TnCK0 TnON — — —
TMnC1 TnM1 TnM0 TnIO1 TnIO0 TnOC TnPOL TnDPX TnCCLR
TMnDL D7 D6 D5 D4 D3 D2 D1 D0
TMnDH D15 D14 D13 D12 D11 D10 D9 D8
TMnAL D7 D6 D5 D4 D3 D2 D1 D0
TMnAH D15 D14 D13 D12 D11 D10 D9 D8
TMnRP TnRP7 TnRP6 TnRP5 TnRP4 TnRP3 TnRP2 TnRP1 TnRP0
TMnDL 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
TMnDH Register
Bit 7 6 5 4 3 2 1 0
Name D15 D14 D13 D12 D11 D10 D9 D8
R/W R R R R R R R R
POR 0 0 0 0 0 0 0 0
TMnAL 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
TMnAH Register
Bit 7 6 5 4 3 2 1 0
Name D15 D14 D13 D12 D11 D10 D9 D8
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
TMnC0 Register
Bit 7 6 5 4 3 2 1 0
Name TnPAU TnCK2 TnCK1 TnCK0 TnON — — —
R/W R/W R/W R/W R/W R/W — — —
POR 0 0 0 0 0 — — —
TMnC1 Register
Bit 7 6 5 4 3 2 1 0
Name TnM1 TnM0 TnIO1 TnIO0 TnOC TnPOL TnDPX TnCCLR
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
TMnRP Register
Bit 7 6 5 4 3 2 1 0
Name TnRP7 TnRP6 TnRP5 TnRP4 TnRP3 TnRP2 TnRP1 TnRP0
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 TnRP7~TnRP0: TMn CCRP 8-bit register, compared with the TMn counter bit 15~bit 8
Comparator P match period:
0: 65536 TMn clocks
1~255: (1~255) × 256 TMn clocks
These eight bits are used to setup the value on the internal CCRP 8-bit register, which
are then compared with the internal counter’s highest eight bits. The result of this
comparison can be selected to clear the internal counter if the TnCCLR bit is set to
zero. Setting the TnCCLR bit to zero ensures that a compare match with the CCRP
values will reset the internal counter. As the CCRP bits are only compared with the
highest eight counter bits, the compare values exist in 256 clock cycle multiples.
Clearing all eight bits to zero is in effect allowing the counter to overflow at its
maximum value.
Time
TnON
TnPAU
TnPOL
CCRP Int.
flag TnPF
CCRA Int.
flag TnAF
CCRP
Time
TnON
TnPAU
TnPOL
No TnAF flag
generated on
CCRA overflow
CCRA Int.
flag TnAF
CCRP Int.
flag TnPF
Timer/Counter Mode
To select this mode, bits TnM1 and TnM0 in the TMnC1 register should be set to 11 respectively.
The Timer/Counter Mode operates in an identical way to the Compare Match Output Mode
generating the same interrupt flags. The exception is that in the Timer/Counter Mode the TMn output
pin is not used. Therefore the above description and Timing Diagrams for the Compare Match
Output Mode can be used to understand its function. As the TMn output pin is not used in this mode,
the pin can be used as a normal I/O pin or other pin-shared function.
If fSYS = 16MHz, TMn clock source is fSYS/4, CCRP = 2 and CCRA = 128,
The TMn PWM output frequency = (fSYS/4) / (2×256) = fSYS/2048 = 7.8125 kHz, duty = 128/(2×256)=
25%.
If the Duty value defined by the CCRA register is equal to or greater than the Period value, then the
PWM output duty is 100%.
The PWM output period is determined by the CCRA register value together with the TM clock while
the PWM duty cycle is defined by the (CCRP×256) value except when the CCRP value is equal to 0.
Time
TnON
TnPAU
TnPOL
CCRA Int.
flag TnAF
CCRP Int.
flag TnPF
Time
TnON
TnPAU
TnPOL
CCRP Int.
flag TnPF
CCRA Int.
flag TnAF
CCRA CCRA
Leading Edge Trailing Edge
S/W Command S/W Command
SET“TnON” TnON bit TnON bit CLR“TnON”
or or
0à1 1à0
TCKn Pin CCRA Compare
Transition Match
Time
TnON
Auto. set by
Software Cleared by TCKn pin Software
Trigger CCRA match Software Software Software Trigger
Trigger Trigger Clear
TCKn pin
TCKn pin
TnPAU Trigger
TnPOL
No CCRP Interrupts
CCRP Int. Flag generated
TnPF
XX
Time
TnON
TnPAU
Active Active
edge Active edge
edge
TMn capture pin
TPn
CCRA
Value XX YY XX YY
TnIO [1:0] 00 – Rising edge 01 – Falling edge 10 – Both edges 11 – Disable Capture
Value
CCRP
Comparator P Match
10-bit Comparator P TnPF Interrupt
fSYS/4 000
fSYS 001 TnOC
b0~b9
fH/16 010
fH/64 011 Counter Clear 0 Output Polarity Pin
10-bit Count-up Counter Control TPn
fTBC 100 1 Control Control
fH 101 TnON TnCCLR
110 TnPAU b0~b9 TnM1, TnM0 TnPOL TnCP
TCKn 111 TnIO1, TnIO0
Comparator A Match
TnCK2~TnCK0
10-bit Comparator A TnAF Interrupt
TnIO1, TnIO0 TnCAPTS
Edge 0
CCRA
Detector 1
Periodic TM Operation
The size of Periodic TM is 10-bit wide and its core is a 10-bit count-up counter which is driven by
a user selectable internal or external clock source. There are also two internal comparators with the
names, Comparator A and Comparator P. These comparators will compare the value in the counter
with CCRP and CCRA registers. The CCRP and CCRA comparators are 10-bit wide whose value is
respectively compared with all counter bits.
The only way of changing the value of the 10-bit counter using the application program is to
clear the counter by changing the TnON bit from low to high. The counter will also be cleared
automatically by a counter overflow or a compare match with one of its associated comparators.
When these conditions occur, a TM interrupt signal will also usually be generated. The Periodic
Type TM can operate in a number of different operational modes, can be driven by different clock
sources including an input pin and can also control the output pins. All operating setup conditions
are selected using relevant internal registers.
TMnDL 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
TMnDH Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — D9 D8
R/W — — — — — — R R
POR — — — — — — 0 0
TMnAL 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
TMnAH Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — D9 D8
R/W — — — — — — R/W R/W
POR — — — — — — 0 0
TMnRPL Register
Bit 7 6 5 4 3 2 1 0
Name TnRP7 TnRP6 TnRP5 TnRP4 TnRP3 TnRP2 TnRP1 TnRP0
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 TnRP7~TnRP0: TMn CCRP Low Byte Register bit 7 ~ bit 0
TMn 10-bit CCRP bit 7 ~ bit 0
TMnRPH Register
Bit 7 6 5 4 3 2 1 0
Name — — — — — — TnRP9 TnRP8
R/W — — — — — — R/W R/W
POR — — — — — — 0 0
TMnC0 Register
Bit 7 6 5 4 3 2 1 0
Name TnPAU TnCK2 TnCK1 TnCK0 TnON — — —
R/W R/W R/W R/W R/W R/W — — —
POR 0 0 0 0 0 — — —
TMnC1 Register
Bit 7 6 5 4 3 2 1 0
Name TnM1 TnM0 TnIO1 TnIO0 TnOC TnPOL TnCAPTS TnCCLR
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
Time
TnON
TnPAU
TnPOL
TMn O/P
Pin
Output not affected by TnAF
flag. Remains High until reset Output Inverts
Output pin set to Output Toggle with
by TnON bit when TnPOL is high
initial Level Low TnAF flag
if TnOC=0 Output Pin
Note TnIO [1:0] = 10 Reset to Initial value
Here TnIO [1:0] = 11 Active High Output select Output controlled by
Toggle Output select other pin-shared function
CCRP
Time
TnON
TnPAU
TnPOL
No TnAF flag
generated on
CCRA overflow
CCRA Int. Flag
TnAF
Timer/Counter Mode
To select this mode, bits TnM1 and TnM0 in the TMnC1 register should be set to 11 respectively.
The Timer/Counter Mode operates in an identical way to the Compare Match Output Mode
generating the same interrupt flags. The exception is that in the Timer/Counter Mode the TMn output
pin is not used. Therefore the above description and Timing Diagrams for the Compare Match
Output Mode can be used to understand its function. As the TMn output pin is not used in this mode,
the pin can be used as a normal I/O pin or other pin-shared function.
Time
TnON
TnPAU
TnPOL
PWM Mode
Note: 1. The counter is cleared by CCRP.
2. A counter clear sets the PWM Period
3. The internal PWM function continues running even when TnIO [1:0] = 00 or 01
4. The TnCCLR bit has no influence on PWM operation
5. n = 0 or 1 for HT66F0175 while n = 1 for HT66F0185
CCRA CCRA
Leading Edge Trailing Edge
S/W Command S/W Command
SET“TnON” TnON bit TnON bit CLR“TnON”
or or
0à1 1à0
TCKn Pin CCRA Compare
Transition Match
Time
TnON
Auto. set by
Software Cleared by TCKn pin Software
Trigger CCRA match Software Software Software Trigger
Trigger Trigger Clear
TCKn pin
TCKn pin
TnPAU Trigger
TnPOL
No CCRP Interrupts
CCRP Int. Flag generated
TnPF
XX
Time
TnON
TnPAU
Active Active Active edge
edge edge
TMn capture pin
TPn or TCKn
CCRA
Value XX YY XX YY
TnIO [1:0] 00 – Rising edge 01 – Falling edge 10 – Both edges 11 – Disable Capture
Value
A/D Overview
These devices contain a multi-channel analog to digital converter which can directly interface to
external analog signals, such as that from sensors or other control signals and convert these signals
directly into a 12-bit digital value. It also can convert the internal signals, such as the Bandgap
reference voltage, into a 12-bit digital value. The external or internal analog signal to be converted is
determined by the SAINS2~SAINS0 bits together with the SACS2~SACS0 bits. Note that when the
external and internal analog signals are simultaneously selected to be converted, the internal analog
signal will have the priority. In the meantime the external analog signal will temporarily be switched
off until the internal analog signal is deselected. More detailed information about the A/D input
signal is described in the “A/D Converter Control Registers” and “A/D Converter Input Signal”
sections respectively.
The accompanying block diagram shows the internal structure of the A/D converter together with its
associated registers.
Device External Input Channel Internal Analog Signals A/D Signal Select Bits
SAINS2~SAINS0;
HT66F0175 AN0~AN7 VDD, VDD/2, VDD/4, VR, VR/2, VR/4
SACS2~SACS0
SAINS2~SAINS0;
HT66F0185 AN0~AN7 VDD, VDD/2, VDD/4, VR, VR/2, VR/4
SACS2~SACS0
VDD
fSYS
VSS
AN0 A/D Clock ADRFS
AN1
SADOL
A/D Converter SADOH
A/D Data
Registers
SAVRS3~SAVRS0
VDD VREFPS
VDD/2
VDD/4
VBG VDD
VR VRI PGA
VR/2 VREFI (Gain=1~4) VR
VR/4
VREFIPS ADPGAEN
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 — SACS2 SACS1 SACS0
SADC1 SAINS2 SAINS10 SAINS0 — — SACKS2 SACKS1 SACKS0
SADC2 ADPGAEN VBGEN VREFIPS VREFPS SAVRS3 SAVRS2 SAVRS1 SAVRS0
ACERL ACE7 ACE6 ACE5 ACE4 ACE3 ACE2 ACE1 ACE0
The analog input pin function selection bits in the ACERL register determine which pins on I/O
Ports are used as external analog channels for the A/D converter input and which pins are not to be
used as the A/D converter input. When the pin is selected to be an A/D input, its original function
whether it is an I/O or other pin-shared functions will be removed. In addition, any internal pull-
high resistor connected to the pin will be automatically removed if the pin is selected to be an A/D
converter input.
• SADC0 Register
Bit 7 6 5 4 3 2 1 0
Name START ADBZ ADCEN ADRFS — SACS2 SACS1 SACS0
R/W R/W R R/W R/W — R/W R/W R/W
POR 0 0 0 0 — 0 0 0
• SADC1 Register
Bit 7 6 5 4 3 2 1 0
Name SAINS2 SAINS10 SAINS0 — — SACKS2 SACKS1 SACKS0
R/W R/W R/W R/W — — R/W R/W R/W
POR 0 0 0 — — 0 0 0
• SADC2 Register
Bit 7 6 5 4 3 2 1 0
Name ADPGAEN VBGEN VREFIPS VREFPS SAVRS3 SAVRS2 SAVRS1 SAVRS0
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
• ACERL Register
Bit 7 6 5 4 3 2 1 0
Name ACE7 ACE6 ACE5 ACE4 ACE3 ACE2 ACE1 ACE0
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
A/D Operation
The START bit in the SADC0 register is used to start the AD conversion. When the microcontroller
sets this bit from low to high and then low again, an analog to digital conversion cycle will be
initiated.
The ADBZ bit in the SADC0 register is used to indicate whether the analog to digital conversion
process is in progress or not. This bit will be automatically set to 1 by the microcontroller after an
A/D conversion is successfully initiated. When the A/D conversion is complete, the ADBZ will be
cleared to 0. In addition, the corresponding A/D interrupt request flag will be set in the interrupt
control register, and if the corresponding interrupt control bits are enabled, an internal interrupt
signal will be generated. This A/D internal interrupt signal will direct the program flow to the
associated A/D internal interrupt address for processing. If the A/D internal interrupt is disabled, the
microcontroller can poll the ADBZ bit in the SADC0 register to check whether it has been cleared
as an alternative method of detecting the end of an A/D conversion cycle.
The clock source for the A/D converter, which originates from the system clock fSYS, 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 maximum A/D
clock source speed 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 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, depending upon the devices, special care must
be taken, as the values may be less than the specified minimum A/D Clock Period.
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.
tON2ST
ADCEN off on off on
ADBZ
End of A/D End of A/D
conversion conversion
Step 1
Select the required A/D conversion clock by properly programming the SACKS2~SACKS0 bits in
the SADC1 register.
Step 2
Enable the A/D converter by setting the ADCEN bit in the SADC0 register to 1.
Step 3
Select which signal is to be connected to the internal A/D converter by correctly configuring the
SAINS2~SAINS0 bits
Select the external channel input to be converted, go to Step 4.
Select the internal analog signal to be converted, go to Step 5.
Step 4
If the A/D input signal comes from the external channel input selecting by configuring the SAINS
bit field, the corresponding pins should first be configured as A/D input function by configuring the
relevant pin-shared function control bits. The desired analog channel then should be selected by
configuring the SACS bit field. After this step, go to Step 6.
Step 5
If the A/D input signal is selected to come from the internal analog signal, the SAINS bit field
should be properly configured and then the external channel input will automatically be disconnected
regardless of the SACS bit field value. After this step, go to Step 6.
Step 6
Select the reference voltgage source by configuring the SAVRS3~SAVRS0 bits.
Step 7
Select the A/D converter output data format by configuring the ADRFS bit.
Step 8
If A/D conversion interrupt is used, the interrupt control registers must be correctly configured
to ensure the A/D interrupt function is active. The master interrupt bontrol bit, EMI, and the A/D
conversion interrupt control bit, ADE, must both be set high in advance.
Step 9
The A/D conversion procedure can now be initialized by setting the START bit from low to high and
then low again.
Step 10
If A/D conversion is in progress, the ADBZ flag will be set high. After the A/D conversion process
is complete, the ADBZ flag will go low and then the output data can be read from SADOH and
SADOL registers.
Note: When checking for the end of the conversion process, if the method of polling the ADBZ bit in the
SADC0 register is used, the interrupt enable step above can be omitted.
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 setting bit ADCEN low 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.
SPI Interface
The SPI interface is often used to communicate with external peripheral devices such as sensors,
Flash or EEPROM memory devices, etc. Originally developed by Motorola, the four line SPI
interface is a synchronous serial data interface that has a relatively simple communication protocol
simplifying the programming requirements when communicating with external hardware devices.
The communication is full duplex and operates as a slave/master type, where the devices can be
either master or slave. Although the SPI interface specification can control multiple slave devices
from a single master, these devices provided only one SCS pin. If the master needs to control
multiple slave devices from a single master, the master can use I/O pin to select the slave devices.
SPI Registers
There are three internal registers which control the overall operation of the SPI interface. These are
the SIMD data register and two registers SIMC0 and SIMC2. Note that the SIMC1 register is only
used by the I2C interface.
Register Bit
Name 7 6 5 4 3 2 1 0
SIMC0 SIM2 SIM1 SIM0 — SIMDEB1 SIMDEB0 SIMEN SIMICF
SIMC2 D7 D6 CKPOLB CKEG MLS CSEN WCOL TRF
SIMD D7 D6 D5 D4 D3 D2 D1 D0
SIMD Register
The SIMD register is used to store the data being transmitted and received. The same register is used
by both the SPI and I2C functions. Before the devices write data to the SPI bus, the actual data to
be transmitted must be placed in the SIMD register. After the data is received from the SPI bus, the
device can read it from the SIMD register. Any transmission or reception of data from the SPI bus
must be made via the SIMD 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
There are also two control registers for the SPI interface, SIMC0 and SIMC2. Note that the SIMC2
register also has the name SIMA which is used by the I2C function. The SIMC1 register is not used
by the SPI function, only by the I2C function. Register SIMC0 is used to control the enable/disable
function and to set the data transmission clock frequency. Register SIMC2 is used for other control
functions such as LSB/MSB selection, write collision flag, etc.
SIMC0 Register
Bit 7 6 5 4 3 2 1 0
Name SIM2 SIM1 SIM0 — SIMDEB1 SIMDEB0 SIMEN SIMICF
R/W R/W R/W R/W — R/W R/W R/W R/W
POR 1 1 1 — 0 0 0 0
SIMC2 Register
Bit 7 6 5 4 3 2 1 0
Name D7 D6 CKPOLB CKEG MLS CSEN WCOL TRF
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
SPI Communication
After the SPI interface is enabled by setting the SIMEN bit high, then in the Master Mode, when
data is written to the SIMD register, transmission/reception will begin simultaneously. When the
data transfer is complete, the TRF flag will be set automatically, but must be cleared using the
application program. In the Slave Mode, when the clock signal from the master has been received,
any data in the SIMD register will be transmitted and any data on the SDI pin will be shifted into
the SIMD register. The master should output a SCS signal to enable the slave devices before a
clock signal is provided. The slave data to be transferred should be well prepared at the appropriate
moment relative to the SCS signal depending upon the configurations of the CKPOLB bit and CKEG
bit. The accompanying timing diagram shows the relationship between the slave data and SCS signal
for various configurations of the CKPOLB and CKEG bits.
The SPI master mode will continue to function even in the IDLE1 Mode if the selected SPI clock
source is running.
SPI Slave Mode Timing – CKEG = 0
I2C Interface
The I 2C interface is used to communicate with external peripheral devices such as sensors,
EEPROM memory etc. Originally developed by Philips, it is a two line low speed serial interface
for synchronous serial data transfer. The advantage of only two lines for communication, relatively
simple communication protocol and the ability to accommodate multiple devices on the same bus
has made it an extremely popular interface type for many applications.
S T A R T s ig n a l
fro m M a s te r
S e n d s la v e a d d r e s s
a n d R /W b it fr o m M a s te r
A c k n o w le d g e
fr o m s la v e
S e n d d a ta b y te
fro m M a s te r
A c k n o w le d g e
fr o m s la v e
S T O P s ig n a l
fro m M a s te r
The SIMDEB1 and SIMDEB0 bits determine the debounce time of the I2C interface. This uses
the system clock to in effect add a debounce time to the external clock to reduce the possibility
of glitches on the clock line causing erroneous operation. The debounce time, if selected, can be
chosen to be either 2 or 4 system clocks. To achieve the required I2C data transfer speed, there
exists a relationship between the system clock, fSYS, and the I2C debounce time. For either the I2C
Standard or Fast mode operation, users must take care of the selected system clock frequency and
the configured debounce time to match the criterion shown in the following table.
I2C Debounce Time Selection I2C Standard Mode (100kHz) I2C Fast Mode (400kHz)
No Devounce fSYS > 2 MHz fSYS > 5 MHz
2 system clock debounce fSYS > 4 MHz fSYS > 10 MHz
4 system clock debounce fSYS > 8 MHz fSYS > 20 MHz
I2C Registers
There are three control registers associated with the I2C bus, SIMC0, SIMC1 and SIMTOC, one
slave address register, SIMA, and one data register, SIMD. The SIMD register, which is shown in
the above SPI section, is used to store the data being transmitted and received on the I2C bus. Before
the microcontroller writes data to the I2C bus, the actual data to be transmitted must be placed in the
SIMD register. After the data is received from the I2C bus, the microcontroller can read it from the
SIMD register. Any transmission or reception of data from the I2C bus must be made via the SIMD
register.
Note that the SIMA register also has the name SIMC2 which is used by the SPI function. Bit SIMEN
and bits SIM2~SIM0 in register SIMC0 are used by the I2C interface.
Register Bit
Name 7 6 5 4 3 2 1 0
SIMC0 SIM2 SIM1 SIM0 — SIMDEB1 SIMDEB0 SIMEN SIMICF
SIMC1 HCF HAAS HBB HTX TXAK SRW IAMWU RXAK
SIMA IICA6 IICA5 IICA4 IICA3 IICA2 IICA1 IICA0 D0
SIMD D7 D6 D5 D4 D3 D2 D1 D0
SIMTOC SIMTOEN SIMTOF SIMTOS5 SIMTOS4 SIMTOS3 SIMTOS2 SIMTOS1 SIMTOS0
SIMD Register
The SIMD register is used to store the data being transmitted and received. The same register is used
by both the SPI and I2C functions. Before the device writes data to the I2C bus, the actual data to
be transmitted must be placed in the SIMD register. After the data is received from the I2C bus, the
device can read it from the SIMD register. Any transmission or reception of data from the I2C bus
must be made via the SIMD 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
SIMA Register
The SIMA register is also used by the SPI interface but has the name SIMC2. The SIMA register is
the location where the 7-bit slave address of the slave device is stored. Bits 7~1 of the SIMA register
define the device slave address. Bit 0 is not defined.
When a master device, which is connected to the I2C bus, sends out an address, which matches the
slave address in the SIMA register, the slave device will be selected. Note that the SIMA register is
the same register address as SIMC2 which is used by the SPI interface.
Bit 7 6 5 4 3 2 1 0
Name IICA6 IICA5 IICA4 IICA3 IICA2 IICA1 IICA0 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~1 IICA6~IICA0: I2C slave address
IICA6~IICA0 is the I2C slave address bit 6 ~ bit 0
Bit 0 Undefined bit
The bit can be read or written by the application program.
There are also three control registers for the I2C interface, SIMC0, SIMC1 and SIMTOC. The
register SIMC0 is used to control the enable/disable function and to set the data transmission
clock frequency.The SIMC1 register contains the relevant flags which are used to indicate the I2C
communication status. The SIMTOC register is used to control the I2C bus time-out function which
is described in the I2C Time-out Control section.
SIMC0 Register
Bit 7 6 5 4 3 2 1 0
Name SIM2 SIM1 SIM0 — SIMDEB1 SIMDEB0 SIMEN SIMICF
R/W R/W R/W R/W — R/W R/W R/W R/W
POR 1 1 1 — 0 0 0 0
SIMC1 Register
Bit 7 6 5 4 3 2 1 0
Name HCF HAAS HBB HTX TXAK SRW IAMWU RXAK
R/W R R R R/W R/W R/W R/W R
POR 1 0 0 0 0 0 0 1
Note: * When a slave address is matched, the devices must be placed in either the transmit mode
and then write data to the SIMD register, or in the receive mode where it must implement a
dummy read from the SIMD register to release the SCL line.
I2C Communication Timing Diagram
S ta rt S la v e A d d r e s s S R W A C K
S C L
S D A 1 0 1 1 0 1 0 1 0
I2 C t i m e - o u t
c o u n te r s ta rt
S to p
S C L
1 0 0 1 0 1 0 0
S D A
I2 C t im e - o u t c o u n t e r r e s e t
o n S C L n e g a tiv e tr a n s itio n
I2C Time-out
When an I2C time-out counter overflow occurs, the counter will stop and the SIMTOEN bit will
be cleared to zero and the SIMTOF bit will be set high to indicate that a time-out condition has
occurred. The time-out condition will also generate an interrupt which uses the I2C interrrupt vector.
When an I2C time-out occurs, the I2C internal circuitry will be reset and the registers will be reset
into the following condition:
Register After I2C Time-out
SIMD, SIMA, SIMC0 No change
SIMC1 Reset to POR condition
The SIMTOF flag can be cleared by the application program. There are 64 time-out period selections
which can be selected using the SIMTOS bits in the SIMTOC register. The time-out duration is
calculated by the formula: ((1~64) × (32/fSUB)). This gives a time-out period which ranges from
about 1ms to 64ms.
SIMTOC Register
Bit 7 6 5 4 3 2 1 0
Name SIMTOEN SIMTOF SIMTOS5 SIMTOS4 SIMTOS3 SIMTOS2 SIMTOS1 SIMTOS0
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
0: Disable
1: Enable
Bit 6 SIMTOF: SIM I2C Time-out flag
0: No time-out occurred
1: Time-out occurred
Bit 5~0 SIMTOS5~SIMTOS0: SIM I2C Time-out period selection
I2C Time-out clock source is fSUB/32
32
I2C Time-out period is equal to (SIMTOS[5:0] + 1) ×
fSUB
Comparators
An analog comparator is contained only within the HT66F0185 device. The comparator function
offers flexibility via their register controlled features such as power-down, polarity select, hysteresis
etc. In sharing their pins with normal I/O pins the comparators do not waste precious I/O pins if
there functions are otherwise unused.
Comparator
Comparator Operation
The HT66F0185 device contains a comparator function which is used to compare two analog
voltages and provide an output based on their difference. Full control over the internal comparator is
provided via the control register CPC assigned to the comparator. The comparator output is recorded
via a bit in the control register, but can also be transferred out onto a shared I/O pin. Additional
comparator functions include output polarity, hysteresis functions and power down control.
Any pull-high resistors connected to the shared comparator input pins will be automatically
disconnected when the comparator is enabled. As the comparator inputs approach their switching
level, some spurious output signals may be generated on the comparator output due to the slow
rising or falling nature of the input signals. This can be minimised by selecting the hysteresis
function which applies a small amount of positive feedback to the comparator. Ideally the
comparator should switch at the point where the positive and negative inputs signals are at the same
voltage level. However, unavoidable input offsets introduce some uncertainties here. The hysteresis
function, if enabled, also increases the switching offset value.
Comparator Interrupt
The comparator possesses its own interrupt function. When the comparator output changes state,
its relevant interrupt flag will be set, and if the corresponding interrupt enable bit is set, then a jump
to its relevant interrupt vector will be executed. Note that it is the changing state of the COUT bit
and not the output pin which generates an interrupt. If the microcontroller is in the SLEEP or IDLE
Mode and the Comparator is enabled, then if the external input lines cause the Comparator output to
change state, the resulting generated interrupt flag will also generate a wake-up. If it is required to
disable a wake-up from occurring, then the interrupt flag should be first set high before entering the
SLEEP or IDLE Mode.
Programming Considerations
If the comparator is enabled, it will remain active when the microcontroller enters the SLEEP or
IDLE Mode, however as it will consume a certain amount of power, the user may wish to consider
disabling it before the SLEEP or IDLE Mode is entered. As comparator pins are shared with normal
I/O pins, the I/O registers for these pins will be read as zero (port control register is “1”) or read as
port data register value (port control register is “0”) if the comparator function is enabled.
CPC Register
Bit 7 6 5 4 3 2 1 0
Name CSEL CEN CPOL COUT COS CMPEG1 CMPEG0 CHYEN
R/W R/W R/W R/W R R/W R/W R/W R/W
POR 1 0 0 0 0 0 0 1
LCD Operation
An external LCD panel can be driven using the devices by configuring the I/O pins as common pins
and segment pins. The LCD driver function is controlled using the LCD control registers which in
addition to controlling the overall on/off function also controls the R-type bias current on the SCOM
and SSEG pins. This enables the LCD COM and SEG driver to generate the necessary VSS, (1/3)
VDD, (2/3)VDD and VDD voltage levels for LCD 1/3 bias operation.
The LCDEN bit in the SLCDC0 register is the overall master control for the LCD driver. This bit is
used in conjunction with the COMnEN and SEGnEN bits to select which I/O pins are used for LCD
driving. Note that the corresponding Port Control register does not need to first setup the pins as
outputs to enable the LCD driver operation.
VDD
SCOM0/SSEG0
(2/3) VDD
LCD LCD
COM/SEG SCOM5/SSEG5
Voltage
Select Analog Switch SSEG6
Circuit
(1/3) VDD
SSEGm
m = 19 for HT66F0175
m = 23 for HT66F0185
ISEL[1:0]
SEGmEN
LCDEN FRAME
LCD Frames
A cyclic LCD waveform includes two frames known as Frame 0 and Frame 1 for which the
following offers a functional explanation.
• Frame 0
To select Frame 0, clear the FRAME bit in the SLCDC 0 register to 0.
In frame 0, the COM signal output can have a value of VDD or a VBIAS value of (1/3)×VDD. The SEG
signal output can have a value of VSS or a VBIAS value of (2/3)×VDD.
• Frame 1
To select Frame 1, set the FRAME bit in the SLCDC0 register to 1.
In frame 1, the COM signal output can have a value of VSS or a VBIAS value of (2/3)×VDD. The SEG
signal output can have a value of VDD or a VBIAS value of (1/3)×VDD.
The COMn waveform is controlled by the application program using the FRAME bit in the
SLCDC0 register and the corresponding pin-shared I/O data bit for the respective COM pin to
determine whether the COMn output has a value of VDD, VSS or VBIAS. The SEGm waveform is
controlled in a similar way using the FRAME bit and the corresponding pin-shared I/O data bit for
the respective SEG pin to determine whether the SEGm output has a value of VDD, VSS or VBIAS.
The accompanying waveform diagram shows a typical 1/3 bias LCD waveform generated using the
application program together with the LCD voltage select circuit. Note that the depiction of a “1”
in the diagram illustrates an illuminated LCD pixel. The COM signal polarity generated on pins
SCOM0~SCOM5, whether “0” or “1”, are generated using the corresponding pin-shared I/O data
register bit.
Frame 0 Frame 1 Frame 0 Frame 1 Frame 0 Frame 0
VDD
1 0 0 0 1 1 0 0
0 0 0 (2/3) VDD
COM0 0 0 0 0 0 0 0 0
0 (1/3) VDD
1 1 1 VSS
1 1 1 VDD
0 0 0 0 0 0 0 0 (2/3) VDD
COM1 0 0 0 0 0 0 0 0 0 (1/3) VDD
1 1 1 VSS
1 1 1 VDD
0 0 0 0 0 0 0 0 (2/3) VDD
COM2 0 0 0 0 0 0 0 0 0 (1/3) VDD
1 1 1 VSS
1 1 1 VDD
0 0 0 0 0 0 0 0 0 (2/3) VDD
COM3 0 0 0 0 0 0 0 0 0 (1/3) VDD
1 1 VSS
1 1 1 1 1 VDD
0 0 0 0 0 0 (2/3) VDD
SEG0 0 0 0 0 0 0 (1/3) VDD
1 1 1 1 1 1 VSS
1 1 1 1 1 1 1 1 1 VDD
0 0 0 (2/3) VDD
SEG1 0 0 (1/3) VDD
1 1 1 1 1 1 1 1 1 VSS
Note: The logical values shown in the above diagram are the corresponding pin-shared I/O data bit value.
1/3 Bias LCD Waveform – 4-COM & 2-SEG application
Register Bit
Name 7 6 5 4 3 2 1 0
SLCDC0 FRAME ISEL1 ISEL0 LCDEN COM3EN COM2EN COM1EN COM0EN
SLCDC1 COM5EN COM4EN COMSEGS5 COMSEGS4 COMSEGS3 COMSEGS2 COMSEGS1 COMSEGS0
SLCDC2 SEG13EN SEG12EN SEG11EN SEG10EN SEG9EN SEG8EN SEG7EN SEG6EN
SLCDC3 — — SEG19EN SEG18EN SEG17EN SEG16EN SEG15EN SEG14EN
Register Bit
Name 7 6 5 4 3 2 1 0
SLCDC0 FRAME ISEL1 ISEL0 LCDEN COM3EN COM2EN COM1EN COM0EN
SLCDC1 COM5EN COM4EN COMSEGS5 COMSEGS4 COMSEGS3 COMSEGS2 COMSEGS1 COMSEGS0
SLCDC2 SEG13EN SEG12EN SEG11EN SEG10EN SEG9EN SEG8EN SEG7EN SEG6EN
SLCDC3 SEG21EN SEG20EN SEG19EN SEG18EN SEG17EN SEG16EN SEG15EN SEG14EN
SLCDC4 — — — — — — SEG23EN SEG22EN
SLCDC0 Register
Bit 7 6 5 4 3 2 1 0
Name FRAME ISEL1 ISEL0 LCDEN COM3EN COM2EN COM1EN COM0EN
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
SLCDC1 Register
Bit 7 6 5 4 3 2 1 0
Name COM5EN COM4EN COMSEGS5 COMSEGS4 COMSEGS3 COMSEGS2 COMSEGS1 COMSEGS0
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
SLCDC2 Register
Bit 7 6 5 4 3 2 1 0
Name SEG13EN SEG12EN SEG11EN SEG10EN SEG9EN SEG8EN SEG7EN SEG6EN
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
UART Interface
The UART interface module is only contained in the HT66F0185 device. The HT66F0185 device
contains an integrated full-duplex asynchronous serial communications UART interface that enables
communication with external devices that contain a serial interface. The UART function has many
features and can transmit and receive data serially by transferring a frame of data with eight or
nine data bits per transmission as well as being able to detect errors when the data is overwritten or
incorrectly framed. The UART function possesses its own internal interrupt which can be used to
indicate when a reception occurs or when a transmission terminates.
The integrated UART function contains the following features:
• Full-duplex, asynchronous communication
• 8 or 9 bits character length
• Even, odd or no parity options
• One or two stop bits
• Baud rate generator with 8-bit prescaler
• Parity, framing, noise and overrun error detection
• Support for interrupt on address detect (last character bit=1)
• Separately enabled transmitter and receiver
• 2-byte Deep FIFO Receive Data Buffer
• Transmit and receive interrupts
• Interrupts can be initialized by the following conditions:
♦ Transmitter Empty
♦ Transmitter Idle
♦ Receiver Full
♦ Receiver Overrun
♦ Address Mode Detect
Register Bit
Name 7 6 5 4 3 2 1 0
USR PERR NF FERR OERR RIDLE RXIF TIDLE TXIF
UCR1 UARTEN BNO PREN PRT STOPS TXBRK RX8 TX8
UCR2 TXEN RXEN BRGH ADDEN WAKE RIE TIIE TEIE
BRG BRG7 BRG6 BRG5 BRG4 BRG3 BRG2 BRG1 BRG0
TXR_RXR TXRX7 TXRX6 TXRX5 TXRX4 TXRX3 TXRX2 TXRX1 TXRX0
TXR_RXR Register
The TXR_RXR register is the data register which is used to store the data to be transmitted on the
TX pin or being received from the RX pin.
Bit 7 6 5 4 3 2 1 0
Name TXRX7 TXRX6 TXRX5 TXRX4 TXRX3 TXRX2 TXRX1 TXRX0
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 TXRX7~TXRX0: UART Transmit/Receive Data bits
USR Register
The USR register is the status register for the UART, which can be read by the program to
determine the present status of the UART. All flags within the USR register are read only and further
explanations are given below.
Bit 7 6 5 4 3 2 1 0
Name PERR NF FERR OERR RIDLE RXIF TIDLE TXIF
R/W R R R R R R R R
POR 0 0 0 0 1 0 1 1
UCR1 Register
The UCR1 register together with the UCR2 register are the UART control registers that are used
to set the various options for the UART function such as overall on/off control, parity control, data
transfer bit length, etc. Further explanation on each of the bits is given below.
Bit 7 6 5 4 3 2 1 0
Name UARTEN BNO PREN PRT STOPS TXBRK RX8 TX8
R/W R/W R/W R/W R/W R/W R/W R W
POR 0 0 0 0 0 0 x 0
“x”: unknown
Bit 7 UARTEN: UART function enable control
0: Disable UART; TX and RX pins are used as other pin-shared functional pins.
1: Enable UART; TX and RX pins can function as UART pins defined by TXEN and
RXEN bits
The UARTEN bit is the UART enable bit. When this bit is equal to “0”, the UART will
be disabled and the RX pin as well as the TX pin will be other pin-shared functional
pins. When the bit is equal to “1”, the UART will be enabled and the TX and RX pins
will function as defined by the TXEN and RXEN enable control bits. When the UART
is disabled, it will empty the buffer so any character remaining in the buffer will be
discarded. In addition, the value of the baud rate counter will be reset. If the UART
is disabled, all error and status flags will be reset. Also the TXEN, RXEN, TXBRK,
RXIF, OERR, FERR, PERR and NF bits will be cleared, while the TIDLE, TXIF and
RIDLE bits will be set. Other control bits in UCR1, UCR2 and BRG registers will
remain unaffected. If the UART is active and the UARTEN bit is cleared, all pending
transmissions and receptions will be terminated and the module will be reset as defined
above. When the UART is re-enabled, it will restart in the same configuration.
Bit 6 BNO: Number of data transfer bits selection
0: 8-bit data transfer
1: 9-bit data transfer
This bit is used to select the data length format, which can have a choice of either
8-bit or 9-bit format. When this bit is equal to “1”, a 9-bit data length format will be
selected. If the bit is equal to “0”, then an 8-bit data length format will be selected. If
9-bit data length format is selected, then bits RX8 and TX8 will be used to store the 9th
bit of the received and transmitted data respectively.
Bit 5 PREN: Parity function enable control
0: Parity function is disabled
1: Parity function is enabled
This bit is the parity function enable bit. When this bit is equal to 1, the parity function
will be enabled. If the bit is equal to 0, then the parity function will be disabled.
Bit 4 PRT: Parity type selection bit
0: Even parity for parity generator
1: Odd parity for parity generator
This bit is the parity type selection bit. When this bit is equal to 1, odd parity type will
be selected. If the bit is equal to 0, then even parity type will be selected.
Bit 3 STOPS: Number of stop bits selection
0: One stop bit format is used
1: Two stop bits format is used
This bit determines if one or two stop bits are to be used. When this bit is equal to “1”,
two stop bits format are used. If the bit is equal to “0”, then only one stop bit format is
used.
UCR2 Register
The UCR2 register is the second of the UART control registers and serves several purposes. One
of its main functions is to control the basic enable/disable operation if the UART Transmitter and
Receiver as well as enabling the various UART interrupt sources. The register also serves to control
the baud rate speed, receiver wake-up function enable and the address detect function enable.
Further explanation on each of the bits is given below.
Bit 7 6 5 4 3 2 1 0
Name TXEN RXEN BRGH ADDEN WAKE RIE TIIE TEIE
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
fSYS fSYS
Baud Rate (BR)
[64(N+1)] [16(N+1)]
By programming the BRGH bit which allows selection of the related formula and programming the
required value in the BRG register, the required baud rate can be setup. Note that because the actual
baud rate is determined using a discrete value, N, placed in the BRG register, there will be an error
associated between the actual and requested value. The following example shows how the BRG
register value N and the error value can be calculated.
BRG Register
Bit 7 6 5 4 3 2 1 0
Name BRG7 BRG6 BRG5 BRG4 BRG3 BRG2 BRG1 BRG0
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 BRG7~BRG0: Baud Rate values
By programming the BRGH bit in the UCR2 register which allows selection of the
related formula described above and programming the required value in the BRG
register, the required baud rate can be setup.
The following diagram shows the transmit and receive waveforms for both 8-bit and 9-bit data
formats.
UART Transmitter
Data word lengths of either 8 or 9 bits can be selected by programming the BNO bit in the UCR1
register. When BNO bit is set, the word length will be set to 9 bits. In this case the 9th bit, which
is the MSB, needs to be stored in the TX8 bit in the UCR1 register. At the transmitter core lies the
Transmitter Shift Register, more commonly known as the TSR, whose data is obtained from the
transmit data register, which is known as the TXR register. The data to be transmitted is loaded
into this TXR register by the application program. The TSR register is not written to with new data
until the stop bit from the previous transmission has been sent out. As soon as this stop bit has been
transmitted, the TSR can then be loaded with new data from the TXR register, if it is available. It
should be noted that the TSR register, unlike many other registers, is not directly mapped into the
Data Memory area and as such is not available to the application program for direct read/write
operations. An actual transmission of data will normally be enabled when the TXEN bit is set, but
the data will not be transmitted until the TXR register has been loaded with data and the baud rate
generator has defined a shift clock source. However, the transmission can also be initiated by first
loading data into the TXR register, after which the TXEN bit can be set. When a transmission of
data begins, the TSR is normally empty, in which case a transfer to the TXR register will result in
an immediate transfer to the TSR. If during a transmission the TXEN bit is cleared, the transmission
will immediately cease and the transmitter will be reset. The TX output pin will then return to the I/
O or other pin-shared function.
Transmitting Data
When the UART is transmitting data, the data is shifted on the TX pin from the shift register, with
the least significant bit LSB first. In the transmit mode, the TXR register forms a buffer between the
internal bus and the transmitter shift register. It should be noted that if 9-bit data format has been
selected, then the MSB will be taken from the TX8 bit in the UCR1 register. The steps to initiate a
data transfer can be summarized as follows:
• Make the correct selection of the BNO, PRT, PREN and STOPS bits to define the required word
length, parity type and number of stop bits.
• Setup the BRG register to select the desired baud rate.
• Set the TXEN bit to ensure that the UART transmitter is enabled and the TX pin is used as a
UART transmitter pin.
• Access the USR register and write the data that is to be transmitted into the TXR register. Note
that this step will clear the TXIF bit.
This sequence of events can now be repeated to send additional data. It should be noted that when
TXIF=0, data will be inhibited from being written to the TXR register. Clearing the TXIF flag is
always achieved using the following software sequence:
1. A USR register access
2. A TXR register write execution
The read-only TXIF flag is set by the UART hardware and if set indicates that the TXR register is
empty and that other data can now be written into the TXR register without overwriting the previous
data. If the TEIE bit is set, then the TXIF flag will generate an interrupt. During a data transmission,
a write instruction to the TXR register will place the data into the TXR register, which will be
copied to the shift register at the end of the present transmission. When there is no data transmission
in progress, a write instruction to the TXR register will place the data directly into the shift register,
resulting in the commencement of data transmission, and the TXIF bit being immediately set. When
a frame transmission is complete, which happens after stop bits are sent or after the break frame, the
TIDLE bit will be set. To clear the TIDLE bit the following software sequence is used:
1. A USR register access
2. A TXR register write execution
Note that both the TXIF and TIDLE bits are cleared by the same software sequence.
Transmitting Break
If the TXBRK bit is set, then the break characters will be sent on the next transmission. Break
character transmission consists of a start bit, followed by 13xN “0” bits, where N=1, 2, etc. If a
break character is to be transmitted, then the TXBRK bit must be first set by the application program
and then cleared to generate the stop bits. Transmitting a break character will not generate a transmit
interrupt. Note that a break condition length is at least 13 bits long. If the TXBRK bit is continually
kept at a logic high level, then the transmitter circuitry will transmit continuous break characters.
After the application program has cleared the TXBRK bit, the transmitter will finish transmitting the
last break character and subsequently send out one or two stop bits. The automatic logic high at the
end of the last break character will ensure that the start bit of the next frame is recognized.
UART Receiver
The UART is capable of receiving word lengths of either 8 or 9 bits can be selected by programming
the BNO bit in the UCR1 register. When BNO bit is set, the word length will be set to 9 bits. In
this case the 9th bit, which is the MSB, will be stored in the RX8 bit in the UCR1 register. At the
receiver core lies the Receiver Shift Register more commonly known as the RSR. The data which
is received on the RX external input pin is sent to the data recovery block. The data recovery block
operating speed is 16 times that of the baud rate, while the main receive serial shifter operates at the
baud rate. After the RX pin is sampled for the stop bit, the received data in RSR is transferred to the
receive data register, if the register is empty. The data which is received on the external RX input pin
is sampled three times by a majority detect circuit to determine the logic level that has been placed
onto the RX pin. It should be noted that the RSR register, unlike many other registers, is not directly
mapped into the Data Memory area and as such is not available to the application program for direct
read/write operations.
Receiving Data
When the UART receiver is receiving data, the data is serially shifted in on the external RX input
pin to the shift register, with the least significant bit LSB first. The RXR register is a two byte deep
FIFO data buffer, where two bytes can be held in the FIFO while the 3rd byte can continue to be
received. Note that the application program must ensure that the data is read from RXR before the
3rd byte has been completely shifted in, otherwise the 3rd byte will be discarded and an overrun error
OERR will be subsequently indicated. The steps to initiate a data transfer can be summarized as
follows:
• Make the correct selection of the BNO, PRT, PREN and STOPS bits to define the required word
length, parity type and number of stop bits.
• Setup the BRG register to select the desired baud rate.
• Set the RXEN bit to ensure that the UART receiver is enabled and the RX pin is used as a UART
receiver pin.
At this point the receiver will be enabled which will begin to look for a start bit.
When a character is received, the following sequence of events will occur:
• The RXIF bit in the USR register will be set then RXR register has data available, at least one
more character can be read.
• When the contents of the shift register have been transferred to the RXR register and if the RIE
bit is set, then an interrupt will be generated.
• If during reception, a frame error, noise error, parity error or an overrun error has been detected,
then the error flags can be set.
The RXIF bit can be cleared using the following software sequence:
1. A USR register access
2. A RXR register read execution
Receiving Break
Any break character received by the UART will be managed as a framing error. The receiver will
count and expect a certain number of bit times as specified by the values programmed into the BNO
and STOPS bits. If the break is much longer than 13 bit times, the reception will be considered as
complete after the number of bit times specified by BNO and STOPS. The RXIF bit is set, FERR
is set, zeros are loaded into the receive data register, interrupts are generated if appropriate and the
RIDLE bit is set. If a long break signal has been detected and the receiver has received a start bit,
the data bits and the invalid stop bit, which sets the FERR flag, the receiver must wait for a valid
stop bit before looking for the next start bit. The receiver will not make the assumption that the
break condition on the line is the next start bit. A break is regarded as a character that contains only
zeros with the FERR flag set. The break character will be loaded into the buffer and no further data
will be received until stop bits are received. It should be noted that the RIDLE read only flag will go
high when the stop bits have not yet been received. The reception of a break character on the UART
registers will result in the following:
• The framing error flag, FERR, will be set.
• The receive data register, RXR, will be cleared.
• The OERR, NF, PERR, RIDLE or RXIF flags will possibly be set.
Idle Status
When the receiver is reading data, which means it will be in between the detection of a start bit and
the reading of a stop bit, the receiver status flag in the USR register, otherwise known as the RIDLE
flag, will have a zero value. In between the reception of a stop bit and the detection of the next start
bit, the RIDLE flag will have a high value, which indicates the receiver is in an idle condition.
Receiver Interrupt
The read only receive interrupt flag, RXIF, in the USR register is set by an edge generated by the
receiver. An interrupt is generated if RIE=1, when a word is transferred from the Receive Shift
Register, RSR, to the Receive Data Register, RXR. An overrun error can also generate an interrupt if
RIE=1.
Noise Error – NF
Over-sampling is used for data recovery to identify valid incoming data and noise. If noise is
detected within a frame, the following will occur:
• The read only noise flag, NF, in the USR register will be set on the rising edge of the RXIF bit.
• Data will be transferred from the shift register to the RXR register.
• No interrupt will be generated. However this bit rises at the same time as the RXIF bit which
itself generates an interrupt.
Note that the NF flag is reset by a USR register read operation followed by an RXR register read
operation.
0
Transmitter Empty Flag TXIF TEIE
1
0
Transmitter Idle Flag TIDLE TIIE
1 UART Interrupt
0 0
Request Flag URE EMI Interrupt
0 URF 1 1 signal to MCU
Receiver Overrun Flag RIE
OR
OERR
1
0
Receiver Data Available 0
ADDEN
RXIF
1 1
RX7 if BNO=0
RX8 if BNO=1
RX Pin WAKE 0
Wake-up
1
UCR2 Register
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 — VLVD2 VLVD1 VLVD0
R/W — — R R/W — R/W R/W R/W
POR — — 0 0 — 0 0 0
LVD Operation
The Low Voltage Detector function operates by comparing the power supply voltage, VDD, with a
pre-specified voltage level stored in the LVDC register. This has a range of between 2.0V and 4.0V.
When the power supply voltage, VDD, falls below this pre-determined value, the LVDO bit will be
set high indicating a low power supply voltage condition. The Low Voltage Detector function is
supplied by a reference voltage which will be automatically enabled. When the device is powered
down the low voltage detector will remain active if the LVDEN bit is high. After enabling the Low
Voltage Detector, a time delay tLVDS should be allowed for the circuitry to stabilise before reading the
LVDO bit. Note also that as the VDD voltage may rise and fall rather slowly, at the voltage nears that
of VLVD, there may be multiple bit LVDO transitions.
VDD
VLVD
LVDEN
LVDO
tLVDS
LVDINT
tLVD
LVD Operation
The Low Voltage Detector also has its own interrupt which is contained within one of the Multi-
function interrupts, 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. When the device is powered down the Low Voltage Detector
will remain active if the LVDEN bit is high. In this case, the LVF interrupt request flag will be set,
causing an interrupt to be generated if VDD falls below the preset LVD voltage. This will cause the
device to wake-up from the SLEEP or 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 SLEEP
or IDLE Mode.
Interrupts
Interrupts are an important part of any microcontroller system. When an external event or an
internal function such as a Timer Module 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. These devices contain several external
interrupt and internal interrupts functions. The external interrupts are generated by the action of
the external INT0 and INT1 pins, while the internal interrupts are generated by various internal
functions such as the TMs, Time Base, LVD, EEPROM, SIM, UART 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 a series of registers, located in the Special Purpose Data Memory, as shown in the
accompanying table. The number of registers depends upon the device chosen but fall into three
categories. The first is the INTC0~INTC2 registers which setup the primary interrupts, the second
is the MFI0~MFI2 registers which setup the Multi-function interrupts. Finally there is an INTEG
register to setup the external interrupt trigger edge type.
Each register contains a number of enable bits to enable or disable individual interrupts 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 — —
INTn Pins INTnE INTnF n=0~1
Multi-function MFnE MFnF n = 0~2
A/D Converter ADE ADF —
Time Base TBnE TBnF n=0~1
SIM SIME SIMF —
LVD LVE LVF —
EEPROM write operation DEE DEF —
TnPE TnPF n = 0~1
TM
TnAE TnAF n = 0~1
Register Bit
Name 7 6 5 4 3 2 1 0
INTEG — — — — INT1S1 INT1S0 INT0S1 INT0S0
INTC0 — MF0F — INT0F MF0E — INT0E EMI
INTC1 TB0F ADF MF2F MF1F TB0E ADE MF2E MF1E
INTC2 — SIMF INT1F TB1F — SIME INT1E TB1E
MFI0 — — T0AF T0PF — — T0AE T0PE
MFI1 — — T1AF T1PF — — T1AE T1PE
MFI2 — — DEF LVF — — DEE LVE
Register Bit
Name 7 6 5 4 3 2 1 0
INTEG — — — — INT1S1 INT1S0 INT0S1 INT0S0
INTC0 — MF0F CPF INT0F MF0E CPE INT0E EMI
INTC1 TB0F ADF MF2F MF1F TB0E ADE MF2E MF1E
INTC2 URF SIMF INT1F TB1F URE SIME INT1E TB1E
MFI0 — — T0AF T0PF — — T0AE T0PE
MFI1 T2AF T2PF T1AF T1PF T2AE T2PE T1AE T1PE
MFI2 — — DEF LVF — — DEE LVE
INTEG Register
Bit 7 6 5 4 3 2 1 0
Name — — — — INT1S1 INT1S0 INT0S1 INT0S0
R/W — — — — R/W R/W R/W R/W
POR — — — — 0 0 0 0
INTC1 Register
Bit 7 6 5 4 3 2 1 0
Name TB0F ADF MF2F MF1F TB0E ADE MF2E MF1E
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
MFI0 Register
Bit 7 6 5 4 3 2 1 0
Name — — T0AF T0PF — — T0AE T0PE
R/W — — R/W R/W — — R/W R/W
POR — — 0 0 — — 0 0
MFI2 Register
Bit 7 6 5 4 3 2 1 0
Name — — DEF LVF — — DEE LVE
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 TM Comparator P or Comparator A 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. Some interrupt sources have their own
individual vector while others share the same multi-function interrupt vector. Once an interrupt
subroutine is serviced, all 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.
External Interrupt
The external interrupts are controlled by signal transitions on the pins INT0~INT1. An external
interrupt request will take place when the external interrupt request flags, INT0F~INT1F, are set,
which will occur when a transition, whose type is chosen by the edge select bits, appears on the
external interrupt pins. To allow the program to branch to its respective interrupt vector address,
the global interrupt enable bit, EMI, and respective external interrupt enable bit, INT0E~INT1E,
must first be set. Additionally the correct interrupt edge type must be selected using the INTEG
register to enable the external interrupt function and to choose the trigger edge type. As the external
interrupt pins are pin-shared with I/O pins, they can only be configured as external interrupt pins if
their external interrupt enable bit in the corresponding interrupt register has been set and the external
interrupt pin is selected by the corresponding pin-shared function selection bits. The pin must also
be setup as an input by setting the corresponding bit in the port control register. When the interrupt
is enabled, the stack is not full and the correct transition type appears on the external interrupt pin,
a subroutine call to the external interrupt vector, will take place. When the interrupt is serviced, the
external interrupt request flags, INT0F~INT1F, will be automatically reset and the EMI bit will be
automatically cleared to disable other interrupts. Note that any pull-high resistor selections on the
external interrupt pins will remain valid even if the pin is used as an external interrupt input.
The INTEG register is used to select the type of active edge that will trigger the external interrupt.
A choice of either rising or falling or both edge types can be chosen to trigger an external interrupt.
Note that the INTEG register can also be used to disable the external interrupt function.
Multi-function Interrupt
Within the device there are up to three Multi-function interrupts. Unlike the other independent
interrupts, these interrupts have no independent source, but rather are formed from other existing
interrupt sources, namely the TM interrupts, LVD interrupt and EEPROM write operation interrupt.
A Multi-function interrupt request will take place when any of the Multi-function interrupt request
flags MFnF are set. The Multi-function interrupt flags will be set when any of their included
functions generate an interrupt request flag. To allow the program to branch to its respective interrupt
vector address, when the Multi-function interrupt is enabled and the stack is not full, and either one
of the interrupts contained within each of Multi-function interrupt occurs, a subroutine call to one of
the Multi-function interrupt vectors will take place. When the interrupt is serviced, the related Multi-
Function request flag will be automatically reset and the EMI bit will be automatically cleared to
disable other interrupts.
However, it must be noted that, although the Multi-function Interrupt request flags will be
automatically reset when the interrupt is serviced, the request flags from the original source of
the Multi-function interrupts will not be automatically reset and must be manually reset by the
application program.
fTB/28 ~ fTB/215 M
Prescaler U
X
Time Base 0 Interrupt
fTBC M
U
fTB TB02~TB00
fSYS/4 X
fTB/212 ~ fTB/215 M
Prescaler U
X
Time Base 1 Interrupt
TBCK
TB11~TB10
TBC Register
Bit 7 6 5 4 3 2 1 0
Name TBON TBCK TB11 TB10 LXTLP TB02 TB01 TB00
R/W R/W R/W R/W R/W R/W R/W R/W R/W
POR 0 0 1 1 0 1 1 1
LVD Interrupt
The Low Voltage Detector Interrupt is contained within the Multi-function Interrupt. An 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, Low Voltage
Interrupt enable bit, LVE, and associated Multi-function interrupt enable bit, 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 Multi-function Interrupt vector, will take place. When the Low Voltage Interrupt is serviced, the
EMI bit will be automatically cleared to disable other interrupts. However, only the Multi-function
interrupt request flag will be also automatically cleared. As the LVF flag will not be automatically
cleared, it has to be cleared by the application program.
EEPROM Interrupt
The EEPROM Write Interrupt is contained within the Multi-function Interrupt. An EEPROM
Write Interrupt request will take place when the EEPROM Write 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, EEPROM Write Interrupt enable bit,
DEE, and associated Multi-function interrupt enable bit 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 respective
Multi-function Interrupt vector will take place. When the EEPROM Write Interrupt is serviced, the
EMI bit will be automatically cleared to disable other interrupts. However, only the Multi-function
interrupt request flag will be automatically cleared. As the DEF flag will not be automatically
cleared, it has to be cleared by the application program.
TM Interrupt
The Compact, Standard and Periodic TMs have two interrupts, one comes from the comparator A
match situation and the other comes from the comparator P match situation. All of the TM interrupts
are contained within the Multi-function Interrupts. For all of the TM types there are two interrupt
request flags and two enable control bits. A TM interrupt request will take place when any of the
TM request flags are set, a situation which occurs when a TM comparator P or A match situation
happens.
To allow the program to branch to its respective interrupt vector address, the global interrupt enable
bit, EMI, respective TM Interrupt enable bit, and relevant Multi-function Interrupt enable bit, MFnE,
must first be set. When the interrupt is enabled, the stack is not full and a TM comparator match
situation occurs, a subroutine call to the relevant Multi-function Interrupt vector locations, will take
place. When the TM interrupt is serviced, the EMI bit will be automatically cleared to disable other
interrupts. However, only the related MFnF flag will be automatically cleared. As the TM interrupt
request flags will not be automatically cleared, they have to be cleared by the application program.
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.
Where a certain interrupt is contained within a Multi-function interrupt, then when the interrupt
service routine is executed, as only the Multi-function interrupt request flags, MFnF, will be
automatically cleared, the individual request flag for the function needs to be 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.
Configuration Options
Configuration options refer to certain options within the MCU that are programmed into the device
during the programming process. During the development process, these options are selected using
the HT-IDE software development tools. As these options are programmed into the device using
the hardware programming tools, once they are selected they cannot be changed later using the
application program. All options must be defined for proper system function, the details of which are
shown in the table.
No. Options
High Speed System Oscillator Selection
1
fH – HXT or HIRC
Low Speed System Oscillator Selection
2
fSUB – LXT or LIRC
HIRC Frequency Selection
3
fHIRC – 8MHz, 12MHz or 16MHz
Application Circuits
VDD
VDD
AN0~AN7
See Oscillator
Section
PA0~PA7
OSC PC0/OSC1
Circuit PC1/OSC2 PB0~PB6
PC0~PC6
OSC PB0/XT1
Circuit PD0~PD3
PB1/XT2
See Oscillator
Section
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 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
ADDM A,[m] Add ACC to Data Memory 1Note Z, C, AC, OV
ADD A,x Add immediate data to ACC 1 Z, C, AC, OV
ADC A,[m] Add Data Memory to ACC with Carry 1 Z, C, AC, OV
ADCM A,[m] Add ACC to Data memory with Carry 1Note Z, C, AC, OV
SUB A,x Subtract immediate data from the ACC 1 Z, C, AC, OV
SUB A,[m] Subtract Data Memory from ACC 1 Z, C, AC, OV
SUBM A,[m] Subtract Data Memory from ACC with result in Data Memory 1Note Z, C, AC, OV
SBC A,[m] Subtract Data Memory from ACC with Carry 1 Z, C, AC, OV
SBCM A,[m] Subtract Data Memory from ACC with Carry, result in Data Memory 1Note Z, C, AC, OV
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.
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
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
TABRD [m] Read table (specific page or current page) to TBLH and Data Memory
Description The low byte of the program code addressed by the table pointer (TBHP and TBLP or only
TBLP if no 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
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 Information.
Additional supplementary information with regard to packaging is listed below. Click on the relevant
section to be transferred to the relevant website page.
• Further Package Information (include Outline Dimensions, Product Tape and Reel Specifications)
• Carton information
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.406 BSC —
B — 0.295 BSC —
C 0.012 — 0.020
C’ — 0.504 BSC —
D — — 0.104
E — 0.050 BSC —
F 0.004 — 0.012
G 0.016 — 0.050
H 0.008 — 0.013
α 0° — 8°
Dimensions in mm
Symbol
Min. Nom. Max.
A — 10.30 BSC —
B — 7.5 BSC —
C 0.31 — 0.51
C’ — 12.8 BSC —
D — — 2.65
E — 1.27 BSC —
F 0.10 — 0.30
G 0.40 — 1.27
H 0.20 — 0.33
α 0° — 8°
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.236 BSC —
B — 0.154 BSC —
C 0.008 — 0.012
C’ — 0.341 BSC —
D — — 0.069
E — 0.025 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.0 BSC —
B — 3.9 BSC —
C 0.20 — 0.30
C’ — 8.66 BSC —
D — — 1.75
E — 0.635 BSC —
F 0.10 — 0.25
G 0.41 — 1.27
H 0.10 — 0.25
α 0° — 8°
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.406 BSC —
B — 0.295 BSC —
C 0.012 — 0.020
C’ — 0.606 BSC —
D — — 0.104
E — 0.050 BSC —
F 0.004 — 0.012
G 0.016 — 0.050
H 0.008 — 0.013
α 0° — 8°
Dimensions in mm
Symbol
Min. Nom. Max.
A — 10.30 BSC —
B — 7.5 BSC —
C 0.31 — 0.51
C’ — 15.4 BSC —
D — — 2.65
E — 1.27 BSC —
F 0.10 — 0.30
G 0.40 — 1.27
H 0.20 — 0.33
α 0° — 8°
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.236 BSC —
B — 0.154 BSC —
C 0.008 — 0.012
C’ — 0.341 BSC —
D — — 0.069
E — 0.025 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.0 BSC —
B — 3.9 BSC —
C 0.20 — 0.30
C’ — 8.66 BSC —
D — — 1.75
E — 0.635 BSC —
F 0.10 — 0.25
G 0.41 — 1.27
H 0.10 — 0.25
α 0° — 8°
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.406 BSC —
B — 0.295 BSC —
C 0.012 — 0.020
C’ — 0.705 BSC —
D — — 0.104
E — 0.050 BSC —
F 0.004 — 0.012
G 0.016 — 0.050
H 0.008 — 0.013
α 0° — 8°
Dimensions in mm
Symbol
Min. Nom. Max.
A — 10.30 BSC —
B — 7.50 BSC —
C 0.31 — 0.51
C’ — 17.9 BSC —
D — — 2.65
E — 1.27 BSC —
F 0.10 — 0.30
G 0.40 — 1.27
H 0.20 — 0.33
α 0° — 8°
Dimensions in inch
Symbol
Min. Nom. Max.
A — 0.236 BSC —
B — 0.154 BSC —
C 0.008 — 0.012
C’ — 0.390 BSC —
D — — 0.069
E — 0.025 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.0 BSC —
B — 3.9 BSC —
C 0.20 — 0.30
C’ — 9.9 BSC —
D — — 1.75
E — 0.635 BSC —
F 0.10 — 0.25
G 0.41 — 1.27
H 0.10 — 0.25
α 0° — 8°