a/d flash mcu with eeprom...ptpi pas1 st — ptm capture input ptp pas1 — cmos ptm output an6 pas1...

121
A/D Flash MCU with EEPROM HT66F0181 Revision: V1.30 Date: December 27, 2019

Upload: others

Post on 06-Nov-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

A/D Flash MCU with EEPROM

HT66F0181

Revision: V1.30 Date: December 27, 2019

Page 2: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 2 December 27, 2019 Rev. 1.30 3 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Table of ContentsFeatures .................................................................................................................6

CPU Features ...............................................................................................................................6Peripheral Features .......................................................................................................................6

General Description .............................................................................................. 7Block Diagram ....................................................................................................... 7Pin Assignment ..................................................................................................... 8Pin Description .....................................................................................................8Absolute Maximum Ratings ............................................................................... 10D.C. Characteristics ............................................................................................ 10

Operating Voltage Characteristics ...............................................................................................10Operating Current Characteristics ...............................................................................................10Standby Current Characteristics ................................................................................................. 11

A.C. Characteristics ............................................................................................ 11High Speed Internal Oscillator – HIRC – Frequency Accuracy ................................................... 11Low Speed Internal Oscillator – LIRC – Frequency Accuracy ....................................................12Operating Frequency Characteristic Curves ...............................................................................12System Start Up Time Characteristics ........................................................................................12

Input/Output Characteristics ............................................................................. 13Memory Characteristics ..................................................................................... 14LVR Electrical Characteristics ........................................................................... 14Internal Reference Voltage Characteristics ...................................................... 14A/D Converter Electrical Characteristics .......................................................... 15Power-on Reset Characteristics ........................................................................ 15System Architecture ........................................................................................... 16

Clocking and Pipelining ...............................................................................................................16Program Counter .........................................................................................................................17Stack ...........................................................................................................................................17Arithmetic and Logic Unit – ALU .................................................................................................18

Flash Program Memory ...................................................................................... 18Structure ......................................................................................................................................18Special Vectors ...........................................................................................................................19Look-up Table ..............................................................................................................................19Table Program Example ..............................................................................................................19In Circuit Programming – ICP .....................................................................................................20On-Chip Debug Support – OCDS ...............................................................................................21

Data Memory .......................................................................................................22Structure ......................................................................................................................................22General Purpose Data Memory ..................................................................................................22Special Purpose Data Memory ...................................................................................................22

Page 3: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 2 December 27, 2019 Rev. 1.30 3 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Special Function Register Description ............................................................. 24Indirect Addressing Registers – IAR0, IAR1 ...............................................................................24Memory Pointers – MP0, MP1 ....................................................................................................24Accumulator – ACC .....................................................................................................................25Program Counter Low Register – PCL ........................................................................................25Look-up Table Registers – TBLP, TBHP, TBLH ...........................................................................25Status Register – STATUS ..........................................................................................................25

Emulated EEPROM Data Memory ..................................................................... 27Emulated EEPROM Data Memory Structure ..............................................................................27Emulated EEPROM Registers ....................................................................................................28Erasing the Emulated EEPROM .................................................................................................31Writing Data to the Emulated EEPROM ......................................................................................31Reading Data from the Emulated EEPROM ...............................................................................31Programming Considerations ......................................................................................................31

Oscillators ...........................................................................................................33Oscillator Overview .....................................................................................................................33System Clock Configurations ......................................................................................................33Internal High Speed RC Oscillator – HIRC .................................................................................34Internal 32kHz Oscillator – LIRC .................................................................................................34

Operating Modes and System Clocks .............................................................. 34System Clocks ............................................................................................................................34System Operation Modes ............................................................................................................35Control Registers ........................................................................................................................36Operating Mode Switching ..........................................................................................................38Standby Current Considerations .................................................................................................42Wake-up ......................................................................................................................................42

Watchdog Timer ..................................................................................................43Watchdog Timer Clock Source ....................................................................................................43Watchdog Timer Control Register ...............................................................................................43Watchdog Timer Operation .........................................................................................................44

Reset and Initialisation ....................................................................................... 45Reset Functions ..........................................................................................................................45Reset Initial Conditions ...............................................................................................................47

Input/Output Ports .............................................................................................. 50Pull-high Resistors ......................................................................................................................50Port A Wake-up ...........................................................................................................................51I/O Port Control Registers ...........................................................................................................51I/O Port Source Current Selection ...............................................................................................52Pin-shared Functions ..................................................................................................................53I/O Pin Structure ..........................................................................................................................55Programming Considerations ......................................................................................................55

Timer Modules – TM ........................................................................................... 56Introduction .................................................................................................................................56TM Operation ..............................................................................................................................56

Page 4: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 4 December 27, 2019 Rev. 1.30 5 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

TM Clock Source .........................................................................................................................56TM Interrupts ...............................................................................................................................57TM External Pins .........................................................................................................................57Programming Considerations ......................................................................................................58

Standard Type TM – STM ................................................................................... 59Standard Type TM Operation ......................................................................................................59Standard Type TM Register Description .....................................................................................59Standard Type TM Operation Modes ..........................................................................................63

Periodic Type TM – PTM ..................................................................................... 73Periodic Type TM Operation........................................................................................................73Periodic Type TM Register Description .......................................................................................73Periodic Type TM Operation Modes ............................................................................................77

Analog to Digital Converter ............................................................................... 86A/D Converter Overview .............................................................................................................86A/D Converter Register Description ............................................................................................87A/D Converter Reference Voltage ...............................................................................................90A/D Converter Operation .............................................................................................................91Conversion Rate and Timing Diagram ........................................................................................91Summary of A/D Conversion Steps .............................................................................................92Programming Considerations ......................................................................................................93A/D Conversion Function ............................................................................................................93A/D Conversion Programming Examples ....................................................................................94

Interrupts .............................................................................................................95Interrupt Registers .......................................................................................................................95Interrupt Operation ......................................................................................................................98External Interrupts .......................................................................................................................99Multi-function Interrupts ...............................................................................................................99A/D Converter Interrupt .............................................................................................................100Timer Module Interrupts ............................................................................................................100Time Base Interrupts .................................................................................................................100Interrupt Wake-up Function .......................................................................................................102Programming Considerations ....................................................................................................102

Application Circuits .......................................................................................... 102Instruction Set ...................................................................................................103

Introduction ...............................................................................................................................103Instruction Timing ......................................................................................................................103Moving and Transferring Data ...................................................................................................103Arithmetic Operations ................................................................................................................103Logical and Rotate Operation ...................................................................................................104Branches and Control Transfer .................................................................................................104Bit Operations ...........................................................................................................................104Table Read Operations .............................................................................................................104Other Operations .......................................................................................................................104

Page 5: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 4 December 27, 2019 Rev. 1.30 5 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Instruction Set Summary ................................................................................. 105Table Conventions .....................................................................................................................105

Instruction Definition ........................................................................................ 107Package Information ........................................................................................ 116

16-pin NSOP (150mil) Outline Dimensions ............................................................................... 11720-pin NSOP (150mil) Outline Dimensions ............................................................................... 11820-pin SOP (300mil) Outline Dimension ................................................................................... 11920-pin SSOP (150mil) Outline Dimensions ...............................................................................120

Page 6: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 6 December 27, 2019 Rev. 1.30 7 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Features

CPU Features• Operating voltage

♦ fSYS=8MHz: 1.8V~5.5V

• Up to 0.5μs instruction cycle with 8MHz system clock at VDD=5V

• Power down and wake-up functions to reduce power consumption

• Oscillator types ♦ Internal High Speed 8MHz RC – HIRC ♦ Internal Low Speed 32kHz RC – LIRC

• Multi-mode operation: FAST, SLOW, IDLE and SLEEP

• Fully integrated internal oscillators require no external components

• All instructions executed in one or two instruction cycles

• Table read instructions

• 63 powerful instructions

• Up to 6-level subroutine nesting

• Bit manipulation instruction

Peripheral Features• Flash Program Memory: 4K×15

• RAM Data Memory: 128×8

• Emulated EEPROM Memory: 32×15

• Watchdog Timer function

• Up to 18 bidirectional I/O lines

• Programmable I/O source current for LED applications

• Dual pin-shared external interrupts

• Multiple Timer Modules for time measurement, input capture, compare match output or PWM output or single pulse output function

• Dual Time Base functions for generation of fixed time interrupt signals

• 8 external channel 10-bit resolution A/D converter with internal reference voltage VVR

• Low voltage reset function

• Package types: 16-pin NSOP, 20-pin SOP/NSOP/SSOP

Page 7: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 6 December 27, 2019 Rev. 1.30 7 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

General DescriptionThe device is a Flash Memory A/D type 8-bit high performance RISC architecture microcontroller. Offering users the convenience of Flash Memory multi-programming features, the device also includes a wide range of functions and features. Other memory includes an area of RAM Data Memory as well as an area of Emulated EEPROM memory for storage of non-volatile data such as serial numbers, calibration data, etc.

Analog feature includes a multi-channel 10-bit A/D converter. Multiple and extremely flexible Timer Modules provide timing, pulse generation and PWM generation functions. Protective features such as an internal Watchdog Timer and Low Voltage Reset function coupled with excellent noise immunity and ESD protection ensures that reliable operation is maintained in hostile electrical environments.

A full choice of internal high and low speed oscillators are provided and the two fully integrated system oscillators require no external components for their implementation. The ability to operate and switch dynamically between a range of operating modes using different clock sources gives users the ability to optimize microcontroller operation and minimize power consumption.

The inclusion of flexible I/O programming features and Time Base funcitons along with other features ensure that the device will find excellent use in electronic metering, environmental monitoring, handheld instruments, household appliances, electronically controlled tools, motor driving in addition to many others.

Block Diagram

Interrupt Controller

BusM

UX

Reset Circuit

Stack6-level

RAM128 × 8

ROM4K × 15EmulatedEEPROM32 × 15

WatchdogTimer

Port ADriver

VDDHIRC8MHz

LIRC32kHz

Timers

Pin-sharedFunction

INT0~INT1

Pin-sharedwith Port B

PA0~PA7

Clock System

Time Bases

HT8 MCU Core

SYSCLKDigital Peripherals

I/O

VSS

PB0~PB6

VDD

VSS

Port BDriver

: Pin-Shared Node

10-bit ADC

VDD

AN0~AN7

Pin-sharedwith Port A & B

VREF

Pin-sharedwith PA5

Analog to DigitalConverter

PC0~PC2Port CDriver

Pin-sharedwith Port A

PTP/STP

LVR

OPA VBG

VSS

VDD

Analog Peripherals

Page 8: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 8 December 27, 2019 Rev. 1.30 9 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Pin Assignment

161514131211109

12345678PA3

VSS

PC1PC2

PC0

PA0/STPI/STP/ICPDA/OCDSDA

PA2/ICPCK/OCDSCKPA7/PTPI/PTP/AN6

PA4/PTCK/AN3

VDDPB0/INT0/AN0PB1/INT1/AN1PB2/STCK/AN2

PA5/VREF/AN4PA6/AN5

HT66F0181/HT66V018116 NSOP-A

PA1

VSS VDD

PC1PC2

PA0/STPI/STP/ICPDA/OCDSDAPA1

PA2/ICPCK/OCDSCKPA3PB6PB5

PB0/INT0/AN0PB1/INT1/AN1PB2/STCK/AN2PA4/PTCK/AN3PA5/VREF/AN4PA6/AN5PA7/PTPI/PTP/AN6PB3/AN7PB4

PC0

HT66F0181/HT66V018120 SOP-A/NSOP-A/SSOP-A

20191817161514131211

12345678910

Note: 1. If the pin-shared pin functions have multiple outputs, the desired pin-shared function is determined by the corresponding software control bits.

2. The OCDSDA and OCDSCK pins are supplied for the OCDS dedicated pins and are only available for the HT66V0181 device which is the OCDS EV chip for the HT66F0181 device.

3. For the less pin count package type there will be unbounded pins which should be properly configured to avoid unwanted power consumption resulting from floating input conditions. Refer to the “Standby Current Considerations” and “Input/Output Ports” sections.

Pin DescriptionThe 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. As each Pin Description table shows the situation for the package with the most pins, not all pins in the tables will be available on smaller package sizes.

Pin Name Function OPT I/T O/T Description

PA0/STPI/STP/ICPDA/OCDSDA

PA0PAWUPAPUPAS0

ST CMOS General purpose I/O. Register enabled pull-up and wake-up

STPI PAS0 ST — STM capture inputSTP PAS0 — CMOS STM output

OCDSDA — ST CMOS OCDS data/address pin, for EV chip onlyICPDA — ST CMOS ICP data/address pin

PA1 PA1 PAWUPAPU ST CMOS General purpose I/O. Register enabled pull-up and wake-up

PA2/OCDSCK/ICPCK

PA2 PAWUPAPU ST CMOS General purpose I/O. Register enabled pull-up and wake-up

OCDSCK — ST — OCDS clock pin, for EV chip onlyICPCK — ST — ICP clock pin

Page 9: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 8 December 27, 2019 Rev. 1.30 9 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Pin Name Function OPT I/T O/T Description

PA3 PA3 PAWUPAPU ST CMOS General purpose I/O. Register enabled pull-up and wake-up

PA4/PTCK/AN3PA4

PAWUPAPUPAS1

ST CMOS General purpose I/O. Register enabled pull-up and wake-up

PTCK PAS1 ST — PTM clock inputAN3 PAS1 AN — A/D converter external input channel 3

PA5/VREF/AN4PA5

PAWUPAPUPAS1

ST CMOS General purpose I/O. Register enabled pull-up and wake-up

VREF PAS1 AN — A/D converter reference voltage input pinAN4 PAS1 AN — A/D converter external input channel 4

PA6/AN5PA6

PAWUPAPUPAS1

ST CMOS General purpose I/O. Register enabled pull-up and wake-up

AN5 PAS1 AN — A/D converter external input channel 5

PA7/PTPI/PTP/AN6

PA7PAWUPAPUPAS1

ST CMOS General purpose I/O. Register enabled pull-up and wake-up

PTPI PAS1 ST — PTM capture inputPTP PAS1 — CMOS PTM outputAN6 PAS1 AN — A/D converter external input channel 6

PB0/INT0/AN0

PB0 PBPUPBS0 ST CMOS General purpose I/O. Register enabled pull-up

INT0INTEGINTC0PBS0

ST — External interrupt input 0

AN0 PBS0 AN — A/D converter external input channel 0

PB1/INT1/AN1

PB1 PBPUPBS0 ST CMOS General purpose I/O. Register enabled pull-up

INT1INTEGINTC1PBS0

ST — External interrupt input 1

AN1 PBS0 AN — A/D converter external input channel 1

PB2/STCK/AN2PB2 PBPU

PBS0 ST CMOS General purpose I/O. Register enabled pull-up

STCK PBS0 ST — STM clock inputAN2 PBS0 AN — A/D converter external input channel 2

PB3/AN7PB3 PBPU

PBS0 ST CMOS General purpose I/O. Register enabled pull-up

AN7 PBS0 AN — A/D converter external input channel 7PB4~PB6 PB4~PB6 PBPU ST CMOS General purpose I/O. Register enabled pull-upPC0~PC2 PC0~PC2 PCPU ST CMOS General purpose I/O. Register enabled pull-upVDD VDD — PWR — Positive power supplyVSS VSS — PWR — Negative power supply

Legend: I/T: Input type; O/T: Output type; OPT: Optional by register option; PWR: Power; ST: Schmitt Trigger input; CMOS: CMOS output; AN: Analog signal.

Page 10: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 10 December 27, 2019 Rev. 1.30 11 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Absolute Maximum RatingsSupply Voltage ...........................................................................................................VSS-0.3V to 6.0V

Input Voltage ..................................................................................................... VSS-0.3V to VDD+0.3V

Storage Temperature ..................................................................................................... -50°C to 125°C

Operating Temperature ................................................................................................... -40°C to 85°C

IOH Total ...................................................................................................................................... -80mA

IOL Total ....................................................................................................................................... 80mA

Total Power Dissipation ........................................................................................................... 500mW

Note: These are stress ratings only. Stresses exceeding the range specified under “Absolute Maximum Ratings” may cause substantial damage to the device. Functional operation of the device at other conditions beyond those listed in the specification is not implied and prolonged exposure to extreme conditions may affect device reliability.

D.C. CharacteristicsFor data in the following tables, note that factors such as oscillator type, operating voltage, operating frequency, pin load conditions, temperature and program instruction type, etc., can all exert an influence on the measured values.

Operating Voltage CharacteristicsTa=-40°C~85°C

Symbol Parameter Test Conditions Min. Typ. Max. Unit

VDDOperating Voltage – HIRC fSYS=8MHz 1.8 — 5.5 VOperating Voltage – LIRC fSYS=32kHz 1.8 — 5.5 V

Operating Current CharacteristicsTa=-40°C~85°C

Symbol Operating ModeTest Conditions

Min. Typ. Max. UnitVDD Conditions

IDD

SLOW Mode – LIRC1.8V

fSYS=32kHz— 1.5 3.0

μA3V — 3 55V — 10 15

FAST Mode – HIRC1.8V

fSYS=8MHz— 0.5 1.0

mA3V — 1 25V — 2 3

Note: When using the characteristic table data, the following notes should be taken into consideration:1. Any digital inputs are set in a non-floating condition.2. All measurements are taken under conditions of no load and with all peripherals in an off state.3. There are no DC current paths.4. All Operating Current values are measured using a continuous NOP instruction program loop.

Page 11: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 10 December 27, 2019 Rev. 1.30 11 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Standby Current CharacteristicsTa=-40°C~85°C

Symbol Standby ModeTest Conditions

Min. Typ. Max. UnitVDD Conditions

ISTB

SLEEP Mode

1.8VWDT off

— 0.1 0.6μA3V — 0.2 0.8

5V — 0.5 1.01.8V

WDT on— 1 3

μA3V — 3 55V — 5 10

IDLE0 Mode – LIRC1.8V

fSUB on— 1.0 1.5

μA3V — 2.5 4.05V — 8 10

IDLE1 Mode – HIRC1.8V

fSUB on, fSYS=8MHz— 240 350

μA3V — 360 5005V — 600 800

Note: When using the characteristic table data, the following notes should be taken into consideration:1. Any digital inputs are set in a non-floating condition.2. All measurements are taken under conditions of no load and with all peripherals in an off state.3. There are no DC current paths.4. All Standby Current values are taken after a HALT instruction execution thus stopping all instruction

execution.

A.C. CharacteristicsFor data in the following tables, note that factors such as oscillator type, operating voltage, operating frequency and temperature, etc., can all exert an influence on the measured values.

High Speed Internal Oscillator – HIRC – Frequency AccuracyDuring the program writing operation the writer will trim the HIRC oscillator at a user selected HIRC frequency and user selected voltage of either 3V or 5V.

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Temp.

fHIRC 8MHz Writer Trimmed HIRC Frequency

3V/5V25°C -1% 8 +1%

MHz

-40°C ~ 85°C -4% 8 +4%

2.2V~5.5V25°C -2.5% 8 +2.5%-40°C ~ 85°C -5% 8 +5%

1.8V~5.5V25°C -5% 8 +3%-40°C ~ 85°C -10% 8 +5%

Note: 1. The 3V/5V values for VDD are provided as these are the two selectable fixed voltages at which the HIRC frequency is trimmed by the writer.

2. The row below the 3V/5V trim voltage row is provided to show the values for the full VDD range operating voltage. It is recommended that the trim voltage is fixed at 3V for application voltage ranges from 1.8V to 3.6V and fixed at 5V for application voltage ranges from 3.3V to 5.5V.

Page 12: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 12 December 27, 2019 Rev. 1.30 13 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Low Speed Internal Oscillator – LIRC – Frequency Accuracy

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Temp.

fLIRC

LIRC Frequency (Writer Trim) 3V/5V 25°C -1% 32 +1%

kHzLIRC Frequency

1.8V~3.6V(trim @ 3V)

-10°C~50°C -4% 32 +4%-40°C~85°C -6% 32 +6%

3.3V~5.5V(trim @ 5V)

-10°C~50°C -4% 32 +4%-40°C~85°C -6% 32 +6%

2.2V~5.5V(trim @ 3V) -40°C~85°C -6% 32 +6%

1.8V~5.5V(trim @ 3V) -40°C~85°C -7% 32 +7%

tSTART LIRC Start-up Time — -40°C~85°C — — 100 μs

Operating Frequency Characteristic CurvesSystem Operating Frequency

Operating Voltage

8MHz

1.8V

~ ~

5.5V

~~

~ ~

System Start Up Time CharacteristicsTa=-40°C~85°C

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

tSST

System Start-up TimeWake-up from Condition where fSYS is Off

— fSYS=fH~fH/64, fH=fHIRC — 16 — tHIRC

— fSYS=fSUB=fLIRC — 2 — tLIRC

System Start-up TimeWake-up from Condition where fSYS is On

— fSYS=fH~fH/64, fH=fHIRC — 2 — tH— fSYS=fSUB=fLIRC — 2 — tSUB

System Speed Switch TimeFAST to SLOW Mode orSLOW to FAST Mode

— fHIRC switches from off → on — 16 — tHIRC

tRSTD

System Reset Delay TimeReset Source from Power-on Reset or LVR Hardware Reset

— RRPOR=5V/ms42 48 54 ms

System Reset Delay TimeLVRC/WDTC Software Reset — —

System Reset Delay TimeReset Source from WDT Overflow — — 14 16 18 ms

tSRESET Minimum Software Reset Width to Reset — — 45 90 120 μs

Note: 1. For the System Start-up time values, whether fSYS is on or off depends upon the mode type and the chosen fSYS system oscillator. Details are provided in the System Operating Modes section.

2. The time units, shown by the symbols, tHIRC, etc., are the inverse of the corresponding frequency values as provided in the frequency tables. For example tHIRC=1/fHIRC, tLIRC=1/fLIRC, etc.

3. If the LIRC is used as the system clock and if it is off when in the SLEEP Mode, then an additional LIRC start up time, tSTART, as provided in the LIRC frequency table, must be added to the tSST time in the table above.

4. The System Speed Switch Time is effectively the time taken for the newly activated oscillator to start up.

Page 13: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 12 December 27, 2019 Rev. 1.30 13 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Input/Output CharacteristicsTa=-40°C~85°C

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

VIL Input Low Voltage for I/O Ports 5V — 0 — 1.5

V— — 0 — 0.2VDD

VIH Input High Voltage for I/O Ports 5V — 3.5 — 5.0

V— — 0.8VDD — VDD

IOL Sink Current for I/O Pins3V

VOL=0.1VDD16 32 —

mA5V 32 65 —

IOH Source Current for I/O Pins

3V VOH=0.9VDD, SLEDCn[m+1, m]=00B (n=0, 1; m=0, 2, 4, 6)

-0.7 -1.5 —mA

5V -1.5 -2.9 —3V VOH=0.9VDD, SLEDCn[m+1, m]=01B

(n=0, 1; m=0, 2, 4, 6)-1.3 -2.5 —

mA5V -2.5 -5.1 —3V VOH=0.9VDD, SLEDCn[m+1, m]=10B

(n=0, 1; m=0, 2, 4, 6)-1.8 -3.6 —

mA5V -3.6 -7.3 —3V VOH=0.9VDD, SLEDCn[m+1, m]=11B

(n=0, 1; m=0, 2, 4, 6)-4 -8 —

mA5V -8 -16 —

RPHPull-high Resistance for I/O Ports (1)

3V LVPU=0PxPU=FFH (Px: PA, PB, PC)

20 60 100

kΩ5V 10 30 503V LVPU=1

PxPU=FFH (Px: PA, PB, PC)6.67 15.00 23.00

5V 3.5 7.5 12.0

ILEAKInput Leakage Current for I/O Ports 5V VIN=VDD or VIN=VSS — — ±1 μA

tTPIxTPI Input Pin Minimum Pulse Width — — 0.3 — — μs

tTCKxTCK Input Pin Minimum Pulse Width — — 0.3 — — μs

tINTExternal Interrupt Minimum Pulse Width — — 0.3 — — μs

Note: The RPH internal pull-high resistance value is calculated by connecting to ground and enabling the input pin with a pull-high resistor and then measuring the pin current at the specified supply voltage level. Dividing the voltage by this measured current provides the RPH value.

Page 14: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 14 December 27, 2019 Rev. 1.30 15 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Memory CharacteristicsTa=-40°C~85°C, unless otherwise specified

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

Flash Program / Emulated EEPROM Memory

VDDOperating Voltage for Read — — 1.8 — 5.5

VOperating Voltage for Erase/Write — Ta=25°C 1.8 — 5.5

tDEW

Erase/Write Time – Flash Program Memory 5V Ta=25°C — 2 3 ms

Erase/Write Cycle Time – Emulated EEPROM Memory

— EWRTS[1:0]=00B, Ta=25°C — 2 3

ms— EWRTS[1:0]=01B,

Ta=25°C — 4 6

— EWRTS[1:0]=10B, Ta=25°C — 8 12

— EWRTS[1:0]=11B, Ta=25°C — 16 24EP Cell Endurance — — 10K — — E/WtRETD ROM Data Retention Time — Ta=25°C — 40 — YearRAM Data MemoryVDD Operating Voltage for Read/Write — — VDDmin — VDDmax VVDR RAM Data Retention Voltage — Device in SLEEP Mode 1.0 — — V

Note: The Emulated EEPROM erase/write operation can only be executed when the fSYS clock frequency is equal to or greater than 2MHz.

LVR Electrical CharacteristicsTa=-40°C~85°C

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

VLVR Low Voltage Reset Voltage — LVR enable, voltage select 1.7V -5% 1.7 +5% V

ILVRBG Operating Current3V

LVR enable, VLVR=1.7V— — 15

μA5V — 15 25

tLVR Minimum Low Voltage Width to Reset — — 120 240 480 μsILVR Additional Current for LVR Enable 5V VBGEN=0 — — 25 μA

Internal Reference Voltage CharacteristicsTa=-40°C~85°C

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

tBGS VBG Turn-on Stable Time — No load — — 50 μs

IBGAdditional Current for Bandgap Reference Enable — VBGEN=1, LVR disable — — 2 μA

Note: The VBG voltage is used as the A/D converter internal OPA input signal.

Page 15: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 14 December 27, 2019 Rev. 1.30 15 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

