Notes: 1. If the pin-shared pin functions have multiple outputs simultaneously, the desired pin-shared function is
determined by the corresponding software control bits.
2. The actual device and its equivalent OCDS EV device share the same package type, however the OCDS
EV device part number is HT45V4050. Pins OCDSCK and OCDSDA which are pin-shared with PA2
and PA0 are only used for the OCDS EV device.
Pin Description
With the exception of the power pins, all pins on the device can be referenced by its Port name,
e.g. PA0, PA1 etc., which refer to the digital I/O function of the pins. However these Port pins are
also shared with other function such as the Analog to Digital Converter, Timer Module pins etc.
The function of each pin is listed in the following table, however the details behind how each pin is
congured is contained in other sections of the datasheet.
Pin NameFunctionOPTI/TO/TDescription
PA0/ICPDA/
OCDSDA
PA1/INT0/SCS
PA0
PAWU
STCMOS
PAS0
ICPDA—STCMOS ICP Address/Data pin
OCDSDA—STCMOS OCDS Address/Data pin, for EV chip only
PAPU
PAPU
PA1
PAWU
STCMOS
PAS0
PAS0
INT0
INTEG
INTC0
ST—External Interrupt 0
IFS1
SCS
PAS0
IFS0
STCMOS SPI slave select
General purpose I/O. Register enabled pull-high and
wake-up.
General purpose I/O. Register enabled pull-high and
wake-up.
Any location within the Program Memory can be dened as a look-up table where programmers can
store xed data. To use the look-up table, the table pointer must rst be setup by placing the address
of the look up data to be retrieved in the table pointer register, TBLP and TBHP. These registers
dene the total address of the look-up table.
After setting up the table pointer pair, the table data can be retrieved from the Program Memory
using the corresponding table read instruction such as "TABRD [m]" or "TABRDL [m]" respectively
when the memory [m] is located in sector 0. If the memory [m] is located in other sectors, the data
can be retrieved from the program memory using the corresponding extended table read instruction
such as "LTABRD [m]" or "LTABRDL [m]" respectively. When the instruction is executed, the
lower order table byte from the Program Memory will be transferred to the user defined Data
Memory register [m] as specified in the instruction. The higher order table data byte from the
Program Memory will be transferred to the TBLH special register.
The accompanying diagram illustrates the addressing data ow of the look-up table.
Last Page or
TBHP Register
TBLP Register
Program Memory
Address
Data
16 bits
Table Program Example
The following example shows how the table pointer and table data is dened and retrieved from the
microcontroller. 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 "1F00H" which refers to the
start address of the last page within the 8K words Program Memory. The table pointer low byte
register is setup here to have an initial value of "06H". This will ensure that the rst data read from
the data table will be at the Program Memory address "1F06H" or 6 locations after the start of the
last page. Note that the value for the table pointer is referenced to the specic address pointed by
the TBLP and TBHP registers if the "TABRD [m]" or "LTABRD [m]" instruction is being used. The
high byte of the table data which in this case is equal to zero will be transferred to the TBLH register
automatically when the "TABRD [m]" or "LTABRD [m]" instruction is executed.
Because the TBLH register is a read/write register and can 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.
Register TBLH
High ByteLow Byte
User Selected
Register
Table Read Program Example
tempreg1 db ? ; temporary register #1
tempreg2 db ? ; temporary register #2
:
mov a,06h ; initialise low table pointer - note that this address is referenced
mov tblp,a ; to the last page or the page that tbhp pointed
mo v a,1Fh ; initialise high table pointer
mov tbhp,a ; it is not necessary to set tbhp if executing tabrdl or ltabrdl
:
tabrd tempreg1 ; transfers value in table referenced by table pointer,
dec tblp ; reduce value of table pointer by one
tabrd tempreg2 ; transfers value in table referenced by table pointer,
; register tempreg2
; the value "00H" will be transferred to the high byte register TBLH
:
org 1F00h ; sets initial address of program memory
dc 00Ah, 00Bh, 00Ch, 00Dh, 00Eh, 00Fh, 01Ah, 01Bh
:
; data at program memory address "1F06H" transferred to tempreg1 and TBLH
; data at program memory address "1F05H" transferred to tempreg2 and TBLH
; in this example the data "1AH" is transferred to tempreg1 and data "0FH" to
In Circuit Programming – ICP
The provision of Flash type Program Memory provides the user with a means of convenient and
easy upgrades and modications to their programs on the same device.
As an additional convenience, Holtek has provided a means of programming the microcontroller 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-
Most 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, IAR1, IAR2
The Indirect Addressing Registers, IAR0, IAR1 and IAR2, 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 specied.
Actions on the IAR0, IAR1 and IAR2 registers will result in no actual read or write operation to
these registers but rather to the memory location specied by their corresponding Memory Pointers,
MP0, MP1L/MP1H or MP2L/MP2H. Acting as a pair, IAR0 and MP0 can together access data
from Sector 0 while the IAR1 register together with MP1L/MP1H register pair and IAR2 register
together with MP2L/MP2H register pair can access data from any sector. As the Indirect Addressing
Registers are not physically implemented, reading the Indirect Addressing Registers directly will
return a result of "00H" and writing to the registers directly will result in no operation.
Memory Pointers – MP0, MP1L/MP1H, MP2L/MP2H
Five Memory Pointers, known as MP0, MP1L, MP1H, MP2L and MP2H 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 specied by the related Memory Pointer. MP0,
together with Indirect Addressing Register, IAR0, are used to access data from Sector 0, while MP1L/
MP1H together with IAR1 and MP2L/MP2H together with IAR2 are used to access data from all
sectors according to the corresponding MP1H or MP2H register. Direct Addressing can be used in all
sectors using the correspongding instruction which can address all available data memory space.
The following example shows how to clear a section of four Data Memory locations already dened
as locations adres1 to adres4.
HT45F4050
A/D NFC Flash MCU
Indirect Addressing Program Example
Example 1
data .section ´data´
adres1 db ?
adres2 db ?
adres3 db ?
adres4 db ?
block db ?
code .section at 0 ´code´
org 00h
start:
mov a,04h ; setup size of block
mo v block,a
data .section ‘data’
adres1 db ?
adres2 db ?
adres3 db ?
adres4 db ?
block db ?
code .section at 0 ‘code’
org 00h
start:
mov a,04h ; setup size of block
mo v block,a
mov a,01h ; setup the memory sector
mo v mp1h,a
mov a,offset adres1 ;AccumulatorloadedwithrstRAMaddress
sdz block ; check if last memory location has been cleared
jmp loop
continue:
:
The important point to note here is that in the example shown above, no reference is made to specic
Data Memory addresses.
Direct Addressing Program Example using extended instructions
data .section ‘data’
temp db ?
code .section at 0 code
org 00h
start:
lmov a,[m] ; move [m] data to acc
lsub a, [m+1] ; compare [m] and [m+1] data
snz c ; [m]>[m+1]?
jmp continue ; no
lmov a,[m] ; yes, exchange [m] and [m+1] data
mo v te m p,a
lmov a,[m+1]
lmov [m],a
mo v a,tem p
lmov [m+1],a
continue:
:
Note: here "m" is a data memory address located in any data memory sectors. For example,
m=1F0H, it indicates address 0F0H in Sector 1.
Accumulator – ACC
The Accumulator is central to the operation of any microcontroller and is closely related with
operations carried out by the ALU. The Accumulator is the place where all intermediate results
from the ALU are stored. Without the Accumulator it would be necessary to write the result of
each calculation or logical operation such as addition, subtraction, shift, etc., to the Data Memory
resulting in higher programming and timing overheads. Data transfer operations usually involve
the temporary storage function of the Accumulator; for example, when transferring data between
one user-defined register and another, it is necessary to do this by passing the data through the
Accumulator as no direct transfer between two registers is permitted.
Program Counter Low Register – PCL
To provide additional program control functions, the low byte of the Program Counter is made
accessible to programmers by locating it within the Special Purpose area of the Data Memory. By
manipulating this register, direct jumps to other program locations are easily implemented. Loading
a value directly into this PCL register will cause a jump to the specied Program Memory location,
however, as the register is only 8-bit wide, only jumps within the current Program Memory page are
permitted. When such operations are used, note that a dummy cycle will be inserted.
Look-up Table Registers – TBLP, TBHP, TBLH
These three special function registers are used to control operation of the look-up table which is
stored in the Program Memory. TBLP and TBHP are the table pointers and indicate the location
where the table data is located. Their value must be setup before any table read commands are
executed. Their value can be changed, for example using the "INC" or "DEC" instructions, allowing
for easy table data pointing and reading. TBLH is the location where the high order byte of the table
data is stored after a table read data instruction has been executed. Note that the lower order table
data byte is transferred to a user dened location.
HT45F4050
A/D NFC Flash MCU
Status Register – STATUS
This 8-bit register contains the zero ag (Z), carry ag (C), auxiliary carry ag (AC), overow ag
(OV), SC ag, CZ ag, power down ag (PDF), and watchdog time-out ag (TO). These arithmetic/
logical operation and system management ags are used to record the status and operation of the
microcontroller.
With the exception of the TO and PDF ags, bits in the status register can be altered by instructions
like most other registers. Any data written into the status register will not change the TO or PDF
flag. In addition, operations related to the status register may give different results due to the
different instruction operations. The TO ag can be affected only by a system power-up, a WDT
time-out or by executing the "CLR WDT" or "HALT" instruction. The PDF ag is affected only by
executing the "HALT" or "CLR WDT" instruction or during a system power-up.
The Z, OV, AC, C SC and CZ ags generally reect the status of the latest operations.
• C is set if an operation results in a carry during an addition operation or if a borrow does not take
place during a subtraction operation; otherwise C is cleared. C is also affected by a rotate through
carry instruction.
• AC is set if an operation results in a carry out of the low nibbles in addition, or no borrow from
the high nibble into the low nibble in subtraction; otherwise AC is cleared.
• Z is set if the result of an arithmetic or logical operation is zero; otherwise Z is cleared.
• OV is set if an operation results in a carry into the highest-order bit but not a carry out of the
highest-order bit, or vice versa; otherwise OV is cleared.
This is the Data EEPROM Write Enable Bit which must be set high before Data
EEPROM write operations are carried out. Clearing this bit to zero will inhibit Data
EEPROM write operations.
Bit 2 WR: EEPROM Write Control
This is the Data EEPROM Write Control Bit and when set high by the application
program will activate a write cycle. This bit will be automatically reset to zero by the
hardware after the write cycle has nished. Setting this bit high will have no effect if
the WREN has not rst been set high.
Bit 1 RDEN: Data EEPROM Read Enable
This is the Data EEPROM Read Enable Bit which must be set high before Data
EEPROM read operations are carried out. Clearing this bit to zero will inhibit Data
EEPROM read operations.
Bit 0 RD: EEPROM Read Control
This is the Data EEPROM Read Control Bit and when set high by the application
program will activate a read cycle. This bit will be automatically reset to zero by the
hardware after the read cycle has nished. Setting this bit high will have no effect if
the RDEN has not rst been set high.
Note that the WREN, WR, RDEN and RD bits can not be set to "1" at the same time
in one instruction. The WR and RD can not be set to "1" at the same time.
0: Disable
1: Enable
0: Write cycle has nished
1: Activate a write cycle
0: Disable
1: Enable
0: Read cycle has nished
1: Activate a read cycle
Reading Data from the EEPROM
To read data from the EEPROM, The EEPROM address of the data to be read must then be placed
in the EEA register. Then the read enable bit, RDEN, in the EEC register must first be set high
to enable the read function. If the RD bit in the EEC register is now set high, a read cycle will be
initiated. Setting the RD bit high will not initiate a read operation if the RDEN bit has not been set.
When the read cycle terminates, the RD bit will be automatically cleared to zero, after which the
data can be read from the EED register. The data will remain in the EED register until another read
or write operation is executed. The application program can poll the RD bit to determine when the
data is valid for reading.
Writing Data to the EEPROM
To write data to the EEPROM, the EEPROM address of the data to be written must rst be placed
in the EEA register and the data placed in the EED register. Then the write enable bit, WREN,
in the EEC register must first be set high to enable the write function. After this, the WR bit in
the EEC register must be immediately set high to initial a write cycle. These two instructions
must be executed consecutively. The global interrupt bit EMI should also first be cleared before
implementing any write operations, and then set again after the write cycle has started. Note that
setting the WR bit high will not initiate a write cycle if the WREN bit has not been set. As the
EEPROM write cycle is controlled using an internal timer whose operation is asynchronous to
microcontroller system clock, a certain time will elapse before the data will have been written into
the EEPROM. Detecting when the write cycle has nished can be implemented either by polling the
WR bit in the EEC register or by using the EEPROM interrupt. When the write cycle terminates,
the WR bit will be automatically cleared to zero by the microcontroller, informing the user that the
data has been written to the EEPROM. The application program can therefore poll the WR bit to
determine when the write cycle has ended.
Write Protection
Protection against inadvertent write operation is provided in several ways. After the device is
powered on the Write Enable bit in the control register will be cleared preventing any write
operations. Also at power-on the Memory Pointer high byte register, MP1H or MP2H, will be reset
to zero, which means that Data Memory Sector 0 will be selected. As the EEPROM control register
is located in Sector 1, this adds a further measure of protection against spurious write operations.
During normal program operation, ensuring that the Write Enable bit in the control register is
cleared will safeguard against incorrect write operations.
HT45F4050
A/D NFC Flash MCU
EEPROM Interrupt
The EEPROM write interrupt is generated when an EEPROM write cycle has ended. The EEPROM
interrupt must rst be enabled by setting the DEE bit in the relevant interrupt register. However, as
the EEPROM is contained within a Multi-function Interrupt, the associated multi-function interrupt
enable bit must also be set. When an EEPROM write cycle ends, the DEF request flag and its
associated multi-function interrupt request ag will both be set. If the global, EEPROM and Multi-
function interrupts are enabled and the stack is not full, a jump to the associated Multi-function
Interrupt vector will take place. When the interrupt is serviced only the Multi-function interrupt ag
will be automatically reset, the EEPROM interrupt ag must be manually reset by the application
These three bits are used to select which clock is used as the system clock source. In
addition to the system clock source directly derived from fH or f
of the high speed system oscillator can also be chosen as the system clock source.
Bit 4 Unimplemented, read as "0"
Bit 3 FHS: High Frequency clock selection
0: HIRC
1: HXT
Bit 2 FSS: Low Frequency clock selection
0: LIRC
1: LXT
Bit 1 FHIDEN: High Frequency oscillator control when CPU is switched off
0: Disable
1: Enable
This bit is used to control whether the high speed oscillator is activated or stopped
when the CPU is switched off by executing an "HALT" instruction.
Bit 0 FSIDEN: Low Frequency oscillator control when CPU is switched off
0: Disable
1: Enable
This bit is used to control whether the low speed oscillator is activated or stopped
when the CPU is switched off by executing an "HALT" instruction.
, a divided version
SUB
• HIRCC Register
Bit76543210
Name————HIRC1HIRC0HIRCFHIRCEN
R/W————R/WR/WRR/W
POR————0001
Bit 7~4 Unimplemented, read as "0"
Bit 3~2 HIRC1~HIRC0: HIRC frequency selection
00: 4MHz
01: 8MHz
10: 12MHz
11: 4MHz
When the HIRC oscillator is enabled or the HIRC frequency selection is changed
by application program, the clock frequency will automatically be changed after the
HIRCF ag is set to 1. It is recommended that the HIRC frequency selected by these
bits is the same as the frequency determined by the conguration option to ensure a
higer HIRC frequency accuracy spedied in the A.C. chanracteristics.
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 or the HIRC frequency selection
is changed by application program, the HIRCF bit will rst be cleared to 0 and then
set to 1 after the HIRC oscillator is stable.
Bit 0 HIRCEN: HIRC oscillator enable control
• HXTC Register
Bit76543210
Name—————HXTMHXTFHXTEN
R/W—————R/WRR/W
POR—————000
Bit 7~3 Unimplemented, read as "0"
Bit 2 HXTM: HXT mode selection
This bit is used to select the HXT oscillator operating mode. Note that this bit must
be properly congured before the HXT is enabled. When the OSC1 and OSC2 pins
are enabled and the HXTEN bit is set to 1 to enable the HXT oscillator, it is invalid to
change the value of this bit. Otherwise, this bit value can be changed with no operation
on the HXT function.
Bit 1 HXTF: HXT oscillator stable ag
This bit is used to indicate whether the HXT oscillator is stable or not. When the
HXTEN bit is set to 1 to enable the HXT oscillator, the HXTF bit will rst be cleared
to 0 and then set to 1 after the HXT oscillator is stable.
Bit 0 HXTEN: HXT oscillator enable control
0: HIRC unstable
1: HIRC stable
0: Disable
1: Enable
0: HXT frequency ≤ 10 MHz
1: HXT frequency > 10 MHz
0: HXT unstable
1: HXT stable
0: Disable
1: Enable
• LXTC Register
Bit76543210
Name——————LXTFLXTEN
R/W——————RR/W
POR——————00
Bit 7~2 Unimplemented, read as "0"
Bit 1 LXTF: LXT oscillator stable ag
0: LXT unstable
1: LXT stable
This bit is used to indicate whether the LXT oscillator is stable or not. When the
LXTEN bit is set to 1 to enable the LXT oscillator, the LXTF bit will rst be cleared
to 0 and then set to 1 after the LXT oscillator is stable.
Bit 0 LXTEN: LXT oscillator enable control
0: Disable
1: Enable
Operating Mode Switching
The 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 NORMAL Mode and SLOW Mode is executed using
the CKS2~CKS0 bits in the SCC register while Mode Switching from the NORMAL/SLOW Modes
to the SLEEP/IDLE Modes is executed via the HALT instruction. When an 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.
The Watchdog Timer is provided to prevent program malfunctions or sequences from jumping to
unknown locations, due to certain uncontrollable external events such as electrical noise.
Watchdog Timer Clock Source
The Watchdog Timer clock source is sourced from the LIRC oscillator. The LIRC internal oscillator
has an approximate frequency of 32kHz and this specied internal clock period can vary with VDD,
temperature and process variations. The Watchdog Timer source clock is then subdivided by a ratio
of 28 to 218 to give longer timeouts, the actual value being chosen using the WS2~WS0 bits in the
WDTC register.
Watchdog Timer Control Register
A single register, WDTC, controls the required timeout period as well as the enable/disable
operation. This register controls the overall operation of the Watchdog Timer.
• WDTC Register
Bit76543210
NameWE4WE3WE2WE1WE0WS2WS1WS0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR01010011
Bit 7~3 WE4~WE0: WDT function software control
10101: Disable
01010: Enable
Other values: Reset MCU
When these bits are changed by the environmental noise or software setting to reset
the microcontroller, the reset operation will be activated after a delay time, t
the WRF bit in the RSTFC register will be set to 1.
These three bits determine the division ratio of the Watchdog Timer source clock,
which in turn determines the timeout period.
• RSTFC Register
Bit76543210
Name————RSTFLVRFLRFWRF
R/W————R/WR/WR/WR/W
POR————0x00
Bit 7~4 Unimplemented, read as "0"
Bit 3 RSTF: Reset control register software reset ag
Refer to the RES Pin Reset section.
Bit 2 LVRF: LVR function reset ag
Refer to the Low Voltage Reset section.
, and
SRESET
"x": unknown
Bit 1 LRF: LVR control register software reset ag
Refer to the Low Voltage Reset section.
Bit 0 WRF: WDT control register software reset ag
0: Not occurred
1: Occurred
This bit is set to 1 by the WDT control register software reset and cleared by the application
program. Note that this bit can only be cleared to 0 by the application program.
Watchdog Timer Operation
The Watchdog Timer operates by providing a device reset when its timer overows. This means
that in the application program and during normal operation the user has to strategically clear the
Watchdog Timer before it overows to prevent the Watchdog Timer from executing a reset. This is
done using the clear watchdog instruction. If the program malfunctions for whatever reason, jumps
to an unknown location, or enters an endless loop, the clear instruction will not be executed in the
correct manner, in which case the Watchdog Timer will overow and reset the device. With regard to
the Watchdog Timer enable/disable function, there are ve bits, WE4~WE0, in the WDTC register
to offer additional enable/disable 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. The WDT function will be
enabled if the WE4~WE0 bits value is 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, t
on these bits will have the value of 01010B.
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. Four methods can be adopted to clear the contents of the Watchdog Timer. The
rst 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. The last is an external hardware reset, which means a low level on the
external reset pin if the external reset pin function is selected by conguring the RSTC register.
There is only one method of using software instruction to clear the Watchdog Timer. That is to use
the single "CLR WDT" instruction to clear the WDT.
The maximum time out period is when the 218 division ratio is selected. As an example, with a
32kHz LIRC oscillator as its source clock, this will give a maximum watchdog period of around 8
seconds for the 218 division ratio, and a minimum timeout of 8ms for the 28 division ration.
If these bits are changed due to adverse environmental conditions, the microcontroller
will be reset. The reset operation will be activated after a delay time, t
RSTF bit in the RSTFC register will be set to 1.
All resets will reset this register to POR value except the WDT time out hardware
warm reset. Note that when if this register is set to 10101010B to select the RES pin
function, this conguration has higher priority than other related pin-shared controls.
• RSTFC Register
Bit76543210
Name————RSTFLVRFLRFWRF
R/W————R/WR/WR/WR/W
POR————0x00
Bit 7~4 Unimplemented, read as "0"
Bit 3 RSTF: Reset control register software reset ag
This bit is set to 1 by the RSTC control register software reset and cleared by the
application program. Note that this bit can only be cleared to 0 by the application
program.
Bit 2 LVRF: LVR function reset ag
Refer to the Low Voltage Reset section.
Bit 1 LRF: LVR control register software reset ag
Refer to the Low Voltage Reset section.
Bit 0 WRF: WDT control register software reset ag
Refer to the Watchdog Timer Control Register section.
01010101: PB5
10101010: RES pin
Other values: Reset MCU
0: Not occurred
1: Occurred
, and the
SRESET
"x": unknown
Low Voltage Reset – LVR
The microcontroller contains a low voltage reset circuit in order to monitor the supply voltage of the
device. The LVR function is always enabled with a specic LVR voltage V
of the device drops to within a range of 0.9V~V
such as might occur when changing the battery,
LVR
. If the supply voltage
LVR
the LVR will automatically reset the device internally and the LVRF bit in the RSTFC register will
also be set to 1. For a valid LVR signal, a low supply voltage, i.e., a voltage in the range between
0.9V~V
must exist for a time greater than that specied by t
LVR
in the LVD & LVR Electrical
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. The actual V
value can be selected by
LVR
the LVS bits in the LVRC register. If the LVS7~LVS0 bits are changed to some certain values by
the environmental noise or software setting, the LVR will reset the device after a delay time, t
When this happens, the LRF bit in the RSTFC register will be set to 1. After power on the register
will have the value of 01100110B. Note that the LVR function will be automatically disabled when
11110000: LVR disable
Any other value: Generates a MCU reset – register is reset to POR value
When an actual low voltage condition occurs, as specied by one of the ve dened
LVR voltage values above, an MCU reset will be generated. The reset operation
will be activated after the low voltage condition keeps more than a t
situation the register contents will remain the same after such a reset occurs.
Any register value, other than the ve dened LVR values above, will also result in the
generation of an MCU reset. The reset operation will be activated after a delay time,
t
. However in this situation the register contents will be reset to the POR value.
SRESET
LVR
time. In this
• RSTFC Register
Bit76543210
Name————RSTFLVRFLRFWRF
R/W————R/WR/WR/WR/W
POR————0x00
Bit 7~4 Unimplemented, read as "0"
Bit 3 RSTF: Reset control register software reset ag
Refer to the RES Pin Reset section.
Bit 2 LVRF: LVR function reset ag
0: Not occurred
1: Occurred
This bit is set to 1 when a specic low voltage reset condition occurs. Note that this bit
can only be cleared to 0 by the application program.
Bit 1 LRF: LVR control register software reset ag
0: Not occurred
1: Occurred
This bit is set to 1 by the LVRC control register contains any undened LVR voltage
register values. This in effect acts like a software-reset function. Note that this bit can
only be cleared to 0 by the application program.
Bit 0 WRF: WDT control register software reset ag
Refer to the Watchdog Timer Control Register section.
Holtek microcontrollers offer considerable exibility on their I/O ports. With the input or output
designation of every pin fully under user program control, pull-high selections for all ports and
wake-up selections on certain pins, the user is provided with an I/O structure to meet the needs of a
wide range of application possibilities.
The device provides bidirectional input/output lines labeled with port names PA~PF. 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
PAPA7PA6PA5PA 4PA 3PA2PA 1PA 0
PACPAC7PAC6PAC5PAC4PAC3PAC2PAC1PAC0
PAPUPAPU7PAPU6PAPU5PAPU4PAPU3PAPU2PAPU1PAPU0
PAWUPAWU7PAWU6PAWU5PAWU4PAWU3PAWU2PAWU1PAWU0
PBPB7PB6PB5PB4PB3PB2PB1PB0
PBCPBC7PBC6PBC5PBC4PBC3PBC2PBC1PBC0
PBPUPBPU7PBPU6PBPU5PBPU4PBPU3PBPU2PBPU1PBPU0
PCPC7PC6PC5PC4PC3PC2PC1PC0
PCCPCC7PCC6PCC5PCC4PCC3PCC2PCC1PCC0
PCPUPCPU7PCPU6PCPU5PCPU4PCPU3PCPU2PCPU1PCPU0
PD————PD3PD2PD1PD0
PDC————PDC3PDC2PDC1PDC0
PDPU————PDPU3PDPU2PDPU1PDPU0
PE———PE4PE3PE2PE1PE0
PEC———PEC4PEC3PEC2PEC1PEC0
PEPU———PEPU4PEPU3PEPU2PEPU1PEPU0
PFPF7PF6PF5PF4PF3PF2PF1PF0
PFCPFC7PFC6PFC5PFC4PFC3PFC2PFC1PFC0
PFPUPFPU7PFPU6PFPU5PFPU4PFPU3PFPU2PFPU1PFPU0
LVPUC———————LVPU
Bit
76543210
"—": Unimplemented, read as "0"
I/O Logic Function Registers List
Pull-high Resistors
Many product applications require pull-high resistors for their switch inputs usually requiring the
use of an external resistor. To eliminate the need for these external resistors, all I/O pins, when
congured as an input have the capability of being connected to an internal pull-high resistor. These
pull-high resistors are selected using the relevant pull-high control registers PAPU~PFPU and
LVPUC and are implemented using weak PMOS transistors. Note that the pull-high resistor can
be controlled by the relevant pull-high control registers only when the pin-shared functional pin is
selected as a logic input or NMOS output. Otherwise, the pull-high resistors can not be enabled.
• PxPU Register
Bit76543210
NamePxPU7PxPU6PxPU5PxPU4PxPU3PxPU2PxPU1PxPU0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
PxPUn: I/O Px.n Pin pull-high function control
0: Disable
1: Enable
The PxPUn bit is used to control the Px.n pin pull-high function. Here the "x" can be A, B, C, D, E
and F. However, the actual available bits for each I/O Port may be different.
HT45F4050
A/D NFC Flash MCU
• LV PUC Register
Bit76543210
Name———————LVPU
R/W———————R/W
POR———————0
Bit 7~1 Unimplemented, read as "0"
Bit 0 LVPU: Low Voltage pull-high resistor control
Port A Wake-up
The HALT instruction forces the microcontroller into the SLEEP or IDLE Modes 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-shared functional pin is selected as general purpose input/output and the
MCU enters the Power down mode.
0: All pin pull-high resistors are 30kΩ @ 5V
1: All pin pull-high resistors are 7.5kΩ @ 5V
Note that as the pull high resistors are formed using long PMOS transistors, lower
operating voltages will result in higher pull high resistor impedances. It is therefore
recommended that for lower voltage applications the lower pull high resistor value is
chosen.
Bit 7~0 PAWU7~PAWU0: PA7~PA0 wake-up function control
I/O Port Control Registers
Each I/O port has its own control register known as PAC~PFC, 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 setup as a CMOS output. If the pin is currently setup 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.
0: Disable
1: Enable
• PxC Register
Bit76543210
NamePxC7PxC6PxC5PxC4PxC3PxC2PxC1PxC0
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR11111111
PxCn: I/O Port x Pin type selection
0: Output
1: Input
The PxCn bit is used to control the pin type selection. Here the "x" can be A, B, C, D, E and F.
However, the actual available bits for each I/O Port may be different.
I/O Port Source Current Control
The device supports different source current driving capability for each I/O port. With the
corresponding selection registers, SLEDCn, specic I/O port can support four levels of the source
current driving capability. Users should refer to the D.C. characteristics section to select the desired
The 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 diagram, it is supplied as a guide only to
assist with the functional understanding of the logc function I/O pins. The wide range of pin-shared
structures does not permit all types to be shown.
Data Bus
Control Bit
D
Q
Pull-high
Register
Select
VDD
Weak
Pull-up
Write Control Register
Chip Reset
Read Control Register
Write Data Register
Read Data Register
System Wake-up
Programming Considerations
Within the user program, one of the rst 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, PAC~PFC, are then programmed to setup
some pins as outputs, these output pins will have an initial high output value unless the associated
port data registers, PA~PF, 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 rst read in the data on the entire port, modify it to
the required new bit values and then rewrite this data back to the output ports.
Port A has the additional capability of providing wake-up functions. When the device is in the
SLEEP or IDLE Mode, various methods are available to wake the device up. One of these is a high
to low transition of any of the Port A pins. Single or multiple pins on Port A can be setup to have this
function.
CK
Q
S
Data Bit
Q
D
Q
CK
S
M
U
X
wake-up Select
Logic Function Input/Output Structure
I/O pin
PA only
Timer Modules – TM
One of the most fundamental functions in any microcontroller devices is the ability to control and
measure time. To implement time related functions 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 exible range of features.
The common features of the different TM types are described here with more detailed information
provided in the individual Compact, Standard and Periodic TM sections.
Introduction
The device contains three TMs and each individual TM can be categorised as a certain type, namely
Compact Type TM, Standard Type TM or Periodic Type TM. Although similar in nature, the
different TM types vary in their feature complexity. The common features to all of the Compact,
Standard and Periodic TMs will be described in this section and the detailed operation regarding
each of the TM types will be described in separate sections. The main features and differences
between the three types of TMs are summarised in the accompanying table.
TM FunctionCTMSTMPTM
Timer/Counter√√√
Input Capture—√√
Compare Match Output√√√
PWM Channels111
Single Pulse Output—11
PWM AlignmentEdgeEdgeEdge
PWM Adjustment Period & DutyDuty or PeriodDuty or PeriodDuty or Period
HT45F4050
A/D NFC Flash MCU
TM Function Summary
TM Operation
The different types of TM offer a diverse range of functions, from simple timing operations to PWM
signal generation. The key to understanding how the TM operates is to see it in terms of a free
running count-up counter whose value is then compared with the value of pre-programmed internal
comparators. When the free running count-up counter has the same value as the pre-programmed
comparator, known as a compare match situation, a TM interrupt signal will be generated which
can clear the counter and perhaps also change the condition of the TM output pin. The internal TM
counter is driven by a user selectable clock source, which can be an internal clock or an external pin.
TM Clock Source
The clock source which drives the main counter in each TM can originate from various sources.
The selection of the required clock source is implemented using the xTCK2~xTCK0 bits in the
xTM control registers, where "x" stands for C, S or P type TM. The clock source can be a ratio of
the system clock, f
The xTCK pin clock source is used to allow an external signal to drive the TM as an external clock
source for event counting.
TM Interrupts
The Compact Type, Standard Type and Periodic Type TMs each have two internal interrupts, one for
each of the internal comparator A or comparator P, which generate a TM interrupt when a compare
match condition occurs. When a TM interrupt is generated it can be used to clear the counter and
also to change the state of the TM output pin.
Each of the TMs, irrespective of what type, has one or two TM input pins, with the label xTCK
and xTPI respectively. 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 STCK and PTCK pins are also used as the external trigger input
pin in single pulse output mode for the STM and PTM respectively.
The other xTM input pin, STPI or PTPI, 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 STIO1~STIO0 or PTIO1~PTIO0 bits in the STMC1 or PTMC1 register respectively. 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 have two output pins, xTP and xTPB. The xTPB is the inverted signal of the xTP
output. 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 or xTPB output pin is also the pin where the TM generates the PWM output waveform.
As the TM input and output pins are pin-shared with other functions, the TM 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.
The TM Counter Registers and the Capture/Compare CCRA and CCRP registers, all have a low and
high byte structure. The high bytes can be directly accessed, but as the low bytes can only be accessed
via an internal 8-bit buffer, reading or writing to these register pairs must be carried out in a specic
way. The important point to note is that data transfer to and from the 8-bit buffer and its related low
byte only takes place when a write or read operation to its corresponding high byte is executed.
As the CCRA and CCRP registers are implemented in the way shown in the following diagram and
accessing these register pairs is carried out in a specic way as described above, it is recommended
to use the "MOV" instruction to access the CCRA and CCRP low byte registers, named 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.
CCR capture input
PTCK
PTPI
PTM
CCR output
PTM Function Pin Block Diagram
xTM Counter Register (Read only)
xTMDHxTMDL
8-bit Buffer
PTP
PTPB
xTMAL
xTM CCRA Register (Read/Write)
PTM CCRP Register (Read/Write)
xTMAH
PTMRPHPTMRPL
Data Bus
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
Although the simplest form of the three TM types, the Compact TM type still contains three
operating modes, which are Compare Match Output, Timer/Event Counter and PWM Output modes.
The Compact TM can also be controlled with an external input pin and can drive two external output
pins.
CTM CoreCTM Input PinCTM Output Pin
16-bit CTMCTCKCTP, CTPB
CCRP
000
f
/4
SYS
001
f
SYS
010
fH/16
011
CTCK
Pin
Control
PxSn IFS0
fH/64
f
SUB
f
SUB
CTCK2~CTCK0
100
101
110
111
CTON
CTPAU
16-bit Count-up Counter
Compact Type TM Operation
At its core is a 16-bit count-up counter which is driven by a user selectable internal or external clock
source. There are also two internal comparators with the names, Comparator A and Comparator
P. These comparators will compare the value in the counter with CCRP and CCRA registers. The
CCRP is 8-bit wide whose value is compared with the highest eight bits in the counter while the
CCRA is 16-bit wide and therefore compares with all counter bits.
The only way of changing the value of the 16-bit counter using the application program, is to
clear the counter by changing the CTON bit from low to high. The counter will also be cleared
automatically by a counter overow or a compare match with one of its associated comparators.
When these conditions occur, a CTM interrupt signal will also usually be generated. The Compact
Type TM can operate in a number of different operational modes, can be driven by different clock
sources including an input pin and can also control two output pins. All operating setup conditions
are selected using relevant internal registers.
b8~b15
Comparator P Match
Counter Clear
CTCCLR
Comparator A Match
0
1
8-bit Comparator P
b0~b15
16-bit Comparator A
CCRA
Compact Type TM Block Diagram
CTMPF Interrupt
CTOC
Output
Control
CTM1, CTM0
CTIO1, CTIO0
CTMAF Interrupt
Polarity
Control
CTPOLPxSn
Pin
Control
CTP
CTPB
Compact Type TM Register Description
Overall operation of the Compact TM is controlled using a series of registers. A read only register
pair exists to store the internal counter 16-bit value, while a read/write register pair exists to store
the internal 16-bit CCRA value. The CTMRP register is used to store the 8-bit CCRP value. The
remaining two registers are control registers which setup the different operating and control modes.
Register
Name
CTMC0CTPAUCTCK2CTCK1CTCK0CTON———
CTMC1CTM1CTM0CTIO1CTIO0CTOCCTPOLCTDPXCTCCLR
CTMDLD7D6D5D4D3D2D1D0
CTMDHD15D14D13D12D 11D10D9D8
CTMALD7D6D5D4D3D2D1D0
CTMAHD15D14D13D12D 11D10D9D8
CTMRPCTRP7CTRP6CTRP5CTRP4CTRP3CTRP2CTRP1CTRP0
76543210
16-bit Compact TM Registers List
Bit
HT45F4050
A/D NFC Flash MCU
• CTMC0 Register
Bit76543210
NameCTPAUCTCK2CTCK1CTCK0CTON———
R/WR/WR/WR/WR/WR/W———
POR00000———
Bit 7 CTPAU: CTM Counter Pause control
0: Run
1: Pause
The counter can be paused by setting this bit high. Clearing the bit to zero restores
normal counter operation. When in a Pause condition the CTM will remain powered
up and continue to consume power. The counter will retain its residual value when
this bit changes from low to high and resume counting from this value when the bit
changes to a low value again.
These three bits are used to select the clock source for the CTM. The external pin
clock source can be chosen to be active on the rising or falling edge. The clock source
f
SYS
can be found in the oscillator section.
Bit 3 CTON: CTM Counter On/Off control
0: Off
1: On
This bit controls the overall on/off function of the CTM. Setting the bit high enables
the counter to run while clearing the bit disables the CTM. Clearing this bit to zero
will stop the counter from counting and turn off the CTM 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 CTM is in
the Compare Match Output Mode or the PWM Output Mode then the CTM output pin
will be reset to its initial condition, as specied by the CTOC bit, when the CTON bit
changes from low to high.
Bit 2~0 Unimplemented, read as "0"
/4
SYS
SYS
SUB
SUB
is the system clock, while fH and f
are other internal clocks, the details of which
SUB
• CTMC1 Register
Bit76543210
NameCTM1CTM0CTIO1CTIO0CTOCCTPOLCTDPXCTCCLR
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~6 CTM1~CTM0: Select CTM Operating Mode
00: Compare Match Output Mode
01: Undened
10: PWM Output Mode
11: Timer/Counter Mode
These bits setup the required operating mode for the CTM. To ensure reliable
operation the CTM should be switched off before any changes are made to the CTM1
and CTM0 bits. In the Timer/Counter Mode, the CTM output pin state is undened.
These two bits are used to determine how the CTM output pin changes state when a
certain condition is reached. The function that these bits select depends upon in which
mode the CTM is running.
In the Compare Match Output Mode, the CTIO1 and CTIO0 bits determine how the
CTM output pin changes state when a compare match occurs from the Comparator A.
The CTM 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 CTM output
pin should be setup using the CTOC bit in the CTMC1 register. Note that the output
level requested by the CTIO1 and CTIO0 bits must be different from the initial value
setup using the CTOC bit otherwise no change will occur on the CTM output pin when
a compare match occurs. After the CTM output pin changes state, it can be reset to its
initial level by changing the level of the CTON bit from low to high.
In the PWM Output Mode, the CTIO1 and CTIO0 bits determine how the CTM
output pin changes state when a certain compare match condition occurs. The PWM
output function is modied by changing these two bits. It is necessary to only change
the values of the CTIO1 and CTIO0 bits only after the CTM has been switched off.
Unpredictable PWM outputs will occur if the CTIO1 and CTIO0 bits are changed
when the CTM is running.
Bit 3 CTOC: CTP Output control
Compare Match Output Mode
PWM Output Mode
This is the output control bit for the CTM output pin. Its operation depends upon
whether CTM is being used in the Compare Match Output Mode or in the PWM
Output Mode. It has no effect if the CTM is in the Timer/Counter Mode. In the
Compare Match Output Mode it determines the logic level of the CTM output pin
before a compare match occurs. In the PWM Output Mode it determines if the PWM
signal is active high or active low.
Bit 2 CTPOL: CTP Output polarity control
This bit controls the polarity of the CTP output pin. When the bit is set high the CTM
output pin will be inverted and not inverted when the bit is zero. It has no effect if the
TM is in the Timer/Counter Mode.
Bit 1 CTDPX: CTM PWM duty/period control
This bit determines which of the CCRA and CCRP registers are used for period and
duty control of the PWM waveform.
00: No change
01: Output low
10: Output high
11: Toggle output
00: PWM output inactive state
01: PWM output active state
10: PWM output
11: Undened
Bit 0 CTCCLR: CTM Counter Clear condition selection
0: CTM Comparator P match
1: CTM Comparator A match
This bit is used to select the method which clears the counter. Remember that the
Compact TM contains two comparators, Comparator A and Comparator P, either of
which can be selected to clear the internal counter. With the CTCCLR bit set high,
the counter will be cleared when a compare match occurs from the Comparator A.
When the bit is low, the counter will be cleared when a compare match occurs from
the Comparator P or with a counter overow. A counter overow clearing method can
only be implemented if the CCRP bits are all cleared to zero. The CTCCLR bit is not
used in the PWM Output Mode.
• CTMDL Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WRRRRRRRR
POR00000000
Bit 7~0 CTM Counter Low Byte Register bit 7 ~ bit 0
CTM 16-bit Counter bit 7 ~ bit 0
• CTMDH Register
Bit76543210
NameD15D14D13D12D11D10D9D8
R/WRRRRRRRR
POR00000000
Bit 7~0 CTM Counter High Byte Register bit 7 ~ bit 0
CTRP7~CTRP0: CTM CCRP 8-bit register, compared with the CTM Counter bit 15 ~ bit 8
Comparator P Match Period=
0: 65536 CTM clocks
1~255: 256 × (1~255) CTM clocks
These eight bits are used to setup the value on the internal CCRP 8-bit register, which
are then compared with the internal counter's highest eight bits. The result of this
comparison can be selected to clear the internal counter if the CTCCLR bit is set to
zero. Setting the CTCCLR bit to zero ensures that a compare match with the CCRP
values will reset the internal counter. As the CCRP bits are only compared with the
highest eight counter bits, the compare values exist in 256 clock cycle multiples.
Clearing all eight bits to zero is in effect allowing the counter to overflow at its
maximum value.
Compact Type TM Operating Modes
The Compact Type TM can operate in one of three operating modes, Compare Match Output Mode,
PWM Output Mode or Timer/Counter Mode. The operating mode is selected using the CTM1 and
CTM0 bits in the CTMC1 register.
Compare Match Output Mode
To select this mode, bits CTM1 and CTM0 in the CTMC1 register, should be set to "00"
respectively. In this mode once the counter is enabled and running it can be cleared by three
methods. These are a counter overow, a compare match from Comparator A and a compare match
from Comparator P. When the CTCCLR bit is low, there are two ways in which the counter can be
cleared. One is when a compare match occurs from Comparator P, the other is when the CCRP bits
are all zero which allows the counter to overow. Here both CTMAF and CTMPF interrupt request
ags for the Comparator A and Comparator P respectively, will both be generated.
If the CTCCLR bit in the CTMC1 register is high then the counter will be cleared when a compare
match occurs from Comparator A. However, here only the CTMAF interrupt request ag will be
generated even if the value of the CCRP bits is less than that of the CCRA registers. Therefore when
CTCCLR is high no CTMPF interrupt request ag will be generated. If the CCRA bits are all zero,
the counter will overow when its reaches its maximum 16-bit, FFFF Hex, value, however here the
CTMAF interrupt request ag will not be generated.
As the name of the mode suggests, after a comparison is made, the CTM output pin will change
state. The CTM output pin condition however only changes state when a CTMAF interrupt request
ag is generated after a compare match occurs from Comparator A. The CTMPF interrupt request
ag, generated from a compare match occurs from Comparator P, will have no effect on the CTM
output pin. The way in which the CTM output pin changes state are determined by the condition of
the CTIO1 and CTIO0 bits in the CTMC1 register. The CTM output pin can be selected using the
CTIO1 and CTIO0 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 CTM output pin, which is setup after
the CTON bit changes from low to high, is setup using the CTOC bit. Note that if the CTIO1 and
CTIO0 bits are zero then no pin change will take place.
HT45F4050
A/D NFC Flash MCU
CCRP=0
Counter overflow
CCRP > 0
CCRP > 0
Counter cleared by CCRP value
Resume
Pause
Counter Value
0xFFFF
CCRP
CCRA
CTON
CTPAU
CTPOL
CCRP Int. flag
CTMPF
CCRA Int. flag
CTMAF
CTM O/P Pin
Output not affected by
Output pin set to
initial Level Low if
CTOC=0
Output Toggle
with CTMAF flag
Here CTIO [1:0] = 11
Toggle Output select
Note CTIO [1:0] = 10
Active High Output select
CTMAF flag. Remains High
until reset by CTON bit
Compare Match Output Mode – CTCCLR=0
Note: 1. With CTCCLR=0, a Comparator P match will clear the counter
2. The CTM output pin is controlled only by the CTMAF ag
3. The output pin is reset to its initial state by a CTON bit rising edge
The Standard Type TM contains ve operating modes, which are Compare Match Output, Timer/
Event Counter, Capture Input, Single Pulse Output and PWM Output modes. The Standard TM can
also be controlled with two external input pins and can drive two external output pins.
STM CoreSTM Input PinSTM Output Pin
16-bit STMSTCK, STPISTP, STPB
CCRP
8-bit Comparator P
16-bit Count-up Counter
STON
STPAU
16-bit Comparator A
STCK
Pin
Control
PxSn IFS0
f
/4
SYS
f
SYS
fH/16
fH/64
f
SUB
f
SUB
STCK2~STCK0
000
001
010
011
100
101
110
111
Standard Type TM Block Diagram
Standard Type TM Operation
The size of Standard TM is 16-bit wide and its core is a 16-bit count-up counter which is driven by
a user selectable internal or external clock source. There are also two internal comparators with the
names, Comparator A and Comparator P. These comparators will compare the value in the counter with
CCRP and CCRA registers. The CCRP comparator is 8-bit wide whose value is compared the with
highest 8 bits in the counter while the CCRA is the sixteen bits and therefore compares all counter bits.
The only way of changing the value of the 16-bit counter using the application program, is to
clear the counter by changing the STON bit from low to high. The counter will also be cleared
automatically by a counter overow or a compare match with one of its associated comparators.
When these conditions occur, a 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 two output pins. All operating setup conditions
are selected using relevant internal registers.
CCRA
b8~b15
b0~b15
Comparator P Match
Counter Clear
STCCLR
Comparator A Match
STIO1, STIO0
Edge
Detector
STMPF Interrupt
STOC
0
1
Output
Control
STM1, STM0
STIO1, STIO0
PxSn IFS0
Control
Polarity
Control
STMAF Interrupt
Pin
STPOL
STPI
Pin
Control
PxSn
STP
STPB
Standard Type TM Register Description
Overall operation of the Standard TM is controlled using a series of registers. A read only register
pair exists to store the internal counter 16-bit value, while a read/write register pair exists to store
the internal 16-bit CCRA value. The STMRP register is used to store the 8-bit CCRP value. The
remaining two registers are control registers which setup the different operating and control modes.
Register
Name
STMC0STPAUSTCK2STCK1STCK0STON———
STMC1STM1STM0STIO1STIO0STOCSTPOLSTDPXSTCCLR
STMDLD7D6D5D4D3D2D1D0
STMDHD15D14D13D12D11D10D9D8
STMALD7D6D5D4D3D2D1D0
STMAHD15D14D13D12D 11D10D9D8
STMRPSTRP7STRP6STRP5STRP4STRP3STRP2STRP1STRP0
76543210
16-bit Standard TM Registers List
Bit
HT45F4050
A/D NFC Flash MCU
• STMC0 Register
Bit76543210
NameSTPAUSTCK2STCK1STCK0STON———
R/WR/WR/WR/WR/WR/W———
POR00000———
Bit 7 STPAU: STM Counter Pause control
0: Run
1: Pause
The counter can be paused by setting this bit high. Clearing the bit to zero restores
normal counter operation. When in a Pause condition the 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 clock
000: f
001: f
010: fH/16
011: fH/64
100: f
101: f
110: STCK rising edge clock
111: 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 f
the system clock, while fH and f
be found in the oscillator section.
Bit 3 STON: STM Counter On/Off control
0: Off
1: 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 or PWM output Mode or Single Pulse Output Mode,
then the STM output pin will be reset to its initial condition, as specied by the STOC
bit, when the STON bit changes from low to high.
Bit 2~0 Unimplemented, read as "0"
SYS
SYS
SUB
SUB
/4
are other internal clocks, the details of which can
SUB
SYS
is
• STMC1 Register
Bit76543210
NameSTM1STM0STIO1STIO0STOCSTPOLSTDPXSTCCLR
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
Bit 7~6 STM1~STM0: Select STM Operating Mode
00: Compare Match Output Mode
01: Capture Input Mode
10: PWM Output Mode or Single Pulse Output Mode
11: Timer/Counter Mode
These bits 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 undened.
Bit 5~4 STIO1~STIO0: Select STM external pin function
Compare Match Output Mode
PWM Output Mode/Single Pulse Output Mode
Capture Input Mode
Timer/Counter Mode
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 TM 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 modied 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.
Bit 3 STOC: STM STP Output control
Compare Match Output Mode
PWM Output Mode/Single Pulse Output Mode
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 control
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.
00: No change
01: Output low
10: Output high
11: Toggle output
00: PWM output inactive state
01: PWM output active state
10: PWM output
11: Single Pulse Output
00: Input capture at rising edge of STPI
01: Input capture at falling edge of STPI
10: Input capture at rising/falling edge of STPI
11: Input capture disabled
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 selection
0: Comparator P match
1: Comparator A match
This bit is used to select the method which clears the counter. Remember that the
Standard 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 overow. A counter overow 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 Register
Bit76543210
NameD7D6D5D4D3D2D1D0
R/WRRRRRRRR
POR00000000
Bit 7~0D7~D0: STM Counter Low Byte Register bit 7 ~ bit 0
STM 16-bit Counter bit 7 ~ bit 0
• STMDH Register
Bit76543210
NameD15D14D13D12D11D10D9D8
R/WRRRRRRRR
POR00000000
Bit 7~0D15~D8: STM Counter High Byte Register bit 7 ~ bit 0
STM 16-bit Counter bit 15 ~ bit 8
• STMAL Register
Bit7654321
NameD7D6D5D4D3D2D1D0
R/W
POR
R/WR/WR/WR/WR/WR/WR/WR/W
0000000
Bit 7~0D7~D0: STM CCRA Low Byte Register bit 7 ~ bit 0
STM 16-bit CCRA bit 7 ~ bit 0
• STMAH Register
Bit76543210
NameD15D14D13D12D11D10D9D8
R/WR/WR/WR/WR/WR/WR/WR/WR/W
POR00000000
0
0
Bit 7~0D15~D8: STM CCRA High Byte Register bit 7 ~ bit 0
These eight bits are used to setup the value on the internal CCRP 8-bit register, which
are then compared with the internal counter's highest eight bits. The result of this
comparison can be selected to clear the internal counter if the STCCLR bit is set to
zero. Setting 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 the
highest eight counter bits, the compare values exist in 256 clock cycle multiples.
Clearing all eight bits to zero is in effect allowing the counter to overflow at its
maximum value.
Standard Type TM Operation Modes
The Standard Type TM can operate in one of ve 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 Mode
To 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 overow, 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 overow. Here both STMAF and STMPF interrupt request ags 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 ag 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 ag will be generated. In the Compare Match Output
Mode, the CCRA can not be set to "0".
If the CCRA bits are all zero, the counter will overow when its reaches its maximum 16-bit, FFFF
Hex, value, however here the STMAF interrupt request ag 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 a STMAF interrupt request
ag is generated after a compare match occurs from Comparator A. The STMPF interrupt request
ag, 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.
HT45F4050
A/D NFC Flash MCU
CCRP=0
Counter overflow
CCRP > 0
CCRP > 0
Counter cleared by CCRP value
Resume
Pause
Counter Value
0xFFFF
CCRP
CCRA
STON
STPAU
STPOL
CCRP Int. flag
STMPF
CCRA Int. flag
STMAF
STM O/P Pin
Output not affected by
Output pin set
to initial Level
Low if STOC=0
Output Toggle
with STMAF flag
Here STIO [1:0] = 11
Toggle Output select
Note STIO [1:0] = 10
Active High Output select
STMAF flag. Remains High
until reset by STON bit
Compare Match Output Mode – STCCLR=0
Note: 1. With STCCLR=0, a Comparator P match will clear the counter
2. The STM output pin is controlled only by the STMAF ag
3. The output pin is reset to its initial state by a STON bit rising edge