A/D Converter Electrical CharacteristicsTa=-40°C~85°C

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

VADI Input Voltage — — 0 — VREF VVREF Reference Voltage — — 1.6 — VDD VNR Resolution — — — — 10 BitDNL Differential Non-linearity — VREF=VDD, tADCK=0.5μs -1.5 — +1.5 LSBINL Integral Non-linearity — VREF=VDD, tADCK=0.5μs -2 — +2 LSB

IADCAdditional Current for A/D Converter Enable

1.8VNo load, tADCK=0.5μs

— 300 420μA3V — 340 500

5V — 500 700tADCK Clock Period — — 0.5 — 10.0 μstON2ST A/D Converter On-to-Start Time — — 4 — — μstADS Sampling Time — — — 4 — tADCK

tADCConversion Time (Including A/D Sampling and Hold Time) — — — 14 — tADCK

OSRR A/D Conversion Offset Error — VREF=VDD -2 - +2 LSB

IOPA Additional Current for OPA Enable3V

No load— 390 550

μA5V — 500 650

VOR OPA Maximum Output Voltage Range3V

—VSS+0.1 — VDD-0.1

V5V VSS+0.1 — VDD-0.1

VVR Fix Voltage Output of OPA 1.8V~5.5V — -5% 1.6 +5% V

Power-on Reset CharacteristicsTa=-40°C~85°C

Symbol ParameterTest Conditions

Min. Typ. Max. UnitVDD Conditions

VPOR VDD Start Voltage to Ensure Power-on Reset — — — — 100 mVRRPOR VDD Rising Rate to Ensure Power-on Reset — — 0.035 — — V/ms

tPORMinimum Time for VDD Stays at VPOR to Ensure Power-on Reset — — 1 — — ms

VDD

tPOR RRPOR

VPOR

Time

Page 16: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 16 December 27, 2019 Rev. 1.30 17 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

System ArchitectureA key factor in the high-performance features of the Holtek range of microcontrollers is attributed to their internal system architecture. The device takes 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 which need one more cycle. An 8-bit wide ALU is used in practically all instruction set operations, which carries out arithmetic operations, logic operations, rotation, increment, decrement, branch decisions, etc. The internal data path is simplified by moving data through the Accumulator and the ALU. Certain internal registers are implemented in the Data Memory and can be directly or indirectly addressed. The simple addressing methods of these registers along with additional architectural features ensure that a minimum of external components is required to provide a functional I/O and A/D control system with maximum reliability and flexibility. This makes the device suitable for low-cost, high-volume production for controller applications.

Clocking and PipeliningThe main system clock, derived from either an HIRC or LIRC oscillator is subdivided into four internally generated non-overlapping clocks, T1~T4. The Program Counter is incremented at the beginning of the T1 clock during which time a new instruction is fetched. The remaining T2~T4 clocks carry out the decoding and execution functions. In this way, one T1~T4 clock cycle forms one instruction cycle. Although the fetching and execution of instructions takes place in consecutive instruction cycles, the pipelining structure of the microcontroller ensures that instructions are effectively executed in one instruction cycle. The exception to this are instructions where the contents of the Program Counter are changed, such as subroutine calls or jumps, in which case the instruction will take one more instruction cycle to execute.

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.

Fetch Inst. (PC)

(System Clock)fSYS

Phase Clock T1

Phase Clock T2

Phase Clock T3

Phase Clock T4

Program Counter PC PC+1 PC+2

PipeliningExecute Inst. (PC-1) Fetch Inst. (PC+1)

Execute Inst. (PC) Fetch Inst. (PC+2)

Execute Inst. (PC+1)

System Clocking and Pipelining

Page 17: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 16 December 27, 2019 Rev. 1.30 17 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Fetch Inst. 11 MOV A,[12H]2 CALL DELAY3 CPL [12H]4 :5 :6 DELAY: NOP

Execute Inst. 1 Fetch Inst. 2 Execute Inst. 2

Fetch Inst. 3 Flush PipelineFetch Inst. 6 Execute Inst. 6

Fetch Inst. 7

Instruction Fetching

Program CounterDuring 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 CounterProgram Counter High Byte PCL Register

PC11~PC8 PCL7~PCL0

Program Counter

The lower byte of the Program Counter, known as the Program Counter Low register or PCL, is available for program control and is a readable and writeable register. By transferring data directly into this register, a short program jump can be executed directly; however, as only this low byte is available for manipulation, the jumps are limited to the present page of memory that is 256 locations. When such program jumps are executed it should also be noted that a dummy cycle will be inserted. Manipulating the PCL register may cause program branching, so an extra cycle is needed to pre-fetch.

StackThis is a special part of the memory which is used to save the contents of the Program Counter only. The stack, organized into 6 levels, 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.

Page 18: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 18 December 27, 2019 Rev. 1.30 19 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

If the stack is overflow, the first Program Counter save in the stack will be lost.

StackPointer

Stack Level 2

Stack Level 1

Stack Level 3:::

Stack Level 6

Program Memory

Program Counter

Bottom of Stack

Top of Stack

Arithmetic and Logic Unit – ALUThe arithmetic-logic unit or ALU is a critical area of the microcontroller that carries out arithmetic and logic operations of the instruction set. Connected to the main microcontroller data bus, the ALU receives related instruction codes and performs the required arithmetic or logical operations after which the result will be placed in the specified register. As these ALU calculation or operations may result in carry, borrow or other status changes, the status register will be correspondingly updated to reflect these changes. The ALU supports the following functions:

• Arithmetic operations: ADD, ADDM, ADC, ADCM, SUB, SUBM, SBC, SBCM, DAA

• Logic operations: AND, OR, XOR, ANDM, ORM, XORM, CPL, CPLA

• Rotation: RRA, RR, RRCA, RRC, RLA, RL, RLCA, RLC

• Increment and Decrement: INCA, INC, DECA, DEC

• Branch decision: JMP, SZ, SZA, SNZ, SIZ, SDZ, SIZA, SDZA, CALL, RET, RETI

Flash Program MemoryThe Program Memory is the location where the user code or program is stored. For the device the Program Memory is Flash type, which means it can be programmed and re-programmed a large number of times, allowing the user the convenience of code modification on the same device. By using the appropriate programming tools, the Flash device offer users the flexibility to conveniently debug and develop their applications while also offering a means of field programming and updating.

StructureThe Program Memory has a capacity of 4K×15 bits. The Program Memory is addressed by the Program Counter and also contains data, table information and interrupt entries. Table data, which can be set in any location within the Program Memory, is addressed by a separate table pointer register.

Page 19: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 18 December 27, 2019 Rev. 1.30 19 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Initialisation Vector

Interrupt Vectors

Look-up Table

000H

004H

n00H

nFFH

FFFH

01CH

15 bits

Program Memory Structure

Special VectorsWithin the Program Memory, certain locations are reserved for the reset and interrupts. The location 000H is reserved for use by the device reset for program initialisation. After a device reset is initiated, the program will jump to this location and begin execution.

Look-up TableAny 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 configured by placing the address of the look up data to be retrieved in the table pointer registers, 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.

Last Page or TBHP Register

TBLP Register

Program Memory

Register TBLH User Selected Register

Address

Data15 bits

High Byte Low Byte

Table Program ExampleThe following example shows how the table pointer and table data is defined and retrieved from the microcontrollers. This example uses raw table data located in the Program Memory which is stored there using the ORG statement. The value at this ORG statement is “F00H” which refers to the start address of the last page within the 4K Program Memory of the device. The table pointer low byte register is set here to have an initial value of “06H”. This will ensure that the first data read from the data table will be at the Program Memory address “F06H” or 6 locations after the start of the last page. Note that the value for the table pointer is referenced to the specific address pointed by the TBLP and TBHP registers if the “TABRD [m]” instruction is being used. The high byte of the table

Page 20: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 20 December 27, 2019 Rev. 1.30 21 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

data which in this case is equal to zero will be transferred to the TBLH register automatically when the “TABRD [m]” instruction is executed.

Because the TBLH register is a read-only register and cannot be restored, care should be taken to ensure its protection if both the main routine and Interrupt Service Routine use table read instructions. If using the table read instructions, the Interrupt Service Routines may change the value of the TBLH and subsequently cause errors if used again by the main routine. As a rule it is recommended that simultaneous use of the table read instructions should be avoided. However, in situations where simultaneous use cannot be avoided, the interrupts should be disabled prior to the execution of any main routine table-read instructions. Note that all table related instructions require two instruction cycles to complete their operation.

Table Read Program Exampletempreg1 db ? ; temporary register #1tempreg2 db ? ; temporary register #2 : :mov a,06h ; initialise low table pointer - note that this address is referencedmov tblp,a ; to the last page or the page that tbhp pointed mov a,0Fh ; initialise high table pointermov tbhp,a : :tabrd tempreg1 ; transfers value in table referenced by table pointer, ; data at program memory address F06H transferred to tempreg1 and TBLHdec tblp ; reduce value of table pointer by onetabrd tempreg2 ; transfers value in table referenced by table pointer, ; data at program memory address F05H transferred to tempreg2 and TBLH ; in this example the data 1AH is transferred to tempreg1 and data 0FH to ; register tempreg2 ; the value 00H will be transferred to the high byte register TBLH : :org 0F00h ; sets initial address of program memorydc 00Ah, 00Bh, 00Ch, 00Dh, 00Eh, 00Fh, 01Ah, 01Bh

In Circuit Programming – ICPThe provision of Flash type Program Memory provides the user with a means of convenient and easy upgrades and modifications to their programs on the same device.

As an additional convenience, Holtek has provided a means of programming the microcontrollers in-circuit using a 4-pin interface. This provides manufacturers with the possibility of manufacturing their circuit boards complete with a programmed or un-programmed microcontroller, and then programming or upgrading the program at a later stage. This enables product manufacturers to easily keep their manufactured products supplied with the latest program releases without removal and re-insertion of the device.

Holtek Writer Pins MCU Programming Pins Pin DescriptionICPDA PA0 Programming serial data/addressICPCK PA2 Programming clockVDD VDD Power supplyVSS VSS Ground

Page 21: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 20 December 27, 2019 Rev. 1.30 21 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

The program memory can be programmed serially in-circuit using this 4-wire interface. Data is downloaded and uploaded serially on a single pin with an additional line for the clock. Two additional lines are required for the power supply. The technical details regarding the in-circuit programming of the device is beyond the scope of this document and will be supplied in supplementary literature.

During the programming process, the user must take care of the ICPDA and ICPCK pins for data and clock programming purposes to ensure that no other outputs are connected to these two pins.

* *

Writer_VDD

ICPDA

ICPCK

Writer_VSS

To other Circuit

VDD

PA0

PA2

VSS

Writer Connector Signals

MCU ProgrammingPins

Note: * may be resistor or capacitor. The resistance of * must be greater than 1kΩ or the capacitance of * must be less than 1nF.

On-Chip Debug Support – OCDSThere is an EV chip named HT66V0181 which is used to emulate the HT66F0181 device. The EV chip device also provides an “On-Chip Debug” function to debug the real MCU device during the development process. The EV chip and the real MCU device are almost functionally compatible except for “On-Chip Debug” function. Users can use the EV chip device to emulate the real chip device behavior by connecting the OCDSDA and OCDSCK pins to the Holtek HT-IDE development tools. The OCDSDA pin is the OCDS Data/Address input/output pin while the OCDSCK pin is the OCDS clock input pin. When users use the EV chip for debugging, other functions which are shared with the OCDSDA and OCDSCK pins in the device will have no effect in the EV chip. However, the two OCDS pins which are pin-shared with the ICP programming pins are still used as the Flash Memory programming pins for ICP. For more detailed OCDS information, refer to the corresponding document named “Holtek e-Link for 8-bit MCU OCDS User’s Guide”.

Holtek e-Link Pins EV Chip Pins Pin DescriptionOCDSDA OCDSDA On-chip debug support data/address input/outputOCDSCK OCDSCK On-chip debug support clock input

VDD VDD Power supplyVSS VSS Ground

Page 22: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 22 December 27, 2019 Rev. 1.30 23 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Data MemoryThe Data Memory is a volatile area of 8-bit wide RAM internal memory and is the location where temporary information is stored.

StructureCategorised into two types, the first of these is an area of RAM, known as the Special Function Data Memory. These registers have fixed locations and are necessary for correct operation of the device. Many of these registers can be read from and written to directly under program control, however, some remain protected from user manipulation. The second area of Data Memory is known as the General Purpose Data Memory, which is reserved for general purpose use. All locations within this area are read and write accessible under program control.

The start address of the Data Memory for the device is 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.

00H

7FH80H

FFH

Special Purpose Data Memory

General Purpose Data Memory

Bank 0

Data Memory Structure

General Purpose Data MemoryAll microcontroller programs require an area of read/write memory where temporary data can be stored and retrieved for use later. It is this area of RAM memory that is known as General Purpose Data Memory. This area of Data Memory is fully accessible by the user programing for both reading and writing operations. By using the bit operation instructions individual bits can be set or reset under program control giving the user a large range of flexibility for bit manipulation in the Data Memory.

Special Purpose Data MemoryThis area of Data Memory is where registers, necessary for the correct operation of the microcontroller, are stored. Most of the registers are both readable and writeable but some are protected and are readable only, the details of which are located under the relevant Special Function Register section. Note that for locations that are unused, any read instruction to these addresses will return the value “00H”.

Page 23: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 22 December 27, 2019 Rev. 1.30 23 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

: Unused, read as 00H

TB0CPSCRWDTC

SCCVBGCLVRCED3HED3LED2HED2LED1HED1LED0HED0LEARECR

SADC1SADC0SADOHSADOL

PCPUPCCPC

PBPUPBCPB

PAWUPAPUPACPA

MFI1MFI0

RSTFCINTC1INTC0INTEGLVPUC

STATUSTBHPTBLHTBLPPCLACC

MP1IAR1MP0IAR0

TB1C

STMC1STMC0

40H41H42H43H44H45H46H47H48H49H4AH4BH4CH4DH4EH4FH50H51H52H

59H58H

5BH5AH

5DH5CH

5FH

53H54H55H56H57H

5EH

60H61H62H

69H68H

6BH6AH

6DH6CH

6FH6EH

63H64H65H66H67H

70H71H72H

78H

7CH

73H74H75H76H77H

7BH

79H7AH

7DH

7FH7EH

Bank 0 Bank 000H01H02H03H04H05H06H07H08H09H0AH0BH0CH0DH0EH0FH10H11H12H

19H18H

1BH1AH

1DH1CH

1FH

13H14H15H16H17H

1EH

20H21H22H

29H28H

2BH2AH

2DH2CH

2FH2EH

23H24H25H26H27H

30H31H32H

38H

3CH

33H34H35H36H37H

3BH

39H3AH

3DH

3FH3EH

HIRCC

SLEDC1SLEDC0

PBS0PAS1PAS0

PTMRPHPTMRPLPTMAHPTMALPTMDHPTMDLPTMC1PTMC0STMAHSTMALSTMDHSTMDL

Special Purpose Data Memory

Page 24: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 24 December 27, 2019 Rev. 1.30 25 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Special Function Register DescriptionMost of the Special Function Register details will be described in the relevant functional section; however several registers require a separate description in this section.

Indirect Addressing Registers – IAR0, IAR1The Indirect Addressing Registers, IAR0 and IAR1, although having their locations in normal RAM register space, do not actually physically exist as normal registers. The method of indirect addressing for RAM data manipulation uses these Indirect Addressing Registers and Memory Pointers, in contrast to direct memory addressing, where the actual memory address is specified. Actions on the IAR0 and IAR1 registers will result in no actual read or write operation to these registers but rather to the memory location specified by their corresponding Memory Pointers, MP0 or MP1. Acting as a pair, IAR0 and MP0 can together access data only from Bank 0 while the IAR1 register together with the MP1 register pair can access data from any Data Memory Bank. As the Indirect Addressing Registers are not physically implemented, reading the Indirect Addressing Registers will return a result of “00H” and writing to the registers will result in no operation.

Memory Pointers – MP0, MP1Two Memory Pointers, known as MP0 and MP1 are provided. These Memory Pointers are physically implemented in the Data Memory and can be manipulated in the same way as normal registers providing a convenient way with which to address and track data. When any operation to the relevant Indirect Addressing Registers is carried out, the actual address that the microcontroller is directed to is the address specified by the related Memory Pointer. MP0, together with Indirect Addressing Register, IAR0, are used to access data from Bank 0, while MP1 and IAR1 are used to access data from all banks. Direct Addressing can be used in Bank 0, all other banks must be addressed indirectly using MP1 and IAR1.

The following example shows how to clear a section of four Data Memory locations already defined as locations adres1 to adres4.

Indirect Addressing Program Example data .section ´data´adres1 db ?adres2 db ?adres3 db ?adres4 db ?block db ?code .section at 0 code´org 00hstart: mov a, 04h ; set size of block mov block, a mova,offsetadres1 ;AccumulatorloadedwithfirstRAMaddress movMP0,a ;setmemorypointerwithfirstRAMaddressloop: clrIAR0 ;clearthedataataddressdefinedbyMP0 incMP0 ;increasememorypointer sdz block ; check if last memory location has been cleared jmp loopcontinue:

The important point to note here is that in the examples shown above, no reference is made to specific Data Memory addresses.

Page 25: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 24 December 27, 2019 Rev. 1.30 25 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Accumulator – ACCThe 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.

Program Counter Low Register – PCLTo provide additional program control functions, the low byte of the Program Counter is made accessible to programmers by locating it within the Special Purpose area of the Data Memory. By manipulating this register, direct jumps to other program locations are easily implemented. Loading a value directly into this PCL register will cause a jump to the specified Program Memory location, however, as the register is only 8-bit wide, only jumps within the current Program Memory page are permitted. When such operations are used, note that a dummy cycle will be inserted.

Look-up Table Registers – TBLP, TBHP, TBLHThese three special function registers are used to control operation of the look-up table which is stored in the Program Memory. TBLP and TBHP are the table pointers and indicate the location where the table data is located. Their value must be set before any table read commands are executed. Their value can be changed, for example using the “INC” or “DEC” instructions, allowing for easy table data pointing and reading. TBLH is the location where the high order byte of the table data is stored after a table read data instruction has been executed. Note that the lower order table data byte is transferred to a user defined location.

Status Register – STATUSThis 8-bit register contains the zero flag (Z), carry flag (C), auxiliary carry flag (AC), overflow flag (OV), power down flag (PDF), and watchdog time-out flag (TO). These arithmetic/logical operation and system management flags are used to record the status and operation of the microcontroller.

With the exception of the TO and PDF flags, bits in the status register can be altered by instructions like most other registers. Any data written into the status register will not change the TO or PDF flag. In addition, operations related to the status register may give different results due to the different instruction operations. The TO flag can be affected only by a system power-up, a WDT time-out or by executing the “CLR WDT” or “HALT” instruction. The PDF flag is affected only by executing the “HALT” or “CLR WDT” instruction or during a system power-up.

The Z, OV, AC and C flags generally reflect the status of the latest operations.

• C is set if an operation results in a carry during an addition operation or if a borrow does not take place during a subtraction operation; otherwise C is cleared. C is also affected by a rotate through carry instruction.

• AC is set if an operation results in a carry out of the low nibbles in addition, or no borrow from the high nibble into the low nibble in subtraction; otherwise AC is cleared.

• Z is set if the result of an arithmetic or logical operation is zero; otherwise Z is cleared.

• OV is set if an operation results in a carry into the highest-order bit but not a carry out of the highest-order bit, or vice versa; otherwise OV is cleared.

Page 26: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 26 December 27, 2019 Rev. 1.30 27 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• PDF is cleared by a system power-up or executing the “CLR WDT” instruction. PDF is set by executing the “HALT” instruction.

• TO is cleared by a system power-up or executing the “CLR WDT” or “HALT” instruction. TO is set by a WDT time-out.

In addition, on entering an interrupt sequence or executing a subroutine call, the status register will not be pushed onto the stack automatically. If the contents of the status registers are important and if the subroutine can corrupt the status register, precautions must be taken to correctly save it.

• STATUS RegisterBit 7 6 5 4 3 2 1 0

Name — — TO PDF OV Z AC CR/W — — R R R/W R/W R/W R/WPOR — — 0 0 x x x x

“x”: UnknownBit 7~6 Unimplemented, read as “0”Bit 5 TO: Watchdog time-out flag

0: After power up or executing the “CLR WDT” or “HALT” instruction1: A watchdog time-out occurred

Bit 4 PDF: Power down flag0: After power up or executing the “CLR WDT” instruction1: By executing the “HALT” instruction

Bit 3 OV: Overflow flag0: No overflow1: 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 zero1: The result of an arithmetic or logical operation is zero

Bit 1 AC: Auxiliary flag0: No auxiliary carry1: 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 subtractionBit 0 C: Carry flag

0: No carry-out1: An operation results in a carry during an addition operation or if a borrow does

not take place during a subtraction operationThe “C” flag is also affected by a rotate through carry instruction.

Page 27: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 26 December 27, 2019 Rev. 1.30 27 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Emulated EEPROM Data MemoryThe device contains an Emulated EEPROM Data Memory, which is by its nature a non-volatile form of re-programmable memory, with data retention even when its power supply is removed. By incorporating this kind of data memory, a whole new host of application possibilities are made available to the designer. The availability of the Emulated EEPROM storage allows information such as product identification numbers, calibration values, specific user data, system setup data or other product information to be stored directly within the product microcontroller.

Emulated EEPROM Data Memory StructureThe Emulated EEPROM Data Memory capacity is 32×15 bits for the device. The Emulated EEPROM Erase operation is carried out in a page format while the Write operation is carried out in 4 words format and the Read operation is carried out in a word format. The page size is assigned with a capacity of 16 words. Note that the Erase operation should be executed before the Write operation is executed.

Operations FormatErase 16 words/pageWrite 4 words/timeRead 1 word/time

Note: Page size=16 words.

Emulated EEPROM Erase/Write/Read Format

Erase Page EAR4 EAR[3:0]0 0 xxxx1 1 xxxx

“x”: Don’t careErase Page Number and Selection

Write Unit EAR[4:2] EAR[1:0]0 000 xx1 001 xx2 010 xx3 011 xx4 100 xx5 101 xx6 110 xx7 111 xx

“x”: Don’t careWrite Unit Number and Selection

Page 28: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 28 December 27, 2019 Rev. 1.30 29 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Emulated EEPROM RegistersSeveral registers control the overall operation of the Emulated EEPROM Data Memory. These are the address register, EAR, the data registers, ED0L/ED0H ~ ED3L/ED3H, and a single control register, ECR.

Register Name

Bit7 6 5 4 3 2 1 0

EAR — — — EAR4 EAR3 EAR2 EAR1 EAR0ED0L D7 D6 D5 D4 D3 D2 D1 D0ED0H — D14 D13 D12 D11 D10 D9 D8ED1L D7 D6 D5 D4 D3 D2 D1 D0ED1H — D14 D13 D12 D11 D10 D9 D8ED2L D7 D6 D5 D4 D3 D2 D1 D0ED2H — D14 D13 D12 D11 D10 D9 D8ED3L D7 D6 D5 D4 D3 D2 D1 D0ED3H — D14 D13 D12 D11 D10 D9 D8ECR EWRTS1 EWRTS0 EEREN EER EWREN EWR ERDEN ERD

Emulated EEPROM Register List

• EAR RegisterBit 7 6 5 4 3 2 1 0

Name — — — EAR4 EAR3 EAR2 EAR1 EAR0R/W — — — R/W R/W R/W R/W R/WPOR — — — 0 0 0 0 0

Bit 7~5 Unimplemented, read as “0”Bit 4~0 EAR4~EAR0: Emulated EEPROM address bit 4 ~ bit 0

• ED0L RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: The first Emulated EEPROM data bit 7 ~ bit 0

• ED0H RegisterBit 7 6 5 4 3 2 1 0

Name — D14 D13 D12 D11 D10 D9 D8R/W — R/W R/W R/W R/W R/W R/W R/WPOR — 0 0 0 0 0 0 0

Bit 7 Unimplemented, read as “0”Bit 6~0 D14~D8: The first Emulated EEPROM data bit 14 ~ bit 8

• ED1L RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: The second Emulated EEPROM data bit 7 ~ bit 0

Page 29: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 28 December 27, 2019 Rev. 1.30 29 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• ED1H RegisterBit 7 6 5 4 3 2 1 0

Name — D14 D13 D12 D11 D10 D9 D8R/W — R/W R/W R/W R/W R/W R/W R/WPOR — 0 0 0 0 0 0 0

Bit 7 Unimplemented, read as “0”Bit 6~0 D14~D8: The second Emulated EEPROM data bit 14 ~ bit 8

• ED2L RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: The third Emulated EEPROM data bit 7 ~ bit 0

• ED2H RegisterBit 7 6 5 4 3 2 1 0

Name — D14 D13 D12 D11 D10 D9 D8R/W — R/W R/W R/W R/W R/W R/W R/WPOR — 0 0 0 0 0 0 0

Bit 7 Unimplemented, read as “0”Bit 6~0 D14~D8: The third Emulated EEPROM data bit 14 ~ bit 8

• ED3L RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: The fourth Emulated EEPROM data bit 7 ~ bit 0

• ED3H RegisterBit 7 6 5 4 3 2 1 0

Name — D14 D13 D12 D11 D10 D9 D8R/W — R/W R/W R/W R/W R/W R/W R/WPOR — 0 0 0 0 0 0 0

Bit 7 Unimplemented, read as “0”Bit 6~0 D14~D8: The fourth Emulated EEPROM data bit 14 ~ bit 8

• ECR RegisterBit 7 6 5 4 3 2 1 0

Name EWRTS1 EWRTS0 EEREN EER EWREN EWR ERDEN ERDR/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~6 EWRTS1~EWRTS0: Emulated EEPROM erase/write time selection00: 2ms01: 4ms10: 8ms11: 16ms

Page 30: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 30 December 27, 2019 Rev. 1.30 31 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Bit 5 EEREN: Emulated EEPROM erase enable0: Disable1: Enable

This bit is used to enable the Emulated EEPROM erase function and must be set high before erase operations are carried out. This bit will be automatically reset to zero by the hardware after the erase cycle has finished. Clearing this bit to zero will inhibit the Emulated EEPROM erase operation.

Bit 4 EER: Emulated EEPROM erase control0: Erase cycle has finished1: Activate an erase cycle

When this bit is set high by the application program, an erase cycle will be activated. This bit will be automatically reset to zero by the hardware after the erase cycle has finished. Setting this bit high will have no effect if the EEREN has not first been set high.

Bit 3 EWREN: Emulated EEPROM write enable0: Disable1: Enable

This bit is used to enable the Emulated EEPROM write function and must be set high before write operations are carried out. This bit will be automatically reset to zero by the hardware after the write cycle has finished. Clearing this bit to zero will inhibit the Emulated EEPROM write operation.

Bit 2 EWR: Emulated EEPROM write control0: Write cycle has finished1: Activate a write cycle

When this bit is set high by the application program, a write cycle will be activated. This bit will be automatically reset to zero by the hardware after the write cycle has finished. Setting this bit high will have no effect if the EWREN has not first been set high.

Bit 1 ERDEN: Emulated EEPROM read enable0: Disable1: Enable

This bit is used to enable the Emulated EEPROM read function and must be set high before read operations are carried out. Clearing this bit to zero will inhibit the Emulated EEPROM read operation.

Bit 0 ERD: Emulated EEPROM Read control0: Read cycle has finished1: Activate a read cycle

When this bit is set high by the application program, a read cycle will be activated. This bit will be automatically reset to zero by the hardware after the read cycle has finished. Setting this bit high will have no effect if the ERDEN has not first been set high.

Note: 1. The EEREN, EER, EWREN, EWR, ERDEN and ERD cannot be set to “1” at the same time in one instruction.

2. Note that the CPU will be stopped when a read, write or erase operation is successfully activated.

3. Ensure that the fSYS clock frequency is equal to or greater than 2MHz and the fSUB clock is stable before executing the erase or write operation.

4. Ensure that the read, write or erase operation is totally complete before executing other operations.

Page 31: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 30 December 27, 2019 Rev. 1.30 31 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Erasing the Emulated EEPROMFor Emulated EEPROM erase operation the desired erase page address should first be placed in the EAR register. The number of the page erase operation is 16 words per page, therefore, the available page erase address is only specified by the EAR4 bit in the EAR register and the content of EAR3~EAR0 in the EAR register is not used to specify the page address. To erase the Emulated EEPROM page, the EEREN bit in the ECR register must first be set high to enable the erase function. After this the EER bit in the ECR register must be immediately set high to initiate an erase cycle. These two instructions must be executed in two consecutive instruction cycles to activate an erase operation successfully. The global interrupt bit EMI should also first be cleared before implementing any erase operations, and then set high again after the a valid erase activation procedure has completed. Note that the CPU will be stopped when an erase operation is successfully activated. When the erase cycle terminates, the CPU will resume executing the application program. And the EER bit will be automatically cleared to zero by the microcontroller, informing the user that the data has been erased. The Emulated EEPROM erased page content will all be zero after an erase operation.

Writing Data to the Emulated EEPROMFor Emulated EEPROM write operation, the data and the desired write unit address should first be placed in the ED0L/ED0H ~ ED3L/ED3H registers and the EAR register respectively. The number of the write operation is 4 words each time, therefore, the available write unit address is only specified by the EAR4~EAR2 bits in the EAR register and the content of EAR1~EAR0 in the EAR register is not used to specify the unit address. To write data to the Emulated EEPROM, the EWREN bit in the ECR register must first be set high to enable the write function. After this the EWR bit in the ECR register must be immediately set high to initiate a write cycle. These two instructions must be executed in two consecutive instruction cycles to activate a write operation successfully. The global interrupt bit EMI should also first be cleared before implementing any write operations, and then set high again after a valid write activation procedure has completed. Note that the CPU will be stopped when a write operation is successfully activated. When the write cycle terminates, the CPU will resume executing the application program. And the EWR bit will be automatically cleared to zero by the microcontroller, informing the user that the data has been written to the Emulated EEPROM.

Reading Data from the Emulated EEPROMFor Emulated EEPROM read operation the desired read address should first be placed in the EAR register. To read data from the Emulated EEPROM, the ERDEN bit in the ECR register must first be set high to enable the read function. After this a read cycle will be initiated if the ERD bit in the ECR register is now set high. Note that the CPU will be stopped when the read operation is successfully activated. When the read cycle terminates, the CPU will resume executing the application program. And the ERD bit will be automatically cleared to zero by the microcontroller, informing the user that the data has been read from the Emulated EEPROM. Then the data can be read from the ED0H/ED0L data register pair by application program. The data will remain in the data register pair until another read, write or erase operation is executed.

Programming ConsiderationsCare must be taken that data is not inadvertently written to the Emulated EEPROM. Protection can be enhanced by ensuring that the Write Enable bit is normally cleared to zero when not writing. 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 or erasing data the EWR or EER bit must be set high immediately after the EWREN or EEREN bit has been set high, to ensure the write or erase cycle executes correctly. The global interrupt bit EMI should also be cleared before a write or erase cycle is executed and then set again after a valid write or erase activation procedure has completed. Note that the device should not enter the IDLE or SLEEP mode until Emulated EEPROM read, write or erase operation is totally complete. Otherwise, Emulated EEPROM read, write or erase operation will fail.

Page 32: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 32 December 27, 2019 Rev. 1.30 33 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Programming ExamplesErasing a Data Page of the Emulated EEPROM – polling methodMOV A,EEPROM_ADRES ;user-definedpageMOV EAR,AMOV A,00H ;Erasetime=2ms(40Hfor4ms,80Hfor8ms,C0Hfor16ms)MOV ECR,ACLR EMISET EEREN ;setEERENbit,enableeraseoperationSET EER ;startEraseCycle–setEERbit–executedimmediatelyafter ;settingEERENbitSET EMIBACK:SZ EER ;checkforerasecycleendJMP BACK:

Writing Data to the Emulated EEPROM – polling methodMOV A,EEPROM_ADRES ;user-definedaddressMOV EAR,AMOV A,EEPROM_DATA0_L ;userdefineddataMOV ED0L,AMOV A,EEPROM_DATA0_HMOV ED0H,AMOV A,EEPROM_DATA1_LMOV ED1L,AMOV A,EEPROM_DATA1_HMOV ED1H,AMOV A,EEPROM_DATA2_LMOV ED2L,AMOV A,EEPROM_DATA2_HMOV ED2H,AMOV A,EEPROM_DATA3_LMOV ED3L,AMOV A,EEPROM_DATA3_HMOV ED3H,AMOV A,00H ;Writetime=2ms(40Hfor4ms,80Hfor8ms,C0Hfor16ms)MOV ECR,ACLR EMISET EWREN ;setEWRENbit,enablewriteoperationSET EWR ;startWriteCycle–setEWRbit–executedimmediately after ;settingEWRENbitSET EMIBACK:SZ EWR ;checkforwritecycleendJMP BACK :

Reading Data from the Emulated EEPROM – polling methodMOV A,EEPROM_ADRES ;userdefinedaddressMOV EAR,ASET ERDEN ;setERDENbit,enablereadoperationSET ERD ;startReadCycle–setERDbitBACK:SZ ERD ;checkforreadcycleendJMP BACKCLR ECR ;disableEmulatedEEPROMreadifnomorereadoperationsarerequiredMOV A,ED0L ;movereaddatatouser-definedregisterMOV READ_DATA_L,AMOV A,ED0HMOV READ_DATA_H,A

Note: For each read operation, the address register should be re-specified followed by setting the ERD bit high to activate a read cycle even if the target address is consecutive.

Page 33: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 32 December 27, 2019 Rev. 1.30 33 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

OscillatorsVarious oscillator options offer the user a wide range of functions according to their various application requirements. The flexible features of the oscillator functions ensure that the best optimisation can be achieved in terms of speed and power saving. Oscillator operations are selected through the relevant control registers.

Oscillator OverviewIn addition to being the source of the main system clock the oscillators also provide clock sources for the Watchdog Timer and Time Base Interrupt. The fully integrated internal oscillators, requiring no external components, are provided to form a wide range of both fast and slow system oscillators. The higher frequency oscillator provides higher performance but carry with it the disadvantage of higher power requirements, while the opposite is of course true for the lower frequency oscillator. 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 FrequencyInternal High Speed RC HIRC 8MHzInternal Low Speed RC LIRC 32kHz

Oscillator Types

System Clock ConfigurationsThere are two oscillator sources, one high speed oscillator and one low speed oscillator. The high speed system clock is sourced from the internal 8MHz RC oscillator, HIRC. The low speed oscillator is the internal 32kHz RC oscillator, LIRC. Selecting whether the low or high speed oscillator is used as the system oscillator is implemented using the CKS2~CKS0 bits in the SCC register and the system clock can be dynamically selected.

High Speed Oscillator

PrescalerHIRC

fH/2

fH/4fH/8

fH/16

fH/32

fH/64

CKS2~CKS0

fSYS

Low Speed Oscillator

LIRC

IDLE0SLEEP

IDLE2SLEEP

fSUB

fSUB

fLIRC

HIRCEN

fH

System Clock Configurations

Page 34: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 34 December 27, 2019 Rev. 1.30 35 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Internal High Speed RC Oscillator – HIRCThe internal RC oscillator is a fully integrated system oscillator requiring no external components. The internal high speed RC oscillator has one fixed frequency of 8MHz. Device trimming during the manufacturing process and the inclusion of internal frequency compensation circuits are used to ensure that the influence of the power supply voltage, temperature and process variations on the oscillation frequency are minimised. Note that this internal system clock option requires no external pins for its operation.

Internal 32kHz Oscillator – LIRCThe Internal 32kHz System Oscillator is a fully integrated low frequency RC oscillator with a typical frequency of 32kHz, requiring no external components for its implementation. Device trimming during the manufacturing process and the inclusion of internal frequency compensation circuits are used to ensure that the influence of the power supply voltage, temperature and process variations on the oscillation frequency are minimised.

Operating Modes and System ClocksPresent day applications require that their microcontrollers have high performance but often still demand that they consume as little power as possible, conflicting requirements that are especially true in battery powered portable applications. The fast clocks required for high performance will by their nature increase current consumption and of course vice versa, lower speed clocks reduce current consumption. As Holtek has provided the device with both high and low speed clock sources and the means to switch between them dynamically, the user can optimise the operation of their microcontroller to achieve the best performance/power ratio.

System ClocksThe device has many different clock sources for both the CPU and peripheral function operation. By providing the user with a wide range of clock options using register programming, a clock system can be configured to obtain maximum application performance.

The main system clock, can come from either a high frequency, fH, or low frequency, fSUB, source, and is selected using the CKS2~CKS0 bits in the SCC register. The high speed system clock is sourced from the HIRC oscillator. The low speed system clock source is sourced from the LIRC oscillator. The other choice, which is a divided version of the high speed system oscillator has a range of fH/2~fH/64.

Page 35: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 34 December 27, 2019 Rev. 1.30 35 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

High Speed Oscillator

HIRC

Low Speed Oscillator

LIRC

HIRCEN

Prescaler

fH/2

fH/4fH/8

fH/16

fH/32

fH/64

CKS2~CKS0

fSYSIDLE0SLEEP

IDLE2SLEEP

fSUB

fSUB

fLIRC

fH

fSUB

fSYS

CLKSEL[1:0]

fPSCPrescaler Time

Bases

TBnON

TBn[2:0]

WDTfSYS/4

Device Clock Configurations

Note: When the system clock source fSYS is switched to fSUB from fH, the high speed oscillator will stop to conserve the power or continue to oscillate to provide the clock source, fH~fH/64, for peripheral circuit to use, which is determined by configuring the corresponding high speed oscillator enable control bit.

System Operation ModesThere are six different modes of operation for the microcontrollers, each one with its own special characteristics and which can be chosen according to the specific performance and power requirements of the application. There are two modes allowing normal operation of the microcontroller, the FAST Mode and SLOW Mode. The remaining four modes, the SLEEP, IDLE0, IDLE1 and IDLE2 Mode are used when the microcontroller CPU is switched off to conserve power.

Operation Mode CPU

Register SettingfSYS fH fSUB fLIRC

FHIDEN FSIDEN CKS2~CKS0FAST On x x 000~110 fH~fH/64 On On OnSLOW On x x 111 fSUB On/Off (1) On On

IDLE0 Off 0 1000~110 Off

Off On On111 On

IDLE1 Off 1 1 xxx On On On On

IDLE2 Off 1 0000~110 On

On Off On111 Off

SLEEP Off 0 0 xxx Off Off Off On/Off (2)

“x”: Don’t careNote: 1. The fH clock will be switched on or off by configuring the corresponding oscillator enable bit

in the SLOW mode.2. The fLIRC clock can be switched on or off which is controlled by the WDT function being

enabled or disabled in the SLEEP mode.

Page 36: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 36 December 27, 2019 Rev. 1.30 37 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

FAST ModeThis is one of the main operating modes where the microcontrollers have all of their functions operational and where the system clock is provided by the high speed oscillator. This mode operates allowing the microcontrollers to operate normally with a clock source which will come from the high speed oscillator, HIRC. The high speed oscillator will however first be divided by a ratio ranging from 1 to 64, the actual ratio being selected by the CKS2~CKS0 bits in the SCC register. Although a high speed oscillator is used, running the microcontrollers at a divided clock ratio reduces the operating current.

SLOW ModeThis is also a mode where the microcontroller operates normally although now with a slower speed clock source. The clock source used will be from fSUB, which is derived from the LIRC oscillator.

SLEEP ModeThe SLEEP Mode is entered when a HALT instruction is executed and when the FHIDEN and FSIDEN bit are low. In the SLEEP mode the CPU will be stopped. The fSUB clock provided to the peripheral function will also be stopped, too. However the fLIRC clock can continues to operate if the WDT function is enabled.

IDLE0 ModeThe IDLE0 Mode is entered when a HALT instruction is executed and when the FHIDEN bit in the SCC register is low and the FSIDEN bit in the SCC register is high. In the IDLE0 Mode the CPU will be switched off but the low speed oscillator will be turned on to drive some peripheral functions.

IDLE1 ModeThe IDLE1 Mode is entered when a HALT instruction is executed and when the FHIDEN bit in the SCC register is high and the FSIDEN bit in the SCC register is high. In the IDLE1 Mode the CPU will be switched off but both the high and low speed oscillators will be turned on to provide a clock source to keep some peripheral functions operational.

IDLE2 ModeThe IDLE2 Mode is entered when a HALT instruction is executed and when the FHIDEN bit in the SCC register is high and the FSIDEN bit in the SCC register is low. In the IDLE2 Mode the CPU will be switched off but the high speed oscillator will be turned on to provide a clock source to keep some peripheral functions operational.

Control RegistersThe SCC and HIRCC registers are used to control the system clock and the corresponding oscillator configurations.

Register Name

Bit7 6 5 4 3 2 1 0

SCC CKS2 CKS1 CKS0 — — — FHIDEN FSIDENHIRCC — — — — — — HIRCF HIRCEN

System Operating Mode Control Register List

Page 37: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 36 December 27, 2019 Rev. 1.30 37 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• SCC RegisterBit 7 6 5 4 3 2 1 0

Name CKS2 CKS1 CKS0 — — — FHIDEN FSIDENR/W R/W R/W R/W — — — R/W R/WPOR 0 0 0 — — — 0 0

Bit 7~5 CKS2~CKS0: System clock selection000: fH

001: fH/2010: fH/4011: fH/8100: fH/16101: fH/32110: fH/64111: fSUB

These three bits are used to select which clock is used as the system clock source. In addition to the system clock source directly derived from fH or fSUB, a divided version of the high speed system oscillator can also be chosen as the system clock source.

Bit 4~2 Unimplemented, read as “0”Bit 1 FHIDEN: High frequency oscillator control when CPU is switched off

0: Disable1: Enable

This bit is used to control whether the high speed oscillator is activated or stopped when the CPU is switched off by executing a “HALT” instruction.

Bit 0 FSIDEN: Low frequency oscillator control when CPU is switched off0: Disable1: Enable

This bit is used to control whether the low speed oscillator is activated or stopped when the CPU is switched off by executing a “HALT” instruction.

• HIRCC RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — HIRCF HIRCENR/W — — — — — — R R/WPOR — — — — — — 0 1

Bit 7~2 Unimplemented, read as “0”Bit 1 HIRCF: HIRC oscillator stable flag

0: HIRC unstable1: HIRC stable

This bit is used to indicate whether the HIRC oscillator is stable or not. When the HIRCEN bit is set to 1 to enable the HIRC oscillator, the HIRCF bit will first be cleared to 0 and then set to 1 after the HIRC oscillator is stable.

Bit 0 HIRCEN: HIRC oscillator enable control0: Disable1: Enable

Page 38: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 38 December 27, 2019 Rev. 1.30 39 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Operating Mode SwitchingThe device can switch between operating modes dynamically allowing the user to select the best performance/power ratio for the present task in hand. In this way microcontroller operations that do not require high performance can be executed using slower clocks thus requiring less operating current and prolonging battery life in portable applications.

In simple terms, mode switching between the FAST Mode and SLOW Mode is executed using the CKS2~CKS0 bits in the SCC register while mode switching from the FAST/SLOW Modes to the SLEEP/IDLE Modes is executed via the HALT instruction. When a HALT instruction is executed, whether the device enters the IDLE Mode or the SLEEP Mode is determined by the condition of the FHIDEN and FSIDEN bits in the SCC register.

FASTfSYS=fH~fH/64

fH onCPU runfSYS onfSUB on

SLOWfSYS=fSUBfSUB on

CPU runfSYS onfH on/off

IDLE0HALT instruction executed

CPU stopFHIDEN=0FSIDEN=1

fH offfSUB on

IDLE1HALT instruction executed

CPU stopFHIDEN=1FSIDEN=1

fH onfSUB on

IDLE2HALT instruction executed

CPU stopFHIDEN=1FSIDEN=0

fH onfSUB off

SLEEPHALT instruction executed

CPU stopFHIDEN=0FSIDEN=0

fH offfSUB off

Page 39: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 38 December 27, 2019 Rev. 1.30 39 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

FAST Mode to SLOW Mode SwitchingWhen running in the FAST Mode, which uses the high speed system oscillator, and therefore consumes more power, the system clock can switch to run in the SLOW Mode by set the CKS2~CKS0 bits to “111” in the SCC register. This will then use the low speed system oscillator which will consume less power. Users may decide to do this for certain operations which do not require high performance and can subsequently reduce power consumption.

The SLOW Mode system clock is sourced from the LIRC oscillator and therefore requires this oscillator to be stable before full mode switching occurs.

FAST Mode

SLOW Mode

CKS2~CKS0=111

SLEEP Mode

FHIDEN=0, FSIDEN=0HALT instruction is executed

IDLE0 Mode

FHIDEN=0, FSIDEN=1HALT instruction is executed

IDLE1 Mode

FHIDEN=1, FSIDEN=1HALT instruction is executed

IDLE2 Mode

FHIDEN=1, FSIDEN=0HALT instruction is executed

Page 40: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 40 December 27, 2019 Rev. 1.30 41 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

SLOW Mode to FAST Mode SwitchingIn the SLOW mode the system clock is derived from fSUB. When system clock is switched back to the FAST mode from fSUB, the CKS2~CKS0 bits should be set to “000” ~ “110” and then the system clock will respectively be switched to fH ~ fH/64.

However, if fH is not used in the SLOW mode and thus switched off, it will take some time to re-oscillate and stabilise when switching to the FAST mode from the SLOW Mode. This is monitored using the HIRCF bit in the HIRCC register. The time duration required for the high speed system oscillator stabilisation is specified in the System Start Up Time Characteristics.

FAST Mode

SLOW Mode

CKS2~CKS0=000~110

SLEEP Mode

FHIDEN=0, FSIDEN=0HALT instruction is executed

IDLE0 Mode

FHIDEN=0, FSIDEN=1HALT instruction is executed

IDLE1 Mode

FHIDEN=1, FSIDEN=1HALT instruction is executed

IDLE2 Mode

FHIDEN=1, FSIDEN=0HALT instruction is executed

Entering the SLEEP ModeThere is only one way for the device to enter the SLEEP Mode and that is to execute the “HALT” instruction in the application program with both the FHIDEN and FSIDEN bits in the SCC register equal to “0”. In this mode all the clocks and functions will be switched off except the WDT function. When this instruction is executed under the conditions described above, the following will occur:

• The system clock will be stopped and the application program will stop at the “HALT” instruction.

• The Data Memory contents and registers will maintain their present condition.

• The I/O ports will maintain their present conditions.

• In the status register, the Power Down flag, PDF, will be set and the Watchdog time-out flag, TO, will be cleared.

• The WDT will be cleared and resume counting if the WDT function is enabled. If the WDT function is disabled, the WDT will be cleared and then stopped.

Page 41: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 40 December 27, 2019 Rev. 1.30 41 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Entering the IDLE0 ModeThere is only one way for the device to enter the IDLE0 Mode and that is to execute the “HALT” instruction in the application program with the FHIDEN bit in the SCC register equal to “0” and the FSIDEN bit in the SCC register equal to “1”. When this instruction is executed under the conditions described above, the following will occur:

• The fH clock will be stopped and the application program will stop at the “HALT” instruction, but the fSUB clock will be on.

• The Data Memory contents and registers will maintain their present condition.

• The I/O ports will maintain their present conditions.

• In the status register, the Power Down flag, PDF, will be set and the Watchdog time-out flag, TO, will be cleared.

• The WDT will be cleared and resume counting if the WDT function is enabled. If the WDT function is disabled, the WDT will be cleared and then stopped.

Entering the IDLE1 ModeThere is only one way for the device to enter the IDLE1 Mode and that is to execute the “HALT” instruction in the application program with both the FHIDEN and FSIDEN bits in the SCC register equal to “1”. When this instruction is executed under the conditions described above, the following will occur:

• The fH and fSUB clocks will be on but the application program will stop at the “HALT” instruction.

• The Data Memory contents and registers will maintain their present condition.

• The I/O ports will maintain their present conditions.

• In the status register, the Power Down flag, PDF, will be set and the Watchdog time-out flag, TO, will be cleared.

• The WDT will be cleared and resume counting if the WDT function is enabled. If the WDT function is disabled, the WDT will be cleared and then stopped.

Entering the IDLE2 ModeThere is only one way for the device to enter the IDLE2 Mode and that is to execute the “HALT” instruction in the application program with the FHIDEN bit in the SCC register equal to “1” and the FSIDEN bit in the SCC register equal to “0”. When this instruction is executed under the conditions described above, the following will occur:

• The fH clock will be on but the fSUB clock will be off and the application program will stop at the “HALT” instruction.

• The Data Memory contents and registers will maintain their present condition.

• The I/O ports will maintain their present conditions.

• In the status register, the Power Down flag, PDF, will be set and the Watchdog time-out flag, TO, will be cleared.

• The WDT will be cleared and resume counting if the WDT function is enabled. If the WDT function is disabled, the WDT will be cleared and then stopped.

Page 42: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 42 December 27, 2019 Rev. 1.30 43 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Standby Current ConsiderationsAs the main reason for entering the SLEEP or IDLE Mode is to keep the current consumption of the device to as low a value as possible, perhaps only in the order of several micro-amps except in the IDLE1 and IDLE2 Mode, there are other considerations which must also be taken into account by the circuit designer if the power consumption is to be minimised. Special attention must be made to the I/O pins on the device. All high-impedance input pins must be connected to either a fixed high or low level as any floating input pins could create internal oscillations and result in increased current consumption. This also applies to the device which has different package types, as there may be unbonded pins. These must either be set as outputs or if set as inputs must have pull-high resistors connected.

Care must also be taken with the loads, which are connected to I/O pins, which are set as outputs. These should be placed in a condition in which minimum current is drawn or connected only to external circuits that do not draw current, such as other CMOS inputs. Also note that additional standby current will also be required if the LIRC oscillator has enabled.

In the IDLE1 and IDLE2 Mode the high speed oscillator is on, if the peripheral function clock source is derived from the high speed oscillator, the additional standby current will also be perhaps in the order of several hundred micro-amps.

Wake-upTo minimise power consumption the device can enter the SLEEP or any IDLE Mode, where the CPU will be switched off. However, when the device is woken up again, it will take a considerable time for the original system oscillator to restart, stabilise and allow normal operation to resume.

After the system enters the SLEEP or IDLE Mode, it can be woken up from one of various sources listed as follows:

• An external falling edge on Port A

• A system interrupt

• A WDT overflow

When the device executes the “HALT” instruction, it will enter the IDLE or SLEEP mode and the PDF flag will be set to 1. The PDF flag will be cleared to 0 if the device experiences a system power-up or executes the clear Watchdog Timer instruction. If the system is woken up by a WDT overflow, a 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 set using the PAWU register to permit a negative transition on the pin to wake-up the system. When a pin wake-up occurs, the program will resume execution at the instruction following the “HALT” instruction. If the system is woken up by an interrupt, then two possible situations may occur. The first is where the related interrupt is disabled or the interrupt is enabled but the stack is full, in which case the program will resume execution at the instruction following the “HALT” instruction. In this situation, the interrupt which woke up the device will not be immediately serviced, but will rather be serviced later when the related interrupt is finally enabled or when a stack level becomes free. The other situation is where the related interrupt is enabled and the stack is not full, in which case the regular interrupt response takes place. If an interrupt request flag is set high before entering the SLEEP or IDLE Mode, the wake-up function of the related interrupt will be disabled.

Page 43: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 42 December 27, 2019 Rev. 1.30 43 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Watchdog TimerThe Watchdog Timer is provided to prevent program malfunctions or sequences from jumping to unknown locations, due to certain uncontrollable external events such as electrical noise.

Watchdog Timer Clock SourceThe Watchdog Timer clock source is provided by the internal clock, fLIRC which is sourced from the LIRC oscillator. The LIRC internal oscillator has an approximate frequency of 32kHz and this specified internal clock period can vary with VDD, temperature and process variations. The Watchdog Timer source clock is then subdivided by a ratio of 28 to 215 to give longer timeouts, the actual value being chosen using the WS2~WS0 bits in the WDTC register.

Watchdog Timer Control RegisterA single register, WDTC, controls the required time-out period, the enable/disable operation as well as the MCU reset operation.

• WDTC RegisterBit 7 6 5 4 3 2 1 0

Name WE4 WE3 WE2 WE1 WE0 WS2 WS1 WS0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 1 0 1 0 1 1 1

Bit 7~3 WE4~WE0: WDT function software control10101: Disable01010: EnableOther values: MCU reset

When these bits are changed to any other values due to environmental noise the microcontroller will be reset; this reset operation will be activated after a delay time, tSRESET, and the WRF bit in the RSTFC register will be set high.

Bit 2~0 WS2~WS0: WDT time-out period selection000: [(28-20)~28]/fLIRC

001: [(29-21)~29]/fLIRC

010: [(210-22)~210]/fLIRC

011: [(211-23)~211]/fLIRC

100: [(212-24)~212]/fLIRC

101: [(213-25)~213]/fLIRC

110: [(214-26)~214]/fLIRC

111: [(215-27)~215]/fLIRC

These three bits determine the division ratio of the Watchdog Timer source clock, which in turn determines the timeout period.

• RSTFC RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — LVRF LRF WRFR/W — — — — — R/W R/W R/WPOR — — — — — x 0 0

“x”: UnknownBit 7~3 Unimplemented, read as “0”Bit 2 LVRF: LVR function reset flag

Refer to the Low Voltage Reset section.Bit 1 LRF: LVR control register software reset flag

Refer to the Low Voltage Reset section.

Page 44: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 44 December 27, 2019 Rev. 1.30 45 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Bit 0 WRF: WDT control register software reset flag0: Not occurred1: 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.

Watchdog Timer OperationThe Watchdog Timer operates by providing a device reset when its timer overflows. This means that in the application program and during normal operation the user has to strategically clear the Watchdog Timer before it overflows to prevent the Watchdog Timer from executing a reset. This is done using the clear watchdog instruction. If the program malfunctions for whatever reason, jumps to an unknown location, or enters an endless loop, the clear instruction will not be executed in the correct manner, in which case the Watchdog Timer will overflow and reset the device. There are five bits, WE4~WE0, in the WDTC register to offer the enable/disable control and reset control of the Watchdog Timer. The WDT function will be disabled when the WE4~WE0 bits are set to a value of 10101B while the WDT function will be enabled if the WE4~WE0 bits are equal to 01010B. If the WE4~WE0 bits are set to any other values, other than 01010B and 10101B, it will reset the device after a delay time, tSRESET. After power on these bits will have a value of 01010B.

WE4~WE0 Bits WDT Function10101B Disable01010B Enable

Any other value MCU reset

Watchdog Timer Function Control

Under normal program operation, a Watchdog Timer time-out will initialise a device reset and set the status bit TO. However, if the system is in the SLEEP or IDLE Mode, when a Watchdog Timer time-out occurs, the TO bit in the status register will be set and only the Program Counter and Stack Pointer will be reset. Three methods can be adopted to clear the contents of the Watchdog Timer. The first is a WDTC software reset, which means a certain value except 01010B and 10101B written into the WE4~WE0 bits, the second is using the Watchdog Timer software clear instruction, the third is via a HALT instruction.

There is only one method of using software instruction to clear the Watchdog Timer. That is to use the single “CLR WDT” instruction to clear the WDT.

The maximum time-out period is when the 215 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 1 second for the 215 division ratio, and a minimum timeout of 8ms for the 28 division ration.

8-stage Divider

Reset MCU

fLIRC 8-to-1 MUX

WS2~WS0

(fLIRC/20 ~ fLIRC/27)

WDT Time-out

(28/fLIRC ~ 215/fLIRC)7-stage Divider

Clear 8-stage divider

Clear 7-stagedivider

WE4~WE0 Bits

WDTC Register“HALT” Instruction

“CLR WDT” Instruction

Watchdog Timer

Page 45: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 44 December 27, 2019 Rev. 1.30 45 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Reset and InitialisationA reset function is a fundamental part of any microcontroller ensuring that the device can be set to some predetermined condition irrespective of outside parameters. The most important reset condition is after power is first applied to the microcontrollers. In this case, internal circuitry will ensure that the microcontrollers, after a short delay, will be in a well-defined state and ready to execute the first program instruction. After this power-on reset, certain important internal registers will be set to defined states before the program commences. One of these registers is the Program Counter, which will be reset to zero forcing the microcontroller to begin program execution from the lowest Program Memory address.

Another reset exists in the form of a Low Voltage Reset, LVR, where a full reset is implemented in situations where the power supply voltage falls below a certain threshold. Another type of reset is when the Watchdog Timer overflows and resets the microcontroller. All types of reset operations result in different register conditions being setup.

Reset FunctionsThere are several ways in which a microcontroller reset can occur through events occurring internally.

Power-on ResetThe most fundamental and unavoidable reset is the one that occurs after power is first applied to the microcontrollers. 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

SST Time-out

tRSTD

Power-on Reset Timing Chart

Low Voltage Reset – LVRThe microcontroller contains a low voltage reset circuit in order to monitor the supply voltage of the device and provides an MCU reset should the value fall below a certain predefined level. This function can be enabled or disabled by the LVRC control register. If the LVRC control register is configured to enable the LVR, the LVR function will be always enabled, except in the SLEEP/IDLE mode, with a specific LVR voltage VLVR. If the supply voltage of the device drops to within a range of 0.9V~VLVR such as might occur when changing the battery in battery powered applications, the LVR will automatically reset the device internally and the LVRF bit in the RSTFC register will also be set high. For a valid LVR signal, a low supply voltage, i.e., a voltage in the range between 0.9V~VLVR must exist for a time greater than that specified by tLVR in the LVR characteristics. If the low supply voltage state does not exceed this value, the LVR will ignore the low supply voltage and will not perform a reset function. If the LVS7~LVS0 bits are set to 01011010B, the LVR function is enabled with a fixed LVR voltage of 1.7V. If the LVS7~LVS0 bits are set to 10100101B, the LVR function is disabled. If the LVS7~LVS0 bits are changed to some different values by environmental noise, the LVR will reset the device after a delay time, tSRESET. When this happens, the LRF bit in the RSTFC register will be set high. After power on the register will have the value of 01011010B. Note that the LVR function will be automatically disabled when the device enters the IDLE or SLEEP mode.

Page 46: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 46 December 27, 2019 Rev. 1.30 47 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

LVR

Internal Reset

tRSTD + tSST

Low Voltage Reset Timing Chart

• LVRC RegisterBit 7 6 5 4 3 2 1 0

Name LVS7 LVS6 LVS5 LVS4 LVS3 LVS2 LVS1 LVS0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 1 0 1 1 0 1 0

Bit 7~0 LVS7~LVS0: LVR voltage select control01011010: 1.7V10100101: LVR disableAny other value: MCU reset – register is reset to POR value

When an actual low voltage condition occurs, as specified above, an MCU reset will be generated. The reset operation will be activated after the low voltage condition keeps more than a tLVR time. In this situation the register contents will remain the same after such a reset occurs.Any register value, other than 01011010B and 10100101B, will also result in the generation of an MCU reset. The reset operation will be activated after a delay time, tSRESET. However in this situation the register contents will be reset to the POR value.

• RSTFC RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — LVRF LRF WRFR/W — — — — — R/W R/W R/WPOR — — — — — x 0 0

“x”: UnknownBit 7~3 Unimplemented, read as “0”Bit 2 LVRF: LVR function reset flag

0: Not occurred1: Occurred

This bit is set high when a specific Low Voltage Reset situation condition occurs. This bit can only be cleared to zero by the application program.

Bit 1 LRF: LVR control register software reset flag0: Not occurred1: Occurred

This bit is set high if the LVRC register contains any non-defined LVRC register values. This in effect acts like a software-reset function. This bit can only be cleared to zero by the application program.

Bit 0 WRF: WDT control register software reset flagRefer to the Watchdog Timer Control Register section.

Page 47: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 46 December 27, 2019 Rev. 1.30 47 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Watchdog Time-out Reset during Normal OperationWhen the Watchdog time-out Reset during normal operations in the FAST or SLOW mode occurs, the Watchdog time-out flag TO will be set to “1”.

WDT Time-out

Internal Reset

tRSTD

WDT Time-out Reset during Normal Operation Timing Chart

Watchdog Time-out Reset during SLEEP or IDLE ModeThe Watchdog time-out Reset during SLEEP or IDLE Mode is a little different from other kinds of reset. Most of the conditions remain unchanged except that the Program Counter and the Stack Pointer will be cleared to “0” and the TO flag will be set to “1”. Refer to the System Start Up Time Characteristics for tSST details.

WDT Time-out

Internal Reset

tSST

WDT Time-out Reset during SLEEP or IDLE Timing Chart

Reset Initial ConditionsThe different types of reset described affect the reset flags in different ways. These flags, known as PDF and TO are located in the status register and are controlled by various microcontroller operations, such as the SLEEP or IDLE Mode function or Watchdog Timer. The reset flags are shown in the table:

TO PDF Reset Conditions0 0 Power-on resetu u LVR reset during FAST and SLOW Mode operation1 u WDT time-out reset during FAST or SLOW Mode operation1 1 WDT time-out reset during IDLE or SLEEP Mode operation

“u”: Unchanged

The following table indicates the way in which the various components of the microcontroller are affected after a power-on reset occurs.

Item Condition After ResetProgram Counter Reset to zeroInterrupts All interrupts will be disabledWDT, Time Bases Cleared after reset, WDT begins countingTimer Modules All Timer Modules will be turned offInput/Output Ports I/O ports will be set as inputsStack Pointer Stack Pointer will point to the top of the stack

The different kinds of resets all affect the internal registers of the microcontroller in different ways. To ensure reliable continuation of normal program execution after a reset occurs, it is important to know what condition the microcontroller is in after a particular reset occurs. The following table describes how each type of reset affects each of the microcontroller internal registers. Note that where more than one package type exists the table will reflect the situation for the larger package type.

Page 48: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 48 December 27, 2019 Rev. 1.30 49 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Register Reset(Power On)

WDT Time-out(Normal Operation)

WDT Time-out(IDLE/SLEEP)

IAR0 x x x x x x x x u u u u u u u u u u u u u u u uMP0 x x x x x x x x u u u u u u u u u u u u u u u uIAR1 x x x x x x x x u u u u u u u u u u u u u u u uMP1 x x x x x x x x u u u u u u u u u u u u u u u uACC x x x x x x x x u u u u u u u u u u u u u u u uPCL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0TBLP x x x x x x x x u u u u u u u u u u u u u u u uTBLH - x x x x x x x - u u u u u u u - u u u u u u uTBHP - - - - x x x x - - - - u u u u - - - - u u u uSTATUS - - 0 0 x x x x - - 1 u u u u u - - 1 1 u u u uLVPUC - - - - - - - 0 - - - - - - - 0 - - - - - - - uINTEG - - - - 0 0 0 0 - - - - 0 0 0 0 - - - - u u u uINTC0 - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - u u u u u u uINTC1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uRSTFC - - - - - x 0 0 - - - - - u u u - - - - - u u uMFI0 - - 0 0 - - 0 0 - - 0 0 - - 0 0 - - u u - - u uMFI1 - - 0 0 - - 0 0 - - 0 0 - - 0 0 - - u u - - u uPA 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 u u u u u u u uPAC 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 u u u u u u u uPAPU 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPAWU 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPB - 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 - u u u u u u uPBC - 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 - u u u u u u uPBPU - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - u u u u u u uPC - - - - - 1 1 1 - - - - - 1 1 1 - - - - - u u uPCC - - - - - 1 1 1 - - - - - 1 1 1 - - - - - u u uPCPU - - - - - 0 0 0 - - - - - 0 0 0 - - - - - u u u

SADOL x x - - - - - - x x - - - - - -u u - - - - - - (ADRFS=0)uuuu uuuu (ADRFS=1)

SADOH x x x x x x x x x x x x x x x xuuuu uuuu (ADRFS=0)- - - - - - u u (ADRFS=1)

SADC0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSADC1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uECR 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uEAR - - - 0 0 0 0 0 - - - 0 0 0 0 0 - - - u u u u uED0L 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uED0H - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - u u u u u u uED1L 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uED1H - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - u u u u u u uED2L 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uED2H - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - u u u u u u uED3L 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uED3H - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - u u u u u u uLVRC 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 u u u u u u u uVBGC - - - - 0 - - - - - - - 0 - - - - - - - u - - -SCC 0 0 0 - - - 0 0 0 0 0 - - - 0 0 u u u - - - u uHIRCC - - - - - - 0 1 - - - - - - 0 1 - - - - - - u u

Page 49: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 48 December 27, 2019 Rev. 1.30 49 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Register Reset(Power On)

WDT Time-out(Normal Operation)

WDT Time-out(IDLE/SLEEP)

WDTC 0 1 0 1 0 111 0 1 0 1 0 111 u u u u u u u uPSCR - - - - - 0 0 0 - - - - - 0 0 0 - - - - - u u uTB0C 0 - - - - 0 0 0 0 - - - - 0 0 0 u - - - - u u uTB1C 0 - - - - 0 0 0 0 - - - - 0 0 0 u - - - - u u uPAS0 - - - - - - 0 0 - - - - - - 0 0 - - - - - - u uPAS1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPBS0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSLEDC0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSLEDC1 - - - - - - 0 0 - - - - - - 0 0 - - - - - - u uSTMC0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSTMC1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSTMDL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSTMDH - - - - - - 0 0 - - - - - - 0 0 - - - - - - u uSTMAL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uSTMAH - - - - - - 0 0 - - - - - - 0 0 - - - - - - u uPTMC0 0 0 0 0 0 - - - 0 0 0 0 0 - - - u u u u u - - -PTMC1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPTMDL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPTMDH - - - - - - 0 0 - - - - - - 0 0 - - - - - - u uPTMAL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPTMAH - - - - - - 0 0 - - - - - - 0 0 - - - - - - u uPTMRPL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u u u u u u u uPTMRPH - - - - - - 0 0 - - - - - - 0 0 - - - - - - u u

Note: “u” stands for unchanged“x” stands for unknown“-” stands for unimplemented

Page 50: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 50 December 27, 2019 Rev. 1.30 51 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Input/Output PortsHoltek microcontrollers offer considerable flexibility on their I/O ports. With the input or output designation of every pin fully under user program control, pull-high selections for all ports and wake-up selections on certain pins, the user is provided with an I/O structure to meet the needs of a wide range of application possibilities.The device provides bidirectional input/output lines labeled with port names PA~PC. 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 Name

Bit7 6 5 4 3 2 1 0

PA PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0PAC PAC7 PAC6 PAC5 PAC4 PAC3 PAC2 PAC1 PAC0PAPU PAPU7 PAPU6 PAPU5 PAPU4 PAPU3 PAPU2 PAPU1 PAPU0PAWU PAWU7 PAWU6 PAWU5 PAWU4 PAWU3 PAWU2 PAWU1 PAWU0PB — PB6 PB5 PB4 PB3 PB2 PB1 PB0PBC — PBC6 PBC5 PBC4 PBC3 PBC2 PBC1 PBC0PBPU — PBPU6 PBPU5 PBPU4 PBPU3 PBPU2 PBPU1 PBPU0PC — — — — — PC2 PC1 PC0PCC — — — — — PCC2 PCC1 PCC0PCPU — — — — — PCPU2 PCPU1 PCPU0LVPUC — — — — — — — LVPU

“—”: Unimplemented, read as “0”I/O Logic Function Register List

Pull-high ResistorsMany 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 a digital input have the capability of being connected to an internal pull-high resistor. These pull-high resistors are selected using registers, LVPUC and PxPU, and are implemented using weak PMOS transistors. The PxPU register is used to determine whether the pull-high function is enabled or not while the LVPUC register is used to select the pull-high resistor value for low voltage power supply applications. The LVPU bit is only available when the corresponding pin pull-high function is enabled. If the pull-high function is disabled, the LVPU bit has no effect on selecting the pull-high resistor value.Note that the pull-high resistor can be controlled by the relevant pull-high control register only when the pin-shared functional pin is selected as a digital input or NMOS output. Otherwise, the pull-high resistors cannot be enabled.

• PxPU RegisterBit 7 6 5 4 3 2 1 0

Name PxPU7 PxPU6 PxPU5 PxPU4 PxPU3 PxPU2 PxPU1 PxPU0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

PxPUn: I/O port x pin pull-high function control0: Disable1: Enable

The PxPUn bit is used to control the pin pull-high function. Here the “x” can be A, B and C. However, the actual available bits for each I/O Port may be different.

Page 51: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 50 December 27, 2019 Rev. 1.30 51 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• LVPUC RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — — LVPUR/W — — — — — — — R/WPOR — — — — — — — 0

Bit 7~1 Unimplemented, read as “0”Bit 0 LVPU: Pull-high resistor selection for low voltage power supply

0: All pin pull-high resistors are 60kΩ @ 3V1: All pin pull-high resistors are 15kΩ @ 3V

The LVPUC register is used to select the pull-high resistor value for low voltage power supply applications. Note that the LVPU bit in the LVPUC register is only available when the corresponding pin pull-high function is enabled. If the pull-high function is disabled, the LVPU bit has no effect on selecting the pull-high resistor value.

Port A Wake-upThe HALT instruction forces the microcontroller into the SLEEP or IDLE Mode which preserves power, a feature that is important for battery and other low-power applications. Various methods exist to wake-up the microcontroller, one of which is to change the logic condition on one of the Port A pins from high to low. This function is especially suitable for applications that can be woken up via external switches. Each pin on Port A can be selected individually to have this wake-up feature using the PAWU register.

Note that the wake-up function can be controlled by the wake-up control registers only when the pin is selected as a general purpose input and the MCU enters the IDLE or SLEEP mode.

• PAWU RegisterBit 7 6 5 4 3 2 1 0

Name PAWU7 PAWU6 PAWU5 PAWU4 PAWU3 PAWU2 PAWU1 PAWU0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

PAWUn: Port A pin wake-up function control0: Disable1: Enable

I/O Port Control RegistersEach I/O port has its own control register known as PAC~PCC, to control the input/output configuration. With this control register, each CMOS output or input can be reconfigured dynamically under software control. Each pin of the I/O ports is directly mapped to a bit in its associated port control register. For the I/O pin to function as an input, the corresponding bit of the control register must be written as a “1”. This will then allow the logic state of the input pin to be directly read by instructions. When the corresponding bit of the control register is written as a “0”, the I/O pin will be set as a CMOS output. If the pin is currently set as an output, instructions can still be used to read the output register. However, it should be noted that the program will in fact only read the status of the output data latch and not the actual logic status of the output pin.

Page 52: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 52 December 27, 2019 Rev. 1.30 53 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• PxC RegisterBit 7 6 5 4 3 2 1 0

Name PxC7 PxC6 PxC5 PxC4 PxC3 PxC2 PxC1 PxC0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 1 1 1 1 1 1 1 1

PxCn: I/O Port x pin type selection0: Output1: Input

The PxCn bit is used to control the pin type selection. Here the “x” can be A, B and C. However, the actual available bits for each I/O Port may be different.

I/O Port Source Current SelectionThe source current of each pin in the device can be configured with different source current which is selected by the corresponding pin source current select bits. Users should refer to the Input/Output Characteristics section to obtain the exact value for different applications.

Register Name

Bit7 6 5 4 3 2 1 0

SLEDC0 SLEDC07 SLEDC06 SLEDC05 SLEDC04 SLEDC03 SLEDC02 SLEDC01 SLEDC00SLEDC1 — — — — — — SLEDC11 SLEDC10

I/O Port Source Current Selection Register List

• SLEDC0 RegisterBit 7 6 5 4 3 2 1 0

Name SLEDC07 SLEDC06 SLEDC05 SLEDC04 SLEDC03 SLEDC02 SLEDC01 SLEDC00R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~6 SLEDC07~SLEDC06: PB6~PB4 source current selection00: Source current = Level 0 (Min.)01: Source current = Level 110: Source current = Level 2 11: Source current = Level 3 (Max.)

Bit 5~4 SLEDC05~SLEDC04: PB3~PB0 source current selection00: Source current = Level 0 (Min.)01: Source current = Level 110: Source current = Level 2 11: Source current = Level 3 (Max.)

Bit 3~2 SLEDC03~SLEDC02: PA7~PA4 source current selection00: Source current = Level 0 (Min.)01: Source current = Level 110: Source current = Level 211: Source current = Level 3 (Max.)

Bit 1~0 SLEDC01~SLEDC00: PA3~PA0 source current selection00: Source current = Level 0 (Min.)01: Source current = Level 110: Source current = Level 211: Source current = Level 3 (Max.)

Page 53: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 52 December 27, 2019 Rev. 1.30 53 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• SLEDC1 RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — SLEDC11 SLEDC10R/W — — — — — — R/W R/WPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 SLEDC11~SLEDC10: PC2~PC0 source current selection

00: Source current = Level 0 (Min.)01: Source current = Level 110: Source current = Level 211: Source current = Level 3 (Max.)

Pin-shared FunctionsThe flexibility of the microcontroller range is greatly enhanced by the use of pins that have more than one function. Limited numbers of pins can force serious design constraints on designers but by supplying pins with multi-functions, many of these difficulties can be overcome. For these pins, the desired function of the multi-function I/O pins is selected by a series of registers via the application program control.

Pin-shared Function Selection RegistersThe 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. The device includes a Port x Output Function Selection register, labeled as PxSn, which can select the desired functions of the multi-function pin-shared pins.

The most important point to note is to make sure that the desired pin-shared function is properly selected and also deselected. For most pin-shared functions, to select the desired pin-shared function, the pin-shared function should first be correctly selected using the corresponding pin-shared control register. After that the corresponding peripheral functional setting should be configured and then the peripheral function can be enabled. However, a special point must be noted for digital input pins, such as xTCK, xTPI and INTn, which share the same pin-shared control configuration with their corresponding general purpose I/O functions when setting the relevant pin-shared control bits. To select these pin functions, in addition to the necessary pin-shared control and peripheral functional setup aforementioned, they must also be set as an input by setting the corresponding bit in the I/O port control register. To correctly deselect the pin-shared function, the peripheral function should first be disabled and then the corresponding pin-shared function control register can be modified to select other pin-shared functions.

RegisterName

Bit7 6 5 4 3 2 1 0

PAS0 — — — — — — PAS01 PAS00PAS1 PAS17 PAS16 PAS15 PAS14 PAS13 PAS12 PAS11 PAS10PBS0 PBS07 PBS06 PBS05 PBS04 PBS03 PBS02 PBS01 PBS00

Pin-shared Function Selection Register List

Page 54: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 54 December 27, 2019 Rev. 1.30 55 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• PAS0 RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — PAS01 PAS00R/W — — — — — — R/W R/WPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 PAS01~PAS00: PA0 pin-shared function selection

00: PA0/STPI01: PA0/STPI10: PA0/STPI11: STP

• PAS1 RegisterBit 7 6 5 4 3 2 1 0

Name PAS17 PAS16 PAS15 PAS14 PAS13 PAS12 PAS11 PAS10R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~6 PAS17~PAS16: PA7 pin-shared function selection00: PA7/PTPI01: PA7/PTPI10: PTP11: AN6

Bit 5~4 PAS15~PAS14: PA6 pin-shared function selection00: PA601: PA610: PA611: AN5

Bit 3~2 PAS13~PAS12: PA5 pin-shared function selection00: PA501: PA510: VREF11: AN4

Bit 1~0 PAS11~PAS10: PA4 pin-shared function selection00: PA4/PTCK01: PA4/PTCK10: PA4/PTCK11: AN3

• PBS0 RegisterBit 7 6 5 4 3 2 1 0

Name PBS07 PBS06 PBS05 PBS04 PBS03 PBS02 PBS01 PBS00R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~6 PBS07~PBS06: PB3 pin-shared function selection00: PB301: PB310: PB311: AN7

Bit 5~4 PBS05~PBS04: PB2 pin-shared function selection00: PB2/STCK01: PB2/STCK10: PB2/STCK11: AN2

Page 55: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 54 December 27, 2019 Rev. 1.30 55 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Bit 3~2 PBS03~PBS02: PB1 pin-shared function selection00: PB1/INT101: PB1/INT110: PB1/INT111: AN1

Bit 1~0 PBS01~PBS00: PB0 pin-shared function selection00: PB0/INT001: PB0/INT010: PB0/INT011: AN0

I/O Pin StructureThe accompanying diagram illustrates the internal structure of the I/O logic function. As the exact logical construction of the I/O pin will differ from this drawing, it is supplied as a guide only to assist with the functional understanding of the I/O logic function. The wide range of pin-shared structures does not permit all types to be shown.

MUX

VDD

Control Bit

Data Bit

Data Bus

Write Control Register

Chip Reset

Read Control Register

Read Data Register

Write Data Register

System Wake-up wake-up Select

I/O pin

Weak Pull-up

Pull-highRegister Select

Q

D

CK

Q

D

CK

Q

QS

S

PA only

Logic Function Input/Output Structure

Programming ConsiderationsWithin the user program, one of the first things to consider is port initialisation. After a reset, all of the I/O data and port control registers will be set high. This means that all I/O pins will default to an input state, the level of which depends on the other connected circuitry and whether pull-high selections have been chosen. If the port control registers are then programmed to set some pins as outputs, these output pins will have an initial high output value unless the associated port data registers are first programmed. Selecting which pins are inputs and which are outputs can be achieved byte-wide by loading the correct values into the appropriate port control register or by programming individual bits in the port control register using the “SET [m].i” and “CLR [m].i” instructions. Note that when using these bit control instructions, a read-modify-write operation takes place. The microcontroller must first read in the data on the entire port, modify it to the required new bit values and then rewrite this data back to the output ports.

Port A has the additional capability of providing wake-up function. When the device is in the SLEEP or IDLE Mode, various methods are available to wake the device up. One of these is a high to low transition of any of the Port A pins. Single or multiple pins on Port A can be set to have this function.

Page 56: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 56 December 27, 2019 Rev. 1.30 57 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Timer Modules – TMOne of the most fundamental functions in any microcontroller devices is the ability to control and measure time. To implement time related functions the 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 Standard and Periodic Type TM sections.

IntroductionThe device contains two Timer Modules and each individual TM can be categorised as a certain type, namely the 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 Standard and Periodic type 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 two types of TMs are summarised in the accompanying table.

TM Function STM PTMTimer/Counter √ √Input Capture √ √Compare Match Output √ √PWM Output √ √Single Pulse Output √ √PWM Alignment Edge EdgePWM Adjustment Period & Duty Duty or Period Duty or Period

TM Function Summary

TM OperationThe 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 SourceThe 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 xTCK2~xTCK0 bits in the xTM control registers, where “x” stands for S or P type TM. The clock source can be a ratio of the system clock, fSYS, or the internal high clock, fH, the fSUB clock source or the external xTCK pin. The xTCK pin clock source is used to allow an external signal to drive the TM as an external clock source for event counting.

Page 57: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 56 December 27, 2019 Rev. 1.30 57 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

TM InterruptsThe Standard or Periodic type TM each has two internal interrupt, 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 PinsEach of the TMs, irrespective of what type, has two TM input pins, with the label xTCK and xTPI. One of the xTM input pin, xTCK, is essentially a clock source for the xTM and is selected using the xTCK2~xTCK0 bits in the xTMC0 register. This external TM input pin allows an external clock source to drive the internal TM. The xTCK input pin can be chosen to have either a rising or falling active edge. The xTCK pin is also used as the external trigger input pin in single pulse output mode for the xTM.

Another xTM input pin, xTPI, which is the capture input whose active edge can be a rising edge, a falling edge or both rising and falling edges and the active edge transition type is selected using the xTIO1~xTIO0 bits in the xTMC1 register. There is another capture input, PTCK, for PTM capture input mode, which can be used as the external trigger input source except the PTPI pin.

The TMs each has one output pin, xTP. 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 xTP output pin is also the pin where the TM generates the PWM output waveform.

As the TM input/output pins are pin-shared with other functions, the TM input/output function must first be setup using relevant pin-shared function selection register. The details of the pin-shared function selection are described in the pin-shared function section.

STM PTMInput Output Input Output

STCK, STPI STP PTCK, PTPI PTP

TM External Pins

STM

STCK

STPCCR output

Clock input

STPICapture input

STM Function Pin Block Diagram

PTM

PTCK

PTPCCR output

Clock input/Capture input

PTPICapture input

PTM Function Pin Block Diagram

Page 58: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 58 December 27, 2019 Rev. 1.30 59 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Programming ConsiderationsThe TM Counter Registers and the Capture/Compare CCRA and CCRP registers, all have a low and high byte structure. The high bytes can be directly accessed, but as the low bytes can only be accessed via an internal 8-bit buffer, reading or writing to these register pairs must be carried out in a 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 xTMAL and PTMRPL, using the following access procedures. Accessing the CCRA or CCRP low byte registers without following these access procedures will result in unpredictable values.

Data Bus

8-bit Buffer

xTMAHxTMAL

xTM Counter Register (Read only)

xTM CCRA Register (Read/Write)

PTMRPHPTMRPL

PTM CCRP Register (Read/Write)

xTMDHxTMDL

The following steps show the read and write procedures:

• Writing Data to CCRA or CCRP ♦ Step 1. Write data to Low Byte xTMAL or PTMRPL

– Note that here data is only written to the 8-bit buffer ♦ Step 2. Write data to High Byte xTMAH or PTMRPH

– Here data is written directly to the high byte registers and simultaneously data is latched from the 8-bit buffer to the Low Byte registers

• Reading Data from the Counter Registers and CCRA or CCRP ♦ Step 1. Read data from the High Byte xTMDH, xTMAH or PTMRPH

– Here data is read directly from the High Byte registers and simultaneously data is latched from the Low Byte register into the 8-bit buffer

♦ Step 2. Read data from the Low Byte xTMDL, xTMAL or PTMRPL – This step reads data from the 8-bit buffer

Page 59: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 58 December 27, 2019 Rev. 1.30 59 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Standard Type TM – STMThe Standard Type TM contains five operating modes, which are Compare Match Output, Timer/Event Counter, Capture Input, Single Pulse Output and PWM Output modes. The Standard type TM can also be controlled with two external input pins and can drive one external output pin.

10-bit Count-up Counter

3-bit Comparator P

CCRP

b7~b9

b0~b9

10-bit Comparator A

STONSTPAU

Comparator A Match

Comparator P Match

Counter Clear 01

Output Control

Polarity Control

STOC

STM1, STM0STIO1, STIO0

STMAF Interrupt

STMPF Interrupt

STPOL

CCRA

STCCLR

Edge Detector STPI

STIO1, STIO0

fSYS

fSYS/4

fH/64fH/16

fSUB

STCK2~STCK0

fSUB

000001010011100101110111STCK

STPPinControl

PAS0

10-bit Standard Type TM Block Diagram

Standard Type TM OperationThe size of Standard type TM is 10-bit wide and its core is a 10-bit count-up counter which is driven by a user selectable internal or external clock source. There are also two internal comparators with the names, Comparator A and Comparator P. These comparators will compare the value in the counter with CCRP and CCRA registers. The CCRP comparator is 3-bit wide whose value is compared with the highest 3 bits in the counter while the CCRA is the 10-bit and therefore compares all counter bits.

The only way of changing the value of the 10-bit counter using the application program, is to clear the counter by changing the STON 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, an STM 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 one output pin. All operating setup conditions are selected using relevant internal registers.

Standard Type TM Register DescriptionOverall operation of the Standard type TM is controlled using a series of registers. A read only register pair exists to store the internal counter 10-bit value, while a read/write register pair exists to store the internal 10-bit CCRA value. The remaining two registers are control registers which setup the different operating and control modes and the 3-bit CCRP value.

RegisterName

Bit7 6 5 4 3 2 1 0

STMC0 STPAU STCK2 STCK1 STCK0 STON STRP2 STRP1 STRP0STMC1 STM1 STM0 STIO1 STIO0 STOC STPOL STDPX STCCLRSTMDL D7 D6 D5 D4 D3 D2 D1 D0STMDH — — — — — — D9 D8STMAL D7 D6 D5 D4 D3 D2 D1 D0STMAH — — — — — — D9 D8

10-bit Standard Type TM Register List

Page 60: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 60 December 27, 2019 Rev. 1.30 61 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• STMC0 RegisterBit 7 6 5 4 3 2 1 0

Name STPAU STCK2 STCK1 STCK0 STON STRP2 STRP1 STRP0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7 STPAU: STM counter pause control0: Run1: Pause

The counter can be paused by setting this bit high. Clearing the bit to zero restores normal counter operation. When in a Pause condition the STM will remain powered up and continue to consume power. The counter will retain its residual value when this bit changes from low to high and resume counting from this value when the bit changes to a low value again.

Bit 6~4 STCK2~STCK0: Select STM counter clock000: fSYS/4001: fSYS

010: fH/16011: fH/64100: fSUB

101: fSUB

110: STCK rising edge clock111: STCK falling edge clock

These three bits are used to select the clock source for the STM. The external pin clock source can be chosen to be active on the rising or falling edge. The clock source fSYS is the system clock, while fH and fSUB are other internal clocks, the details of which can be found in the oscillator section.

Bit 3 STON: STM counter on/off control0: Off1: On

This bit controls the overall on/off function of the STM. Setting the bit high enables the counter to run while clearing the bit disables the STM. Clearing this bit to zero will stop the counter from counting and turn off the STM which will reduce its power consumption. When the bit changes state from low to high the internal counter value will be reset to zero, however when the bit changes from high to low, the internal counter will retain its residual value until the bit returns high again. If the STM is in the Compare Match Output Mode, PWM Output Mode and Single Pulse Output Mode then the STM output pin will be reset to its initial condition, as specified by the STOC bit, when the STON bit changes from low to high.

Bit 2~0 STRP2~STRP0: STM CCRP 3-bit register, compared with the STM counter bit 9 ~ bit 7Comparator P Match Period

000: 1024 STM clocks001: 128 STM clocks010: 256 STM clocks011: 384 STM clocks100: 512 STM clocks101: 640 STM clocks110: 768 STM clocks111: 896 STM clocks

These three bits are used to setup the value on the internal CCRP 3-bit register, which are then compared with the internal counter's highest three bits. The result of this comparison can be selected to clear the internal counter if the STCCLR bit is cleared to zero. Clearing the STCCLR 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

Page 61: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 60 December 27, 2019 Rev. 1.30 61 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

the highest three counter bits, the compare values exist in 128 clock cycle multiples. Clearing all three bits to zero is in effect allowing the counter to overflow at its maximum value.

• STMC1 RegisterBit 7 6 5 4 3 2 1 0

Name STM1 STM0 STIO1 STIO0 STOC STPOL STDPX STCCLRR/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~6 STM1~STM0: Select STM operating mode00: Compare Match Output Mode01: Capture Input Mode10: PWM Output Mode or Single Pulse Output Mode11: Timer/Counter Mode

These bits setup the required operating mode for the STM. To ensure reliable operation the STM should be switched off before any changes are made to the STM1 and STM0 bits. In the Timer/Counter Mode, the STM output pin state is undefined.

Bit 5~4 STIO1~STIO0: Select STM functionCompare Match Output Mode

00: No change01: Output low10: Output high11: Toggle output

PWM Output Mode/Single Pulse Output Mode00: PWM output inactive state01: PWM output active state10: PWM output11: Single Pulse Output

Capture Input Mode00: Input capture at rising edge of STPI01: Input capture at falling edge of STPI10: Input capture at rising/falling edge of STPI11: Input capture disabled

Timer/Counter ModeUnused

These two bits are used to determine how the STM output pin changes state when a certain condition is reached. The function that these bits select depends upon in which mode the STM is running.In the Compare Match Output Mode, the STIO1 and STIO0 bits determine how the STM output pin changes state when a compare match occurs from the Comparator A. The STM output pin can be setup to switch high, switch low or to toggle its present state when a compare match occurs from the Comparator A. When the bits are both zero, then no change will take place on the output. The initial value of the STM output pin should be setup using the STOC bit in the STMC1 register. Note that the output level requested by the STIO1 and STIO0 bits must be different from the initial value setup using the STOC bit otherwise no change will occur on the STM output pin when a compare match occurs. After the STM output pin changes state, it can be reset to its initial level by changing the level of the STON bit from low to high.In the PWM Output Mode, the STIO1 and STIO0 bits determine how the STM output pin changes state when a certain compare match condition occurs. The PWM output function is modified by changing these two bits. It is necessary to only change the values of the STIO1 and STIO0 bits only after the STM has been switched off. Unpredictable PWM outputs will occur if the STIO1 and STIO0 bits are changed when the STM is running.

Page 62: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 62 December 27, 2019 Rev. 1.30 63 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Bit 3 STOC: STM STP output controlCompare Match Output Mode

0: Initial low1: Initial high

PWM Output Mode/Single Pulse Output Mode0: Active low1: Active high

This is the output control bit for the STM output pin. Its operation depends upon whether STM is being used in the Compare Match Output Mode or in the PWM Output Mode/Single Pulse Output Mode. It has no effect if the STM is in the Timer/Counter Mode. In the Compare Match Output Mode it determines the logic level of the STM output pin before a compare match occurs. In the PWM Output Mode it determines if the PWM signal is active high or active low. In the Single Pulse Output Mode it determines the logic level of the STM output pin when the STON bit changes from low to high.

Bit 2 STPOL: STM STP output polarity control0: Non-invert1: Invert

This bit controls the polarity of the STP output pin. When the bit is set high the STM output pin will be inverted and not inverted when the bit is zero. It has no effect if the STM is in the Timer/Counter Mode.

Bit 1 STDPX: STM PWM period/duty control0: CCRP – period; CCRA – duty1: CCRP – duty; CCRA – period

This bit determines which of the CCRA and CCRP registers are used for period and duty control of the PWM waveform.

Bit 0 STCCLR: STM counter clear condition selection0: Comparator P match1: Comparator A match

This bit is used to select the method which clears the counter. Remember that the Standard type TM contains two comparators, Comparator A and Comparator P, either of which can be selected to clear the internal counter. With the STCCLR bit set high, the counter will be cleared when a compare match occurs from the Comparator A. When the bit is low, the counter will be cleared when a compare match occurs from the Comparator P or with a counter overflow. A counter overflow clearing method can only be implemented if the CCRP bits are all cleared to zero. The STCCLR bit is not used in the PWM Output Mode, Single Pulse Output Mode or Capture Input Mode.

• STMDL RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R R R R R R R RPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: STM counter low byte register bit 7 ~ bit 0STM 10-bit counter bit 7 ~ bit 0

• STMDH RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — D9 D8R/W — — — — — — R RPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 D9~D8: STM counter high byte register bit 1 ~ bit 0

STM 10-bit counter bit 9 ~ bit 8

Page 63: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 62 December 27, 2019 Rev. 1.30 63 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• STMAL RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: STM CCRA low byte register bit 7 ~ bit 0STM 10-bit CCRA bit 7 ~ bit 0

• STMAH RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — D9 D8R/W — — — — — — R/W R/WPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 D9~D8: STM CCRA high byte register bit 1 ~ bit 0

STM 10-bit counter bit 9 ~ bit 8

Standard Type TM Operation ModesThe Standard Type TM can operate in one of five operating modes, Compare Match Output Mode, PWM Output Mode, Single Pulse Output Mode, Capture Input Mode or Timer/Counter Mode. The operating mode is selected using the STM1 and STM0 bits in the STMC1 register.

Compare Match Output ModeTo select this mode, bits STM1 and STM0 in the STMC1 register, should be set to 00 respectively. In this mode once the counter is enabled and running it can be cleared by three methods. These are a counter overflow, a compare match from Comparator A and a compare match from Comparator P. When the STCCLR bit is low, there are two ways in which the counter can be cleared. One is when a compare match from Comparator P, the other is when the CCRP bits are all zero which allows the counter to overflow. Here both STMAF and STMPF interrupt request flags for Comparator A and Comparator P respectively, will both be generated.

If the STCCLR bit in the STMC1 register is high then the counter will be cleared when a compare match occurs from Comparator A. However, here only the STMAF interrupt request flag will be generated even if the value of the CCRP bits is less than that of the CCRA registers. Therefore when STCCLR is high no STMPF interrupt request flag will be generated. In the Compare Match Output Mode, the CCRA can not be cleared to “0”. If the CCRA bits are all zero, the counter will overflow when its reaches its maximum 10-bit, 3FF Hex, value, however here the STMAF interrupt request flag will not be generated.

As the name of the mode suggests, after a comparison is made, the STM output pin, will change state. The STM output pin condition however only changes state when an STMAF interrupt request flag is generated after a compare match occurs from Comparator A. The STMPF interrupt request flag, generated from a compare match occurs from Comparator P, will have no effect on the STM output pin. The way in which the STM output pin changes state are determined by the condition of the STIO1 and STIO0 bits in the STMC1 register. The STM output pin can be selected using the STIO1 and STIO0 bits to go high, to go low or to toggle from its present condition when a compare match occurs from Comparator A. The initial condition of the STM output pin, which is setup after the STON bit changes from low to high, is setup using the STOC bit. Note that if the STIO1 and STIO0 bits are zero then no pin change will take place.

Page 64: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 64 December 27, 2019 Rev. 1.30 65 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

0x3FF

CCRP

CCRA

STON

STPAU

STPOL

CCRP Int. Flag STMPF

CCRA Int. Flag STMAF

STM O/P Pin

Time

CCRP=0

CCRP > 0

Counter overflow

CCRP > 0

Counter cleared by CCRP value

Pause

Resume

Stop

Counter Restart

STCCLR = 0; STM [1:0] = 00

Output pin set to initial Level Low if STOC=0

Output Toggle with STMAF flag

Note STIO [1:0] = 10 Active High Output selectHere STIO [1:0] = 11

Toggle Output select

Output not affected by STMAF flag. Remains High until reset by STON bit

Output PinReset to Initial value

Output controlled by other pin-shared function

Output Invertswhen STPOL is high

Compare Match Output Mode – STCCLR=0

Note: 1. With STCCLR=0 a Comparator P match will clear the counter2. The STM output pin is controlled only by the STMAF flag3. The output pin is reset to its initial state by an STON bit rising edge

Page 65: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 64 December 27, 2019 Rev. 1.30 65 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

0x3FF

CCRP

CCRA

STON

STPAU

STPOL

CCRP Int. Flag STMPF

CCRA Int. Flag STMAF

STM O/P Pin

Time

CCRA=0

CCRA = 0Counter overflow

CCRA > 0 Counter cleared by CCRA value

Pause

Resume

Stop Counter Restart

STCCLR = 1; STM [1:0] = 00

Output pin set to initial Level Low if STOC=0

Output Toggle with STMAF flag

Note STIO [1:0] = 10 Active High Output selectHere STIO [1:0] = 11

Toggle Output select

Output not affected by STMAF flag. Remains High until reset by STON bit

Output PinReset to Initial value

Output controlled by other pin-shared function

Output Invertswhen STPOL is high

STMPF not generated

No STMAF flag generated onCCRA overflow

Output doesnot change

Compare Match Output Mode – STCCLR=1

Note: 1. With STCCLR=1 a Comparator A match will clear the counter2. The STM output pin is controlled only by the STMAF flag3. The output pin is reset to its initial state by an STON bit rising edge4. An STMPF flag is not generated when STCCLR=1

Page 66: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 66 December 27, 2019 Rev. 1.30 67 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Timer/Counter ModeTo select this mode, bits STM1 and STM0 in the STMC1 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 STM 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 STM output pin is not used in this mode, the pin can be used as a normal I/O pin or other pin-shared function.

PWM Output ModeTo select this mode, bits STM1 and STM0 in the STMC1 register should be set to 10 respectively and also the STIO1 and STIO0 bits should be set to 10 respectively. The PWM function within the STM is useful for applications which require functions such as motor control, heating control, illumination control etc. By providing a signal of fixed frequency but of varying duty cycle on the STM output pin, a square wave AC waveform can be generated with varying equivalent DC RMS values.

As both the period and duty cycle of the PWM waveform can be controlled, the choice of generated waveform is extremely flexible. In the PWM Output Mode, the STCCLR bit has no effect as the PWM period. Both of the CCRA and CCRP registers are used to generate the PWM waveform, one register is used to clear the internal counter and thus control the PWM waveform frequency, while the other one is used to control the duty cycle. Which register is used to control either frequency or duty cycle is determined using the STDPX bit in the STMC1 register. The PWM waveform frequency and duty cycle can therefore be controlled by the values in the CCRA and CCRP registers.

An interrupt flag, one for each of the CCRA and CCRP, will be generated when a compare match occurs from either Comparator A or Comparator P. The STOC bit in the STMC1 register is used to select the required polarity of the PWM waveform while the two STIO1 and STIO0 bits are used to enable the PWM output or to force the STM output pin to a fixed high or low level. The STPOL bit is used to reverse the polarity of the PWM output waveform.

• 10-bit STM, PWM Output Mode, Edge-aligned Mode, STDPX=0CCRP 1~7 0Period CCRP×128 1024Duty CCRA

If fSYS=8MHz, TM clock source is fSYS/4, CCRP=2 and CCRA=128,

The STM PWM output frequency=(fSYS/4)/(2×128)=fSYS/1024=7.8125kHz, duty=128/(2×128)=50%.

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%.

• 10-bit STM, PWM Output Mode, Edge-aligned Mode, STDPX=1CCRP 1~7 0Period CCRADuty CCRP×128 1024

The PWM output period is determined by the CCRA register value together with the STM clock while the PWM duty cycle is defined by the CCRP register value.

Page 67: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 66 December 27, 2019 Rev. 1.30 67 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

CCRP

CCRA

STON

STPAU

STPOL

CCRP Int. Flag STMPF

CCRA Int. Flag STMAF

STM O/P Pin(STOC=1)

Time

Counter cleared by CCRP

Pause ResumeCounter Stop if STON bit low

Counter Reset when STON returns high

STDPX = 0; STM [1:0] = 10

PWM Duty Cycle set by CCRA

PWM resumes operation

Output controlled by other pin-shared function Output Inverts

when STPOL = 1PWM Period set by CCRP

STM O/P Pin(STOC=0)

PWM Output Mode – STDPX=0

Note: 1. Here STDPX=0 – Counter cleared by CCRP2. A counter clear sets the PWM Period3. The internal PWM function continues running even when STIO [1:0]=00 or 014. The STCCLR bit has no influence on PWM operation

Page 68: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 68 December 27, 2019 Rev. 1.30 69 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

CCRP

CCRA

STON

STPAU

STPOL

CCRP Int. Flag STMPF

CCRA Int. Flag STMAF

STM O/P Pin (STOC=1)

Time

Counter cleared by CCRA

Pause ResumeCounter Stop if STON bit low

Counter Reset when STON returns high

STDPX = 1; STM [1:0] = 10

PWM Duty Cycle set by CCRP

PWM resumes operation

Output controlled by other pin-shared function Output Inverts

when STPOL = 1PWM Period set by CCRA

STM O/P Pin (STOC=0)

PWM Output Mode – STDPX=1

Note: 1. Here STDPX=1 – Counter cleared by CCRA2. A counter clear sets the PWM Period3. The internal PWM function continues even when STIO [1:0]=00 or 014. The STCCLR bit has no influence on PWM operation

Page 69: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 68 December 27, 2019 Rev. 1.30 69 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Single Pulse Output ModeTo select this mode, bits STM1 and STM0 in the STMC1 register should be set to 10 respectively and also the STIO1 and STIO0 bits should be set to 11 respectively. The Single Pulse Output Mode, as the name suggests, will generate a single shot pulse on the STM output pin.

The trigger for the pulse output leading edge is a low to high transition of the STON bit, which can be implemented using the application program. However in the Single Pulse Output Mode, the STON bit can also be made to automatically change from low to high using the STCK pin, which will in turn initiate the Single Pulse output. When the STON bit transitions to a high level, the counter will start running and the pulse leading edge will be generated. The STON bit should remain high when the pulse is in its active state. The generated pulse trailing edge will be generated when the STON bit is cleared to zero, which can be implemented using the application program or when a compare match occurs from Comparator A.

However a compare match from Comparator A will also automatically clear the STON bit and thus generate the Single Pulse output trailing edge. In this way the CCRA value can be used to control the pulse width. A compare match from Comparator A will also generate an STM interrupt. The counter can only be reset back to zero when the STON bit changes from low to high when the counter restarts. In the Single Pulse Output Mode CCRP is not used. The STCCLR and STDPX bits are not used in this Mode.

STON bit0 → 1

S/W Command SET“STON”

orSTCK Pin Transition

STON bit1 → 0

CCRA Trailing Edge

S/W Command CLR“STON”

orCCRA Compare Match

STP Output Pin

Pulse Width = CCRA Value

CCRA Leading Edge

Single Pulse Generation

Page 70: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 70 December 27, 2019 Rev. 1.30 71 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

CCRP

CCRA

STON

STPAU

STPOL

CCRP Int. Flag STMPF

CCRA Int. Flag STMAF

STM O/P Pin(STOC=1)

Time

Counter stopped by CCRA

PauseResume Counter Stops by

software

Counter Reset when STON returns high

STM [1:0] = 10 ; STIO [1:0] = 11

Pulse Width set by CCRA

Output Invertswhen STPOL = 1

No CCRP Interrupts generated

STM O/P Pin(STOC=0)

STCK pin

Software Trigger

Cleared by CCRA match

STCK pin Trigger

Auto. set by STCK pin

Software Trigger

Software Clear

Software TriggerSoftware

Trigger

Single Pulse Output Mode

Note: 1. Counter stopped by CCRA2. CCRP is not used3. The pulse triggered by the STCK pin or by setting the STON bit high4. An STCK pin active edge will automatically set the STON bit high5. In the Single Pulse Output Mode, STIO [1:0] must be set to 11 and can not be changed

Page 71: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 70 December 27, 2019 Rev. 1.30 71 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Capture Input ModeTo select this mode bits STM1 and STM0 in the STMC1 register should be set to 01 respectively. This mode enables external signals to capture and store the present value of the internal counter and can therefore be used for applications such as pulse width measurements. The external signal is supplied on the STPI pin, whose active edge can be a rising edge, a falling edge or both rising and falling edges; the active edge transition type is selected using the STIO1 and STIO0 bits in the STMC1 register. The counter is started when the STON bit changes from low to high which is initiated using the application program.

When the required edge transition appears on the STPI pin the present value in the counter will be latched into the CCRA registers and an STM interrupt generated. Irrespective of what events occur on the STPI pin the counter will continue to free run until the STON bit changes from high to low. When a CCRP compare match occurs the counter will reset back to zero; in this way the CCRP value can be used to control the maximum counter value. When a CCRP compare match occurs from Comparator P, an STM interrupt will also be generated. Counting the number of overflow interrupt signals from the CCRP can be a useful method in measuring long pulse widths. The STIO1 and STIO0 bits can select the active trigger edge on the STPI pin to be a rising edge, falling edge or both edge types. If the STIO1 and STIO0 bits are both set high, then no capture operation will take place irrespective of what happens on the STPI pin, however it must be noted that the counter will continue to run. The STCCLR and STDPX bits are not used in this Mode.

Page 72: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 72 December 27, 2019 Rev. 1.30 73 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

YY

CCRP

STON

STPAU

CCRP Int. Flag STMPF

CCRA Int. Flag STMAF

CCRA Value

Time

Counter cleared by CCRP

PauseResume

Counter Reset

STM [1:0] = 01

STM capture pin STPI

XX

Counter Stop

STIO [1:0] Value

XX YY XX YY

Activeedge Active

edgeActive edge

00 – Rising edge 01 – Falling edge 10 – Both edges 11 – Disable Capture

Capture Input Mode

Note: 1. STM [1:0]=01 and active edge set by the STIO [1:0] bits2. An STM capture input pin active edge transfers the counter value to CCRA3. STCCLR bit not used4. No output function – STOC and STPOL bits are not used5. CCRP determines the counter value and the counter has a maximum count value when CCRP is equal to zero

Page 73: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 72 December 27, 2019 Rev. 1.30 73 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Periodic Type TM – PTMThe Periodic Type TM contains five operating modes, which are Compare Match Output, Timer/Event Counter, Capture Input, Single Pulse Output and PWM Output modes. The Periodic Type TM can also be controlled with two external input pins and can drive one external output pin.

fSYS

fSYS/4

fH/64fH/16

fSUB

PTCK

000001010011100101110111

PTCK2~PTCK0

10-bit Count-up Counter

10-bit Comparator P

CCRP

b0~b9

b0~b9

10-bit Comparator A

PTONPTPAU

Comparator A Match

Comparator P Match

Counter Clear 01

Output Control

Polarity Control

Pin Control PTP

PTOC

PTM1~PTM0PTIO1~PTIO0

PTMAF Interrupt

PTMPF Interrupt

PTPOL

CCRA

PTCCLR

Edge Detector

PTPI

PTIO1~PTIO0

fSUB

10

PTCAPTS

PAS1

10-bit Periodic Type TM Block Diagram

Periodic Type TM OperationThe size of Periodic Type 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 PTON 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 PTM 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.

Periodic Type TM Register DescriptionOverall operation of the Periodic Type TM is controlled using a series of registers. A read only register pair exists to store the internal counter 10-bit value, while two read/write register pairs exist to store the internal 10-bit CCRA and CCRP value. The remaining two registers are control registers which setup the different operating and control modes.

Register Name

Bit7 6 5 4 3 2 1 0

PTMC0 PTPAU PTCK2 PTCK1 PTCK0 PTON — — —PTMC1 PTM1 PTM0 PTIO1 PTIO0 PTOC PTPOL PTCAPTS PTCCLRPTMDL D7 D6 D5 D4 D3 D2 D1 D0PTMDH — — — — — — D9 D8PTMAL D7 D6 D5 D4 D3 D2 D1 D0PTMAH — — — — — — D9 D8PTMRPL D7 D6 D5 D4 D3 D2 D1 D0PTMRPH — — — — — — D9 D8

10-bit Periodic Type TM Register List

Page 74: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 74 December 27, 2019 Rev. 1.30 75 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• PTMC0 RegisterBit 7 6 5 4 3 2 1 0

Name PTPAU PTCK2 PTCK1 PTCK0 PTON — — —R/W R/W R/W R/W R/W R/W — — —POR 0 0 0 0 0 — — —

Bit 7 PTPAU: PTM counter pause control0: Run1: Pause

The counter can be paused by setting this bit high. Clearing the bit to zero restores normal counter operation. When in a Pause condition the PTM will remain powered up and continue to consume power. The counter will retain its residual value when this bit changes from low to high and resume counting from this value when the bit changes to a low value again.

Bit 6~4 PTCK2~PTCK0: Select PTM counter clock000: fSYS/4001: fSYS

010: fH/16011: fH/64100: fSUB

101: fSUB

110: PTCK rising edge clock111: PTCK falling edge clock

These three bits are used to select the clock source for the PTM. The external pin clock source can be chosen to be active on the rising or falling edge. The clock source fSYS is the system clock, while fH and fSUB are other internal clocks, the details of which can be found in the oscillator section.

Bit 3 PTON: PTM counter on/off control0: Off1: On

This bit controls the overall on/off function of the PTM. Setting the bit high enables the counter to run while clearing the bit to zero disables the PTM. Clearing this bit to zero will stop the counter from counting and turn off the PTM which will reduce its power consumption. When the bit changes state from low to high the internal counter value will be reset to zero, however when the bit changes from high to low, the internal counter will retain its residual value until the bit returns high again. If the PTM is in the Compare Match Output Mode, PWM Output Mode or Single Pulse Output Mode then the PTM output pin will be reset to its initial condition, as specified by the PTOC bit, when the PTON bit changes from low to high.

Bit 2~0 Unimplemented, read as “0”

• PTMC1 RegisterBit 7 6 5 4 3 2 1 0

Name PTM1 PTM0 PTIO1 PTIO0 PTOC PTPOL PTCAPTS PTCCLRR/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~6 PTM1~PTM0: Select PTM operating mode00: Compare Match Output Mode01: Capture Input Mode10: PWM Output Mode or Single Pulse Output Mode11: Timer/Counter Mode

These bits setup the required operating mode for the PTM. To ensure reliable operation the PTM should be switched off before any changes are made to the PTM1 and PTM0 bits. In the Timer/Counter Mode, the PTM output pin state is undefined.

Page 75: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 74 December 27, 2019 Rev. 1.30 75 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Bit 5~4 PTIO1~PTIO0: Select PTM functionCompare Match Output Mode

00: No change01: Output low10: Output high11: Toggle output

PWM Output Mode/Single Pulse Output Mode00: PWM output inactive state01: PWM output active state10: PWM output11: Single Pulse Output

Capture Input Mode00: Input capture at rising edge of PTPI or PTCK01: Input capture at falling edge of PTPI or PTCK10: Input capture at rising/falling edge of PTPI or PTCK11: Input capture disabled

Timer/Counter ModeUnused

These two bits are used to determine how the PTM output pin changes state when a certain condition is reached. The function that these bits select depends upon in which mode the PTM is running.In the Compare Match Output Mode, the PTIO1 and PTIO0 bits determine how the PTM output pin changes state when a compare match occurs from the Comparator A. The PTM output pin can be setup to switch high, switch low or to toggle its present state when a compare match occurs from the Comparator A. When the bits are both zero, then no change will take place on the output. The initial value of the PTM output pin should be setup using the PTOC bit in the PTMC1 register. Note that the output level requested by the PTIO1 and PTIO0 bits must be different from the initial value setup using the PTOC bit otherwise no change will occur on the PTM output pin when a compare match occurs. After the PTM output pin changes state, it can be reset to its initial level by changing the level of the PTON bit from low to high.In the PWM Output Mode, the PTIO1 and PTIO0 bits determine how the TM output pin changes state when a certain compare match condition occurs. The PTM output function is modified by changing these two bits. It is necessary to only change the values of the PTIO1 and PTIO0 bits only after the PTM has been switched off. Unpredictable PWM outputs will occur if the PTIO1 and PTIO0 bits are changed when the PTM is running.

Bit 3 PTOC: PTM PTP output controlCompare Match Output Mode

0: Initial low1: Initial high

PWM Output Mode/Single Pulse Output Mode0: Active low1: Active high

This is the output control bit for the PTM output pin. Its operation depends upon whether PTM is being used in the Compare Match Output Mode or in the PWM Output Mode/Single Pulse Output Mode. It has no effect if the PTM is in the Timer/Counter Mode. In the Compare Match Output Mode it determines the logic level of the PTM output pin before a compare match occurs. In the PWM Output Mode it determines if the PWM signal is active high or active low. In the Single Pulse Output Mode it determines the logic level of the PTM output pin when PTON bit changes from low to high.

Bit 2 PTPOL: PTM PTP output polarity control0: Non-invert1: Invert

Page 76: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 76 December 27, 2019 Rev. 1.30 77 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

This bit controls the polarity of the PTP output pin. When the bit is set high the PTM output pin will be inverted and not inverted when the bit is zero. It has no effect if the PTM is in the Timer/Counter Mode.

Bit 1 PTCAPTS: PTM capture trigger source selection0: From PTPI pin1: From PTCK pin

Bit 0 PTCCLR: PTM counter clear condition selection0: Comparator P match1: Comparator A match

This bit is used to select the method which clears the counter. Remember that the Periodic type TM contains two comparators, Comparator A and Comparator P, either of which can be selected to clear the internal counter. With the PTCCLR bit set high, the counter will be cleared when a compare match occurs from the Comparator A. When the bit is low, the counter will be cleared when a compare match occurs from the Comparator P or with a counter overflow. A counter overflow clearing method can only be implemented if the CCRP bits are all cleared to zero. The PTCCLR bit is not used in the PWM Output Mode, Single Pulse Output Mode or Capture Input Mode.

• PTMDL RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R R R R R R R RPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: PTM counter low byte register bit 7 ~ bit 0PTM 10-bit counter bit 7 ~ bit 0

• PTMDH RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — D9 D8R/W — — — — — — R RPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 D9~D8: PTM counter high byte register bit 1 ~ bit 0

PTM 10-bit counter bit 9 ~ bit 8

• PTMAL RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: PTM CCRA low byte register bit 7 ~ bit 0PTM 10-bit CCRA bit 7 ~ bit 0

• PTMAH RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — D9 D8R/W — — — — — — R/W R/WPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 D9~D8: PTM CCRA high byte register bit 1 ~ bit 0

PTM 10-bit CCRA bit 9 ~ bit 8

Page 77: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 76 December 27, 2019 Rev. 1.30 77 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• PTMRPL RegisterBit 7 6 5 4 3 2 1 0

Name D7 D6 D5 D4 D3 D2 D1 D0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~0 D7~D0: PTM CCRP low byte register bit 7 ~ bit 0PTM 10-bit CCRP bit 7 ~ bit 0

• PTMRPH RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — — D9 D8R/W — — — — — — R/W R/WPOR — — — — — — 0 0

Bit 7~2 Unimplemented, read as “0”Bit 1~0 D9~D8: PTM CCRP high byte register bit 1 ~ bit 0

PTM 10-bit CCRP bit 9 ~ bit 8

Periodic Type TM Operation ModesThe Periodic Type TM can operate in one of five operating modes, Compare Match Output Mode, PWM Output Mode, Single Pulse Output Mode, Capture Input Mode or Timer/Counter Mode. The operating mode is selected using the PTM1 and PTM0 bits in the PTMC1 register.

Compare Match Output ModeTo select this mode, bits PTM1 and PTM0 in the PTMC1 register, should be set to 00 respectively. In this mode once the counter is enabled and running it can be cleared by three methods. These are a counter overflow, a compare match from Comparator A and a compare match from Comparator P. When the PTCCLR bit is low, there are two ways in which the counter can be cleared. One is when a compare match from Comparator P, the other is when the CCRP bits are all zero which allows the counter to overflow. Here both PTMAF and PTMPF interrupt request flags for Comparator A and Comparator P respectively, will both be generated.

If the PTCCLR bit in the PTMC1 register is high then the counter will be cleared when a compare match occurs from Comparator A. However, here only the PTMAF interrupt request flag will be generated even if the value of the CCRP bits is less than that of the CCRA registers. Therefore when PTCCLR is high no PTMPF interrupt request flag will be generated. In the Compare Match Output Mode, the CCRA can not be cleared to “0”. If the CCRA bits are all zero, the counter will overflow when its reaches its maximum 10-bit, 3FF Hex, value, however here the PTMnAF interrupt request flag will not be generated.

As the name of the mode suggests, after a comparison is made, the PTM output pin will change state. The PTM output pin condition however only changes state when a PTMAF interrupt request flag is generated after a compare match occurs from Comparator A. The PTMPF interrupt request flag, generated from a compare match occurs from Comparator P, will have no effect on the PTM output pin. The way in which the PTM output pin changes state are determined by the condition of the PTIO1 and PTIO0 bits in the PTMC1 register. The PTM output pin can be selected using the PTIO1 and PTIO0 bits to go high, to go low or to toggle from its present condition when a compare match occurs from Comparator A. The initial condition of the PTM output pin, which is setup after the PTON bit changes from low to high, is setup using the PTOC bit. Note that if the PTIO1 and PTIO0 bits are zero then no pin change will take place.

Page 78: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 78 December 27, 2019 Rev. 1.30 79 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

0x3FF

CCRP

CCRA

PTON

PTPAU

PTPOL

CCRP Int. Flag PTMPF

CCRA Int. Flag PTMAF

PTM O/P Pin

Time

CCRP=0

CCRP > 0

Counter overflowCCRP > 0Counter cleared by CCRP value

Pause

Resume

Stop

Counter Restart

Output pin set to initial Level Low if PTOC=0

Output Toggle with PTMAF flag

Note PTIO [1:0] = 10 Active High Output select

Here PTIO [1:0] = 11 Toggle Output select

Output not affected by PTMAF flag. Remains High until reset by PTON bit

Output PinReset to Initial value

Output controlled by other pin-shared function

Output Invertswhen PTPOL is high

PTCCLR = 0; PTM [1:0] = 00

Compare Match Output Mode – PTCCLR=0

Note: 1. With PTCCLR=0, a Comparator P match will clear the counter2. The PTM output pin is controlled only by the PTMAF flag3. The output pin is reset to its initial state by a PTON bit rising edge

Page 79: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 78 December 27, 2019 Rev. 1.30 79 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

0x3FF

CCRP

CCRA

PTON

PTPAU

PTPOL

CCRP Int. Flag PTMPF

CCRA Int. Flag PTMAF

PTM O/P Pin

Time

CCRA=0

CCRA = 0Counter overflowCCRA > 0 Counter cleared by CCRA value

Pause

Resume

Stop Counter Restart

Output pin set to initial Level Low if PTOC=0

Output Toggle with PTMAF flag

Note PTIO [1:0] = 10 Active High Output select

Here PTIO [1:0] = 11 Toggle Output select

Output not affected by PTMAF flag. Remains High until reset by PTON bit

Output PinReset to Initial value

Output controlled by other pin-shared function

Output Invertswhen PTPOL is high

PTMPF not generated

PTCCLR = 1; PTM [1:0] = 00

No PTMAF flag generated onCCRA overflow

Output doesnot change

Compare Match Output Mode – PTCCLR=1

Note: 1. With PTCCLR=1, a Comparator A match will clear the counter2. The PTM output pin is controlled only by the PTMAF flag3. The output pin is reset to its initial state by a PTON bit rising edge4. A PTMPF flag is not generated when PTCCLR=1

Page 80: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 80 December 27, 2019 Rev. 1.30 81 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Timer/Counter ModeTo select this mode, bits PTM1 and PTM0 in the PTMC1 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 PTM 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 PTM output pin is not used in this mode, the pin can be used as a normal I/O pin or other pin-shared function.

PWM Output ModeTo select this mode, bits PTM1 and PTM0 in the PTMC1 register should be set to 10 respectively and also the PTIO1 and PTIO0 bits should be set to 10 respectively. The PWM function within the PTM is useful for applications which require functions such as motor control, heating control, illumination control, etc. By providing a signal of fixed frequency but of varying duty cycle on the PTM output pin, a square wave AC waveform can be generated with varying equivalent DC RMS values.

As both the period and duty cycle of the PWM waveform can be controlled, the choice of generated waveform is extremely flexible. In the PWM Output mode, the PTCCLR bit has no effect as the PWM period. Both of the CCRP and CCRA registers are used to generate the PWM waveform, one register is used to clear the internal counter and thus control the PWM waveform frequency, while the other one is used to control the duty cycle. The PWM waveform frequency and duty cycle can therefore be controlled by the values in the CCRA and CCRP registers.

An interrupt flag, one for each of the CCRA and CCRP, will be generated when a compare match occurs from either Comparator A or Comparator P. The PTOC bit in the PTMC1 register is used to select the required polarity of the PWM waveform while the two PTIO1 and PTIO0 bits are used to enable the PWM output or to force the PTM output pin to a fixed high or low level. The PTPOL bit is used to reverse the polarity of the PWM output waveform.

• 10-bit PTM, PWM Output Mode, Edge-aligned ModeCCRP 1~1023 0Period 1~1023 1024Duty CCRA

If fSYS=8MHz, PTM clock source select fSYS/4, CCRP=512 and CCRA=128,

The PTM PWM output frequency=(fSYS/4)/512=fSYS/2048=4kHz, duty=128/512=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%.

Page 81: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 80 December 27, 2019 Rev. 1.30 81 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

CCRP

CCRA

PTON

PTPAU

PTPOL

CCRP Int. Flag PTMPF

CCRA Int. Flag PTMAF

PTM O/P Pin(PTOC=1)

Time

Counter cleared by CCRP

Pause Resume Counter Stop if PTON bit low

Counter Reset when PTON returns high

PWM Duty Cycle set by CCRA

PWM resumes operation

Output controlled by other pin-shared function Output Inverts

When PTPOL = 1PWM Period set by CCRP

PTM O/P Pin(PTOC=0)

PTM [1:0] = 10

PWM Output Mode

Note: 1. The counter is cleared by CCRP2. A counter clear sets the PWM Period3. The internal PWM function continues running even when PTIO [1:0]=00 or 014. The PTCCLR bit has no influence on PWM operation

Page 82: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 82 December 27, 2019 Rev. 1.30 83 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Single Pulse Output ModeTo select this mode, bits PTM1 and PTM0 in the PTMC1 register should be set to 10 respectively and also the PTIO1 and PTIO0 bits should be set to 11 respectively. The Single Pulse Output Mode, as the name suggests, will generate a single shot pulse on the PTM output pin.

The trigger for the pulse output leading edge is a low to high transition of the PTON bit, which can be implemented using the application program. However in the Single Pulse Output Mode, the PTON bit can also be made to automatically change from low to high using the external PTCK pin, which will in turn initiate the Single Pulse output. When the PTON bit transitions to a high level, the counter will start running and the pulse leading edge will be generated. The PTON bit should remain high when the pulse is in its active state. The generated pulse trailing edge will be generated when the PTON bit is cleared to zero, which can be implemented using the application program or when a compare match occurs from Comparator A.

However a compare match from Comparator A will also automatically clear the PTON bit and thus generate the Single Pulse output trailing edge. In this way the CCRA value can be used to control the pulse width. A compare match from Comparator A will also generate a PTM interrupt. The counter can only be reset back to zero when the PTON bit changes from low to high when the counter restarts. In the Single Pulse Output Mode CCRP is not used. The PTCCLR is not used in this Mode.

PTON bit0 1

S/W Command SET“PTON”

orPTCK Pin Transition

PTON bit1 0

CCRATrailing Edge

S/W Command CLR“PTON”

orCCRA Compare Match

PTP Output Pin

Pulse Width = CCRA Value

CCRA Leading Edge

Single Pulse Generation

Page 83: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 82 December 27, 2019 Rev. 1.30 83 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

CCRP

CCRA

PTON

PTPAU

PTPOL

CCRP Int. Flag PTMPF

CCRA Int. Flag PTMAF

PTM O/P Pin(PTOC=1)

Time

Counter stopped by CCRA

PauseResume Counter Stops by

software

Counter Reset when PTON returns high

Pulse Width set by CCRA

Output Invertswhen PTPOL = 1

PTM O/P Pin(PTOC=0)

PTCK pin

Software Trigger

PTCK pin Trigger

Auto. set by PTCK pin

Software Clear

Software Trigger

PTM [1:0] = 10; PTIO [1:0] = 11

No CCRP Interrupts generated

Software Trigger

Cleared by CCRA match Software

Trigger

Single Pulse Output Mode

Note: 1. Counter stopped by CCRA2. CCRP is not used3. The pulse triggered by the PTCK pin or by setting the PTON bit high4. A PTCK pin active edge will automatically set the PTON bit high5. In the Single Pulse Output Mode, PTIO [1:0] must be set to 11 and can not be changed

Page 84: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 84 December 27, 2019 Rev. 1.30 85 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Capture Input ModeTo select this mode bits PTM1 and PTM0 in the PTMC1 register should be set to 01 respectively. This mode enables external signals to capture and store the present value of the internal counter and can therefore be used for applications such as pulse width measurements. The external signal is supplied on the PTPI or PTCK pin, selected by the PTCAPTS bit in the PTMC1 register. The input pin active edge can be either a rising edge, a falling edge or both rising and falling edges; the active edge transition type is selected using the PTIO1 and PTIO0 bits in the PTMC1 register. The counter is started when the PTON bit changes from low to high which is initiated using the application program.

When the required edge transition appears on the PTPI or PTCK pin the present value in the counter will be latched into the CCRA registers and a PTM interrupt generated. Irrespective of what events occur on the PTPI or PTCK pin the counter will continue to free run until the PTON bit changes from high to low. When a CCRP compare match occurs the counter will reset back to zero; in this way the CCRP value can be used to control the maximum counter value. When a CCRP compare match occurs from Comparator P, a PTM interrupt will also be generated. Counting the number of overflow interrupt signals from the CCRP can be a useful method in measuring long pulse widths. The PTIO1 and PTIO0 bits can select the active trigger edge on the PTPI or PTCK pin to be a rising edge, falling edge or both edge types. If the PTIO1 and PTIO0 bits are both set high, then no capture operation will take place irrespective of what happens on the PTPI or PTCK pin, however it must be noted that the counter will continue to run.

As the PTPI or PTCK pin is pin shared with other functions, care must be taken if the PTM is in the Input Capture Mode. This is because if the pin is setup as an output, then any transitions on this pin may cause an input capture operation to be executed. The PTCCLR, PTOC and PTPOL bits are not used in this Mode.

Page 85: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 84 December 27, 2019 Rev. 1.30 85 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Counter Value

YY

CCRP

PTON

PTPAU

CCRP Int. Flag PTMPF

CCRA Int. Flag PTMAF

CCRA Value

Time

Counter cleared by CCRP

PauseResume

Counter Reset

PTM [1:0] = 01

PTM Capture pinPTPI or PTCK

XX

Counter Stop

PTIO [1:0] Value

XX YY XX YY

Active edge Active

edge

00 – Rising edge 01 – Falling edge 10 – Both edges 11 – Disable Capture

Active edge

Capture Input Mode

Note: 1. PTM [1:0]=01 and active edge set by the PTIO [1:0] bits2. A PTM Capture input pin active edge transfers the counter value to CCRA3. PTCCLR bit not used4. No output function – PTOC and PTPOL bits are not used5. CCRP determines the counter value and the counter has a maximum count value when CCRP is equal to zero

Page 86: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 86 December 27, 2019 Rev. 1.30 87 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Analog to Digital ConverterThe need to interface to real world analog signals is a common requirement for many electronic systems. However, to properly process these signals by a microcontroller, they must first be converted into digital signals by A/D converters. By integrating the A/D conversion electronic circuitry into the microcontroller, the need for external components is reduced significantly with the corresponding follow-on benefits of lower costs and reduced component space requirements.

A/D Converter OverviewThe device contains a multi-channel analog to digital converter which can directly interface to external analog signals, such as that from sensors or other control signals, or the internal analog signals, such as an internal voltage sourced from the A/D converter power divided by 4, and convert these signals directly into a 10-bit digital value. When the external analog signal is to be converted, the corresponding pin-shared control bit should first be properly configured and then the desired external channel input should be selected using the SACS3~SACS0 bits and SAINS2~SAINS0 bits. More detailed information about the A/D input signal selection is described in the “A/D Converter Control Registers” and “A/D Converter Input Signals” sections respectively.

External Input Channels Internal Signal A/D Channel

Selection Bits

8: AN0~AN7 VDD/4 SAINS2~SAINS0,SACS3~SACS0

The accompanying block diagram shows the overall internal structure of the A/D converter together with its associated registers.

Pin-shared Selection SACS3~SACS0

A/D Converter

START ADBZ ADCEN

VSS

A/D Clock

÷ 2N

(N=0~7)

fSYS

SACKS2~SACKS0

VDD

ADCEN

SADOL

SADOH

AN0

AN1

AN7 A/D Reference Voltage

A/D DataRegisters

ADRFS

VDD

SAVRS1~SAVRS0VREF

Pin-shared Selection

AN6

SAINS2~SAINS0

VDD/4 VVROPAVBG

A/D Converter Structure

Page 87: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 86 December 27, 2019 Rev. 1.30 87 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

A/D Converter Register DescriptionOverall operation of the A/D converter is controlled using five registers. A read only register pair exists to store the A/D converter data 10-bit single value. The remaining two registers are control registers which configure the operating and control function of the A/D converter. The VBGC register contains the VBGEN bit to control the bandgap reference voltage, which can be used as the OPA input signal.

Register Name

Bit7 6 5 4 3 2 1 0

SADOL(ADRFS=0) D1 D0 — — — — — —

SADOL(ADRFS=1) D7 D6 D5 D4 D3 D2 D1 D0

SADOH(ADRFS=0) D9 D8 D7 D6 D5 D4 D3 D2

SADOH(ADRFS=1) — — — — — — D9 D8

SADC0 START ADBZ ADCEN ADRFS SACS3 SACS2 SACS1 SACS0SADC1 SAINS2 SAINS1 SAINS0 SAVRS1 SAVRS0 SACKS2 SACKS1 SACKS0VBGC — — — — VBGEN — — —

A/D Converter Register List

A/D Converter Data Registers – SADOL, SADOHAs the internal A/D converter provides a 10-bit digital conversion value, it requires two data registers to store the converted value. These are a high byte register, known as SADOH, and a low byte register, known as SADOL. After the conversion process takes place, these registers can be directly read by the microcontroller to obtain the digitised conversion value. As only 10 bits of the 16-bit register space is utilised, the format in which the data is stored is controlled by the ADRFS bit in the SADC0 register, as shown in the accompanying table. D0~D9 are the conversion result data bits. Any unused bits will be read as zero. Note that A/D data registers contents will be unchanged if the A/D converter is disabled.

ADRFSSADOH SADOL

7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 00 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 01 0 0 0 0 0 0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

A/D Converter Data Registers

A/D Converter Control Registers – SADC0, SADC1To control the function and operation of the A/D converter, two control registers known as SADC0 and SADC1 are provided. These 8-bit registers define functions such as the selection of which analog channel is connected to the internal A/D converter, the digitised data format, the A/D clock source as well as controlling the start function and monitoring the A/D converter busy status. As each device contains only one actual analog to digital converter hardware circuit, each of the external analog signal inputs must be routed to the converter. The SAINS2~SAINS0 bits in the SADC1 register are used to determine that the analog signal to be converted comes from the internal analog signal or external analog channel input. The SACS3~SACS0 bits in the SADC0 register are used to determine which external channel input is selected to be converted.

Page 88: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 88 December 27, 2019 Rev. 1.30 89 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

The relevant pin-shared function selection bits determine which pins on I/O Ports are used as analog inputs 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 function 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 RegisterBit 7 6 5 4 3 2 1 0

Name START ADBZ ADCEN ADRFS SACS3 SACS2 SACS1 SACS0R/W R/W R R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7 START: Start the A/D conversion0→1→0: Start A/D conversion

This bit is used to initiate an A/D conversion process.Bit 6 ADBZ: A/D converter busy flag

0: No A/D conversion is in progress1: A/D conversion is in progress

This read only flag is used to indicate whether the A/D conversion is in progress or not. When the START bit is set from low to high and then to low again, the ADBZ flag will be set to 1 to indicate that the A/D conversion is initiated. The ADBZ flag will be cleared to 0 after the A/D conversion is complete.

Bit 5 ADCEN: A/D converter function enable control0: Disable1: Enable

This bit controls the A/D internal function. This bit should be set to 1 to enable the A/D converter. If the bit is cleared to zero, then the A/D converter will be switched off reducing the device power consumption. When the A/D converter function is disabled, the contents of the A/D data register pair known as SADOH and SADOL will be unchanged.

Bit 4 ADRFS: A/D converter data format selection0: A/D converter data format → SADOH=D[9:2]; SADOL=D[1:0]1: A/D converter data format → SADOH=D[9:8]; SADOL=D[7:0]

This bit controls the format of the 10-bit converted A/D value in the two A/D data registers. Details are provided in the A/D data register section.

Bit 3~0 SACS3~SACS0: A/D converter external analog channel input selection0000: AN00001: AN10010: AN20011: AN30100: AN40101: AN50110: AN60111: AN71000~1111: Undefined, input floating

These bits are used to select which external analog input channel is to be converted. When the external analog input channel is selected, the SAINS bit field must set to “000” or “101~111”. Details are summarized in the “A/D Converter Input Signal Selection” table.

Page 89: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 88 December 27, 2019 Rev. 1.30 89 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• ADC1 RegisterBit 7 6 5 4 3 2 1 0

Name SAINS2 SAINS1 SAINS0 SAVRS1 SAVRS0 SACKS2 SACKS1 SACKS0R/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7~5 SAINS2~SAINS0: A/D converter input signal selection000: External source – External analog channel input, ANn001: Unused, connected to ground010: Unused, connected to ground011: Unused, connected to ground100: Internal source – Internal signal derived from VDD/4101~111: External source – External analog channel input, ANn

Care must be taken if the SAINS2~SAINS0 bits are set to “100” to select the internal analog signal to be converted. When the internal analog signal is selected to be converted, the external input pin must never be selected as the A/D converter input channel by properly setting the SACS3~SACS0 bits with a value from 1000 to 1111. Otherwise, the external channel input will be connected together with the internal analog signal. This will result in unpredictable situations such as an irreversible damage

Bit 4~3 SAVRS1~SAVRS0: A/D converter reference voltage selection00: External VREF pin01: Internal A/D converter power supply, VDD

10: Internal OPA output, VVR

11: External VREF pinThese bits are used to select the A/D converter reference voltage. Care must be taken if the SAVRS1~SAVRS0 bits are set to “01” or “10” to select the internal reference voltage sources. In this condition, the VREF pin can not be configured as the reference voltage input by properly configuring the corresponding pin-shared function control bit. Otherwise, the external input voltage on the VREF pin will be connected together with the internal reference voltage. This will result in unpredictable situations.

Bit 2~0 SACKS2~SACKS0: A/D conversion clock source selection000: fSYS

001: fSYS/2010: fSYS/4011: fSYS/8100: fSYS/16101: fSYS/32110: fSYS/64111: fSYS/128These three bits are used to select the clock source for the A/D converter.

• VBGC RegisterBit 7 6 5 4 3 2 1 0

Name — — — — VBGEN — — —R/W — — — — R/W — — —POR — — — — 0 — — —

Bit 7~4 Unimplemented, read as “0”Bit 3 VBGEN: VBG Bandgap reference control

0: Disable1: Enable

Note that the Bandgap circuit is enabled when the LVR function is enabled or when the VBGEN bit is set high.

Bit 2~0 Unimplemented, read as “0”

Page 90: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 90 December 27, 2019 Rev. 1.30 91 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

A/D Converter Reference VoltageThe reference voltage supply to the A/D converter can be supplied from the internal A/D converter power supply voltage, VDD, or internal operational amplifer output voltage, VVR, or from an external reference source supplied on pin VREF. The desired selection is made using the SAVRS1~SAVRS0 bits. When the SAVRS bit field is set to “01”, the A/D converter reference voltage will come from the power supply voltage, VDD. When the SAVRS bit field is set to “10”, the A/D converter reference voltage will come from the internal operational amplifer output voltage, VVR. Otherwise, if the SAVRS bit field is set to other value except “01” and “10”, the A/D converter reference voltage will come from the VREF pin. As the VREF pin is pin-shared with other functions, when the VREF pin is selected as the reference voltage supply pin, the VREF pin-shared function control bit should be properly configured to disable other pin functions. However, if the internal reference signal is selected as the reference voltage, the VREF pin must not be configured as the reference voltage input function to avoid the internal connection between the VREF pin and the internal reference signal. The analog input values must not be allowed to exceed the selected reference voltage.

SAVRS[1:0] Reference Source Description00, 11 VREF pin From external A/D converter reference pin VREF

01 VDD From internal A/D converter power supply voltage10 VVR From internal operational amplifier output voltage

A/D Converter Reference Voltage Selection

A/D Converter Input SignalsAll the external A/D converter analog channel input pins are pin-shared with the I/O pins as well as other functions. The corresponding control bits for each A/D converter external input pin in the pin-shared function selection register determine whether the input pins are set as A/D converter analog inputs or whether they have other functions. If the pin is set to be as an A/D converter analog channel input, the original pin functions will be disabled. In this way, pins can be changed under program control to change their function between A/D inputs and other functions. All pull high resistors, which are set through register programming, will be automatically disconnected if the pins are set as A/D inputs. Note that it is not necessary to first set the A/D pin as an input in the port control register to enable the A/D input as when the pin-shared function control bits enable an A/D input, the status of the port control register will be overridden.

If the SAINS2~SAINS0 bits are set to “000” or “101~111”, the external analog channel input is selected to be converted and the SACS3~SACS0 bits can determine which actual external channel is selected to be converted. If the SAINS2~SAINS0 bits are set to “100”, the VDD/4 voltage is selected to be converted. Note that if the internal analog signal is selected to be converted, the external input channel determined by the SACS3~SACS0 bits must be switched to a non-existed A/D input channel by properly setting the SACS bit field with a value from “1000” to “1111”.

SAINS[2:0] SACS[3:0] Input Signals Description

000, 101~1110000~0111 AN0~AN7 External channel analog input ANn1000~1111 — Floating, no external channel is selected

001~011 1000~1111 GND Unused, connected to ground100 1000~1111 VDD/4 Internal signal derived from VDD/4

A/D Converter Input Signal Selection

Page 91: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 90 December 27, 2019 Rev. 1.30 91 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

A/D Converter OperationThe START bit in the SADC0 register is used to start the A/D 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 associated interrupts are enabled, an appropriate 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 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, if 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 or greater than the maximum A/D clock period, which may result in inaccurate A/D conversion values. Refer to the following table for examples, special care must be taken to values marked with an asterisk *, as these values may be less or greater than the specified A/D clock period.

fSYS

A/D Clock Period (tADCK)SACKS[2:0]

= 000(fSYS)

SACKS[2:0]= 001(fSYS/2)

SACKS[2:0]= 010(fSYS/4)

SACKS[2:0]= 011

(fSYS/8)

SACKS[2:0]= 100

(fSYS/16)

SACKS[2:0]= 101

(fSYS/32)

SACKS[2:0]= 110

(fSYS/64)

SACKS[2:0]= 111

(fSYS/128)1MHz 1μs 2μs 4μs 8μs 16μs * 32μs * 64μs * 128μs *2MHz 500ns 1μs 2μs 4μs 8μs 16μs * 32μs * 64μs *4MHz 250ns * 500ns 1μs 2μs 4μs 8μs 16μs * 32μs *8MHz 125ns * 250ns * 500ns 1μs 2μs 4μs 8μs 16μs *

A/D Clock Period Examples

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.

Conversion Rate and Timing DiagramA complete A/D conversion contains two parts, data sampling and data conversion. The data sampling which is defined as tADS takes 4 A/D clock cycles and the data conversion takes 10 A/D clock cycles. Therefore a total of 14 A/D clock cycles for an external input A/D conversion which is defined as tADC are necessary.

Maximum single A/D conversion rate = A/D clock period / 14

Page 92: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 92 December 27, 2019 Rev. 1.30 93 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

The accompanying diagram shows graphically the various stages involved in an analog to digital conversion process and its associated timing. After an A/D conversion process has been initiated by the application program, the microcontroller internal hardware will begin to carry out the conversion, during which time the program can continue with other functions. The time taken for the A/D conversion is 14 tADCK clock cycles where tADCK is equal to the A/D clock period.

ADCEN

START

ADBZ

SACS[3:0](SAINS[2:0]=000B)

off on off on

tON2ST

A/D sampling time A/D sampling time

Start of A/D conversion Start of A/D conversion Start of A/D conversion

End of A/D conversion

End of A/D conversion

tADC

A/D conversion timetADC

A/D conversion timetADC

A/D conversion time

0011B 0010B 0000B 0001B

A/D channel switch

tADS tADS

A/D Conversion Timing – External Channel Input

Summary of A/D Conversion StepsThe following summarises the individual steps that should be executed in order to implement an A/D conversion process.

• Step 1Select the required A/D conversion clock by correctly programming bits SACKS2~SACKS0 in the SADC1 register.

• Step 2Enable the A/D converter by setting the ADCEN bit in the SADC0 register to 1.

• Step 3Select which signal is to be connected to the internal A/D converter by correctly configuring the SAINS bit field in the SADC1 register.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 4If the A/D input signal comes from the external channel input selected by configuring the SAINS bit field, the corresponding pin should 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 5Before the A/D input signal is selected to come from the internal analog signal by configuring the SAINS bit field, the corresponding external input pin must be switched to a non-existed channel input by setting the SACS3~SACS0 bits with a value from 1000 to 1111. The desired internal analog signal then can be selected by configuring the SAINS bit field. After this step, go to Step 6.

• Step 6Select the reference voltage source by configuring the SAVRS1~SAVRS0 bits in the SADC1 register. If the A/D converter power supply voltage or the operational amplifier output voltage is selected, the external reference input pin function must be disabled by properly configuring the corresponding pin-shared control bits.

Page 93: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 92 December 27, 2019 Rev. 1.30 93 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• Step 7Select A/D converter output data format by setting the ADRFS bit in the SADC0 register.

• Step 8If the 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 control bit, EMI, and the A/D converter interrupt control bit, ADE, must both be set high in advance.

• Step 9The A/D conversion procedure can now be initiated by setting the START bit from low to high and then low again.

• Step 10If 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 ConsiderationsDuring microcontroller operations where the A/D converter is not being used, the A/D internal circuitry can be switched off to reduce power consumption, by clearing bit ADCEN to 0 in the SADC0 register. When this happens, the internal A/D converter circuits will not consume power irrespective of what analog voltage is applied to their input lines. If the A/D converter input lines are used as normal I/Os, then care must be taken as if the input voltage is not at a valid logic level, then this may lead to some increase in power consumption.

A/D Conversion FunctionAs the device contains a 10-bit A/D converter, its full-scale converted digitised value is equal to 3FFH. Since the full-scale analog input value is equal to the actual A/D converter reference voltage, VREF, this gives a single bit analog input value of VREF divided by 1024.

1 LSB = VREF ÷ 1024

The A/D converter input voltage value can be calculated using the following equation:

A/D input voltage = A/D output digital value × VREF ÷ 1024

The diagram shows the ideal transfer function between the analog input value and the digitised output value for the A/D converter. Except for the digitised zero value, the subsequent digitised values will change at a point 0.5 LSB below where they would change without the offset, and the last full scale digitised value will change at a point 1.5 LSB below the VREF level. Note that here the VREF voltage is the actual A/D converter reference voltage determined by the SAVRS field.

3FFH

3FEH

3FDH

03H

02H

01H

0 1 2 3 1021 1022 1023 1024

VREF1024

Analog Input Voltage

A/D Conversion Result

1.5 LSB

0.5 LSB

Ideal A/D Transfer Function

Page 94: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 94 December 27, 2019 Rev. 1.30 95 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

A/D Conversion Programming ExamplesThe following two programming examples illustrate how to configure and implement an A/D conversion. In the first example, the method of polling the ADBZ bit in the SADC0 register is used to detect when the conversion cycle is complete, whereas in the second example, the A/D interrupt is used to determine when the conversion is complete.

Example: using an ADBZ polling method to detect the end of conversionclr ADE ; disable ADC interruptmov a,03h ; select fSYS/8asA/Dclockandmov SADC1,a ; select external channel input and external reference input mov a,03h ;setPBS0toconfigurepinAN0mov PBS0,amov a,20hmov SADC0,a ;enableA/DandconnectAN0channeltoA/Dconverter : :start_conversion:clrSTART ;highpulseonstartbittoinitiateconversionsetSTART ;resetA/DclrSTART ;startA/Dpolling_EOC:szADBZ ;polltheSADC0registerADBZbittodetectendofA/Dconversionjmppolling_EOC ;continuepollingmova,SADOL ;readlowbyteconversionresultvaluemovSADOL_buffer,a ;saveresulttouserdefinedregistermova,SADOH ;readhighbyteconversionresultvaluemovSADOH_buffer,a ;saveresulttouserdefinedregister : :jmpstart_conversion ;startnextA/Dconversion

Example: using the interrupt method to detect the end of conversionclr ADE ; disable ADC interruptmov a,03h ; select fSYS/8asA/Dclockandmov SADC1,a ; select external channel input and external reference input mov a,03h ;setPBS0toconfigurepinAN0mov PBS0,amov a,20hmov SADC0,a ;enableA/DandconnectAN0channeltoA/Dconverter : :Start_conversion:clrSTART ;highpulseonSTARTbittoinitiateconversionsetSTART ;resetA/DclrSTART ;startA/DclrADF ;clearADCinterruptrequestflagset ADE ; enable ADC interruptsetEMI ;enableglobalinterrupt : :ADC_ISR: ;ADCinterruptserviceroutinemovacc_stack,a ;saveACCtouserdefinedmemorymova,STATUSmovstatus_stack,a ;saveSTATUStouserdefinedmemory : :

Page 95: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 94 December 27, 2019 Rev. 1.30 95 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

mova,SADOL ;readlowbyteconversionresultvaluemovSADOL_buffer,a ;saveresulttouserdefinedregistermova,SADOH ;readhighbyteconversionresultvaluemovSADOH_buffer,a ;saveresulttouserdefinedregister::EXIT_INT_ISR:mova,status_stackmovSTATUS,a ;restoreSTATUSfromuserdefinedmemorymova,acc_stack ;restoreACCfromuserdefinedmemoryreti

InterruptsInterrupts are an important part of any microcontroller system. When an external event or an internal function such as a TM Comparator P, Comparator A match, requires microcontroller attention, its corresponding interrupt will enforce a temporary suspension of the main program allowing the microcontroller to direct attention to its needs. The device contains several external interrupt and internal interrupt functions. The external interrupts are generated by the action of the external INT0~INT1 pins, while the internal interrupts are generated by internal functions including the TMs, A/D converter and Time Bases.

Interrupt RegistersOverall 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 falls into two categories. The first is the INTC0~INTC1 registers which set the primary interrupts, the second is the INTEG register to set the external interrupt trigger edge type.

Each register contains a number of enable bits to enable or disable individual registers as well as interrupt flags to indicate the presence of an interrupt request. The naming convention of these follows a specific pattern. First is listed an abbreviated interrupt type, then the (optional) number of that interrupt followed by either an “E” for enable/disable bit or “F” for request flag.

Function Enable Bit Request Flag NotesGlobal EMI — —INTn Pin INTnE INTnF n=0~1A/D Converter ADE ADF —Time Bases TBnE TBnF n=0~1Multi-function MFnE MFnF n=0~1

STMSTMPE STMPF —STMAE STMAF —

PTMPTMPE PTMPF —PTMAE PTMAF —

Interrupt Register Bit Naming Conventions

Page 96: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 96 December 27, 2019 Rev. 1.30 97 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Register Name

Bit7 6 5 4 3 2 1 0

INTEG — — — — INT1S1 INT1S0 INT0S1 INT0S0INTC0 — MF1F MF0F INT0F MF1E MF0E INT0E EMIINTC1 ADF INT1F TB1F TB0F ADE INT1E TB1E TB0EMFI0 — — STMAF STMPF — — STMAE STMPEMFI1 — — PTMAF PTMPF — — PTMAE PTMPE

Interrupt Register List

• INTEG RegisterBit 7 6 5 4 3 2 1 0

Name — — — — INT1S1 INT1S0 INT0S1 INT0S0R/W — — — — R/W R/W R/W R/WPOR — — — — 0 0 0 0

Bit 7~4 Unimplemented, read as “0”Bit 3~2 INT1S1~INT1S0: Interrupt edge control for INT1 pin

00: Disable01: Rising edge10: Falling edge11: Rising and falling edges

Bit 1~0 INT0S1~INT0S0: Interrupt edge control for INT0 pin00: Disable01: Rising edge10: Falling edge11: Rising and falling edges

• INTC0 RegisterBit 7 6 5 4 3 2 1 0

Name — MF1F MF0F INT0F MF1E MF0E INT0E EMIR/W — R/W R/W R/W R/W R/W R/W R/WPOR — 0 0 0 0 0 0 0

Bit 7 Unimplemented, read as “0”Bit 6 MF1F: Multi-function interrupt 1 request flag

0: No request1: Interrupt request

Bit 5 MF0F: Multi-function interrupt 0 request flag0: No request1: Interrupt request

Bit 4 INT0F: INT0 interrupt request flag0: No request1: Interrupt request

Bit 3 MF1E: Multi-function interrupt 1 control0: Disable1: Enable

Bit 2 MF0E: Multi-function interrupt 0 control0: Disable1: Enable

Bit 1 INT0E: INT0 interrupt control0: Disable1: Enable

Page 97: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 96 December 27, 2019 Rev. 1.30 97 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Bit 0 EMI: Global interrupt control0: Disable1: Enable

• INTC1 RegisterBit 7 6 5 4 3 2 1 0

Name ADF INT1F TB1F TB0F ADE INT1E TB1E TB0ER/W R/W R/W R/W R/W R/W R/W R/W R/WPOR 0 0 0 0 0 0 0 0

Bit 7 ADF: A/D converter interrupt request flag0: No request1: Interrupt request

Bit 6 INT1F: INT1 interrupt request flag0: No request1: Interrupt request

Bit 5 TB1F: Time Base 1 interrupt request flag0: No request1: Interrupt request

Bit 4 TB0F: Time Base 0 interrupt request flag0: No request1: Interrupt request

Bit 3 ADE: A/D converter interrupt control0: Disable1: Enable

Bit 2 INT1E: INT1 interrupt control0: Disable1: Enable

Bit 1 TB1E: Time Base 1 interrupt control0: Disable1: Enable

Bit 0 TB0E: Time Base 0 interrupt control0: Disable1: Enable

• MFI0 RegisterBit 7 6 5 4 3 2 1 0

Name — — STMAF STMPF — — STMAE STMPER/W — — R/W R/W — — R/W R/WPOR — — 0 0 — — 0 0

Bit 7~6 Unimplemented, read as “0”Bit 5 STMAF: STM comparator A match interrupt request flag

0: No request1: Interrupt request

Bit 4 STMPF: STM comparator P match interrupt request flag0: No request1: Interrupt request

Bit 3~2 Unimplemented, read as “0”Bit 1 STMAE: STM comparator A match interrupt control

0: Disable1: Enable

Bit 0 STMPE: STM comparator P match interrupt control0: Disable1: Enable

Page 98: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 98 December 27, 2019 Rev. 1.30 99 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

• MFI1 RegisterBit 7 6 5 4 3 2 1 0

Name — — PTMAF PTMPF — — PTMAE PTMPER/W — — R/W R/W — — R/W R/WPOR — — 0 0 — — 0 0

Bit 7~6 Unimplemented, read as “0”Bit 5 PTMAF: PTM comparator A match interrupt request flag

0: No request1: Interrupt request

Bit 4 PTMPF: PTM comparator P match interrupt request flag0: No request1: Interrupt request

Bit 3~2 Unimplemented, read as “0”Bit 1 PTMAE: PTM comparator A match interrupt control

0: Disable1: Enable

Bit 0 PTMPE: PTM comparator P match interrupt control0: Disable1: Enable

Interrupt OperationWhen the conditions for an interrupt event occur, such as a TM Comparator P, Comparator A match, 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 an “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 diagram 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 the other interrupts will be blocked, as the global interrupt enable bit, EMI bit will be cleared automatically. This will prevent any further interrupt nesting from occurring. However, if other interrupt requests occur during this interval, although the interrupt will not be immediately serviced, the request flag will still be recorded.

If an interrupt requires immediate servicing while the program is already in another interrupt service routine, the EMI bit should be set after entering the routine, to allow interrupt nesting. If the stack is full, the interrupt request will not be acknowledged, even if the related interrupt is enabled, until the Stack Pointer is decremented. If immediate service is desired, the stack must be prevented from becoming full. In case of simultaneous requests, the accompanying diagram shows the priority that

Page 99: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 98 December 27, 2019 Rev. 1.30 99 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

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.

Interrupt Name

Request Flags

Enable Bits

Master Enable Vector

EMI auto disabled in ISR

PriorityHigh

Low

Interrupts contained within Multi-Function Interrupts

xxE Enable Bits

xxF Request Flag, auto reset in ISR

LegendxxF Request Flag, no auto reset in ISR

PTM P PTMPF PTMPE

04HINT0 Pin INT0F INT0E EMI

1CHA/D Converter ADF ADE EMI

EMI 08HM. Funct. 0 MF0F MF0EInterrupt Name

Request Flags

Enable Bits

EMI 0CHM. Funct. 1 MF1F MF1E

EMI 14HTime Base 1 TB1F TB1E

PTM A PTMAF PTMAE

18HINT1 Pin INT1F INT1E EMI

STM P STMPF STMPE

STM A STMAF STMAEEMI 10HTime Base 0 TB0F TB0E

Interrupt Structure

External InterruptsThe external interrupts are controlled by signal transitions on the INTn pins. An external interrupt request will take place when the external interrupt request flag, INTnF, is 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 the external interrupt enable bit, INTnE, 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 bits in the corresponding interrupt registers has been set and the external interrupt pins are selected by the corresponding pin-shared function selection bits. The pins must also be set 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 pins, a subroutine call to the external interrupt vector, will take place. When the interrupt is serviced, the external interrupt request flag, INTnF, will be automatically reset and the EMI bit will be automatically cleared to disable other interrupts. Note that any pull-high resistor selection on the external interrupt pin 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 InterruptsWithin the device there are two 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.

A Multi-function interrupt request will take place when the Multi-function interrupt request flag MFnF is 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

Page 100: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 100 December 27, 2019 Rev. 1.30 101 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

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.

A/D Converter InterruptAn A/D converter interrupt request will take place when the A/D converter interrupt request flag, ADF, is set, which occurs when the A/D conversion process finishes. To allow the program to branch to its respective interrupt vector address, the global interrupt enable bit, EMI, and A/D converter interrupt enable bit, ADE, must first be set. When the interrupt is enabled, the stack is not full and the A/D conversion process has ended, a subroutine call to the A/D converter interrupt vector, will take place. When the A/D converter interrupt is serviced, the A/D converter interrupt flag, ADF, will be automatically cleared. The EMI bit will also be automatically cleared to disable other interrupts.

Timer Module InterruptsThe Standard and Periodic type TMs each has 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.

Time Base InterruptsThe function of the Time Base Interrupts is to provide regular time signal in the form of an internal interrupt. It is controlled by the overflow signals from the timer function. When this happens its interrupt request flag TBnF will be set. To allow the program to branch to its interrupt vector address, the global interrupt enable bit, EMI and Time Base enable bit, TBnE, must first be set. When the interrupt is enabled, the stack is not full and the Time Base overflows, a subroutine call to its interrupt vector location will take place. When the interrupt is serviced, the interrupt request flag, TBnF, will be automatically reset and the EMI bit will be cleared to disable other interrupts.

The purpose of the Time Base Interrupts is to provide an interrupt signal at fixed time periods. Its clock source, fPSC, originates from the internal clock source fSYS, fSYS/4 or fSUB and then passes through a divider, the division ratio of which is selected by programming the appropriate bits in the TBnC register to obtain longer interrupt periods whose value ranges. The clock source which in turn controls the Time Base interrupt period is selected using the CLKSEL[1:0] bits in the PSCR register.

Page 101: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 100 December 27, 2019 Rev. 1.30 101 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

MUX

fSYS/4fSYS

fSUB

Prescaler

CLKSEL[1:0]

fPSC

fPSC/28 ~ fPSC/215 MUX

MUX

TB0[2:0]

TB1[2:0]

Time Base 0 Interrupt

Time Base 1 Interrupt

TB0ON

TB1ON

fPSC/28 ~ fPSC/215

Time Base Interrupts

• PSCR RegisterBit 7 6 5 4 3 2 1 0

Name — — — — — PSCEN CLKSEL1 CLKSEL0R/W — — — — — R/W R/W R/WPOR — — — — — 0 0 0

Bit 7~3 Unimplemented, read as “0”Bit 2 PSCEN: Prescaler control

0: Disable1: Enable

This PSCEN bit is the prescaler clock enable/disable control bit. When the prescale clock is not in use, clearing this bit to zero can reduce extra power consumption.

Bit 1~0 CLKSEL1~CLKSEL0: Prescaler clock source fPSC selection00: fSYS

01: fSYS/41x: fSUB

• TBnC RegisterBit 7 6 5 4 3 2 1 0

Name TBnON — — — — TBn2 TBn1 TBn0R/W R/W — — — — R/W R/W R/WPOR 0 — — — — 0 0 0

Bit 7 TBnON: Time Base n control0: Disable1: Enable

Bit 6~3 Unimplemented, read as “0”Bit 2~0 TBn2~TBn0: Time Base n time-out period selection

000: 28/fPSC

001: 29/fPSC

010: 210/fPSC

011: 211/fPSC

100: 212/fPSC

101: 213/fPSC

110: 214/fPSC

111: 215/fPSC

Page 102: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 102 December 27, 2019 Rev. 1.30 103 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Interrupt Wake-up FunctionEach of the interrupt functions has the capability of waking up the microcontroller when in the SLEEP or IDLE Mode. A wake-up is generated when an interrupt request flag changes from low to high and is independent of whether the interrupt is enabled or not. Therefore, even though the device is in the SLEEP or IDLE Mode and its system oscillator stopped, situations such as external edge transitions on the external interrupt pin may cause their respective interrupt flag to be set high and consequently generate an interrupt. Care must therefore be taken if spurious wake-up situations are to be avoided. If an interrupt wake-up function is to be disabled then the corresponding interrupt request flag should be set high before the device enters the SLEEP or IDLE Mode. The interrupt enable bits have no effect on the interrupt wake-up function.

Programming ConsiderationsBy disabling the relevant interrupt enable bits, a requested interrupt can be prevented from being serviced, however, once an interrupt request flag is set, it will remain in this condition in the interrupt register until the corresponding interrupt is serviced or until the request flag is cleared by the application program.

It is recommended that programs do not use the “CALL” instruction within the interrupt service subroutine. Interrupts often occur in an unpredictable manner or need to be serviced immediately. If only one stack is left and the interrupt is not well controlled, the original control sequence will be damaged once a CALL subroutine is executed in the interrupt subroutine.

Every interrupt has the capability of waking up the microcontroller when it is in the SLEEP or IDLE Mode, the wake up being generated when the interrupt request flag changes from low to high. If it is required to prevent a certain interrupt from waking up the microcontroller then its respective request flag should be first set high before enter SLEEP or IDLE Mode.

As only the Program Counter is pushed onto the stack, then when the interrupt is serviced, if the contents of the accumulator, status register or other registers are altered by the interrupt service program, their contents should be saved to the memory at the beginning of the interrupt service routine.

To return from an interrupt subroutine, either an RET or RETI instruction may be executed. The RETI instruction in addition to executing a return to the main program also automatically sets the EMI bit high to allow further interrupts. The RET instruction however only executes a return to the main program leaving the EMI bit in its present zero state and therefore disabling the execution of further interrupts.

Application Circuits

VDD

VSS

VDD

0.1µF

PA0~PA7

PB0~PB6

PC0~PC2

Page 103: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 102 December 27, 2019 Rev. 1.30 103 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Instruction Set

IntroductionCentral 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 TimingMost 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.

Moving and Transferring DataThe transfer of data within the microcontroller program is one of the most frequently used operations. Making use of three kinds of MOV instructions, data can be transferred from registers to the Accumulator and vice-versa as well as being able to move specific immediate data directly into the Accumulator. One of the most important data transfer applications is to receive data from the input ports and transfer data to the output ports.

Arithmetic OperationsThe 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.

Page 104: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 104 December 27, 2019 Rev. 1.30 105 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Logical and Rotate OperationThe standard logical operations such as AND, OR, XOR and CPL all have their own instruction within the Holtek microcontroller instruction set. As with the case of most instructions involving data manipulation, data must pass through the Accumulator which may involve additional programming steps. In all logical data operations, the zero flag may be set if the result of the operation is zero. Another form of logical data manipulation comes from the rotate instructions such as RR, RL, RRC and RLC which provide a simple means of rotating one bit right or left. Different rotate instructions exist depending on program requirements. Rotate instructions are useful for serial port programming applications where data can be rotated from an internal register into the Carry bit from where it can be examined and the necessary serial bit set high or low. Another application which rotate data operations are used is to implement multiplication and division calculations.

Branches and Control TransferProgram branching takes the form of either jumps to specified locations using the JMP instruction or to a subroutine using the CALL instruction. They differ in the sense that in the case of a subroutine call, the program must return to the instruction immediately when the subroutine has been carried out. This is done by placing a return instruction "RET" in the subroutine which will cause the program to jump back to the address right after the CALL instruction. In the case of a JMP instruction, the program simply jumps to the desired location. There is no requirement to jump back to the original jumping off point as in the case of the CALL instruction. One special and extremely useful set of branch instructions are the conditional branches. Here a decision is first made regarding the condition of a certain data memory or individual bits. Depending upon the conditions, the program will continue with the next instruction or skip over it and jump to the following instruction. These instructions are the key to decision making and branching within the program perhaps determined by the condition of certain input switches or by the condition of internal data bits.

Bit OperationsThe 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.

Table Read OperationsData storage is normally implemented by using registers. However, when working with large amounts of fixed data, the volume involved often makes it inconvenient to store the fixed data in the Data Memory. To overcome this problem, Holtek microcontrollers allow an area of Program Memory to be set as a table where data can be directly stored. A set of easy to use instructions provides the means by which this fixed data can be referenced and retrieved from the Program Memory.

Other OperationsIn 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.

Page 105: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 104 December 27, 2019 Rev. 1.30 105 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Instruction Set SummaryThe following table depicts a summary of the instruction set categorised according to function and can be consulted as a basic instruction reference using the following listed conventions.

Table Conventionsx: Bits immediate data m: Data Memory address A: Accumulator i: 0~7 number of bits addr: Program memory address

Mnemonic Description Cycles Flag AffectedArithmeticADD A,[m] Add Data Memory to ACC 1 Z, C, AC, OVADDM A,[m] Add ACC to Data Memory 1Note Z, C, AC, OVADD A,x Add immediate data to ACC 1 Z, C, AC, OVADC A,[m] Add Data Memory to ACC with Carry 1 Z, C, AC, OVADCM A,[m] Add ACC to Data memory with Carry 1Note Z, C, AC, OVSUB A,x Subtract immediate data from the ACC 1 Z, C, AC, OVSUB A,[m] Subtract Data Memory from ACC 1 Z, C, AC, OVSUBM A,[m] Subtract Data Memory from ACC with result in Data Memory 1Note Z, C, AC, OVSBC A,[m] Subtract Data Memory from ACC with Carry 1 Z, C, AC, OVSBCM A,[m] Subtract Data Memory from ACC with Carry, result in Data Memory 1Note Z, C, AC, OVDAA [m] Decimal adjust ACC for Addition with result in Data Memory 1Note CLogic OperationAND A,[m] Logical AND Data Memory to ACC 1 ZOR A,[m] Logical OR Data Memory to ACC 1 ZXOR A,[m] Logical XOR Data Memory to ACC 1 ZANDM A,[m] Logical AND ACC to Data Memory 1Note ZORM A,[m] Logical OR ACC to Data Memory 1Note ZXORM A,[m] Logical XOR ACC to Data Memory 1Note ZAND A,x Logical AND immediate Data to ACC 1 ZOR A,x Logical OR immediate Data to ACC 1 ZXOR A,x Logical XOR immediate Data to ACC 1 ZCPL [m] Complement Data Memory 1Note ZCPLA [m] Complement Data Memory with result in ACC 1 ZIncrement & DecrementINCA [m] Increment Data Memory with result in ACC 1 ZINC [m] Increment Data Memory 1Note ZDECA [m] Decrement Data Memory with result in ACC 1 ZDEC [m] Decrement Data Memory 1Note ZRotateRRA [m] Rotate Data Memory right with result in ACC 1 NoneRR [m] Rotate Data Memory right 1Note NoneRRCA [m] Rotate Data Memory right through Carry with result in ACC 1 CRRC [m] Rotate Data Memory right through Carry 1Note CRLA [m] Rotate Data Memory left with result in ACC 1 NoneRL [m] Rotate Data Memory left 1Note NoneRLCA [m] Rotate Data Memory left through Carry with result in ACC 1 CRLC [m] Rotate Data Memory left through Carry 1Note C

Page 106: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 106 December 27, 2019 Rev. 1.30 107 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Mnemonic Description Cycles Flag AffectedData MoveMOV A,[m] Move Data Memory to ACC 1 NoneMOV [m],A Move ACC to Data Memory 1Note NoneMOV A,x Move immediate data to ACC 1 NoneBit OperationCLR [m].i Clear bit of Data Memory 1Note NoneSET [m].i Set bit of Data Memory 1Note NoneBranch OperationJMP addr Jump unconditionally 2 NoneSZ [m] Skip if Data Memory is zero 1Note NoneSZA [m] Skip if Data Memory is zero with data movement to ACC 1Note NoneSZ [m].i Skip if bit i of Data Memory is zero 1Note NoneSNZ [m].i Skip if bit i of Data Memory is not zero 1Note NoneSIZ [m] Skip if increment Data Memory is zero 1Note NoneSDZ [m] Skip if decrement Data Memory is zero 1Note NoneSIZA [m] Skip if increment Data Memory is zero with result in ACC 1Note NoneSDZA [m] Skip if decrement Data Memory is zero with result in ACC 1Note NoneCALL addr Subroutine call 2 NoneRET Return from subroutine 2 NoneRET A,x Return from subroutine and load immediate data to ACC 2 NoneRETI Return from interrupt 2 NoneTable Read OperationTABRD [m] Read table (specific page or current page) to TBLH and Data Memory 2Note NoneTABRDL [m] Read table (last page) to TBLH and Data Memory 2Note NoneMiscellaneousNOP No operation 1 NoneCLR [m] Clear Data Memory 1Note NoneSET [m] Set Data Memory 1Note NoneCLR WDT Clear Watchdog Timer 1 TO, PDFCLR WDT1 Pre-clear Watchdog Timer 1 TO, PDFCLR WDT2 Pre-clear Watchdog Timer 1 TO, PDFSWAP [m] Swap nibbles of Data Memory 1Note NoneSWAPA [m] Swap nibbles of Data Memory with result in ACC 1 NoneHALT Enter power down mode 1 TO, PDF

Note: 1. For skip instructions, if the result of the comparison involves a skip then up to 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.3. For the "CLR WDT1" and "CLR WDT2" instructions the TO and PDF flags may be affected by the

execution status. The TO and PDF flags are cleared after both "CLR WDT1" and "CLR WDT2" instructions are consecutively executed. Otherwise the TO and PDF flags remain unchanged.

Page 107: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 106 December 27, 2019 Rev. 1.30 107 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Instruction Definition

ADC A,[m] Add Data Memory to ACC with CarryDescription The contents of the specified Data Memory, Accumulator and the carry flag are added. The result is stored in the Accumulator.Operation ACC ← ACC + [m] + CAffected flag(s) OV, Z, AC, C

ADCM A,[m] Add ACC to Data Memory with CarryDescription The contents of the specified Data Memory, Accumulator and the carry flag are added. The result is stored in the specified Data Memory.Operation [m] ← ACC + [m] + CAffected flag(s) OV, Z, AC, C

ADD A,[m] Add Data Memory to ACCDescription The contents of the specified Data Memory and the Accumulator are added. The result is stored in the Accumulator.Operation ACC ← ACC + [m]Affected flag(s) OV, Z, AC, C

ADD A,x Add immediate data to ACCDescription The contents of the Accumulator and the specified immediate data are added. The result is stored in the Accumulator.Operation ACC ← ACC + xAffected flag(s) OV, Z, AC, C

ADDM A,[m] Add ACC to Data MemoryDescription The contents of the specified Data Memory and the Accumulator are added. The result is stored in the specified Data Memory.Operation [m] ← ACC + [m]Affected flag(s) OV, Z, AC, C

AND A,[m] Logical AND Data Memory to ACCDescription Data in the Accumulator and the specified Data Memory perform a bitwise logical AND operation. The result is stored in the Accumulator.Operation ACC ← ACC ″AND″ [m]Affected flag(s) Z

AND A,x Logical AND immediate data to ACCDescription Data in the Accumulator and the specified immediate data perform a bit wise logical AND operation. The result is stored in the Accumulator.Operation ACC ← ACC ″AND″ xAffected flag(s) Z

ANDM A,[m] Logical AND ACC to Data MemoryDescription Data in the specified Data Memory and the Accumulator perform a bitwise logical AND operation. The result is stored in the Data Memory.Operation [m] ← ACC ″AND″ [m]Affected flag(s) Z

Page 108: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 108 December 27, 2019 Rev. 1.30 109 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

CALL addr Subroutine callDescription Unconditionally calls a subroutine at the specified address. The Program Counter then increments by 1 to obtain the address of the next instruction which is then pushed onto the stack. The specified address is then loaded and the program continues execution from this new address. As this instruction requires an additional operation, it is a two cycle instruction.Operation Stack ← Program Counter + 1 Program Counter ← addrAffected flag(s) None

CLR [m] Clear Data MemoryDescription Each bit of the specified Data Memory is cleared to 0.Operation [m] ← 00HAffected flag(s) None

CLR [m].i Clear bit of Data MemoryDescription Bit i of the specified Data Memory is cleared to 0.Operation [m].i ← 0Affected flag(s) None

CLR WDT Clear Watchdog TimerDescription The TO, PDF flags and the WDT are all cleared. Operation WDT cleared TO ← 0 PDF ← 0Affected flag(s) TO, PDF

CLR WDT1 Pre-clear Watchdog TimerDescription The TO, PDF flags and the WDT are all cleared. Note that this instruction works in conjunction with CLR WDT2 and must be executed alternately with CLR WDT2 to have effect. Repetitively executing this instruction without alternately executing CLR WDT2 will have no effect.Operation WDT cleared TO ← 0 PDF ← 0 Affected flag(s) TO, PDF

CLR WDT2 Pre-clear Watchdog TimerDescription The TO, PDF flags and the WDT are all cleared. Note that this instruction works in conjunction with CLR WDT1 and must be executed alternately with CLR WDT1 to have effect. Repetitively executing this instruction without alternately executing CLR WDT1 will have no effect.Operation WDT cleared TO ← 0 PDF ← 0Affected flag(s) TO, PDF

CPL [m] Complement Data MemoryDescription Each bit of the specified Data Memory is logically complemented (1′s complement). Bits which previously contained a 1 are changed to 0 and vice versa.Operation [m] ← [m]Affected flag(s) Z

Page 109: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 108 December 27, 2019 Rev. 1.30 109 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

CPLA [m] Complement Data Memory with result in ACCDescription Each bit of the specified Data Memory is logically complemented (1′s complement). Bits which previously contained a 1 are changed to 0 and vice versa. The complemented result is stored in the Accumulator and the contents of the Data Memory remain unchanged.Operation ACC ← [m]Affected flag(s) Z

DAA [m] Decimal-Adjust ACC for addition with result in Data MemoryDescription 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 + 66HAffected flag(s) C

DEC [m] Decrement Data MemoryDescription Data in the specified Data Memory is decremented by 1.Operation [m] ← [m] − 1Affected flag(s) Z

DECA [m] Decrement Data Memory with result in ACCDescription Data in the specified Data Memory is decremented by 1. The result is stored in the Accumulator. The contents of the Data Memory remain unchanged.Operation ACC ← [m] − 1Affected flag(s) Z

HALT Enter power down modeDescription This instruction stops the program execution and turns off the system clock. The contents of the Data Memory and registers are retained. The WDT and prescaler are cleared. The power down flag PDF is set and the WDT time-out flag TO is cleared.Operation TO ← 0 PDF ← 1Affected flag(s) TO, PDF

INC [m] Increment Data Memory Description Data in the specified Data Memory is incremented by 1.Operation [m] ← [m] + 1Affected flag(s) Z

INCA [m] Increment Data Memory with result in ACCDescription Data in the specified Data Memory is incremented by 1. The result is stored in the Accumulator. The contents of the Data Memory remain unchanged.Operation ACC ← [m] + 1Affected flag(s) Z

Page 110: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 110 December 27, 2019 Rev. 1.30 111 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

JMP addr Jump unconditionallyDescription The contents of the Program Counter are replaced with the specified address. Program execution then continues from this new address. As this requires the insertion of a dummy instruction while the new address is loaded, it is a two cycle instruction.Operation Program Counter ← addrAffected flag(s) None

MOV A,[m] Move Data Memory to ACCDescription The contents of the specified Data Memory are copied to the Accumulator.Operation ACC ← [m]Affected flag(s) None

MOV A,x Move immediate data to ACCDescription The immediate data specified is loaded into the Accumulator.Operation ACC ← xAffected flag(s) None

MOV [m],A Move ACC to Data Memory Description The contents of the Accumulator are copied to the specified Data Memory.Operation [m] ← ACCAffected flag(s) None

NOP No operationDescription No operation is performed. Execution continues with the next instruction.Operation No operationAffected flag(s) None

OR A,[m] Logical OR Data Memory to ACCDescription Data in the Accumulator and the specified Data Memory perform a bitwise logical OR operation. The result is stored in the Accumulator.Operation ACC ← ACC ″OR″ [m]Affected flag(s) Z

OR A,x Logical OR immediate data to ACCDescription Data in the Accumulator and the specified immediate data perform a bitwise logical OR operation. The result is stored in the Accumulator.Operation ACC ← ACC ″OR″ xAffected flag(s) Z

ORM A,[m] Logical OR ACC to Data MemoryDescription Data in the specified Data Memory and the Accumulator perform a bitwise logical OR operation. The result is stored in the Data Memory.Operation [m] ← ACC ″OR″ [m]Affected flag(s) Z

RET Return from subroutineDescription The Program Counter is restored from the stack. Program execution continues at the restored address.Operation Program Counter ← StackAffected flag(s) None

Page 111: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 110 December 27, 2019 Rev. 1.30 111 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

RET A,x Return from subroutine and load immediate data to ACCDescription 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 ← xAffected flag(s) None

RETI Return from interruptDescription The Program Counter is restored from the stack and the interrupts are re-enabled by setting the EMI bit. EMI is the master interrupt global enable bit. If an interrupt was pending when the RETI instruction is executed, the pending Interrupt routine will be processed before returning to the main program.Operation Program Counter ← Stack EMI ← 1Affected flag(s) None

RL [m] Rotate Data Memory leftDescription The contents of the specified Data Memory are rotated left by 1 bit with bit 7 rotated into bit 0.Operation [m].(i+1) ← [m].i; (i=0~6) [m].0 ← [m].7Affected flag(s) None

RLA [m] Rotate Data Memory left with result in ACCDescription The contents of the specified Data Memory are rotated left by 1 bit with bit 7 rotated into 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 ← [m].7Affected flag(s) None

RLC [m] Rotate Data Memory left through CarryDescription The contents of 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 bit 0.Operation [m].(i+1) ← [m].i; (i=0~6) [m].0 ← C C ← [m].7Affected flag(s) C

RLCA [m] Rotate Data Memory left through Carry with result in ACCDescription 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].7Affected flag(s) C

RR [m] Rotate Data Memory rightDescription The contents of the specified Data Memory are rotated right by 1 bit with bit 0 rotated into bit 7.Operation [m].i ← [m].(i+1); (i=0~6) [m].7 ← [m].0Affected flag(s) None

Page 112: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 112 December 27, 2019 Rev. 1.30 113 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

RRA [m] Rotate Data Memory right with result in ACCDescription Data in the specified Data Memory is rotated right by 1 bit with bit 0 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 ← [m].0Affected flag(s) None

RRC [m] Rotate Data Memory right through CarryDescription The contents of 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.Operation [m].i ← [m].(i+1); (i=0~6) [m].7 ← C C ← [m].0Affected flag(s) C

RRCA [m] Rotate Data Memory right through Carry with result in ACCDescription 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].0Affected flag(s) C

SBC A,[m] Subtract Data Memory from ACC with CarryDescription 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 Accumulator. 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 ACC ← ACC − [m] − CAffected flag(s) OV, Z, AC, C

SBCM A,[m] Subtract Data Memory from ACC with Carry and result in Data MemoryDescription 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] − CAffected flag(s) OV, Z, AC, C

SDZ [m] Skip if decrement Data Memory is 0Description The contents of the specified Data Memory are first decremented by 1. If the result is 0 the following instruction is skipped. 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 [m] ← [m] − 1 Skip if [m]=0Affected flag(s) None

Page 113: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 112 December 27, 2019 Rev. 1.30 113 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

SDZA [m] Skip if decrement Data Memory is zero with result in ACCDescription 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=0Affected flag(s) None

SET [m] Set Data MemoryDescription Each bit of the specified Data Memory is set to 1.Operation [m] ← FFHAffected flag(s) None

SET [m].i Set bit of Data MemoryDescription Bit i of the specified Data Memory is set to 1.Operation [m].i ← 1Affected flag(s) None

SIZ [m] Skip if increment Data Memory is 0Description The contents of the specified Data Memory are first incremented by 1. If the result is 0, the following instruction is skipped. 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 [m] ← [m] + 1 Skip if [m]=0 Affected flag(s) None

SIZA [m] Skip if increment Data Memory is zero with result in ACCDescription 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=0Affected flag(s) None

SNZ [m].i Skip if bit i of Data Memory is not 0Description If bit i of the specified Data Memory is not 0, the following instruction is skipped. 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 0 the program proceeds with the following instruction.Operation Skip if [m].i ≠ 0Affected flag(s) None

SUB A,[m] Subtract Data Memory from ACCDescription The specified Data Memory is subtracted from the contents of the Accumulator. The result is stored in the Accumulator. 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 ACC ← ACC − [m]Affected flag(s) OV, Z, AC, C

Page 114: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 114 December 27, 2019 Rev. 1.30 115 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

SUBM A,[m] Subtract Data Memory from ACC with result in Data MemoryDescription 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

SUB A,x Subtract immediate data from ACCDescription The immediate data specified by the code is subtracted from the contents of the Accumulator. The result is stored in the Accumulator. 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 ACC ← ACC − xAffected flag(s) OV, Z, AC, C

SWAP [m] Swap nibbles of Data MemoryDescription The low-order and high-order nibbles of the specified Data Memory are interchanged.Operation [m].3~[m].0 ↔ [m].7~[m].4Affected flag(s) None

SWAPA [m] Swap nibbles of Data Memory with result in ACCDescription The low-order and high-order nibbles of the specified Data Memory are interchanged. The result is stored in the Accumulator. The contents of the Data Memory remain unchanged.Operation ACC.3~ACC.0 ← [m].7~[m].4 ACC.7~ACC.4 ← [m].3~[m].0Affected flag(s) None

SZ [m] Skip if Data Memory is 0Description If the contents of the specified Data Memory is 0, the following instruction is skipped. 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 Skip if [m]=0Affected flag(s) None

SZA [m] Skip if Data Memory is 0 with data movement to ACCDescription The contents of the specified Data Memory are copied to the Accumulator. If the value is zero, the following instruction is skipped. 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] Skip if [m]=0Affected flag(s) None

SZ [m].i Skip if bit i of Data Memory is 0Description If bit i of the specified Data Memory is 0, the following instruction is skipped. 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 Skip if [m].i=0Affected flag(s) None

Page 115: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 114 December 27, 2019 Rev. 1.30 115 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

TABRD [m] Read table (specific page or current page) to TBLH and Data MemoryDescription 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 MemoryDescription 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

XOR A,[m] Logical XOR Data Memory to ACCDescription Data in the Accumulator and the specified Data Memory perform a bitwise logical XOR operation. The result is stored in the Accumulator.Operation ACC ← ACC ″XOR″ [m]Affected flag(s) Z

XORM A,[m] Logical XOR ACC to Data MemoryDescription Data in the specified Data Memory and the Accumulator perform a bitwise logical XOR operation. The result is stored in the Data Memory.Operation [m] ← ACC ″XOR″ [m]Affected flag(s) Z

XOR A,x Logical XOR immediate data to ACCDescription Data in the Accumulator and the specified immediate data perform a bitwise logical XOR operation. The result is stored in the Accumulator.Operation ACC ← ACC ″XOR″ xAffected flag(s) Z

Page 116: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 116 December 27, 2019 Rev. 1.30 117 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Package Information

Note that the package information provided here is for consultation purposes only. As this information may be updated at regular intervals users are reminded to consult the Holtek website for the latest version of the Package/Carton Information.

Additional supplementary information with regard to packaging is listed below. Click on the relevant section to be transferred to the relevant website page.

• Package Information (include Outline Dimensions, Product Tape and Reel Specifications)

• The Operation Instruction of Packing Materials

• Carton information

Page 117: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 116 December 27, 2019 Rev. 1.30 117 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

16-pin NSOP (150mil) Outline Dimensions

� �

� �

� �

��

� �

SymbolDimensions in inch

Min. Nom. Max.A — 0.236 BSC —B — 0.154 BSC —C 0.012 — 0.020 C' — 0.390 BSC —D — — 0.069 E — 0.050 BSC —F 0.004 — 0.010 G 0.016 — 0.050 H 0.004 — 0.010 α 0° ― 8°

SymbolDimensions in mm

Min. Nom. Max.A — 6.000 BSC —B — 3.900 BSC —C 0.31 — 0.51 C' — 9.900 BSC —D — — 1.75 E — 1.270 BSC —F 0.10 — 0.25 G 0.40 — 1.27 H 0.10 — 0.25 α 0° ― 8°

Page 118: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 118 December 27, 2019 Rev. 1.30 119 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

20-pin NSOP (150mil) Outline Dimensions

� �

� �

� �

� �

� �

� ��

SymbolDimensions in inch

Min. Nom. Max.A 0.228 0.236 0.244 B 0.146 0.154 0.161 C 0.009 — 0.012 C’ 0.382 0.390 0.398 D — — 0.069 E — 0.032 BSC —F 0.002 — 0.009 G 0.020 — 0.031 H 0.008 — 0.010 α 0° — 8°

SymbolDimensions in mm

Min. Nom. Max.A 5.80 6.00 6.20 B 3.70 3.90 4.10 C 0.23 — 0.30 C’ 9.70 9.90 10.10 D — — 1.75 E — 0.80 BSC —F 0.05 — 0.23 G 0.50 — 0.80 H 0.21 — 0.25 α 0° — 8°

Page 119: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 118 December 27, 2019 Rev. 1.30 119 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

20-pin SOP (300mil) Outline Dimension

� �

� �

� �

� �

� �

� ��

SymbolDimensions in inch

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°

SymbolDimensions in mm

Min. Nom. Max.A — 10.30 BSC —B — 7.50 BSC —C 0.31 — 0.51 C’ — 12.80 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°

Page 120: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 120 December 27, 2019 Rev. 1.30 121 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

20-pin SSOP (150mil) Outline Dimensions

� �

� �

� �

� �

� �

� � ��

SymbolDimensions in inch

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.0098 G 0.016 — 0.05 H 0.004 — 0.01 α 0° — 8°

SymbolDimensions in mm

Min. Nom. Max.A — 6.000 BSC —B — 3.900 BSC —C 0.20 — 0.30 C’ — 8.660 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°

Page 121: A/D Flash MCU with EEPROM...PTPI PAS1 ST — PTM capture input PTP PAS1 — CMOS PTM output AN6 PAS1 AN — A/D converter external input channel 6 PB0/INT0/AN0 PB0 PBPU PBS0 …

Rev. 1.30 120 December 27, 2019 Rev. 1.30 121 December 27, 2019

HT66F0181A/D Flash MCU with EEPROM

HT66F0181A/D Flash MCU with EEPROM

Copyright© 2019 by HOLTEK SEMICONDUCTOR INC.

The information appearing in this Data Sheet is believed to be accurate at the time of publication. However, Holtek assumes no responsibility arising from the use of the specifications described. The applications mentioned herein are used solely for the purpose of illustration and Holtek makes no warranty or representation that such applications will be suitable without further modification, nor recommends the use of its products for application that may present a risk to human life due to malfunction or otherwise. Holtek's products are not authorized for use as critical components in life support devices or systems. Holtek reserves the right to alter its products without prior notification. For the most up-to-date information, please visit our web site at http://www.holtek.com.