HOLTEK HT45R37V

HT45R37V
TinyPowerTM C/R-F Type 8-Bit OTP MCU
Technical Document
· Application Note
- HA0075E MCU Reset and Oscillator Circuits Application Note
Features
· Operating voltage:
· 2-channel 12-bit resolution A/D converter
fSYS=32768Hz: 2.2V~5.5V
fSYS=4MHz: 2.2V~5.5V
fSYS=8MHz: 3.0V~5.5V
fSYS=12MHz: 4.5V~5.5V
· 1-channel 12-bit PWM output shared with I/O line
· Low voltage reset function - 2.1V, 3.15V, 4.2V
· Low voltage detect function - 2.2V, 3.3V, 4.4V
· Bit manipulation instruction
· OTP Program Memory: 4K´15
· 15-Bit table read instructions
· RAM Data Memory: 160´8
· 63 powerful instructions
· 16 bidirectional I/O lines
· Up to 0.33ms instruction cycle with 12MHz system
· Three external interrupt input shared with I/O lines
clock at VDD=5V
· Two 8-bit programmable Timer/Event Counter
· All instructions executed in one or two machine
with overflow interrupt and 7-stage prescaler
cycles
· External C/R to F converter
· Idle/Sleep mode and wake-up functions to reduce
· 9-Channel Capacitor/Resistor sensor inputs
power consumption
· Integrated Crystal, IRC, ERC and RTC oscillator
· Time-Base and RTC interrupt
· Fully integrated internal RC oscillator available with
· Integrated DC 24V to 5V LDO regulator
three frequencies: 4MHz, 8MHz or 12MHz
· Buzzer and filament 5V to 24V output level shifter
· Watchdog Timer function
· 24-bit shift register/latch for VFD panel driving 24
· LIRC or RTC oscillator function for watchdog timer
grid/segment outputs
· PFD and Buzzer for audio frequency generation
· Integrated 3-line serial VFD interface for
· Dual Serial Interfaces: SPI and I2C
grid/segment display control
· 4 operating modes: normal, slow, idle and sleep
· 52-pin QFP package type
· 6-level subroutine nesting
General Description
The HT45R37V is a TinyPowerTM C/R to F Type 8-bit high
performance RISC architecture microcontroller designed
especially for VFD applications. As a C/R to F type of
MCU, the device can interface to 9 external C or R type
sensors and convert their values to a frequency value for
processing. In addition its internal A/D converter allows
the device to interface directly to analog signals and its integrated dual channel Pulse Width Modulators allows control of external motors, LEDs etc.
addition to low power consumption, high performance,
I/O flexibility and low-cost, provides the device with the
versatility for a wide range of products in the home appliance and industrial application areas. Some of these
products could include electronic metering, environmental monitoring, handheld instruments, electronically controlled tools, motor driving in addition to many others.
The unique Holtek TinyPower technology also gives the
devices extremely low current consumption characteristics, an extremely important consideration in the present
trend for low power battery powered applications. The
usual Holtek MCU features such as power down and
wake-up functions, oscillator options, programmable
frequency divider, etc. combine to ensure user applications require a minimum of external components.
The device is specifically designed for VFD applications
that interface directly to VFD panels.
With their fully integrated SPI and I2C functions, designers are provided with a means of easy communication
with external peripheral hardware. The benefits of integrated A/D, C/R to F converter, and PWM functions, in
Rev. 1.00
1
October 20, 2009
HT45R37V
Block Diagram
L o w
V o lta g e
D e te c t
O T P
P r o g r a m m in g
C ir c u itr y
I/O
P o rts
O T P
P ro g ra m
M e m o ry
W a tc h d o g
T im e r
W a tc h d o g
T im e r O s c illa to r
L o w
V o lta g e
R e s e t
V F D D r iv e r
& L D O
R e g u la to r
R e s e t
C ir c u it
8 - b it
R IS C
M C U
C o re
In te rru p t
C o n tr o lle r
E x te rn a l
R C /C ry s ta l
O s c illa to r
R A M
D a ta
M e m o ry
S ta c k
In te rn a l R C
O s c illa to r
E x te rn a l R T C
O s c illa to r
A /D
C o n v e rte r
I2C /S P I
C /R to F
G e n e ra to r
P r o g r a m m a b le
F re q u e n c y
G e n e ra to r
T im e r s
P W M
G e n e ra to r
Pin Assignment
V F D 1
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V
V S S /A V S
O
S
0
9
8
7
6
5
4
P A 4 /T M R 1
P A 5 /S C K
3
P A 3
P D 0 /P
P B
/P F
W M
P B
/S C
/S C
2
1
0
R C O
P A 0 /B
P A 1 /B
P A 2 /T M R
C R E F
R R E F
U T /IN
Z /R C 0
Z /R C 1
0 /R C 2
N C
0 /A N 0
D /R C 3
0 /R C 8
1 /A N 1
S /R C 4
L /R C 5
5 2 5 1 5 0 4 9 4 8 4 7 4 6 4 5 4 4 4 3 4 2 4 1 4 0
1
3 9
3 8
2
3 7
3
3 6
4
5
3 5
6
H T 4 5 R 3 7 V
5 2 Q F P -A
7
8
9
1 0
1 1
1 2
1 3
1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6
3 4
3 3
3 2
3 1
3 0
2 9
2 8
2 7
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
V F D
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
2 0
2 1
2 2
2 3
F 1 O
B Z O
B Z O
V C C
B Z I
P C 1
P C 2
V D D
P C 0
P C 3
P C 4
P A 7
P A 6
/O
/O
/A
/R
/O
/O
/IN
/IN
S C 1
S C 2
V D D
E S
S C 3
S C 4
T 1 /S D O /R C 7
T 0 /S D I/S D A /R C 6
Rev. 1.00
2
October 20, 2009
HT45R37V
Pin Description
Pin Name
I/O
PA0/BZ/RC0
PA1/BZ/RC1
PA2/TMR0/RC2
PA3/PFD/RC3
I/O
PA4/TMR1/SCS/RC4
SIM
PA5/SCK/SCL/RC5
PA6/INT0/SDI/SDA/RC6
PA7/INT1/SDO/RC7
PB0/AN0
PB1/AN1
PB2/F1
PB3/STROBE
PB4/CLK
PB5/DATA
PC0/RES
PC1/OSC1
PC2/OSC2
PC3/OSC3
PC4/OSC4
Rev. 1.00
I/O
I/O
I/O
Configuration
Option
Description
BZ/BZ
PFD
RC0~RC7
Bidirectional 8-bit input/output port. Each individual bit on this port
can be configured as a wake-up input using the PAWU register.
Software instructions determine if the pin is a CMOS output or
Schmitt trigger input. A pull high resistor can be connected to each
pin using the PAPU register. Pins PA0, PA1, PA3, PA2, PA4, PA6
and PA7 are shared with BZ, BZ, PFD, TMR0, TMR1, INT0 and
INT1 respectively. PA7 is also pin-shared with the SPI bus data
output line, SDO. PA6 is also pin-shared with the SPI bus data line,
SDI and the I2C Bus data line SDA. PA5 is also pin-shared with the
SPI bus clock line, SCK, and the I2C Bus clock line SCL. PA4 is
also pin-shared with the SPI bus select line, SCS. The C/R to F
converter inputs RC0~RC7 are shared with pins Pins PA0~PA7
respectively.
¾
Bidirectional 2-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. A pull
high resistor can be connected to each pin using the PBPU register. PB is pin-shared with the A/D input pins. The A/D inputs are selected via software instructions. Once selected as an A/D input,
the I/O function and pull-high resistor selections are disabled automatically.
¾
Bidirectional 4-bit internal input/output port. Software instructions
determine if the pin is a CMOS output or Schmitt trigger input. A
pull high resistor can be connected to each pin using the PBPU
register.
PB2~PB5 are used to control the VFD driver interface by selected
as the I/O function. These pins should only be used as outputs and
as VFD interface pins and not as normal I/O pins.
PC0 or RES
Bidirectional line I/O. Software instructions determine if the pin is
an NMOS output or Schmitt Trigger input. A configuration option
determines if the pin is to be used as a RES pin or as an I/O pin.
This pin does not have an internal pull-high function.
I/O
Bidirectional 2-line I/O. Software instructions determine if the pins
are CMOS outputs or Schmitt Trigger inputs. A pull high resistor
can be connected to each pin using the PCPU register. Configuration options determine if the pins are to be used as oscillator pins
or I/O pins. Configuration options also determine which oscillator
1.Int. RC OSC mode is selected. The three oscillator modes are:
2.Crystal OSC 1. Internal RC OSC: both pins configured as I/Os.
3.Ext. RC OSC 2. External crystal OSC: both pins configured as OSC1/OSC2.
3. External RC OSC+PC2: PC1 is configured as OSC1 pin, PC2
configured as an I/O.
If the internal RC OSC is selected, the frequency will be fixed at either
4MHz, 8MHz or 12MHz, dependent upon which configuration option
is chosen.
I/O
Bidirectional 2-line I/O. Software instructions determine if the pins
are CMOS outputs or Schmitt Trigger inputs. A pull high resistor
can be connected to each pin using the PCPU register. Configuration options determine if the pins are to be used as oscillator pins
or I/O pins. If configuration options select oscillator pins, the pins
are connected to a 32768Hz crystal oscillator.
RTC OSC
3
October 20, 2009
HT45R37V
Pin Name
I/O
Configuration
Option
Description
Bidirectional 1-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. A pull
high resistor can be connected to each pin using the PDPU register. The PWM outputs, PWM0, are pin shared with pins PD0, the
function of which is chosen using the PWM registers. The C/R to F
converter inputs RC8 are shared with pins PD0.
PD0/PWM0/RC8
I/O
RC8
PD1~PD7
¾
¾
These seven pads are internal I/O and not bound out.
RCOUT/IN
I
¾
Capacitor or resistor connection pin to RC OSC/ Oscillation input.
RREF
I
¾
Reference resistor connection pin
CREF
I
¾
Reference capacitor connection pin
F1O
O
¾
High voltage filament output signal
BZO
BZO
O
¾
High voltage buzzer complement output signals
BZI
I
¾
Buzzer control Schmitt Trigger input.
VO
¾
¾
LDO regulator output
VCC
¾
¾
High voltage positive power supply for driving the VFD filament,
F1O, BZO and BZO outputs. An external 10uF capacitor is recommended to be connected to ground on the PCB to reduce surge
voltages.
VFD0~VFD23
O
¾
High voltage grid/segment output for VFD panel
VDD/AVDD
¾
¾
Positive power supply/analog positive power supply.
VSS/AVSS
¾
¾
Negative power supply, ground/analog negative power supply,
ground
Note:
1. Pin PB2~PB5 are four internal pins only and not bound out and its port control register must setup this pin
as an output.
2. PB2~PB5 individual pins can be selected to have a pull-high resistor.
Absolute Maximum Ratings
Supply Voltage ...........................VSS-0.3V to VSS+6.0V
Storage Temperature ............................-50°C to 125°C
Input Voltage..............................VSS-0.3V to VDD+0.3V
VCC Supply Voltage.....................................12V to 24V
IOH Total ..............................................................-80mA
Operating Temperature...........................-40°C to 85°C
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 this device at other conditions beyond those listed
in the specification is not implied and prolonged exposure to extreme conditions may affect device reliability.
Rev. 1.00
4
October 20, 2009
HT45R37V
D.C. Characteristics
Ta=25°C
Test Conditions
Symbol
Parameter
Min.
Typ.
Max.
Unit
fSYS=4MHz
2.2
¾
5.5
V
fSYS=8MHz
3.0
¾
5.5
V
fSYS=12MHz
4.5
¾
5.5
V
VDD VCC
VDD
Operating Voltage
¾
¾
Conditions
AVDD
A/D Operating Voltage
¾
¾
¾
2.7
¾
5.5
V
IDD1
Operating Current
(Crystal OSC, RC OSC)
3V
¾
¾
170
250
mA
5V
¾
No load,
fSYS=fM=1MHz
¾
380
700
mA
3V
¾
¾
240
360
mA
5V
¾
¾
490
800
mA
3V
¾
¾
440
660
mA
5V
¾
¾
900
1350
mA
3V
¾
¾
380
570
mA
5V
¾
¾
720
1080
mA
IDD2
IDD3
IDD4
Operating Current
(Crystal OSC, RC OSC)
Operating Current
(Crystal OSC, RC OSC)
Operating Current
(EC Mode, Filter On)
No load,
fSYS=fM=2MHz
No load,
fSYS=fM=4MHz (note 4)
No load,
fSYS=fM=4MHz
IDD5
Operating Current
(Crystal OSC, RC OSC)
5V
¾
No load,
fSYS=fM=8MHz
¾
1.8
2.7
mA
IDD6
Operating Current
(Crystal OSC, RC OSC)
5V
¾
No load,
fSYS=fM=12MHz
¾
2.6
4.0
mA
Operating Current
(Slow Mode, fM=4MHz)
(Crystal OSC, RC OSC)
3V
¾
¾
150
220
IDD7
mA
5V
¾
¾
340
510
mA
3V
¾
¾
180
270
mA
5V
¾
¾
400
600
mA
3V
¾
¾
270
400
mA
5V
¾
¾
560
840
mA
3V
¾
¾
240
360
mA
5V
¾
¾
540
810
mA
3V
¾
¾
320
480
mA
5V
¾
¾
680
1020
mA
3V
¾
¾
500
750
mA
5V
¾
¾
1000
1500
mA
Operating Current
(fSYS=32768Hz (note 1)
or 32K_INT internal RC OSC)
3V
¾
¾
8
16
mA
5V
¾
¾
15
30
mA
Standby Current ( Sleep)
(fSYS, fSUB, fS, fWDT=off)
3V
¾
¾
¾
1
mA
5V
¾
¾
¾
2
mA
Standby Current ( Sleep)
(fSYS, fWDT=fSUB=32768Hz
(note 1) or 32K_INT RC OSC)
3V
¾
¾
2
4
mA
5V
¾
¾
4
6
mA
IDD8
IDD9
IDD10
IDD11
IDD12
IDD13
ISTB1
ISTB2
Rev. 1.00
Operating Current
(Slow Mode, fM=4MHz)
(Crystal OSC, RC OSC)
Operating Current
(Slow Mode, fM=4MHz)
(Crystal OSC, RC OSC)
Operating Current
(Slow Mode, fM=8MHz)
(Crystal OSC, RC OSC)
Operating Current
(Slow Mode, fM=8MHz)
(Crystal OSC, RC OSC)
Operating Current
(Slow Mode, fM=8MHz)
(Crystal OSC, RC OSC)
No load,
fSYS=fSLOW=500kHz
No load,
fSYS=fSLOW=1MHz
No load,
fSYS=fSLOW=2MHz
No load,
fSYS=fSLOW=1MHz
No load,
fSYS=fSLOW=2MHz
No load,
fSYS=fSLOW=4MHz
No load, WDT off
No load, system HALT,
WD off
No load, system HALT,
WDT on
5
October 20, 2009
HT45R37V
Test Conditions
Symbol
Parameter
VDD VCC
Min.
Typ.
Max.
Unit
¾
2
4
mA
¾
4
6
mA
Conditions
Standby Current ( Idle)
(fSYS, fWDT=off;
fS=fSUB=32768Hz (note 1)
or 32K_INT RC OSC)
3V
¾
5V
¾
VIL1
Input Low Voltage for I/O Ports,
TMR and INT
¾
¾
¾
0
¾
0.3VDD
V
VIH1
Input High Voltage for I/O Ports,
¾
TMR and INT
¾
¾
0.7VDD
¾
VDD
V
VIL2
Input Low Voltage (RES)
¾
¾
¾
0
¾
0.4VDD
V
VIH2
Input High Voltage (RES)
¾
¾
¾
0.9VDD
¾
VDD
V
¾
¾
Configuration option: 2.1V
1.98
2.1
2.22
V
¾
¾
Configuration option: 3.15V
2.98
3.15
3.32
V
¾
¾
Configuration option: 4.2V
3.98
4.2
4.42
V
¾
¾
Configuration option: 2.2V
2.08
2.2
2.32
V
¾
¾
Configuration option: 3.3V
3.12
3.3
3.50
V
¾
¾
Configuration option: 4.4V
4.12
4.4
4.70
V
3V
¾
6
12
¾
mA
5V
¾
10
25
¾
mA
3V
¾
-2
-4
¾
mA
5V
¾
-5
-8
¾
mA
3V
¾
0.8
1.5
¾
mA
5V
¾
2
4
¾
mA
Pull-high Resistance for I/O
Ports
3V
¾
20
60
100
kW
5V
¾
10
30
50
kW
VAD
A/D Input Voltage
¾
¾
¾
0
¾
AVDD
V
VREF
A/D Input Reference Voltage
Range
¾
¾
¾
¾
AVDD
¾
V
DNL
A/C Differential Non-Linearity
¾
¾
AVDD=5V, VREF=AVDD,
tAD=0.5ms
-2
¾
2
LSB
INL
ADC Integral Non-Linearity
¾
¾
AVDD=5V, VREF=AVDD,
tAD=0.5ms
-4
¾
4
LSB
IADC
Additional Power Consumption 3V
if A/D Converter is Used
5V
¾
¾
0.5
1
mA
¾
1.5
3
mA
ISTB3
VLVR
VLVD
IOL1
IOH1
IOL2
RPH
Low Voltage Reset Voltage
Low Voltage Detector Voltage
I/O Port Sink Current Except PC0
I/O Port Source Current
PC0 Sink Current
No load, system HALT,
WDT off
VOL=0.1VDD
VOH=0.9VDD
VOL=0.1VDD
¾
¾
¾
VO
LDO Output Voltage
¾
¾
¾
4.7
5.0
5.3
V
VCC
VFD, F1O, BZO and BZO
Output Supply Voltage
¾
¾
¾
12
¾
24
V
IOUT
Maximum LDO Output Current
¾
¾
For VCC³5V
10
¾
¾
mA
DVLNR Line Regulation
¾
¾
VIN=(VOUT+0.1V) to 24V,
IOUT=1mA
¾
0.2
¾
%/V
DVLDR Load Regulation
¾
¾
IOUT=100mA to 20mA,
COUT=10pF
¾
0.1
0.2
%/mA
Rev. 1.00
6
October 20, 2009
HT45R37V
Test Conditions
Symbol
Parameter
Min.
Typ.
Max.
Unit
25
30
35
mV
18V No load, VFD outputs, all
24V output low, CLK=100kHz
¾
70
110
mA
¾
90
135
mA
18V No load, VFD outputs, all
24V output high, CLK=100kHz
¾
70
110
mA
¾
90
135
mA
18V
¾
100
150
mA
¾
120
180
mA
¾
80
120
mA
¾
100
150
mA
¾
70
105
mA
¾
90
135
mA
2.5
5.0
¾
mA
5.0
10.0
¾
mA
-15
-30
¾
mA
-22
-25
¾
mA
15
30
¾
mA
25
50
¾
mA
-15
-30
¾
mA
-25
-50
2.5
5.0
¾
mA
5.0
10.0
¾
mA
-6
-12
¾
mA
-10
-20
¾
mA
VDD VCC
VDRO
Dropout Voltage
¾
ICC1
Logic Operating Current 1
5V
ICC2
Logic Operating Current 2
ICC3
Buzzer Operating Current
5V
¾
5V
Conditions
IOUT=1mA
No load, BZI input 50kHz
24V
18V
ICC4
Filament Operating Current
5V
No load, F1 input 50kHz
24V
ISTB
18V
Standby Current (LDO Always
On, WDT Enable/Disable)
5V
F1O Sink Current
5V
No load
24V
18V
IOL2
VOL= 0.1VCC
24V
18V
IOH2
F1O Source Current
5V
VOH= 0.9VCC
24V
18V
IOL3
BZO/BZO Sink Current
5V
VOL= 0.1VCC
24V
18V
IOH3
BZO/BZO Source Current
5V
VOH= 0.9VCC
24V
18V
IOL4
Grid/Segment Sink Current
5V
VOL= 0.1VCC
24V
18V
IOH4
Grid/Segment Source Current
5V
VOH= 0.9VCC
24V
Note:
mA
1. 32768Hz is in slow start mode (RTCC.4=1) for the D.C. current measurement.
2. fS is the internal clock for Buzzer, RTC, Time base and WDT.
3. Both Timer/Event Counters are off. Timer filter is disabled for all test conditions.
4. All peripherals are in OFF condition if not mentioned at IDD, ISTB tests.
Rev. 1.00
7
October 20, 2009
HT45R37V
A.C. Characteristics
Symbol
Parameter
System Clock
(Crystal OSC, ERC OSC)
fSYS1
fSYS2
System Clock (HIRC OSC)
Ta=25°C
Test Conditions
Min.
Typ.
Max.
Unit
2.2V~5.5V
400
¾
4000
kHz
3.0V~5.5V
400
¾
8000
kHz
4.5V~5.5V
400
¾
12000
kHz
5V
-2%
4000
+2%
kHz
5V
-2%
8000
+2%
kHz
5V
-2%
12000
+2%
kHz
¾
32768
¾
Hz
-2%
4000
+2%
kHz
¾
32768
¾
Hz
2.2V~5.5V
0
¾
4000
kHz
3.0V~5.5V
0
¾
8000
kHz
4.5V~5.5V
0
¾
12000
kHz
VDD
¾
¾
Conditions
fSYS3
System Clock
(RTC Crystal OSC)
¾
2.2V~5.5V
f4MRCOSC
4MHz External RC OSC
5V
External R=150kW
fRTCOSC
RTC Frequency
¾
fTIMER
Timer I/P Frequency
(TMR0/TMR1)
¾
¾
fRC32K
32K RC Period (LIRC)
¾
28.1
31.25
34.4
ms
tRES
External Reset Low Pulse Width
¾
¾
1
¾
¾
ms
tLVR
Low Voltage Reset Time
¾
¾
0.1
0.4
0.6
ms
tSST1
System Start-up Timer Period
¾
Power-on
¾
1024
¾
tSYS*
tSST2
System Start-up Timer Period
for XTAL or RTC oscillator
¾
Wake-up from Power
Down Mode
¾
1024
¾
tSYS*
tSST3
System Start-up Timer Period
for RC or External Clock
¾
Wake-up from Power
Down Mode
¾
1
2
tSYS*
tINT
Interrupt Pulse Width
¾
¾
1
¾
¾
ms
tAD
A/D Clock Period
¾
¾
0.5
¾
¾
ms
tADC
A/D Conversion Time
¾
¾
¾
16
¾
tAD
RESTD
Reset Delay Time
¾
¾
¾
100
¾
ms
Propagation Delay Time
(Clock to VFD Output)
¾
VCC=15V
¾
100
200
ns
Propagation Delay Time
(Strobe to VFD Output)
¾
VCC=15V
¾
100
200
ns
tTHL,
tTLH
Output Transition Time
¾
VCC=15V
¾
40
80
ns
tSU
Data Setup Time
¾
VCC=15V
¾
10
20
ns
tCS
Setup Time (Clock to Strobe)
¾
VCC=15V
¾
10
20
ns
tH
Hold Time (Data to Clock)
¾
VCC=15V
¾
10
20
ns
tSC
75
150
ns
tPHL,
tPLH
2.2V~5.5V, After Trim
Hold Time (Clock to Strobe)
¾
VCC=15V
¾
tr, tf
Clock Input Rise or Fall Time
¾
VCC=15V
¾
¾
20
ns
tWC
Clock Pulse Width
¾
VCC=15V
¾
40
83
ns
tWL
Strobe Pulse Width
¾
VCC=15V
¾
35
70
ns
fmax
Maximum Clock Input Frequency
¾
VCC=15V
¾
8
¾
MHz
Note:
*tSYS=1/fSYS1, 1/fSYS2 or 1/fSYS3
Rev. 1.00
8
October 20, 2009
HT45R37V
A.C. Waveforms
1 /fm
a x
V O
C L K
5 0 %
V S S
tS
tW
tH
U
tW
C
C
V O
D A T A
V S S
tP
tP
L H
H L
V O
V F D n
tT
tT
L H
V S S
H L
Data Propagation Delays, Setup and Hold Times
V O
D A T A
V S S
tC
C L K
tS
S
C
V O
5 0 %
V S S
tW
L
V O
S T R O B E
V S S
tP
L H
, tP
H L
V O
V F D n
V S S
Strobe Propagation Delays, Setup and Hold Times
Rev. 1.00
9
October 20, 2009
HT45R37V
Power-on Reset Characteristics
Symbol
Test Conditions
Parameter
VDD
Conditions
Min.
Typ.
Max.
Unit
VPOR
VDD Start Voltage to Ensure
Power-on Reset
¾
¾
¾
¾
100
mV
RRVDD
VDD raising rate to Ensure
Power-on Reset
¾
¾
0.035
¾
¾
V/ms
tPOR
Minimum Time for VDD Stays at
VPOR to Ensure Power-on Reset
¾
¾
1
¾
¾
ms
V
D D
tP
O R
R R
V D D
V
P O R
T im e
Rev. 1.00
10
October 20, 2009
HT45R37V
System Architecture
Clocking and Pipelining
A key factor in the high-performance features of the
Holtek range of microcontrollers is attributed to their internal system architecture. The range of devices take
advantage of the usual features found within RISC
microcontrollers providing increased speed of operation
and enhanced performance. The pipelining scheme is
implemented in such a way that instruction fetching and
instruction execution are overlapped, hence instructions
are effectively executed in one cycle, with the exception
of branch or call instructions. An 8-bit wide ALU is used
in practically all instruction set operations, which carries
out arithmetic operations, logic operations, rotation, increment, decrement, branch decisions, etc. The internal
data path is simplified by moving data through the Accumulator and the ALU. Certain internal registers are implemented in the Data Memory and can be directly or
indirectly addressed. The simple addressing methods of
these registers along with additional architectural features ensure that a minimum of external components is
required to provide a functional I/O and A/D control system with maximum reliability and flexibility. This makes
the device suitable for low-cost, high-volume production
for controller applications.
The main system clock, derived from either a Crystal/Resonator or RC 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.
O s c illa to r C lo c k
( S y s te m C lo c k )
P h a s e C lo c k T 1
P h a s e C lo c k T 2
P h a s e C lo c k T 3
P h a s e C lo c k T 4
P ro g ra m
C o u n te r
P ip e lin in g
P C
P C + 1
F e tc h In s t. (P C )
E x e c u te In s t. (P C -1 )
P C + 2
F e tc h In s t. (P C + 1 )
E x e c u te In s t. (P C )
F e tc h In s t. (P C + 2 )
E x e c u te In s t. (P C + 1 )
System Clocking and Pipelining
M O V A ,[1 2 H ]
2
C A L L D E L A Y
3
C P L [1 2 H ]
4
:
5
:
6
1
D E L A Y :
F e tc h In s t. 1
E x e c u te In s t. 1
F e tc h In s t. 2
E x e c u te In s t. 2
F e tc h In s t. 3
F lu s h P ip e lin e
F e tc h In s t. 6
E x e c u te In s t. 6
F e tc h In s t. 7
N O P
Instruction Fetching
Rev. 1.00
11
October 20, 2009
HT45R37V
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 writable 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.
During program execution, the Program Counter is used
to keep track of the address of the next instruction to be
executed. It is automatically incremented by one each
time an instruction is executed except for instructions,
such as ²JMP² or ²CALL² that demand a jump to a
non-consecutive Program Memory address. It must be
noted that only the lower 8 bits, known as the Program
Counter Low Register, are directly addressable.
The lower byte of the Program Counter is fully accessible under program control. Manipulating the PCL might
cause program branching, so an extra cycle is needed
to pre-fetch. Further information on the PCL register can
be found in the Special Function Register section.
When executing instructions requiring jumps to
non-consecutive addresses such as a jump instruction,
a subroutine call, interrupt or reset, etc., the
microcontroller manages program control by loading the
required address into the Program Counter. For conditional skip instructions, once the condition has been
met, the next instruction, which has already been
fetched during the present instruction execution, is discarded and a dummy cycle takes its place while the correct instruction is obtained.
Program Counter Bits
Mode
b11
b10
b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
Initial Reset
0
0
0
0
0
0
0
0
0
0
0
0
External Interrupt 0
0
0
0
0
0
0
0
0
0
1
0
0
External Interrupt 1
0
0
0
0
0
0
0
0
1
0
0
0
Timer/Event Counter 0 Overflow
0
0
0
0
0
0
0
0
1
1
0
0
Timer/Event Counter 1 Overflow
0
0
0
0
0
0
0
1
0
0
0
0
SPI/I C Interrupt
0
0
0
0
0
0
0
1
0
1
0
0
C/R to F Converter Interrupt
0
0
0
0
0
0
0
1
0
1
0
0
Time Base Interrupt
0
0
0
0
0
0
0
1
1
0
0
0
RTC Interrupt
0
0
0
0
0
0
0
1
1
0
0
0
A/D Converter Interrupt
0
0
0
0
0
0
0
1
1
0
0
0
@3
@2
@1
@0
2
Skip
Program Counter + 2
Loading PCL
PC11 PC10 PC9
PC8
@7
@6
@5
@4
Jump, Call Branch
#11
#10
#9
#8
#7
#6
#5
#4
#3
#2
#1
#0
Return from Subroutine
S11
S10
S9
S8
S7
S6
S5
S4
S3
S2
S1
S0
Program Counter
Note:
PC11~PC8: Current Program Counter bits
#11~#0: Instruction code address bits
Rev. 1.00
@7~@0: PCL bits
S11~S0: Stack register bits
12
October 20, 2009
HT45R37V
· Rotation RRA, RR, RRCA, RRC, RLA, RL, RLCA,
Stack
RLC
This is a special part of the memory which is used to
save the contents of the Program Counter only. The
stack has multiple levels depending upon the device
and is neither part of the data nor part of the program
space, and is neither readable nor writeable. The activated level is indexed by the Stack Pointer, SP, 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.
P ro g ra m
· Increment and Decrement INCA, INC, DECA, DEC
· Branch decision, JMP, SZ, SZA, SNZ, SIZ, SDZ,
SIZA, SDZA, CALL, RET, RETI
Program Memory
The Program Memory is the location where the user
code or program is stored. For these device the Program Memory is an OTP type, which means it can be
programmed only one time. By using the appropriate
programming tools, this OTP memory device offer users
the flexibility to conveniently debug and develop their
applications while also offering a means of field programming.
C o u n te r
Structure
T o p o f S ta c k
S ta c k L e v e l 1
The Program Memory has a capacity of 4K by 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 setup in any
location within the Program Memory, is addressed by a
separate table pointer register.
S ta c k L e v e l 2
S ta c k
P o in te r
B o tto m
S ta c k L e v e l 3
o f S ta c k
P ro g ra m
M e m o ry
S ta c k L e v e l 6
Special Vectors
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.
Within the Program Memory, certain locations are reserved for special usage such as reset and interrupts.
· Location 000H
This vector 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.
· Location 004H
This vector is used by the external interrupt 0. If the
external interrupt pin receives an active edge, the program will jump to this location and begin execution if
the external interrupt is enabled and the stack is not
full.
Arithmetic and Logic Unit - ALU
The 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:
· Location 008H
This vector is used by the external interrupt 1. If the
external interrupt pin receives an active edge, the program will jump to this location and begin execution if
the external interrupt is enabled and the stack is not
full.
· Location 00CH
This internal vector is used by the Timer/Event Counter 0. If a Timer/Event Counter 0 overflow occurs, the
program will jump to this location and begin execution
if the timer/event counter interrupt is enabled and the
stack is not full.
· Arithmetic operations: ADD, ADDM, ADC, ADCM,
SUB, SUBM, SBC, SBCM, DAA
· Logic operations: AND, OR, XOR, ANDM, ORM,
XORM, CPL, CPLA
Rev. 1.00
13
October 20, 2009
HT45R37V
0 0 0 H
0 0 4 H
This internal vector is used by the Multi-function Interrupt 1. The Multi-function Interrupt 1 vector is shared
by the Real Time Clock interrupt and Time Base interrupt, A/D converter interrupt. When a interrupt signal
is generated, the program will jump to this location
and begin execution if the interrupt is enabled and the
stack is not full.
E x te rn a l IN T 0
In te rru p t V e c to r
0 0 8 H
E x te rn a l IN T 1
In te rru p t V e c to r
0 0 C H
T im e r C o u n te r 0
In te rru p t V e c to r
0 1 0 H
0 1 4 H
· Location 018H
In itia lis a tio n
V e c to r
T im e r C o u n te r 1
In te rru p t V e c to r
Look-up Table
Any location within the Program Memory can be defined
as a look-up table where programmers can store fixed
data. To use the look-up table, the table pointer must
first be setup by placing the lower order address of the
look up data to be retrieved in the table pointer register,
TBLP. This register defines the lower 8-bit address of
the look-up table.
S P I/I2C In te rru p t,
R /C to F C o n v e rte r
In te rru p t V e c to r
0 1 8 H
T im e B a s e , R T C ,
A /D C o n v e rte r
In te rru p t V e c to r
After setting up the table pointer, the table data can be
retrieved from the current Program Memory page or last
Program Memory page using the ²TABRDC[m]² or
²TABRDL [m]² instructions, respectively. When these instructions are 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².
n 0 0 H
n F F H
F 0 0 H
F F F H
1 5 b its
N o t Im p le m e n te d
Program Memory Structure
· Location 010H
This internal vector is used by the Timer/Event Counter 1. If a Timer/Event Counter 1 overflow occurs, the
program will jump to this location and begin execution
if the timer/event counter interrupt is enabled and the
stack is not full.
The following diagram illustrates the addressing/data
flow of the look-up table:
P ro g ra m C o u n te r
H ig h B y te
P ro g ra m
M e m o ry
T B L P
· Location 014H
This internal vector is used by the Multi-function Interrupt 0. The Multi-function Interrupt 0 vector is shared
by the SPI/I2C and the C/R to F converter interrupt.
When an interrupt signal is generated, the program
will jump to this location and begin execution if the interrupt is enabled and the stack is not full.
T B L H
T a b le C o n te n ts H ig h B y te
S p e c ifie d b y [m ]
T a b le C o n te n ts L o w
B y te
Table Location Bits
Instruction
b11
b10
b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
TABRDC [m]
PC11
PC10
PC9
PC8
@7
@6
@5
@4
@3
@2
@1
@0
TABRDL [m]
1
1
1
1
@7
@6
@5
@4
@3
@2
@1
@0
Table Location
Note:
PC11~PC8: Current Program Counter bits
@7~@0: Table Pointer TBLP bits
Rev. 1.00
14
October 20, 2009
HT45R37V
Table Program Example
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.
The following example shows how the table pointer and
table data is defined and retrieved from the
microcontroller. This example uses raw table data located in the last page 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 HT45R37. The table pointer is setup 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 first address of the present page if the ²TABRDC [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 ²TABRDL [m]² instruction is executed.
Tempreg1 db
tempreg2 db
:
:
mov
mov
?
?
; temporary register #1
; temporary register #2
a,06h
; initialise table pointer - note that this address is referenced
tblp,a
; to the last page or present page
tempreg1
;
;
;
;
:
:
tabrdl
dec tblp
tabrdl
:
:
org F00h
dc
transfers value in table referenced by table pointer
to tempregl
data at prog. memory address ²F06H² transferred to
tempreg1 and TBLH
; reduce value of table pointer by one
tempreg2
;
;
;
;
;
;
transfers value in table referenced by table pointer
to tempreg2
data at prog.memory address ²F05H² transferred to
tempreg2 and TBLH
in this example the data ²1AH² is transferred to
tempreg1 and data ²0FH² to register tempreg2
; sets initial address of last page
00Ah, 00Bh, 00Ch, 00Dh, 00Eh, 00Fh, 01Ah, 01Bh
:
:
Rev. 1.00
15
October 20, 2009
HT45R37V
Data Memory
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².
The Data Memory is a volatile area of 8-bit wide RAM
internal memory and is the location where temporary information is stored. Divided into two sections, the first of
these is an area of RAM where special function registers
are located. 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 reserved for general purpose use. All
locations within this area are read and write accessible
under program control.
0 0 H
0 1 H
0 2 H
0 3 H
0 4 H
0 5 H
0 6 H
0 7 H
0 8 H
0 9 H
0 A H
0 B H
0 C H
0 D H
0 E H
0 F H
1 0 H
1 1 H
1 2 H
1 3 H
1 4 H
1 5 H
1 6 H
1 7 H
1 8 H
1 9 H
1 A H
1 B H
1 C H
1 D H
1 E H
1 F H
2 0 H
2 1 H
2 2 H
2 3 H
2 4 H
2 5 H
2 6 H
2 7 H
2 8 H
2 9 H
2 A H
2 B H
2 C H
2 D H
2 E H
2 F H
3 0 H
3 1 H
3 2 H
3 3 H
3 4 H
3 5 H
3 6 H
3 7 H
3 8 H
3 9 H
3 A H
3 B H
3 C H
3 D H
3 E H
3 F H
4 0 H ~ 5 H F
Structure
The Data Memory is subdivided into two sections, the
Special Purpose Data Memory and the General Purpose Data Memory. The start address of the Data Memory is the address ²00H². The last Data Memory
address is ²FFH².
0 0 H
S p e c ia l P u r p o s e
D a ta M e m o ry
5 F H
6 0 H
G e n e ra l P u rp o s e
D a ta M e m o ry
F F H
Data Memory Structure
Note:
Most of the Data Memory bits can be directly manipulated using the ²SET [m].i² and ²CLR [m].i²
with the exception of a few dedicated bits. The
Data Memory can also be accessed through the
memory pointer registers MP0 and MP1.
General Purpose Data Memory
All 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 Data Memory
that is known as General Purpose Data Memory. This
area of Data Memory is fully accessible by the user program for both read and write operations. By using the
²SET [m].i² and ²CLR [m].i² 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 Memory
This area of Data Memory is where registers, necessary
for the correct operation of the microcontroller, are
stored. Most of the registers are both read and write type
but some are protected and are read only, the details of
Rev. 1.00
IA R 0
M P 0
IA R 1
M P 1
A C C
P C L
T B L P
T B L H
R T C C
S T A T U S
IN T C 0
T M R 0
T M R 0 C
P A
P A C
P B
P B C
P C
P C C
P D
P D C
P W M 0 L
P W M 0 H
P W M 1 L
P W M 1 H
IN T C 1
M F IC 0
M F IC 1
A S C R 0
A S C R 1
A S C R 2
A D R L
A D R H
A D C R
A C S R
C L K M O D
P A W U
P A P U
P B P U
P C P U
P D P U
IN T E D G E
M IS C
T M R A H
T M R A L
R C O C C R
T M R B H
T M R B L
R C O C R
S IM C T L 0
S IM C T L 1
S IM D R
S IM A R /S IM C T L 2
T M R 1
T M R 1 C
: U n u s e d re a d a s "0 0 "
: U n u s e d re a d a s u n k n o w n
Special Purpose Data Memory
16
October 20, 2009
HT45R37V
Special Function Registers
To ensure successful operation of the microcontroller,
certain internal registers are implemented in the Data
Memory area. These registers ensure correct operation
of internal functions such as timers, interrupts, etc., as
well as external functions such as I/O data control and
A/D converter operation. The location of these registers
within the Data Memory begins at the address 00H. Any
unused Data Memory locations between these special
function registers and the point where the General Purpose Memory begins is reserved for future expansion
purposes, attempting to read data from these locations
will return a value of 00H.
Memory Pointer, MP0 or MP1. As the Indirect Addressing Registers are not physically implemented,
reading the Indirect Addressing Registers indirectly will
return a result of ²00H² and writing to the registers indirectly will result in no operation.
Memory Pointers - MP0, MP1
Two 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.
Indirect Addressing Registers - IAR0, IAR1
The Indirect Addressing Registers, IAR0 and IAR1, although having their locations in normal register space,
do not actually physically exist as normal registers. The
method of indirect addressing for 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
The following example shows how to clear a section of
four RAM locations already defined as locations adres1
to adres4.
data .section ¢data¢
adres1
db ?
adres2
db ?
Adres3
db ?
adres4
db ?
block
db ?
code .section at 0 ¢code¢
org 00h
start:
mov
mov
mov
mov
a,04h
block,a
a,offset adres1
mp0,a
; setup size of block
loop:
clr
inc
sdz
jmp
IAR0
mp0
block
loop
; clear the data at address defined by MP0
; increment memory pointer
; check if last memory location has been cleared
; Accumulator loaded with first RAM address
; setup memory pointer with first RAM address
continue:
The important point to note here is that in the example shown above, no reference is made to specific RAM addresses.
Rev. 1.00
17
October 20, 2009
HT45R37V
Accumulator - ACC
Status Register - STATUS
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.
This 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.
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 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.
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 ad-
dition 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.
Look-up Table Registers - TBLP, TBLH
· Z is set if the result of an arithmetic or logical operation
These two special function registers are used to control
operation of the look-up table which is stored in the Program Memory. TBLP is the table pointer and indicates
the location where the table data is located. Its value
must be setup before any table read commands are executed. Its 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.
· OV is set if an operation results in a carry into the high-
is zero; otherwise Z is cleared.
est-order bit but not a carry out of the highest-order bit,
or vice versa; otherwise OV is cleared.
· PDF is cleared by a system power-up or executing the
²CLR WDT² instruction. PDF is set by executing the
²HALT² instruction.
· TO is cleared by a system power-up or executing the
²CLR WDT² or ²HALT² instruction. TO is set by a
WDT time-out.
b 7
b 0
T O
P D F
O V
Z
A C
C
S T A T U S R e g is te r
A r
C a
A u
Z e
ith m e
r r y fla
x ilia r y
r o fla g
O v e r flo w
g
tic /L o g ic O p e r a tio n F la g s
c a r r y fla g
fla g
S y s te m M
P o w e r d o w
W a tc h d o g
N o t im p le m
a n
n
tim
e
a g e m e n t F la g s
fla g
e - o u t fla g
n te d , re a d a s "0 "
Status Register
Rev. 1.00
18
October 20, 2009
HT45R37V
isters during normal program operation is a useful feature of these devices.
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.
Pulse Width Modulator Registers
The devices contain two Pulse Width Modulator outputs
each with their own related independent control register
pair, known as PWM0L/PWM0H and PWM1L/ PWM1H.
The 12-bit contents of each register pair, which defines
the duty cycle value for the modulation cycle of the Pulse
Width Modulator, along with an enable bit are contained
in these register pairs.
Interrupt Control Registers
These 8-bit registers, known as the INTC0, INTC1,
MFIC0, MFIC1 and INTEDGE registers, control the operation of the external and internal Timer/Event Counter
interrupt, Time Base interrupt, Real Time Clock interrupt, A/D converter interrupt, C/R to F converter interrupt and SPI/I2C interrupt. By setting various bits within
these registers using standard bit manipulation instructions, the enable/disable function of each interrupt can be
independently controlled. A master interrupt bit within this
register, the EMI bit, acts like a global enable/disable and
is used to set all of the interrupt enable bits on or off. This
bit is cleared when an interrupt routine is entered to disable further interrupt and is set by executing the ²RETI²
instruction.
A/D Converter Registers - ADRL, ADRH, ADCR, ACSR
The device contains a multiple channel 12-bit A/D converter. The correct operation of the A/D requires the use
of two data registers and two control registers. The two
data registers, a high byte data register known as
ADRH, and a low byte data register known as ADRL, are
the register locations where the digital value is placed
after the completion of an analog to digital conversion
cycle. Functions such as the A/D enable/disable, A/D
channel selection and A/D clock frequency are determined using the two control registers, ADCR and ACSR.
Timer/Event Counter Registers
C/R to F Converter Registers
The devices contains two 8-bit Timer/Event Counters.
The registers, TMR0 and TMR1 are the locations where
the timer values are located. These registers can also
be preloaded with fixed data to allow different time
intervals to be setup. The 8-bit Timer/Event Counters
have an associated control register, TMR0C and
TMR1C, which contain the setup information for these
timers, determines in what mode the timer is to be used
as well as containing the timer on/off control function.
The device contains a 9-channel C/R to F converter.
The correct operation of the C/R to F converter requires
the use of two 16-bit counters and five control registers.
The two 16-bit counters, a high byte register known as
TMRAH/TMRBH, and a low byte register known as
TMRAL/TMRBL. The channel selection of the C/R to F
converter is setup via the ASCR0~ASCR2 control registers. The configuration of the C/R to F converter is setup
via the RCOCCR or RCOCR control registers.
Input/Output Ports and Control Registers
Serial Interface Registers
Within the area of Special Function Registers, the I/O
registers and their associated control registers play a
prominent role. All I/O ports have a designated register
correspondingly labeled as PA, PB, PC and PD. These
labeled I/O registers are mapped to specific addresses
within the Data Memory as shown in the Data Memory
table, which are used to transfer the appropriate output
or input data on that port. With each I/O port there is an
associated control register labeled PAC, PBC, PCC and
PDC, also mapped to specific addresses with the Data
Memory. The control register specifies which pins of that
port are set as inputs and which are set as outputs. To
setup a pin as an input, the corresponding bit of the control register must be set high, for an output it must be set
low. During program initialization, it is important to first
setup the control registers to specify which pins are outputs and which are inputs before reading data from or
writing data to the I/O ports. One flexible feature of these
registers is the ability to directly program single bits using the ²SET [m].i² and ²CLR [m].i² instructions. The
ability to change I/O pins from output to input and vice
versa by manipulating specific bits of the I/O control regRev. 1.00
The device contains two serial interfaces, an SPI and an
I2C interface. The SIMCTL0, SIMCTL1, SIMCTL2 and
SIMAR are the control registers for the Serial Interface
function while the SIMDR is the data register for the Serial Interface Data.
Port A Wake-up Register - PAWU
All pins on Port A have a wake-up function enable a low
going edge on these pins to wake-up the device when it
is in a power down mode. The pins on Port A that are
used to have a wake-up function are selected using this
resister.
Pull-High Resistors - PAPU, PBPU, PCPU, PDPU
All I/O pins on Ports PA, PB, PC and PD, if setup as inputs, can be connected to an internal pull-high resistor.
The pins which require a pull-high resistor to be connected are selected using these registers.
19
October 20, 2009
HT45R37V
Register - CLKMOD
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.
The device operates using a dual clock system whose
mode is controlled using this register. The register controls functions such as the clock source, the idle mode
enable and the division ratio for the slow clock.
Port A Open Drain Function
All I/O pins in the device have CMOS structures, however Port A pins PA0~PA3 can also be setup as open
drain structures. This is implemented using the ODE0~
ODE3 bits in the MISC register.
Miscellaneous Register - MISC
The miscellaneous register is used to control two functions. The four lower bits are used for the Watchdog
Timer control, while the highest four bits are used to select open drain outputs for pins PA0~PA3.
I/O Port Control Registers
Each I/O port has its own control register known as PAC,
PBC, PCC and PDC, to control the input/output configuration. With this control register, each CMOS output or
input with or without pull-high resistor structures 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.
Input/Output Ports
Holtek microcontrollers offer considerable flexibility on
their I/O ports. With the input or output designation of every pin fully under user program control, pull-high selections for all ports and wake-up selections on certain
pins, the user is provided with an I/O structure to meet
the needs of a wide range of application possibilities.
The device provides multiple bidirectional input/output
lines labeled with port names PA, PB, PC and PD.
These I/O ports are mapped to the 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.
Pin-shared Functions
The flexibility of the microcontroller range is greatly enhanced by the use of pins that have more than one function. Limited numbers of pins can force serious design
constraints on designers but by supplying pins with
multi-functions, many of these difficulties can be overcome. For some pins, the chosen function of the
multi-function I/O pins is set by configuration options
while for others the function is set by application program control.
Pull-high Resistors
Many product applications require pull-high resistors for
their switch inputs usually requiring the use of an external resistor. To eliminate the need for these external resistors, all I/O pins, when configured as an input have
the capability of being connected to an internal pull-high
resistor. These pull-high resistors are selected using
registers PAPU, PBPU, PCPU and PDPU and are implemented using weak PMOS transistors.
· External Interrupt Inputs
The external interrupt pins INT0 and INT1 are
pin-shared with I/O pins. For applications not requiring
external interrupt inputs, the pin-shared external interrupt pin can be used as a normal I/O pin, however to
do this, the external interrupt enable bits in the INTC0
register must be disabled.
Port A Wake-up
The HALT instruction forces the microcontroller into a
Power Down condition 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. After
a HALT instruction forces the microcontroller into entering a Power Down condition, the processor will remain
in a low-power state until the logic condition of the selected wake-up pin on Port A changes from high to low.
This function is especially suitable for applications that
Rev. 1.00
· External Timer Clock Input
The external timer pins TMR0 and TMR1 are
pin-shared with I/O pins. To configure them to operate
as timer inputs, the corresponding control bits in the
timer control register must be correctly set and the pin
must also be setup as an input. Note that the original
I/O function will remain even if the pin is setup to be
used as an external timer input.
20
October 20, 2009
HT45R37V
b 7
O D E 3
O D E 2
O D E 1
O D E 0
W D T E N 3
W D T E N 2
b 0
W D T E N 0
W D T E N 1
M IS C
R e g is te r
W a tc h d o g T im e r E n a b le C o n tr o l
- d e s c r ib e d e ls e w h e r e
P A 0 O p e n D r a in C o n tr o l
1 : e n a b le
0 : d is a b le
P A 1 O p e n D r a in C o n tr o l
1 : e n a b le
0 : d is a b le
P A 2 O p e n D r a in C o n tr o l
1 : e n a b le
0 : d is a b le
P A 3 O p e n D r a in C o n tr o l
1 : e n a b le
0 : d is a b le
PA0~PA3 Open Drain Control - MISC
V
P u ll- H ig h
O p tio n
C o n tr o l B it
D a ta B u s
Q
D
W r ite C o n tr o l R e g is te r
W e a k
P u ll- u p
Q
C K
S
C h ip R e s e t
R e a d C o n tr o l R e g is te r
I/O
p in
A /D
In p u t P o rt
D a ta B it
Q
D
W r ite D a ta R e g is te r
C K
Q
S
R e a d D a ta R e g is te r
S y s te m
D D
M
U
X
W a k e -u p
W a k e - u p S e le c t
P A o n ly
Generic Input/Output Structure
V
D a ta B u s
W r ite C o n tr o l R e g is te r
P u ll- H ig h
R e g is te r
S e le c t
C o n tr o l B it
Q
D
D D
W e a k
P u ll- u p
Q
C K
S
C h ip R e s e t
R e a d C o n tr o l R e g is te r
W r ite D a ta R e g is te r
D a ta B it
Q
D
C K
S
Q
M
R e a d D a ta R e g is te r
P C R 2
P C R 1
P C R 0
T o A /D
U
X
A n a lo g
In p u t
S e le c to r
C o n v e rte r
A C S 2 ~ A C S 0
A/D Input/Output Structure
Rev. 1.00
21
October 20, 2009
HT45R37V
b 7
P X P U 7
P X P U 1
b 0
P X P U 0
P A P U , P B P U , P C P U , P D P U
R e g is te r
P A .0 , P B .0 , P D .0 P u ll- h ig h
1 : e n a b le
0 : d is a b le
P A .1 , P B .1 , P C .1 , P D .1 P u ll- h ig h
1 : e n a b le
0 : d is a b le
P A .7 , P B .5 , P C .4 , P D .7 P u ll- h ig h
1 : e n a b le
0 : d is a b le
Pull-High Resistor Register - PAPU, PBPU, PCPU, PDPU
· PFD Output
Programming Considerations
The device contains a PFD function whose single output is pin-shared with I/O pin PA3. The output function
of this pin is chosen via a configuration option and remains fixed after the device is programmed. Note that
the corresponding bit of the port control register,
PAC.3, must setup the pin as an output to enable the
PFD output. If the PAC port control register has setup
the pin as an input, then the pin will function as a normal logic input with the usual pull-high selection, even
if the PFD configuration option has been selected.
Within the user program, one of the first things to consider is port initialisation. After a reset, all of the I/O data
and port control registers will be set high. This means
that all I/O pins will default to an input state, the level of
which depends on the other connected circuitry and
whether pull-high selections have been chosen. If the
port control registers, PAC, PBC, PCC and PDC, 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, PB, PC and PD,
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.
· PWM Outputs
The device contains two PWM outputs shared with
pins PD0 and PD1. The PWM output functions are
chosen via registers. Note that the corresponding bit
of the port control register, PDC, must setup the pin as
an output to enable the PWM output. If the PDC port
control register has setup the pin as an input, then the
pin will function as a normal logic input with the usual
pull-high selection, even if the PWM registers have
enabled the PWM function.
· A/D Inputs
The device contains a multi-channel A/D converter inputs. All of these analog inputs are pin-shared with I/O
pins on Port B. If these pins are to be used as A/D inputs and not as normal I/O pins then the corresponding
bits in the A/D Converter Control Register, ADCR, must
be properly set. There are no configuration options associated with the A/D function. If used as I/O pins, then
full pull-high resistor register remain, however if used
as A/D inputs then any pull-high resistor selections associated with these pins will be automatically disconnected.
T 1
S y s te m
T 3
T 4
T 1
T 2
T 3
T 4
P o rt D a ta
W r ite to P o r t
R e a d fro m
P o rt
Read/Write Timing
Port A has the additional capability of providing wake-up
functions. When the device is in the Power Down 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.
I/O Pin Structures
The accompanying diagrams illustrate the internal
structures of some I/O pin types. As the exact logical
construction of the I/O pin will differ from these drawings, they are supplied as a guide only to assist with the
functional understanding of the I/O pins. The wide range
of pin-shared structures does not permit all types to be
shown.
Rev. 1.00
T 2
C lo c k
22
October 20, 2009
HT45R37V
VFD Driver
24-bit Shift Register/Latch
The device includes a VFD driver function to drive VFD
panel high voltage filaments and buzzer. The
microcontroller communicates serially with the VFD
driver transmitting the display data into a 24-bit shift register within the driver. This VFD driver converts the shift
register into VFD panel driving signals and makes the
necessary voltage level shifting. The microcontroller will
only transmit data to the VFD driver, no data is transmitted from the VFD driver to the microcontroller.
Data transmitted from the microcontroller is transmitted
serially and will be first written into a 24-bit shift register
located within the VFD driver. These 24-bits are used to
control the VFD panel segments, VFD0~VFD15, and
grid, VFD16~VFD23, lines. The control method is as follows:
· Use the ²DATA² and ²CLK² lines to shift data into the
internal 24-bit shift register. Data is clocked into the
shift-register on the positive clock edge. This data corresponds to the desired VFD0~VFD23 output display
data. The VFD outputs will only change if the
STROBE line is high. If the STROBE line is low, only
the shift register data will be modified and the VFD
outputs will remain the same.
VFD Interface
A five line interface exists between the microcontroller
and the VFD driver as shown in the diagram.
Data transmission between the microcontroller and the
VFD interface is conducted via a three line interface using the CLK, DATA and STROBE lines. As data communication is only one way the microcontroller I/O pins
must bet setup as outputs.
· Use the ²STROBE² line to latch the shift-register data
to the VFD0~VFD23 outputs. When the STROBE line
is high, the shift register data will be latched to the
VFD lines. Note that the STROBE line is level and not
edge triggered.
The buzzer control input BZI will be transformed into a
complementary pair of outputs BZO and BZO by a converter in the VFD driver. These complementary buzzer
outputs will also be level shifted to a higher voltage by
the converter. The VFD driver filament control input, F1,
will also be shifted to a high voltage output called F1O,
that can be used to switch the filaments on and off.
P B 3
P B 4
P B 5
I/O
P B 2
P a d N a m e
S T R O B E
C L K
D A T A
B Z I
F 1
V F D 0
S h ift
R e g is te r
& L a tc h
C o m p le m e n t
O u tp u t
C o n v e rte r
V F D 2 3
L e v e l
S h ifte r
B Z O
B Z O
F 1 O
V F D
D r iv e r
O u tp u ts
VFD Driver
C L K
D A T A
S T R O B E
V F D 0
VFD Display Control Timing Diagram
Rev. 1.00
23
October 20, 2009
HT45R37V
Programming Considerations
The accompanying table shows the 24-bit shift register/latch function truth table:
Clock Strobe Data
VFD0
VFDn
­
0
X
­
1
0
0
VFDn-1
­
1
1
1
VFDn-1
¯
1
1
Note:
After power on all the I/O lines will be automatically
setup as inputs. However as lines PB2~PB5 are used to
drive the VFD interface, they should be setup as outputs
after power is applied to the device. Allowing the VFD interface control lines to be setup as inputs will create an
incorrect VFD display operation. It is advised that the
configuration options select pull-high resistors to be
connected to these lines to keep the lines at a fixed high
level when power is initially applied and until the lines
can be setup as outputs.
No change No change
No change No change
²X² means don¢t care
²VFDn² means VFD1~VFD23
Programming Example
The following example shows how the VFD display data is programmed by the microcontroller.
strobe
equ pb.3
clk
equ pb.4
data
equ pb.5
data_2_register:
; send data to vfd driver
mov a,024d
; shift register counter
mov count,a
clr strobe
; strobe = 0
data_2_register_1:
clr clk
; clk = 0
set data
; data = 1
snz vfd_grid.7
clr data
; data = 0
rlc vfd_segl
; shift data to vfd[7:0]
rlc vfd_segh
; shift data to vfd[15:8]
rlc vfd_grid
; shift data to vfd[22:16]
set clk
; clk = 1 (rising edge)
sdz count
jmp data_2_register_1
set strobe
; strobe = 1, vfd output
ret
Rev. 1.00
24
October 20, 2009
HT45R37V
Timer/Event Counters
The provision of timers form an important part of any
microcontroller, giving the designer a means of carrying
out time related functions. The device contains two 8-bit
count-up timers. As each timer has three different operating modes, they can be configured to operate as a
general timer, an external event counter or as a pulse
width measurement device. The provision of a prescaler
to the clock circuitry of the 8-bit Timer/Event Counter
also gives added range to this timer.
preload register will be in an unknown condition. Note
that if the Timer/Event Counter is switched off and data
is written to its preload registers, this data will be immediately written into the actual timer registers. However, if
the Timer/Event Counter is enabled and counting, any
new data written into the preload data registers during
this period will remain in the preload registers and will
only be written into the timer registers the next time an
overflow occurs.
There are two types of registers related to the
Timer/Event Counters. The first are the registers that
contain the actual value of the Timer/Event Counter and
into which an initial value can be preloaded. Reading
from these registers retrieves the contents of the
Timer/Event Counter. The second type of associated
register is the Timer Control Register which defines the
timer options and determines how the Timer/Event
Counter is to be used. The Timer/Event Counters can
have the their clock configured to come from an internal
clock source. In addition, their clock source can also be
configured to come from an external timer pin.
Timer Control Registers - TMR0C, TMR1C
The flexible features of the Holtek microcontroller
Timer/Event Counters enable them to operate in three
different modes, the options of which are determined by
the contents of their respective control register.
It is the Timer Control Register together with its corresponding timer registers that control the full operation of
the Timer/Event Counters. Before the timers can be
used, it is essential that the appropriate Timer Control
Register is fully programmed with the right data to ensure its correct operation, a process that is normally carried out during program initialisation.
Configuring the Timer/Event Counter Input Clock
Source
To choose which of the three modes the timer is to operate in, either in the timer mode, the event counting mode
or the pulse width measurement mode, bits 7 and 6 of
the corresponding Timer Control Register, which are
known as the bit pair TnM1/TnM0, must be set to the required logic levels. The timer-on bit, which is bit 4 of the
Timer Control Register and known as TnON, depending
upon which timer is used, provides the basic on/off control of the respective timer. Setting the bit high allows the
counter to run, clearing the bit stops the counter. For timers that have prescalers, bits 0~2 of the Timer Control
Register determine the division ratio of the input clock
prescaler. The prescaler bit settings have no effect if an
external clock source is used. If the timer is in the event
count or pulse width measurement mode, the active
transition edge level type is selected by the logic level of
bit 3 of the Timer Control Register which is known as
TnE.
The internal timer¢s clock can originate from various
sources. The system clock source is used when the
Timer/Event Counter is in the timer mode or in the pulse
width measurement mode. This internal clock source is
fSYS which is also divided by a prescaler, the division ratio of which is conditioned by the Timer Control Register,
TMRnC, bits TnPSC0~ TnPSC2.
An external clock source is used when the timer is in the
event counting mode, the clock source being provided
on an external timer pin TMR0 or TMR1 depending
upon which timer is used. Depending upon the condition
of the TnE bit, each high to low, or low to high transition
on the external timer pin will increment the counter by
one.
Timer Registers - TMR0, TMR1
The timer registers are special function registers located in
the Special Purpose Data Memory and is the place where
the actual timer value is stored. These registers are known
as TMR0 or TMR1. The value in the timer registers increases by one each time an internal clock pulse is received or an external transition occurs on the external
timer pin. The timer will count from the initial value loaded
by the preload register to the full count of FFH at which
point the timer overflows and an internal interrupt signal is
generated. The timer value will then be reset with the initial
preload register value and continue counting.
Configuring the Timer Mode
In this mode, the Timer/Event Counter can be utilised to
measure fixed time intervals, providing an internal interrupt signal each time the Timer/Event Counter overflows. To operate in this mode, the Operating Mode
Select bit pair, TnM1/TnM0, in the Timer Control Register must be set to the correct value as shown.
Control Register Operating Mode
Select Bits for the Timer Mode
1
0
In this mode the internal clock, fSYS , is used as the internal clock for the Timer/Event Counter. However, the
clock source, fSYS, for the 8-bit timer is further divided by
To achieve a maximum full range count of FFH for the
8-bit timer, the preload registers must first be cleared to
all zeros. It should be noted that after power-on, the
Rev. 1.00
Bit7 Bit6
25
October 20, 2009
HT45R37V
D a ta B u s
R e lo a d
P r e lo a d R e g is te r
T n P S C 2 ~ T n P S C 0
(1 /1 ~ 1 /1 2 8 )
fS
7 - s ta g e P r e s c a le r
Y S
T n M 1
T n M 0
F ilte r
T M R n
F ilte r O n /O ff
C o n fig u r a tio n o p tio n
T im e r /E v e n t
C o u n te r
T im e r /E v e n t C o u n te r
M o d e C o n tro l
O v e r flo w
to In te rru p t
8 - b it T im e r /E v e n t C o u n te r
T n O N
¸ 2
P F D n
T n E
8-bit Timer/Event Counter Structure (n=0, 1)
M
P F D 0
P F D 1
U
X
P F D
C o n fig u r a tio n
O p tio n
b 7
T n M 1 T n M 0
b 0
T n O N
T n E
T n P S C 2
T n P S C 1
T n P S C 0
T M R n C
R e g is te r (n = 0 , 1 )
T im e r p r e s c a le r r a te s e le
T n P
T n P S C 2 T n P S C 1
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
E v e n t C
1 : c o u n
0 : c o u n
P u ls e W
1 : s ta rt
0 : s ta rt
o u n te r a c tiv e e d g
t o n fa llin g e d g e
t o n r is in g e d g e
id th M e a s u r e m e n
c o u n tin g o n r is in g
c o u n tin g o n fa llin g
0
c t
S C 0
1
0
1
0
1
0
1
T im e r
1 :1
1 :2
1 :4
1 :8
1 :1
1 :3
1 :6
1 :1
R a te
6
4
2
2 8
e s e le c t
t a c tiv e e d g e s e le c t
e d g e , s to p o n fa llin g e d g e
e d g e , s to p o n r is in g e d g e
T im e r /E v e n t C o u n te r c o u n tin g e n a b le
1 : e n a b le
0 : d is a b le
N o t im p le m e n te d , r e a d a s " 0 "
O p e r a tin
T n M 1 T
0
0
1
1
g m o d e
n M 0
n o
0
e v
1
tim
0
p u
1
s e le c t
m o d
e n t c
e r m
ls e w
e a v a ila b le
o u n te r m o d e
o d e
id th m e a s u r e m e n t m o d e
Timer/Event Counter Control Register - TMRnC
Rev. 1.00
26
October 20, 2009
HT45R37V
a prescaler, the value of which is determined by the
Prescaler Rate Select bits TnPSC2~TnPSC0, which are
bits 2~0 in the Timer Control Register. After the other
bits in the Timer Control Register have been setup, the
enable bit TnON or TnON, which is bit 4 of the Timer
Control Register, can be set high to enable the
Timer/Event Counter to run. Each time an internal clock
cycle occurs, the Timer/Event Counter increments by
one. When it is full and overflows, an interrupt signal is
generated and the Timer/Event Counter will reload the
value already loaded into the preload register and continue counting. The interrupt can be disabled by ensuring that the Timer/Event Counter Interrupt Enable bit in
the corresponding Interrupt Control Register, is reset to
zero.
corresponding Interrupt Control Register, is reset to
zero.
Configuring the Event Counter Mode
Configuring the Pulse Width Measurement Mode
In this mode, a number of externally changing logic
events, occurring on the external timer pin, can be recorded by the Timer/Event Counter. To operate in this
mode, the Operating Mode Select bit pair, TnM1/TnM0,
in the Timer Control Register must be set to the correct
value as shown.
In this mode, the Timer/Event Counter can be utilised to
measure the width of external pulses applied to the external timer pin. To operate in this mode, the Operating
Mode Select bit pair, TnM1/TnM0, in the Timer Control
Register must be set to the correct value as shown.
Control Register Operating Mode
Select Bits for the Event Counter Mode
As the external timer pin is shared with an I/O pin, to ensure that the pin is configured to operate as an event
counter input pin, two things have to happen. The first is
to ensure that the Operating Mode Select bits in the
Timer Control Register place the Timer/Event Counter in
the Event Counting Mode, the second is to ensure that
the port control register configures the pin as an input. It
should be noted that in the event counting mode, even if
the microcontroller is in the Power Down Mode, the
Timer/Event Counter will continue to record externally
changing logic events on the timer input pin. As a result
when the timer overflows it will generate a timer interrupt
and corresponding wake-up source.
Control Register Operating Mode
Select Bits for the Pulse Width
Measurement Mode
Bit7 Bit6
0
1
Bit7 Bit6
1
1
In this mode the internal clock, fSYS, is used as the internal clock for the Timer/Event Counter. However, the
clock source, fSYS, for the 8-bit timer is further divided by
a prescaler, the value of which is determined by the
Prescaler Rate Select bits TnPSC2~TnPSC0, which are
bits 2~0 in the Timer Control Register. After the other
bits in the Timer Control Register have been setup, the
enable bit TnON, which is bit 4 of the Timer Control Register, can be set high to enable the Timer/Event Counter,
however it will not actually start counting until an active
edge is received on the external timer pin.
In this mode, the external timer pin, is used as the
Timer/Event Counter clock source, however it is not divided by the internal prescaler. After the other bits in the
Timer Control Register have been setup, the enable bit
TnON, which is bit 4 of the Timer Control Register, can
be set high to enable the Timer/Event Counter to run. If
the Active Edge Select bit, TnE, which is bit 3 of the
Timer Control Register, is low, the Timer/Event Counter
will increment each time the external timer pin receives
a low to high transition. If the Active Edge Select bit is
high, the counter will increment each time the external
timer pin receives a high to low transition. When it is full
and overflows, an interrupt signal is generated and the
Timer/Event Counter will reload the value already
loaded into the preload register and continue counting.
The interrupt can be disabled by ensuring that the
Timer/Event Counter Interrupt Enable bit in the
If the Active Edge Select bit TnE, which is bit 3 of the
Timer Control Register, is low, once a high to low transition has been received on the external timer pin, the
Timer/Event Counter will start counting until the external
timer pin returns to its original high level. At this point the
enable bit will be automatically reset to zero and the
P r e s c a le r O u tp u t
In c re m e n t
T im e r C o n tr o lle r
T im e r + 1
T im e r + 2
T im e r + N
T im e r + N + 1
Timer Mode Timing Chart
E x te rn a l E v e n t
In c re m e n t
T im e r C o u n te r
T im e r + 1
T im e r + 2
T im e r + 3
Event Counter Mode Timing Chart
Rev. 1.00
27
October 20, 2009
HT45R37V
E x te rn a l T M R
P in In p u t
T n O N
- w ith T n E = 0
P r e s c a le r O u tp u t
In c re m e n t
T im e r C o u n te r
+ 1
T im e r
+ 2
+ 3
+ 4
Pulse Width Measure Mode Timing Chart
T im e r O v e r flo w
P F D
C lo c k
P A 3 D a ta
P F D
O u tp u t a t P A 3
PFD Output Control
Timer/Event Counter will stop counting. If the Active
Edge Select bit is high, the Timer/Event Counter will begin counting once a low to high transition has been received on the external timer pin and stop counting when
the external timer pin returns to its original low level. As
before, the enable bit will be automatically reset to zero
and the Timer/Event Counter will stop counting. It is important to note that in the Pulse Width Measurement
Mode, the enable bit is automatically reset to zero when
the external control signal on the external timer pin returns to its original level, whereas in the other two
modes the enable bit can only be reset to zero under
program control.
As the external timer pin is shared with an I/O pin, to ensure that the pin is configured to operate as a pulse
width measurement pin, two things have to happen. The
first is to ensure that the Operating Mode Select bits in
the Timer Control Register place the Timer/Event Counter in the Pulse Width Measurement Mode, the second
is to ensure that the port control register configures the
pin as an input.
The residual value in the Timer/Event Counter, which
can now be read by the program, therefore represents
the length of the pulse received on the external timer
pin. As the enable bit has now been reset, any further
transitions on the external timer pin will be ignored. Not
until the enable bit is again set high by the program can
the timer begin further pulse width measurements. In
this way, single shot pulse measurements can be easily
Made.
The PFD output is pin-shared with the I/O pin PA3. The
PFD function is selected via configuration option, however, if not selected, the pin can operate as a normal I/O
pin.
Programmable Frequency Divider - PFD
The Programmable Frequency Divider provides a
means of producing a variable frequency output suitable
for applications requiring a precise frequency generator.
The clock source for the PFD circuit can originate from
either Timer/Event Counter 0 or Timer/Event Counter 1
overflow signal selected via configuration option. The
output frequency is controlled by loading the required
values into the timer registers and prescaler registers to
give the required division ratio. The timer will begin to
count-up from this preload register value until full, at
which point an overflow signal is generated, causing the
PFD output to change state. The timer will then be automatically reloaded with the preload register value and
continue counting-up.
It should be noted that in this mode the Timer/Event
Counter is controlled by logical transitions on the external timer pin and not by the logic level. When the
Timer/Event Counter is full and overflows, an interrupt
signal is generated and the Timer/Event Counter will reload the value already loaded into the preload register
and continue counting. The interrupt can be disabled by
ensuring that the Timer/Event Counter Interrupt Enable
bit in the corresponding Interrupt Control Register, is reset to zero.
Rev. 1.00
28
October 20, 2009
HT45R37V
register is full, the microcontroller will generate an internal interrupt signal directing the program flow to the respective internal interrupt vector. For the pulse width
measurement mode, the internal system clock is also
used as the timer clock source but the timer will only run
when the correct logic condition appears on the external
timer input pin. As this is an external event and not synchronized with the internal timer clock, the
microcontroller will only see this external event when the
next timer clock pulse arrives. As a result, there may be
small differences in measured values requiring programmers to take this into account during programming. The
same applies if the timer is configured to be in the event
counting mode, which again is an external event and not
synchronised with the internal system or timer clock.
For the PFD output to function, it is essential that the corresponding bit of the Port A control register PAC bit 3 is setup
as an output. If setup as an input the PFD output will not
function, however, the pin can still be used as a normal input pin. The PFD output will only be activated if bit PA3 is
set to ²1². This output data bit is used as the on/off control
bit for the PFD output. Note that the PFD output will be low
if the PA3 output data bit is cleared to ²0².
Using this method of frequency generation, and if a
crystal oscillator is used for the system clock, very precise values of frequency can be generated.
Prescaler
Bits TnPSC0~TnPSC2 of the control register can be
used to define the pre-scaling stages of the internal
clock source of the Timer/Event Counter. The
Timer/Event Counter overflow signal can be used to
generate signals for the PFD and Timer Interrupt.
When the Timer/Event Counter is read, or if data is written to the preload register, the clock is inhibited to avoid
errors, however as this may result in a counting error, this
should be taken into account by the programmer. Care
must be taken to ensure that the timers are properly initialised before using them for the first time. The associated timer enable bits in the interrupt control register must
be properly set otherwise the internal interrupt associated
with the timer will remain inactive. The edge select, timer
mode and clock source control bits in timer control register must also be correctly set to ensure the timer is properly configured for the required application. It is also
important to ensure that an initial value is first loaded into
the timer registers before the timer is switched on; this is
because after power-on the initial values of the timer registers are unknown. After the timer has been initialised
the timer can be turned on and off by controlling the enable bit in the timer control register. Note that setting the
timer enable bit high to turn the timer on, should only be
executed after the timer mode bits have been properly
setup. Setting the timer enable bit high together with a
mode bit modification, may lead to improper timer operation if executed as a single timer control register byte
write instruction.
I/O Interfacing
The Timer/Event Counter, when configured to run in the
event counter or pulse width measurement mode, require the use of external pins for correct operation. As
these pins are shared pins they must be configured correctly to ensure they are setup for use as Timer/Event
Counter inputs and not as a normal I/O pins. This is implemented by ensuring that the mode select bits in the
Timer/Event Counter control register, select either the
event counter or pulse width measurement mode. Additionally the Port Control Register must be set high to ensure that the pin is setup as an input. Any pull-high
resistor on these pins will remain valid even if the pin is
used as a Timer/Event Counter input.
Timer/Event Counter Pins Internal Filter
The external Timer/Event Counter pins are connected to
an internal filter to reduce the possibility of unwanted
event counting events or inaccurate pulse width measurements due to adverse noise or spikes on the external Timer/Event Counter input signal. As this internal
filter circuit will consume a limited amount of power, a
configuration option is provided to switch off the filter
function, an option which may be beneficial in power
sensitive applications, but in which the integrity of the input signal is high. Care must be taken when using the filter on/off configuration option as it will be applied not
only to both external Timer/Event Counter pins but also
to the external interrupt input pins. Individual
Timer/Event Counter or external interrupt pins cannot
be selected to have a filter on/off function.
When the Timer/Event counter overflows, its corresponding interrupt request flag in the interrupt control
register will be set. If the timer interrupt is enabled this
will in turn generate an interrupt signal. However irrespective of whether the interrupts are enabled or not, a
Timer/Event counter overflow will also generate a
wake-up signal if the device is in a Power-down condition. This situation may occur if the Timer/Event Counter
is in the Event Counting Mode and if the external signal
continues to change state. In such a case, the
Timer/Event Counter will continue to count these external events and if an overflow occurs the device will be
woken up from its Power-down condition. To prevent
such a wake-up from occurring, the timer interrupt request flag should first be set high before issuing the
HALT instruction to enter the Power Down Mode.
Programming Considerations
When configured to run in the timer mode, the internal
system clock is used as the timer clock source and is
therefore synchronised with the overall operation of the
microcontroller. In this mode when the appropriate timer
Rev. 1.00
29
October 20, 2009
HT45R37V
Timer Program Example
This program example shows how the Timer/Event Counter registers are setup, along with how the interrupts are enabled and managed. Note how the Timer/Event Counter is turned on, by setting bit 4 of the Timer Control Register. The
Timer/Event Counter can be turned off in a similar way by clearing the same bit. This example program sets the
Timer/Event Counter to be in the timer mode, which uses the internal system clock as the clock source.
org 04h
; external interrupt vector
reti
org 0Ch
; Timer/Event Counter 0 interrupt vector
jmp tmrint
; jump here when the Timer/Event Counter 0 overflows
:
org 20h
; main program
;internal Timer/Event Counter 0 interrupt routine
tmrint:
:
; Timer/Event Counter 0 main program placed here
:
reti
:
:
begin:
;setup Timer 0 registers
mov a,09bh
; setup Timer 0 preload value
mov tmr0,a;
mov a,081h
; setup Timer 0 control register
mov tmr0c,a
; timer mode and prescaler set to /2
; setup interrupt register
mov a,009h
; enable master interrupt and timer interrupt
mov int0c,a
set tmr0c.4
; start Timer/Event Counter 0 - note mode bits must be previously setup
C/R to F Converter
The Timer A clock source comes from the system clock
or from the system clock/4, determined by the RCOM
bits in the RCOCCR register. This clock source determines the value in the TMRAL/TMRAH registers. The
Timer B clock source comes from the external RC oscillator circuit and therefore determines the value in the
TMRBL/TMRBL registers. It is a combination of a fixed
frequency clock source driving Timer A and a varying
frequency clock source driving Timer B that enables external resistance and capacitance values to be measured.
The C/R to F Converter function within the device enables external resistance and capacitance to be converted into a frequency. With this function the device has
a way of measuring external capacitance and resistance values and can therefore be used in applications
such as touch switches.
C/R to F Operation
The C/R to F function is implemented using an external
RC oscillator. A single external reference resistor and
external reference capacitor are required to be connected as shown. These components and the internal
inverter circuits form an oscillator circuit whose frequency is dependent upon the value of the external capacitance and resistance. By using two internal 16-bit
programmable count-up timers, known as Timer A and
Timer B, the converted frequency value can be measured.
The OVB bit, in the RCOCR register, decides whether
Timer A or Timer B overflows. When this happens, the
RCOCF bit will be set and an external RC oscillation
converter interrupt occurs. When the C/R to F converter
causes Timer A or Timer B to overflow, the RCOCON bit
in the RCOCCR register will be reset to zero and the
counter will stop counting. Writing initial values to the
TMRAL/TMRAH and TMRBL/TMRBH registers places
a start value into Timer A and Timer B. Note that writing
to the low byte registers, TMRAL and TMRBL, only
writes the data into a low byte buffer. However writing to
the high byte registers, TMRAH and TMRBH, will write
both the high byte values and the low byte buffer values
directly into the Timer A and Timer B simultaneously.
The value of the two internal 16-bit programmable
count-up counters, known as Timer A and Timer B, are
stored within two pairs of registers, TMRAL/TMRAH and
TMRBL/TMRBH registers. Two other registers,
RCOCCR and RCOCR control the overall operation of
the C/R to F converter.
Rev. 1.00
30
October 20, 2009
HT45R37V
S y s te m
S y s te m
C lo c k
C lo c k /4
S 1
O V B = 0
S 2
T im e r A
C /R
to F C o n v e rte r In te rru p t
R C O C O N
O V B = 1
T im e r B
C /R
R e s e t R C O C O N
to F O u tp u t
C/R to F Converter
b 7
R C O M 2
b 0
R C O M 1
R C O M 0
R C O C O N
R C O C C R
R e g is te r
N o t im p le m e n te d , r e a d a s " 0 "
U n d e fin e d b it, th is b it c a n r e a d /w r ite
E n a b le o r d is a b le C /R to F c o n v e r te r
D e fin e th e T im e r A c lo c k s o u r c e
R C O M 2
R C O M 1
R C O M 0
0
0
0
s
1
0
0
s
0
1
0
u
1
1
0
u
0
0
1
u
1
0
1
u
0
1
1
u
1
1
1
u
y s te
y s te
n u s
n u s
n u s
n u s
n u s
n u s
m
m
e d
c lo c k
c lo c k /4
e d
e d
e d
e d
e d
RCOCCR Register
b 0
R W
R W
R W
R W
R C O
O V B
R C O C C R
R e g is te r
0 : T im e r A o v e r flo w
1 : T im e r B o v e r flo w
1 : e n a b le
0 : d is a b le
N o t im p le m e n te d , r e a d a s " 0 "
4 - b it r e a d /w r ite r e g is te r s fo r u s e r d e fin e d
RCOCR Register
Rev. 1.00
31
October 20, 2009
HT45R37V
ternal channels using its internal analog switch function.
This enables applications such as multi-channel or matrix touch switch applications to be implemented. The
bits in the ASCR0~ASCR1 registers select which of the
9-channels is to be connected to the internal C/R to F
converter. The bits in the ASCR2 register selects what
happens to the channel when the channel is inactive.
When a channel is inactive it can be selected to be
pulled low to ground or not using bits in the ASCR2 register. As there are only 8-bits to control 9-channels the
function is selected in channel pairs. There are configuration options which must first be selected to choose
which pins are to be used as inputs to the C/R to F converter.
The values in Timer A and Timer B is changed by writing
to the high byte registers, TMRAH and TMRBH, but writing to the low byte registers TMRAL and TMRBL will
keep the values in Timer A and Timer B unchanged.
Reading registers TMRAH and TMRBH will also latch
the TMRAL TMRBL values into the low byte buffer to
avoid false timing problems. Reading from registers
TMRAL and TMRBL returns the contents of the low byte
buffer only. Therefore, the low byte of Timer A and Timer
B cannot be read directly. TMRAH and TMRBH must be
read first to ensure that the low byte contents of Timer A
and Timer B are latched into the buffer.
The external resistor and capacitor, together with internal inverters, form an oscillation circuit which is the clock
source for Timer B and therefore the input to registers
TMRBL and TMRBH. The RCOM0, RCOM1 and
RCOM2 bits of RCOCCR define the clock source of
Timer A.
If the configuration options have selected PA0~PA7 to
be normal I/O pins, then the corresponding bit 0~bit7
bits in the ASCR0 register will have no function and will
be read as zero. Similarly if the configuration options
have selected PD0 to be normal I/O pins, then the corresponding bit 0 bit in the ASCR1 register will have no
function and will be read as zero.
If the RCOCON bit in the RCOCCR register is set high,
Timer A and Timer B will start counting until either Timer
A or Timer B overflows. The relevant Timer will then generate an interrupt request flag which is the RCOCF bit in
the INTC1 register. Timer A and Timer B will stop counting and will also reset the RCOCON bit to zero at the
same time. If the RCOCON bit is set high, then the
TMRAL/TMRAH and TMRBL/TMRBH register cannot
be read or written to.
If the configuration options have selected PA0~PA7 to
be normal I/O pins, then the corresponding bits in the
ASCR2 register, bit 0 ~ bit3, must be cleared to zero to
disable the RC0/RC1, RC2/RC3, RC4/RC5 and RC6/RC7
pull-low resistors. Similarly if the configuration options
have selected PD0 to be normal I/O pin, then the corresponding bits in the ASCR2 register, bit 4, must be cleared
to zero to disable the RC8 pull-low resistor. the ASCR2
register bit7~bit5 must to be cleared to zero by application program.
C/R to F Converter Analog Switches
The device contains only one internal C/R to F converter
function, however it can be connected to any of the 9 ex-
R e
A
A
A
g is
S C
S C
S C
te rs
R 0
R 1
R 2
M C U
A .S .0 ~ A .S .8
R C 0 ~
R C 8
E x te rn a l R C
R C 0
A .S .0
R C 1
A .S .1
A n a lo g
S w itc h e s
A S C R 0 /A S C R 1
R e g is te r C o n tr o l
R C 0 ~ R C 8
P u ll- lo w
A S C R 2
R e g is te r C o n tr o l
R C 7
A .S .7
R C 8
A .S .8
R C O U T /IN
R R E F
A n a lo g S w itc h
T im e r B
C lo c k S o u r c e
C R E F
Analog Switches and C/R to F Oscillator
Rev. 1.00
32
October 20, 2009
HT45R37V
b 7
b 0
A S 7 O N
A S 0 O N
A S 1 O N
A S C R 0 R e g is te r
R C 0
1 : R C 0 c o n n e c t to C /R to F c o n v e rte r
0 : R C 0 c o n n e c t to p u ll- lo w o r d is c o n n e c t
R C 1
1 : R C 1 c o n n e c t to C /R to F c o n v e rte r
0 : R C 1 c o n n e c t to p u ll- lo w o r d is c o n n e c t
R C 7
1 : R C 7 c o n n e c t to C /R to F c o n v e rte r
0 : R C 7 c o n n e c t to p u ll- lo w o r d is c o n n e c t
ASCR0 Register
b 7
b 0
A S 8 O N
A S C R 1 R e g is te r
R C 8
1 : R C 8 c o n n e c t to C /R to F c o n v e rte r
0 : R C 8 c o n n e c t to p u ll- lo w o r d is c o n n e c t
B it 7 ~ B it 1
U n im p le m e n te d , r e a d a s " 0 "
ASCR1 Register
b 7
R e s e rv e d
b 0
R e s e rv e d
R e s e rv e d
A S P L O N 4 A S P L O N 3 A S P L O N 2 A S P L O N 1 A S P L O N 0
A S C R 2 R e g is te r
R C 0 /R C 1 d is c o n n e c te d c o n d itio n
1 : R C 0 /R C 1 p u lle d lo w
0 : R C 0 /R C 1 flo a tin g
R C 2 /R C 3 d is c o n n e c te d c o n d itio n
1 : R C 2 /R C 3 p u lle d lo w
0 : R C 2 /R C 3 flo a tin g
R C 4 /R C 5 d is c o n n e c te d c o n d itio n
1 : R C 4 /R C 5 p u lle d lo w
0 : R C 4 /R C 5 flo a tin g
R C 6 /R C 7 d is c o n n e c te d c o n d itio n
1 : R C 6 /R C 7 p u lle d lo w
0 : R C 6 /R C 7 flo a tin g
R C 8 /R C 9 d is c o n n e c te d c o n d itio n
1 : R C 8 /P D 1 p u lle d lo w
0 : R C 8 /P D 1 flo a tin g
R e s e r v e d b it
1 : u n p r e d ic a b le o p e r a tio n - b it m u s t N O T b e s e t to " 1 "
0 : c o r r e c t le v e l - b it m u s t b e s e t to " 0 " fo r c o r r e c t o p e r a tio n
ASCR2 Register
Rev. 1.00
33
October 20, 2009
HT45R37V
Programming Example
The following example shows the principles of how the C/R to F converter function is programmed:
External RC oscillation converter mode example program - Timer A overflow:
clr RCOCCR
mov a, 00000010b
;
mov RCOCR,a
clr mfic0.1
;
clr mfic0.5
mov a, low (65536-1000) ;
mov tmral, a
;
mov a, high (65536-1000)
mov tmrah, a
mov a, 00h
;
mov tmrbl, a
mov a, 00h
mov tmrbh, a
mov a, 00110000b
;
mov RCOCCR, a
p10:
clr wdt
snz mfic0.5
;
jmp p10
clr mfic0.5
;
;
Rev. 1.00
Enable External RC oscillation mode and set Timer A overflow
Clear External RC Oscillation Converter interrupt request flag
Give timer A initial value
Timer A count 1000 time and then overflow
Give timer B initial value
Timer A clock source=fSYS/4 and timer on
Polling External RC Oscillation Converter interrupt request flag
Clear External RC Oscillation Converter interrupt request flag
Program continue
34
October 20, 2009
HT45R37V
Pulse Width Modulator
The device contains twos Pulse Width Modulation,
PWM, outputs. Useful for such applications such as motor speed control, the PWM function provides an output
with a fixed frequency, but with a duty cycle that can be
varied by setting particular values into the corresponding PWM register pair.
Channel
PWM
Mode
Output
Pin
Register
Names
1
8+4
PD0
PWM0L~
PWM0H
2
8+4
PD1
PWM1L~
PWM1H
8+4 PWM Mode Modulation
Each full PWM cycle, as it is 12-bits wide, has 4096 clock
periods. However, in the 8+4 PWM mode, each PWM cycle is subdivided into sixteen individual sub-cycles known
as modulation cycle 0 ~ modulation cycle 15, denoted as
²i² in the table. Each one of these sixteen sub-cycles contains 256 clock cycles. In this mode, a modulation frequency increase of sixteen is achieved. The 12-bit PWM
register value, which represents the overall duty cycle of
the PWM waveform, is divided into two groups. The first
group which consists of bit4~bit11 is denoted here as the
DC value. The second group which consists of bit0~bit3
is known as the AC value. In the 8+4 PWM mode, the
duty cycle value of each of the two modulation sub-cycles
is shown in the following table.
PWM Overview
A register pair, located in the Data Memory is assigned
to each Pulse Width Modulator output and are known as
the PWM registers. It is in each register pair that the
12-bit value, which represents the overall duty cycle of
one modulation cycle of the output waveform, should be
placed. The PWM registers also contain the enable/disable control bit for the PWM outputs. To increase the
PWM modulation frequency, each modulation cycle is
modulated into sixteen individual modulation
sub-sections, known as the 8+4 mode. Note that it is
only necessary to write the required modulation value
into the corresponding PWM register as the subdivision
of the waveform into its sub-modulation cycles is implemented automatically within the microcontroller hardware. The PWM clock source is the system clock fSYS.
Parameter
Modulation cycle i
(i=0~15)
PWM Cycle
Frequency
PWM Cycle
Duty
fSYS/256
fSYS/4096
(PWM register
value)/4096
Rev. 1.00
DC (Duty Cycle)
i<AC
DC+1
256
i³AC
DC
256
8+4 Mode Modulation Cycle Values
The accompanying diagram illustrates the waveforms
associated with the 8+4 mode of PWM operation. It is
important to note how the single PWM cycle is subdivided into 16 individual modulation cycles, numbered
0~15 and how the AC value is related to the PWM value.
PWM Output Control
The two outputs, PWM0 and PWM1, are shared with
pins PD0 and PD1. To operate as a PWM output and not
as an I/O pin, bit 0 of the relevant PWM low byte register
bit must be set high. A zero must also be written to the
corresponding bit in the PDC port control register, to ensure that the PWM0 output pin is setup as an output. After these two initial steps have been carried out, and of
course after the required PWM 12-bit value has been
written into the PWM register pair register, setting the
corresponding bit in the PD data register high will enable
the PWM data to appear on the pin. Writing a zero to the
bit will disable the PWM output function and force the
output low. In this way, the Port D data output register
bits, can also be used as an on/off control for the PWM
function. Note that if the enable bit in the PWM register
is set high to enable the PWM function, but if the corresponding bit in the PDC control register is high to configure the pin as an input, then the pin can still function as a
normal input line, with pull-high resistor selections.
This method of dividing the original modulation cycle
into a further 16 sub-cycles enables the generation of
higher PWM frequencies, which allow a wider range of
applications to be served. As long as the periods of the
generated PWM pulses are less than the time constants
of the load, the PWM output will be suitable as such long
time constant loads will average out the pulses of the
PWM output. The difference between what is known as
the PWM cycle frequency and the PWM modulation frequency should be understood. As the PWM clock is the
system clock, fSYS, and as the PWM value is 12-bits
wide, the overall PWM cycle frequency is fSYS/4096.
However, when in the 8+4 mode of operation, the PWM
modulation frequency will be fSYS/256.
PWM
Modulation
Frequency
AC (0~15)
35
October 20, 2009
HT45R37V
PWM Programming Example
The following sample program shows how the PWM output is setup and controlled.
mov
mov
clr
clr
set
set
:
:
clr
fS
Y S
a,64h
pwm0h,a
pwm0l
pdc.0
pwm0en
pd.0
:
:
pd.0
;
;
;
;
;
;
setup PWM0 value to 1600 decimal which is 640H
setup PWM0H register value
setup PWM0L register value
setup pin PD0 as an output
set the PWM0 enable bit
Enable the PWM0 output
; PWM0 output disabled - PD0 will remain low
/2
[P W M ] = 1 6 0 0
P W M
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 1 /2 5 6
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 1 /2 5 6
1 0 1 /2 5 6
1 0 1 /2 5 6
1 0 0 /2 5 6
1 0 0 /2 5 6
1 0 1 /2 5 6
1 0 0 /2 5 6
1 0 1 /2 5 6
[P W M ] = 1 6 0 1
P W M
[P W M ] = 1 6 0 2
P W M
[P W M ] = 1 6 1 5
P W M
1 0 1 /2 5 6
P W M
1 0 1 /2 5 6
m o d u la tio n p e r io d : 2 5 6 /fS
M o d u la tio n c y c le 0
1 0 1 /2 5 6
Y S
M o d u la tio n c y c le 1
P W M
M o d u la tio n c y c le 2
c y c le : 4 0 9 6 /fS
M o d u la tio n c y c le 1 5
M o d u la tio n c y c le 0
Y S
8+4 PWM Mode
P W M 0 H ~ P W M 1 H
H ig h B y te R e g is te r s
b 7
1 1
1 0
9
8
7
6
5
P W M 0 L ~ P W M 1 L
L o w B y te R e g is te r s
b 0
4
b 7
3
2
1
0
b 0
E N
P W M
R e g is te r s
P W M O n /O ff C o n tro l
1 : P W M e n a b le
0 : I/O p in e n a b le
N o t im p le m e n te d , r e a d a s " 0 "
P W M A C
b its 0 ~ 3
V a lu e
P W M D C V a lu e
b its 4 ~ 1 1
PWM Register Pairs
Rev. 1.00
36
October 20, 2009
HT45R37V
Analog to Digital Converter
The 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.
Input
Pins
2
12
PB0~PB1
Bit
4
Bit
3
Bit
2
Bit
1
Bit
0
ADRL
D3
D2
D1
D0
¾
¾
¾
¾
ADRH
D11 D10 D9
D8
D7
D6
D5
D4
The ACS2~ACS0 bits in the ADCR register define the
channel number. As the device contains only one actual
analog to digital converter circuit, each of the individual
2 analog inputs must be routed to the converter. It is the
function of the ACS2~ACS0 bits in the ADCR register to
determine which analog channel is actually connected
to the internal A/D converter.
A/D Converter Data Registers - ADRL, ADRH
The device, which has an internal 12-bit A/D converter,
requires two data registers, a high byte register, known
as ADRH, and a low byte register, known as ADRL. After
the conversion process takes place, these registers can
be directly read by the microcontroller to obtain the digitised conversion value. Only the high byte register,
ADRH, utilises its full 8-bit contents. The low byte register utilises only 4 bit of its 8-bit contents as it contains
only the lowest bits of the 12-bit converted value.
The ADCR control register also contains the
PCR2~PCR0 bits which determine which pins on Port B
are used as analog inputs for the A/D converter and
which pins are to be used as normal I/O pins. Note that if
the PCR2~PCR0 bits are all set to zero, then all the Port
B pins will be setup as normal I/Os and the internal A/D
converter circuitry will be powered off to reduce the power
consumption.
The START bit in the register is used to start and reset
the A/D converter. When the microcontroller sets this bit
from low to high and then low again, an analog to digital
In the following table, D0~D11 is the A/D conversion
data result bits.
A C S R
Bit
5
To control the function and operation of the A/D converter, two control registers known as ADCR and ACSR
are provided. These 8-bit registers define functions
such as the selection of which analog channel is connected to the internal A/D converter, which pins are
used as analog inputs and which are used as normal
I/Os, the A/D clock source as well as controlling the start
function and monitoring the A/D converter end of conversion status.
The accompanying block diagram shows the overall internal structure of the A/D converter, together with its associated registers.
fS
Bit
6
A/D Converter Control Registers - ADCR, ACSR
The device contains an 2-channel analog to digital converter which can directly interface to external analog signals, such as that from sensors or other control signals
and convert these signals directly into either a 12-bit digital value.
Conversion
Bits
Bit
7
A/D Data Registers
A/D Overview
Input
Channels
Register
Y S
C lo c k
D iv id e r
¸ N
R e g is te r
A D O N B B it
A /D E n a b le
A V
A /D
R e fe re n c e
V o lta g e
P B 0 /A N 0
A /D
P o s itiv e P o w e r S u p p ly
A D R L
A D C
P B 1 /A N 1
A D R H
A /D
A V
P C R 0 ~ P C R 2
D D
A D C S 0 ~ A D C S 2
E O C B
S T A R T
A /D D a ta
R e g is te r s
G ro u n d
S S
A D C R
R e g is te r
A/D Converter Structure
Rev. 1.00
37
October 20, 2009
HT45R37V
b 7
S T A R T
E O C B
P C R 2
P C R 1
P C R 0
A C S 2
A C S 1
b 0
A C S 0
A D C R
R e g is te r
S e le c t
A C S 2
0 0 0 :
0 0 1 :
O th e r:
A /D
A
A N
A N
U n
P o rt
P C R
0 0 0
0 0 1
0 1 0
O th e
B A
2
: P
: P
: P
r: U
/D
P
B
B
B
n
c h a n n e l
C S 1 A C S 0
0
1
p r e d ic ta b le o p e r a tio n - b its m u s t N O T b e s e t e x c e p t " 0 0 0 " a n d " 0 0 1 "
c h a n
C R 1
0 a n d
0 is A
0 a n d
p r e d ic
n e l c o n fig u r a tio
P C R 0
P B 1 a re I/O
/D in p u t, P B 1 is
P B 1 a re A /D In
ta b le o p e r a tio n
n s
I/O
p u t
- b its m u s t N O T b e s e t e x c e p t " 0 0 0 " , " 0 0 1 " a n d " 0 1 0 "
E n d o f A /D c o n v e r s io n fla g
1 : A /D c o n v e r s io n w a itin g o r in p r o g r e s s
0 : A /D c o n v e r s io n e n d e d
S ta r t th e A /D c o n v e r s io n
0 ® 1 ® 0 : S ta rt
A/D Converter Control Register - ADCR
conversion cycle will be initiated. When the START bit is
brought from low to high but not low again, the EOCB bit
in the ADCR register will be set high and the analog to
digital converter will be reset. It is the START bit that is
used to control the overall on/off operation of the internal
analog to digital converter.
register and the value of the PCR bits in the ADCR register. Both the ADONB bit must cleared to zero and the
value of the PCR bits must have a non-zero value for the
A/D converter to be enabled.
The EOCB bit in the ADCR register is used to indicate
when the analog to digital conversion process is complete. This bit will be automatically cleared to zero by the
microcontroller after a conversion cycle has ended. In
addition, the corresponding A/D interrupt request flag
will be set in the interrupt control register, and if the 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 be used to
poll the EOCB bit in the ADCR register to check whether
it has been cleared as an alternative method of detecting the end of an A/D conversion cycle.
ADONB
A/D
0
x
Off
>0
0
On
>0
1
Off
Although the A/D clock source is determined by the system clock fSYS, and by bits ADCS2, ADCS1 and ADCS0,
there are some limitations on the maximum A/D clock
source speed that can be selected. As the minimum value
of permissible A/D clock period, tAD, is 0.5ms, care must be
taken for system clock speeds in excess of 4MHz. For
system clock speeds in excess of 4MHz, the ADCS2,
ADCS1 and ADCS0 bits should not be set to ²000². Doing
so will give A/D clock periods that are less than the minimum A/D clock period which may result in inaccurate A/D
conversion values. Refer to the following table for examples, where values marked with an asterisk * show where,
depending upon the device, special care must be taken,
as the values may be less than the specified minimum A/D
Clock Period.
The clock source for the A/D converter, which originates
from the system clock fSYS, is first divided by a division
ratio, the value of which is determined by the ADCS2,
ADCS1 and ADCS0 bits in the ACSR register.
Controlling the on/off function of the A/D converter circuitry is implemented using the ADONB bit in the ACSR
Rev. 1.00
PCR
38
October 20, 2009
HT45R37V
A/D Clock Period (tAD)
fSYS
ADCS2, ADCS1,
ADCS0=000
(fSYS/2)
ADCS2, ADCS1,
ADCS0=001
(fSYS/8)
ADCS2, ADCS1,
ADCS0=010
(fSYS/32)
ADCS2, ADCS1,
ADCS0=011
1MHz
2ms
8ms
32ms
Undefined
2MHz
1ms
4ms
16ms
Undefined
4MHz
500ns*
2ms
8ms
Undefined
8MHz
250ns*
1ms
4ms
Undefined
12MHz
167ns*
667ns*
2.67ms
Undefined
A/D Clock Period Examples
b 7
T E S T
A D O N B
b 0
A D C S 2 A D C S 1 A D C S 0
A C S R
R e g is te r
S e le c t A /D c o n v e r te r c lo c k s o u r
A D C S 0
A D C S 2
A D C S 1
:
0
0
0
:
1
0
0
:
0
0
1
:
1
0
1
:
0
1
0
:
1
1
0
:
0
1
1
:
1
1
1
c e
s y s
s y s
s y s
u n d
s y s
s y s
s y s
u n d
te m
te m
te m
e fin
te m
te m
te m
e fin
c lo
c lo
c lo
e d
c lo
c lo
c lo
e d
c k /2
c k /8
c k /3 2
c k
c k /4
c k /1 6
N o t im p le m e n te d , r e a d a s " 0 "
A /D O n /O ff c o n tr o l b it
1 : d is a b le
0 : e n a b le
F o r te s t m o d e u s e o n ly
A/D Converter Control Register - ACSR
A/D Input Pins
the channel selection bits have changed, then, within a
time frame of one to ten instruction cycles, the START bit
in the ADCR register must first be set high and then immediately cleared to zero. This will ensure that the EOCB
flag is correctly set to a high condition.
All of the A/D analog input pins are pin-shared with the
I/O pins on Port B. Bits PCR2~PCR0 in the ADCR register, determine whether the input pins are setup as normal Port B input/output pins or whether they are setup
as analog inputs. In this way, pins can be changed under
program control to change their function from normal I/O
operation to analog inputs and vice versa. Pull-high resistors, which are setup through register programming,
apply to the input pins only when they are used as normal I/O pins, if setup as A/D inputs the pull-high resistors
will be automatically disconnected. Note that it is not
necessary to first setup the A/D pin as an input in the
PBC port control register to enable the A/D input as
when the PCR2~PCR0 bits enable an A/D input, the status of the port control register will be overridden. The
A/D converter has its own power supply pins AVDD and
AVSS pin. The analog input values must not be allowed
to exceed the value of AVDD.
Summary of A/D Conversion Steps
The following summarises the individual steps that
should be executed in order to implement an A/D conversion process.
· Step 1
Select the required A/D conversion clock by correctly
programming bits ADCS2, ADCS1 and ADCS0 in the
register.
· Step 2
Enable the A/D by clearing the in the ACSR register to
zero.
· Step 3
Select which channel is to be connected to the internal
A/D converter by correctly programming the
ACS2~ACS0 bits which are also contained in the register.
Initialising the A/D Converter
The internal A/D converter must be initialised in a special
way. Each time the Port B A/D channel selection bits are
modified by the program, the A/D converter must be
re-initialised. If the A/D converter is not initialised after the
channel selection bits are changed, the EOCB flag may
have an undefined value, which may produce a false end
of conversion signal. To initialise the A/D converter after
Rev. 1.00
· Step 4
Select which pins on Port B are to be used as A/D inputs and configure them as A/D input pins by correctly
programming the PCR2~PCR0 bits in the ADCR register. Note that this step can be combined with Step 2
into a single ADCR register programming operation.
39
October 20, 2009
HT45R37V
P C R 2 ~
P C R 0
0 0 0 B
0 0 1 B
0 0 1 B
0 0 0 B
A D O N B
tO
A D C
m o d u le
O N
N 2 S T
o n
A /D
tA
s a m p lin g tim e
A /D
tA
D C S
o ff
s a m p lin g tim e
o n
o ff
D C S
S T A R T
E O C B
A C S 2 ~
A C S 0
x x x B
P o w e r-o n
R e s e t
0 0 0 B
0 0 0 B
0 0 0 B
S ta rt o f A /D
c o n v e r s io n
S ta rt o f A /D
c o n v e r s io n
S ta rt o f A /D
c o n v e r s io n
R e s e t A /D
c o n v e rte r
R e s e t A /D
c o n v e rte r
A /D
N o te :
R e s e t A /D
c o n v e rte r
E n d o f A /D
c o n v e r s io n
1 : D e fin e p o r t c o n fig u r a tio n
2 : S e le c t a n a lo g c h a n n e l
x x x B
E n d o f A /D
c o n v e r s io n
tA D C
c o n v e r s io n tim e
A /D
A /D c lo c k m u s t b e fs y s , fS Y S /2 , fS Y S /4 , fS Y S /8 , fS Y S /1 6 o r fS
tA D C S = 4 tA D
tA D C = tA D C S + n * tA D ; n = b it c o u n t o f A D C r e s o lu tio n
Y S
tA D C
c o n v e r s io n tim e
/3 2
A/D Conversion Timing
· Step 5
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 16tAD
where tAD is equal to the A/D clock period.
If the interrupts are to be used, the interrupt control registers must be correctly configured to ensure the A/D
converter interrupt function is active. The master interrupt control bit, EMI, in the INTC0 interrupt control register must be set to ²1², the multi-function interrupt
enable bit, EMFI1, in the INTC1 register and the A/D
converter interrupt bit, EADI, in the MFIC1 register
must also be set to ²1².
Programming Considerations
When programming, special attention must be given to
the A/D channel selection bits in the register. If these
bits are all cleared to zero no external pins will be selected for use as A/D input pins allowing the pins to be
used as normal I/O pins. When this happens the power
supplied to the internal A/D circuitry will be reduced resulting in a reduction of supply current. This ability to reduce power by turning off the internal A/D function by
clearing the A/D channel selection bits may be an important consideration in battery powered applications. The
ADONB bit in the ACSR register can also be used to
power down the A/D function.
· Step 6
The analog to digital conversion process can now be
initialised by setting the START bit in the ADCR register from ²0² to ²1² and then to ²0² again. Note that this
bit should have been originally set to ²0².
· Step 7
To check when the analog to digital conversion process is complete, the EOCB bit in the ADCR register
can be polled. The conversion process is complete
when this bit goes low. When this occurs the A/D data
registers ADRL and ADRH can be read to obtain the
conversion value. As an alternative method if the interrupts are enabled and the stack is not full, the program can wait for an A/D interrupt to occur.
Note:
Another important programming consideration is that
when the A/D channel selection bits change value, the
A/D converter must be re-initialised. This is achieved by
pulsing the START bit in the ADCR register immediately
after the channel selection bits have changed state. The
exception to this is where the channel selection bits are
all cleared, in which case the A/D converter is not required to be re-initialised.
When checking for the end of the conversion
process, if the method of polling the EOCB bit in
the ADCR register is used, the interrupt enable
step above can be omitted.
The accompanying diagram shows graphically the various stages involved in an analog to digital conversion
process and its associated timing.
A/D Programming Example
The following two programming examples illustrate how
to setup and implement an A/D conversion. In the first
example, the method of polling the EOCB bit in the
ADCR 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.
The setting up and operation of the A/D converter function is fully under the control of the application program as
there are no configuration options associated with the
A/D converter. After an A/D conversion process has been
initiated by the application program, the microcontroller
Rev. 1.00
40
October 20, 2009
HT45R37V
Example: using an EOCB polling method to detect the end of conversion
clr EADI
; disable ADC interrupt
mov a,00000001B
mov ACSR,a
; select fSYS/8 as A/D clock and turn on ADONB bit
mov a,00001000B
; setup ADCR register to configure Port PB0 as A/D inputs
mov ADCR,a
; and select AN0 to be connected to the A/D converter
:
:
; As the Port B channel bits have changed the
; following START
; signal (0-1-0) must be issued
; instruction cycles
:
Start_conversion:
clr START
set START
; reset A/D
clr START
; start A/D
Polling_EOC:
sz
EOCB
; poll the ADCR register EOCB bit to detect end
; of A/D conversion
jmp polling_EOC
; continue polling
mov a,ADRL
; read low byte conversion result value
mov adrl_buffer,a
; save result to user defined register
mov a,ADRH
; read high byte conversion result value
mov adrh_buffer,a
; save result to user defined register
:
jmp start_conversion
; start next A/D conversion
Example: using the interrupt method to detect the end of conversion
clr EADI
; disable ADC interrupt
mov a,00000001B
mov ACSR,a
; select fSYS/8 as A/D clock and turn on ADONB bit
mov
a,00001000B
mov
ADCR,a
:
; setup ADCR register to configure Port PB0
; as A/D inputs
; and select AN0 to be connected to the A/D
; As the Port B channel bits have changed the
; following START signal(0-1-0) must be issued
;
:
Start_conversion:
clr START
set START
clr START
clr ADF
set EADI
set EMFI1
set EMI
:
:
:
; ADC interrupt service routine
ADC_:
mov acc_stack,a
a,STATUS
mov status_stack,a
:
:
mov a,ADRL
mov adrl_buffer,a
mov a,ADRH
mov adrh_buffer,a
:
:
EXIT__ISR:
mov a,status_stack
mov STATUS,a
mov a,acc_stack
clr ADF
reti
Rev. 1.00
;
;
;
;
;
;
reset A/D
start A/D
clear ADC interrupt request flag
enable ADC interrupt
enable multi-function 1 interrupt
enable global interrupt
; save ACC to user defined memory
; save STATUS to user defined memory
;
;
;
;
read
save
read
save
low byte conversion result value
result to user defined register
high byte conversion result value
result to user defined register
; restore STATUS from user defined memory
; restore ACC from user defined memory
; clear ADC interrupt flag
41
October 20, 2009
HT45R37V
1 .5 L S B
F F F H
F F E H
F F D H
A /D C o n v e r s io n
R e s u lt
0 .5 L S B
0 3 H
0 2 H
0 1 H
0
1
2
3
4 0 9 3 4 0 9 4
4 0 9 5 4 0 9 6
(
A V D D
)
4 0 9 6
A n a lo g In p u t V o lta g e
Ideal A/D Transfer Function
A/D Transfer Function
The communication is full duplex and operates as a
slave/master type, where the MCU can be either master
or slave. Although the SPI interface specification can
control multiple slave devices from a single master,
here, as only a single select pin, SCS, is provided only
one slave device can be connected to the SPI bus.
As the device contain a 12-bit A/D converter, its
full-scale converted digitised value is equal to FFFH.
Since the full-scale analog input value is equal to the
AVDD voltage, this gives a single bit analog input value of
AVDD/4096. The diagram show the ideal transfer function between the analog input value and the digitised
output value for the A/D converter.
S P I M a s te r
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 AVDD level.
S P I S la v e
S C K
S C K
S D O
S D I
S D I
S C S
S D O
S C S
SPI Master/Slave Connection
Serial Interface Function
SPI Interface Operation
The device contains a Serial Interface Function, which
includes both the four line SPI interface and the two line
I2C interface types, to allow an easy method of communication with external peripheral hardware. Having relatively simple communication protocols, these serial
interface types allow the microcontroller to interface to
external SPI or I2C based hardware such as sensors,
Flash or EEPROM memory, etc. The SIM interface pins
are pin-shared with other I/O pins therefore the SIM interface function must first be selected using a configuration option. As both interface types share the same pins
and registers, the choice of whether the SPI or I2C type
is used is made using a bit in an internal register.
The SPI interface is a full duplex synchronous serial
data link. It is a four line interface with pin names SDI,
SDO, SCK and SCS. Pins SDI and SDO are the Serial
Data Input and Serial Data Output lines, SCK is the Serial Clock line and SCS is the Slave Select line. As the
SPI interface pins are pin-shared with normal I/O pins
and with the I2C function pins, the SPI interface must
first be enabled by selecting the SIM enable configuration option and setting the correct bits in the
SIMCTL0/SIMCTL2 register. After the SPI configuration
option has been configured it can also be additionally
disabled or enabled using the SIMEN bit in the
SIMCTL0 register. Communication between devices
connected to the SPI interface is carried out in a
slave/master mode with all data transfer initiations being
implemented by the master. The Master also controls
the clock signal. As the device only contains a single
SCS pin only one slave device can be utilised.
SPI Interface
The SPI interface is often used to communicate with external peripheral devices such as sensors, Flash or
EEPROM memory devices etc. Originally developed by
Motorola, the four line SPI interface is a synchronous
serial data interface that has a relatively simple communication protocol simplifying the programming requirements when communicating with external hardware
devices.
Rev. 1.00
The SPI function in this device offers the following features:
42
¨
Full duplex synchronous data transfer
¨
Both Master and Slave modes
October 20, 2009
HT45R37V
¨
LSB first or MSB first data transmission modes
¨
Transmission complete flag
¨
Rising or falling active clock edge
¨
WCOL and CSEN bit enabled or disable select
Configuration Option
Function
SIM Function
SIM interface enable/disable
SPI CSEN bit
Enable/Disable
SPI WCOL bit
Enable/Disable
SPI Interface Configuration Options
The status of the SPI interface pins is determined by a
number of factors such as whether the device is in the
master or slave mode and upon the condition of certain
control bits such as CSEN, SIMEN and SCS. In the table
I, Z represents an input floating condition.
SPI Registers
There are three internal registers which control the overall operation of the SPI interface. These are the SIMDR
data register and two control registers SIMCTL0 and
SIMCTL2. Note that the SIMCTL1 register is only used
by the I2C interface.
There are several configuration options associated with
the SPI interface. One of these is to enable the SIM
function which selects the SIM pins rather than normal
I/O pins. Note that if the configuration option does not
select the SIM function then the SIMEN bit in the
SIMCTL0 register will have no effect. Another two SIM
configuration options determine if the CSEN and WCOL
bits are to be used.
Master - SIMEN=1
Slave - SIMEN=1
Master/Salve
SIMEN=0
CSEN=0
CSEN=1
CSEN=0
CSEN=1
SCS=0
CSEN=1
SCS=1
SCS
Z
Z
L
Z
I, Z
I, Z
SDO
Z
O
O
O
O
Z
SDI
Z
I, Z
I, Z
I, Z
I, Z
Z
SCK
Z
H: CKPOL=0
L: CKPOL=1
H: CKPOL=0
L: CKPOL=1
I, Z
I, Z
Z
Pin
Note:
²Z² floating, ²H² output high, ²L² output low, ²I² Input, ²O²output level, ²I,Z² input floating (no pull-high)
SPI Interface Pin Status
D a ta B u s
S IM D R
T x /R x S h ift R e g is te r
C K E N b it
C K P O L b it
C lo c k
E d g e /P o la r ity
C o n tro l
S C K P in
fS Y S
fS U B
T im e r /E v e n t C o u n te r
S D I P in
S D O
P in
E n a b le /D is a b le
B u s y
S ta tu s
C o n fig u r a tio n
O p tio n
W C O L F la g
T R F F la g
C lo c k
S o u r c e S e le c t
S C S P in
C S E N
b it
C o n fig u r a tio n
O p tio n
E n a b le /D is a b le
SPI Block Diagram
Rev. 1.00
43
October 20, 2009
HT45R37V
b 7
S IM 2
b 0
S IM 1
S IM 0
R e s e rv e d R e s e rv e d R e s e rv e d S IM E N
S IM C T L 0 R e g is te r
N o t im p le m e n t e d , r e a d a s '0 "
S P I/I2C O n /O f c o n tro l
1 : e n a b le
0 : d is a b le
R e s e r v e d b it
1 : u n p r e d ic a b le o p e r a tio n - b it m u s t N O T b e s e t to " 1 "
0 : c o r r e c t le v e l - b it m u s t b e s e t to " 0 " fo r c o r r e c t o p e r a tio n
S P I/I2C
S IM 2
0
0
0
0
1
1
1
1
M a s te r /S la
S IM 1
S
0
0
1
1
0
0
1
1
v e a n d C lo c k
IM 0
0
m a s te r,
1
m a s te r,
0
m a s te r,
1
m a s te r,
0
m a s te r,
1
S la v e
I2C m o d
0
N o t u s e
1
C o n tro l
fS
fS
fS
fS
Y S
Y S
Y S
/4
/1 6
/6 4
U B
d
T im e r /E v e n t C o u n te r 0 o u tp u t/2
e
SPI/I2C Control Register - SIMCTL0
b 7
H C F
b 0
H A A S
H B B
H T X
T X A K
S R W
R X A K
S IM C T L 1 R e g is te r
R e c e iv e a c k n o w le d g e fla g
1 : n o t a c k n o w le d g e d
0 : a c k n o w le d g e d
N o t im p le m e n te d , r e a d a s " 0 "
M a s te r d a ta r e a d /w r ite r e q u e s t fla g
1 : re q u e s t d a ta re a d
0 : r e q u e s t d a ta w r ite
T r a n s m it a c k n o w le d g e fla g
1 : d o n 't a c k n o w le d g e
0 : a c k n o w le d g e
T r a n s m it/R e c e iv e m o d e
1 : tr a n s m it m o d e
0 : r e c e iv e m o d e
I2 C b u s b u s y fla g
1 : b u s y
0 : n o t b u s y
C a llin g a d d r e s s m a tc h e d fla g
1 : m a tc h e d
0 : n o t m a tc h e d
D a ta tr a n s fe r fla g
1 : tr a n s fe r c o m p le te
0 : tr a n s fe r n o t c o m p le te
I2C Control Register - SIMCTL1
b 0
b 7
C K P O L
C K E G
M L S
C S E N
W C O L
T R F
S IM C T L 2 R e g is te r
T r a n s m it/R e c e iv e c o m p le te fla g
1 : fin is h e d
0 : in p r o g r e s s
W r ite c o llis io n fla g
1 : c o llis io n
0 : n o c o llis io n
S C S p in e n a b le
1 : e n a b le
0 : S C S flo a tin g
D a ta s h ift o r d e r
1 : M S B
0 : L S B
S P I C lo c k E d g e S e le c t
1 : s e e te x t
0 : s e e te x t
S P I C lo c k P o la r ity
1 : s e e te x t
0 : s e e te x t
N o t im p le m e n te d , r e a d a s " 0 "
SPI Control Register - SIMCTL2
Rev. 1.00
44
October 20, 2009
HT45R37V
will be in a floating condition and the SPI operating
current will be reduced to a minimum value. When the
bit is high the SPI interface is enabled. The SIMconfiguration option must have first enabled the SIM interface for this bit to be effective. Note that when the
SIMEN bit changes from low to high the contents of
the SPI control registers will be in an unknown condition and should therefore be first initialised by the application program.
The SIMDR register is used to store the data being
transmitted and received. The same register is used by
b o t h t h e S P I and I 2 C f u n c t i o n s . B ef o r e t h e
microcontroller writes data to the SPI bus, the actual
data to be transmitted must be placed in the SIMDR register. After the data is received from the SPI bus, the
microcontroller can read it from the SIMDR register. Any
transmission or reception of data from the SPI bus must
be made via the SIMDR register.
Bit
7
6
5
4
3
2
1
· SIM0~SIM2
These bits setup the overall operating mode of the SIM
function. As well as selecting if the I2C or SPI function,
they are used to control the SPI Master/Slave selection and the SPI Master clock frequency. The SPI
clock is a function of the system clock but can also be
chosen to be sourced from the Timer/Event Counter. If
the SPI Slave Mode is selected then the clock will be
supplied by an external Master device.
0
Label SD7 SD6 SD5 SD4 SD3 SD2 SD1 SD0
R/W
R/W R/W R/W R/W R/W R/W R/W R/W
There are also two control registers for the SPI interface, SIMCTL0 and SIMCTL2. Note that the SIMCTL2
register also has the name SIMAR which is used by the
I2C function. The SIMCTL1 register is not used by the
SPI function, only by the I 2 C function. Register
SIMCTL0 is used to control the enable/disable function
and to set the data transmission clock frequency. Register SIMCTL2 is used for other control functions such as
LSB/MSB selection, write collision flag etc. The
SIMIDLE bit in the CLKMOD register is used to select if
the SIM continues running when the device is in the
IDLE mode. Setting the bit high allows the SIM to maintain operation when the device is in the Idle mode.
Clearing the bit to zero disables any SIM operations
when in the Idle mode.
The following gives further explanation of each
SIMCTL1 register bit:
SPI Master/Slave Clock
Control and I2C Enable
SIM0
SIM1
SIM2
0
0
0
SPI Master, fSYS/4
0
0
1
SPI Master, fSYS/16
0
1
0
SPI Master, fSYS/64
0
1
1
SPI Master, fSUB
1
0
0
SPI Master Timer/Event
Counter 0 output/2
1
0
1
SPI Slave
1
1
0
I2C mode
1
1
0
Not used
· SIMEN
The bit is the overall on/off control for the SPI interface. When the SIMEN bit is cleared to zero to disable
the SPI interface, the SDI, SDO, SCK and SCS lines
Rev. 1.00
45
October 20, 2009
HT45R37V
S IM E N = 1 , C S E N = 0 ( E x te r n a l P u ll- H ig h )
S C S
S IM E N , C S E N = 1
S C K (C K P O L = 1 , C K E G = 0 )
S C K (C K P O L = 0 , C K E G = 0 )
S C K (C K P O L = 1 , C K E G = 1 )
S C K (C K P O L = 0 , C K E G = 1 )
S D O
(C K E G = 0 )
D 7 /D 0
D 6 /D 1
D 5 /D 2
D 4 /D 3
D 3 /D 4
D 2 /D 5
D 1 /D 6
D 0 /D 7
S D O
(C K E G = 1 )
D 7 /D 0
D 6 /D 1
D 5 /D 2
D 4 /D 3
D 3 /D 4
D 2 /D 5
D 1 /D 6
D 0 /D 7
S D I D a ta C a p tu re
W r ite to S IM D R
SPI Master Mode Timing
S C S
S C K (C K P O L = 1 )
S C K (C K P O L = 0 )
S D O
D 7 /D 0
D 6 /D 1
D 5 /D 2
D 4 /D 3
D 3 /D 4
D 2 /D 5
D 1 /D 6
D 0 /D 7
D 2 /D 5
D 1 /D 6
D 0 /D 7
S D I D a ta C a p tu re
W r ite to S IM D R
( S D O n o t c h a n g e u n til fir s t S C K e d g e )
SPI Slave Mode Timing (CKEG=0)
S C S
S C K (C K P O L = 1 )
S C K (C K P O L = 0 )
S D O
D 7 /D 0
D 6 /D 1
D 5 /D 2
D 4 /D 3
D 3 /D 4
S D I D a ta C a p tu re
W r ite to S IM D R
( S D O c h a n g e a s s o o n a s w r itin g o c c u r ; S D O = flo a tin g if S C S = 1 )
N o te : F o r S P I s la v e m o d e , if S IM E N = 1 a n d C S E N = 0 , S P I is a lw a y s e n a b le d
a n d ig n o r e th e S C S le v e l.
SPI Slave Mode Timing (CKEG=1)
Rev. 1.00
46
October 20, 2009
HT45R37V
A
S P I tra n s fe r
W r ite D a ta
in to S IM D R
C le a r W C O L
M a s te r
m a s te r o r
s la v e
?
S IM [2 :0 ]= 0 0 0 ,
0 0 1 ,0 1 0 ,0 1 1 o r 1 0 0
S la v e
Y
W C O L = 1 ?
N
S IM [2 :0 ]= 1 0 1
N
c o n fig u r e
C S E N a n d M L S
T r a n s m is s io n
c o m p le te d ?
(T R F = 1 ? )
Y
S IM E N = 1
R e a d D a ta
fro m S IM D R
A
C le a r T R F
T ra n s fe r
F in is h e d ?
N
Y
E N D
SPI Transfer Control Flowchart
Rev. 1.00
47
October 20, 2009
HT45R37V
SPI Control Register - SIMCTL2
TRF flag will be set automatically, but must be cleared
using the application program. In the Slave Mode, when
the clock signal from the master has been received, any
data in the SIMDR register will be transmitted and any
data on the SDI pin will be shifted into the SIMDR register. The master should output an SCS signal to enable
the slave device before a clock signal is provided and
slave data transfers should be enabled/disabled before/after an SCS signal is received.
The SIMCTL2 register is also used by the I2C interface
but has the name SIMAR.
· TRF
The TRFbit is the Transmit/Receive Complete flag and
is set high automatically when an SPI data transmission is completed, but must be cleared by the application program. It can be used to generate an interrupt.
· WCOL
The SPI will continue to function even after a HALT instruction has been executed.
The WCOL bit is used to detect if a data collision has
occurred. If this bit is high it means that data has been
attempted to be written to the SIMDR register during a
data transfer operation. This writing operation will be
ignored if data is being transferred. The bit can be
cleared by the application program. Note that using
the WCOL bit can be disabled or enabled via configuration option.
I2C Interface
The I2C interface is used to communicate with external
peripheral devices such as sensors, EEPROM memory
etc. Originally developed by Philips, it is a two line low
speed serial interface for synchronous serial data transfer. The advantage of only two lines for communication,
relatively simple communication protocol and the ability
to accommodate multiple devices on the same bus has
made it an extremely popular interface type for many
applications.
· CSEN
The CSEN bit is used as an on/off control for the SCS
pin. If this bit is low then the SCS pin will be disabled
and placed into a floating condition. If the bit is high
the SCS pin will be enabled and used as a select pin.
Note that using the CSEN bit can be disabled or enabled via configuration option.
I2C Interface Operation
· MLS
The I2C serial interface is a two line interface, a serial
data line, SDA, and serial clock line, SCL. As many devices may be connected together on the same bus, their
outputs are both open drain types. For this reason it is
necessary that external pull-high resistors are connected to these outputs. Note that no chip select line exists, as each device on the I2C bus is identified by a
unique address which will be transmitted and received
on the I2C bus.
This is the data shift select bit and is used to select
how the data is transferred, either MSB or LSB first.
Setting the bit high will select MSB first and low for
LSB first.
· CKEG and CKPOL
These two bits are used to setup the way that the
clock signal outputs and inputs data on the SPI bus.
These two bits must be configured before data transfer is executed otherwise an erroneous clock edge
may be generated. The CKPOL bit determines the
base condition of the clock line, if the bit is high then
the SCK line will be low when the clock is inactive.
When the CKPOL bit is low then the SCK line will be
high when the clock is inactive. The CKEG bit determines active clock edge type which depends upon the
condition of CKPOL.
CKPOL
CKEG
SCK Clock Signal
0
0
High Base Level
Active Rising Edge
0
1
High Base Level
Active Falling Edge
1
0
Low Base Level
Active Falling Edge
1
1
Low Base Level
Active Rising Edge
When two devices communicate with each other on the
bidirectional I2C bus, one is known as the master device
and one as the slave device. Both master and slave can
transmit and receive data, however, it is the master device that has overall control of the bus. For these devices, which only operates in slave mode, there are two
S T A R T s ig n a l
fro m M a s te r
S e n d s la v e a d d r e s s
a n d R /W b it fr o m M a s te r
A c k n o w le d g e
fr o m s la v e
S e n d d a ta b y te
fro m M a s te r
SPI Communication
A c k n o w le d g e
fr o m s la v e
After the SPI interface is enabled by setting the SIMEN
bit high, then in the Master Mode, when data is written to
the SIMDR register, transmission/reception will begin simultaneously. When the data transfer is complete, the
Rev. 1.00
S T O P s ig n a l
fro m M a s te r
48
October 20, 2009
HT45R37V
D a ta B u s
I2C
H T X B it
S C L P in
S D A P in
M
X
S la v e A d d r e s s R e g is te r
(S IM A R )
A d d re s s
C o m p a ra to r
D ir e c tio n C o n tr o l
D a ta in L S B
D a ta O u t M S B
U
D a ta R e g is te r
(S IM D R )
S h ift R e g is te r
R e a d /w r ite S la v e
A d d re s s M a tc h
H A A S B it
S R W
I2C
In te rru p t
B it
E n a b le /D is a b le A c k n o w le d g e
T r a n s m it/R e c e iv e
C o n tr o l U n it
8 - b it D a ta C o m p le te
D e te c t S ta rt o r S to p
H C F B it
H B B B it
I2C Block Diagram
methods of transferring data on the I2C bus, the slave
transmit mode and the slave receive mode.
SIMCTL0 are used by the I2C interface. The SIMCTL0
register is shown in the above SPI section.
There are several configuration options associated with
the I2C interface. One of these is to enable the function
which selects the SIM pins rather than normal I/O pins.
Note that if the configuration option does not select the
SIMfunction then the SIMENbit in the SIMCTL0 register
will have no effect. A configuration option exists to allow
a clock other than the system clock to drive the I2C interface. Another configuration option determines the
debounce time of the I2C interface. This uses the internal clock to in effect add a debounce time to the external
clock to reduce the possibility of glitches on the clock
line causing erroneous operation. The debounce time, if
selected, can be chosen to be either 1 or 2 system
clocks.
· SIMIDLE
SIM
The SIMIDLE bit is used to select if the I2C interface
continues running when the device is in the IDLE
mode. Setting the bit high allows the I2C interface to
maintain operation when the device is in the Idle
mode. Clearing the bit to zero disables any I2C operations when in the Idle mode.
This SPI/I2C idle mode control bit is located at
CLKMOD register bit4.
· SIMEN
The SIMEN bit is the overall on/off control for the I2C
interface. When the SIMENbit is cleared to zero to disable the I2C interface, the SDA and SCL lines will be in
a floating condition and the I2C operating current will
be reduced to a minimum value. When the bit is high
the I2C interface is enabled. The SIMconfiguration option must have first enabled the SIM interface for this
bit to be effective. Note that when the SIMEN bit
changes from low to high the contents of the I2C control registers will be in an unknown condition and
should therefore be first initialised by the application
program
Function
SIM function
SIM Interface enable or disable
I2C debounce
No debounce, 1 system clock;
2 system clocks
I2C Interface Configuration Options
· SIM0~SIM2
I2C Registers
These bits setup the overall operating mode of the
SIM function. To select the I2C function, bits SIM2~
SIM0 should be set to the value 110.
There are three control registers associated with the I2C
bus, SIMCTL0, SIMCTL1 and SIMARand one data register, SIMDR. The SIMDRregister, which is shown in the
above SPI section, is used to store the data being transmitted and received on the I 2 C bus. Before the
microcontroller writes data to the I2C bus, the actual data
to be transmitted must be placed in the SIMDR register.
After the data is received from the I 2 C bus, the
microcontroller can read it from the SIMDRregister. Any
transmission or reception of data from the I2C bus must
be made via the SIMDR register.
· RXAK
The RXAK flag is the receive acknowledge flag. When
the RXAK bit has been reset to zero it means that a
correct acknowledge signal has been received at the
9th clock, after 8 bits of data have been transmitted.
When in the transmit mode, the transmitter checks the
RXAK bit to determine if the receiver wishes to receive
the next byte. The transmitter will therefore continue
sending out data until the RXAK bit is set high. When
this occurs, the device will release the SDA line to allow the master to send a STOP signal to release the
bus.
Note that the SIMAR register also has the name
SIMCTL2 which is used by the SPI function. Bits
SIMIDLE, SIMEN and bits SIM0~SIM2 in register
Rev. 1.00
49
October 20, 2009
HT45R37V
dresses match then this bit will be high, if there is no
match then the flag will be low.
S ta rt
· HCF
W r ite S la v e
A d d re s s to S IM A R
The HCF flag is the data transfer flag. This flag will be
zero when data is being transferred. Upon completion
of an 8-bit data transfer the flag will go high and an interrupt will be generated.
S E T S IM [2 :0 ]= 1 1 0
S E T S IM E N
I2C Control Register - SIMAR
D is a b le
I C B u s
In te rru p t= ?
2
E n a b le
The SIMARregister is also used by the SPI interface but
has the name SIMCTL2.
C L R E S IM
P o ll S IM F to d e c id e
w h e n to g o to I2C B u s IS R
S E T E S IM
S e t E M F I0
W a it fo r In te r r u p t
G o to M a in P r o g r a m
G o to M a in P r o g r a m
The SIMARregister is the location where the 7-bit slave
address of the microcontroller is stored. Bits 1~7 of the
SIMAR register define the microcontroller slave address. Bit 0 is not defined. When a master device, which
is connected to the I2C bus, sends out an address,
which matches the slave address in the SIMARregister,
the microcontroller slave device will be selected. Note
that the SIMAR register is the same register as
SIMCTL2 which is used by the SPI interface.
I2C Bus Initialisation Flow Chart
· SRW
The SRW bit is the Slave Read/Write bit. This bit determines whether the master device wishes to transmit or receive data from the I2C bus. When the
transmitted address and slave address match, that is
when the HAAS bit is set high, the device will check
the SRW bit to determine whether it should be in
transmit mode or receive mode. If the SRW bit is high,
the master is requesting to read data from the bus, so
the device should be in transmit mode. When the
SRW bit is zero, the master will write data to the bus,
therefore the device should be in receive mode to
read this data.
I2C Bus Communication
Communication on the I2C bus requires four separate
steps, a START signal, a slave device address transmission, a data transmission and finally a STOP signal.
When a START signal is placed on the I2C bus, all devices on the bus will receive this signal and be notified of
the imminent arrival of data on the bus. The first seven
bits of the data will be the slave address with the first bit
being the MSB. If the address of the microcontroller
matches that of the transmitted address, the HAAS bit in
the SIMCTL1 register will be set and an I2C interrupt will
be generated. After entering the interrupt service routine, the microcontroller slave device must first check
the condition of the HAAS bit to determine whether the
interrupt source originates from an address match or
from the completion of an 8-bit data transfer. During a
data transfer, note that after the 7-bit slave address has
been transmitted, the following bit, which is the 8th bit, is
the read/write bit whose value will be placed in the SRW
bit. This bit will be checked by the microcontroller to determine whether to go into transmit or receive mode. Before any transfer of data to or from the I2C bus, the
microcontroller must initialise the bus, the following are
steps to achieve this:
· TXAK
The TXAK flag is the transmit acknowledge flag. After
the receipt of 8-bits of data, this bit will be transmitted
to the bus on the 9th clock. To continue receiving more
data, this bit has to be reset to zero before further data
is received.
· HTX
The HTX flag is the transmit/receive mode bit. This
flag should be set high to set the transmit mode and
low for the receive mode.
· HBB
The HBB flag is the I2C busy flag. This flag will be high
when the I2C bus is busy which will occur when a
START signal is detected. The flag will be reset to
zero when the bus is free which will occur when a
STOP signal is detected.
Step 1
· HASS
Write the slave address of the microcontroller to the I2C
bus address register SIMAR.
The HASS flag is the address match flag. This flag is
used to determine if the slave device address is the
same as the master transmit address. If the adb 7
S A 6
b 0
S A 5
S A 4
S A 3
S A 2
S A 1
S A 0
S IM A R
R e g is te r
U n d e fin e d
I2C
d e v ic e s la v e a d d r e s s
I C Slave Address Register - SIMAR
2
Rev. 1.00
50
October 20, 2009
HT45R37V
S C L
S R W
S la v e A d d r e s s
S ta rt
0
1
S D A
1
1
0
1
0
1
D a ta
S C L
1
0
0
1
A C K
0
A C K
0
1
0
S to p
0
S D A
S = S
S A =
S R =
M = S
D = D
A = A
P = S
S
ta rt (1
S la v e
S R W
la v e d
a ta (8
C K (R
to p (1
S A
b it)
A d d r e s s ( 7 b its )
b it ( 1 b it)
e v ic e s e n d a c k n o w le d g e b it ( 1 b it)
b its )
X A K b it fo r tr a n s m itte r , T X A K b it fo r r e c e iv e r 1 b it)
b it)
S R
M
D
A
D
A
S
S A
S R
M
D
A
D
A
P
2
I C Communication Timing Diagram
S ta rt
N o
N o
Y e s
H A A S = 1
?
Y e s
Y e s
H T X = 1
?
S R W = 1
?
N o
R e a d fro m
S IM D R
S E T H T X
C L R H T X
C L R T X A K
R E T I
W r ite to
S IM D R
D u m m y R e a d
F ro m S IM D R
R E T I
R E T I
Y e s
R X A K = 1
?
N o
C L R H T X
C L R T X A K
W r ite to
S IM D R
D u m m y R e a d
fro m S IM D R
R E T I
R E T I
I2C Bus ISR Flow Chart
Rev. 1.00
51
October 20, 2009
HT45R37V
· Acknowledge Bit
Step 2
After the master has transmitted a calling address,
any slave device on the I2C bus, whose own internal
address matches the calling address, must generate
an acknowledge signal. This acknowledge signal will
inform the master that a slave device has accepted its
calling address. If no acknowledge signal is received
by the master then a STOP signal must be transmitted
by the master to end the communication. When the
HAAS bit is high, the addresses have matched and
the microcontroller slave device must check the SRW
bit to determine if it is to be a transmitter or a receiver.
If the SRW bit is high, the microcontroller slave device
should be setup to be a transmitter so the HTX bit in
the SIMCTL1 register should be set to ²1² if the SRW
bit is low then the microcontroller slave device should
be setup as a receiver and the HTX bit in the SIMCTL1
register should be set to ²0².
Set the SIMEN bit in the SIMCTL0 register to ²1² to enable the I2C bus.
Step 3
Set the ESIM and EMFI0 bits of the interrupt control
register to enable the I2C bus interrupt.
· Start Signal
The START signal can only be generated by the master device connected to the I2C bus and not by the
microcontroller, which is only a slave device. This
START signal will be detected by all devices connected to the I2C bus. When detected, this indicates
that the I2C bus is busy and therefore the HBB bit will
be set. A START condition occurs when a high to low
transition on the SDA line takes place when the SCL
line remains high.
· Data Byte
· Slave Address
The transmitted data is 8-bits wide and is transmitted
after the slave device has acknowledged receipt of its
slave address. The order of serial bit transmission is
the MSB first and the LSB last. After receipt of 8-bits of
data, the receiver must transmit an acknowledge signal, level ²0², before it can receive the next data byte.
If the transmitter does not receive an acknowledge bit
signal from the receiver, then it will release the SDA
line and the master will send out a STOP signal to release control of the I2C bus. The corresponding data
will be stored in the SIMDR register. If setup as a
transmitter, the microcontroller slave device must first
write the data to be transmitted into the SIMDR register. If setup as a receiver, the microcontroller slave device must read the transmitted data from the SIMDR
register.
The transmission of a START signal by the master will
be detected by all devices on the I2C bus. To determine which slave device the master wishes to communicate with, the address of the slave device will be
sent out immediately following the START signal. All
slave devices, after receiving this 7-bit address data,
will compare it with their own 7-bit slave address. If the
address sent out by the master matches the internal
address of the microcontroller slave device, then an
internal I2C bus interrupt signal will be generated. The
next bit following the address, which is the 8th bit, defines the read/write status and will be saved to the
SRW bit of the SIMCTL1 register. The device will then
transmit an acknowledge bit, which is a low level, as
the 9th bit. The microcontroller slave device will also
set the status flag HAAS when the addresses match.
As an I2C bus interrupt can come from two sources,
when the program enters the interrupt subroutine, the
HAAS bit should be examined to see whether the interrupt source has come from a matching slave address or from the completion of a data byte transfer.
When a slave address is matched, the device must be
placed in either the transmit mode and then write data
to the SIMDR register, or in the receive mode where it
must implement a dummy read from the SIMDR register to release the SCL line.
S C L
S D A
S ta r t b it
D a ta
a llo w
c h a n g e
S to p b it
Data Timing Diagram
· Receive Acknowledge Bit
· SRW Bit
When the receiver wishes to continue to receive the
next data byte, it must generate an acknowledge bit,
known as TXAK, on the 9th clock. The microcontroller
slave device, which is setup as a transmitter will check
the RXAK bit in the SIMCTL1 register to determine if it
is to send another data byte, if not then it will release
the SDA line and await the receipt of a STOP signal
from the master.
The SRW bit in the SIMCTL1 register defines whether
the microcontroller slave device wishes to read data
from the I2C bus or write data to the I2C bus. The
microcontroller should examine this bit to determine if
it is to be a transmitter or a receiver. If the SRW bit is
set to ²1² then this indicates that the master wishes to
re a d da t a f r o m t he I 2 C bus , t her e f o r e t h e
microcontroller slave device must be setup to send
data to the I2C bus as a transmitter. If the SRW bit is
²0² then this indicates that the master wishes to send
data to the I2C bus, therefore the microcontroller slave
device must be setup to read data from the I2C bus as
a receiver.
Rev. 1.00
D a ta
s ta b le
52
October 20, 2009
HT45R37V
Buzzer
Operating in a similar way to the Programmable Frequency Divider, the Buzzer function provides a means of
producing a variable frequency output, suitable for applications such as Piezo-buzzer driving or other external
circuits that require a precise frequency generator.
that generates fS, which in turn controls the buzzer frequency, can originate from three different sources, the
32768Hz oscillator, the 32K_INT oscillator or the System oscillator/4, the choice of which is determined by
the fS clock source configuration option. Note that the
buzzer frequency is controlled by configuration options,
which select both the source clock for the internal clock
fS and the internal division ratio. There are no internal
registers associated with the buzzer frequency.
Buzzer Operation
The BZ and BZ pins form a complementary pair, and are
pin-shared with I/O pins, PA0 and PA1. A configuration
option is used to select from one of three buzzer options.
The first option is for both pins PA0 and PA1 to be used
as normal I/Os, the second option is for both pins to be
configured as BZ and BZ buzzer pins, the third option
selects only the PA0 pin to be used as a BZ buzzer pin
with the PA1 pin retaining its normal I/O pin function.
Note that the BZ pin is the inverse of the BZ pin which together generate a differential output which can supply
more power to connected interfaces such as buzzers.
If the configuration options have selected both pins PA0
and PA1 to function as a BZ and BZ complementary pair
of buzzer outputs, then for correct buzzer operation it is
essential that both pins must be setup as outputs by setting bits PAC0 and PAC1 of the PAC port control register
to zero. The PA0 data bit in the PA data register must
also be set high to enable the buzzer outputs, if set low,
both pins PA0 and PA1 will remain low. In this way the
single bit PA0 of the PA register can be used as an on/off
control for both the BZ and BZ buzzer pin outputs. Note
that the PA1 data bit in the PA register has no control
over the BZ buzzer pin PA1.
The buzzer is driven by the internal clock source, , which
then passes through a divider, the division ratio of which
is selected by configuration options to provide a range of
buzzer frequencies from fS/22 to fS/29. The clock source
PA0/PA1 Pin Function Control
PAC Register
PAC0
PAC Register
PAC1
PA Data Register
PA0
PA Data Register
PA1
Output
Function
0
0
1
x
PA0=BZ
PA1=BZ
0
0
0
x
PA0=²0²
PA1=²0²
0
1
1
x
PA0=BZ
PA1=input line
0
1
0
x
PA0=²0²
PA1=input line
1
0
x
D
PA0=input line
PA1=D
1
1
x
x
PA0=input line
PA0=input line
²x² stands for don¢t care
²D² stands for Data ²0² or ²1²
fS
Y S
/4
3 2 7 6 8 H z
3 2 K _ IN T
fS S o u rc e
C o n fig u r a tio n
O p tio n
fS
C o n fig u r a tio n O p tio n
D iv id e b y 2 2 ~ 2 9
B Z
B Z
Buzzer Function
Rev. 1.00
53
October 20, 2009
HT45R37V
Note that no matter what configuration option is chosen
for the buzzer, if the port control register has setup the
pin to function as an input, then this will override the configuration option selection and force the pin to always
behave as an input pin. This arrangement enables the
pin to be used as both a buzzer pin and as an input pin,
so regardless of the configuration option chosen; the actual function of the pin can be changed dynamically by
the application program by programming the appropriate port control register bit.
If configuration options have selected that only the PA0
pin is to function as a BZ buzzer pin, then the PA1 pin
can be used as a normal I/O pin. For the PA0 pin to function as a BZ buzzer pin, PA0 must be setup as an output
by setting bit PAC0 of the PAC port control register to
zero. The PA0 data bit in the PA data register must also
be set high to enable the buzzer output, if set low pin
PA0 will remain low. In this way the PA0 bit can be used
as an on/off control for the BZ buzzer pin PA0. If the
PAC0 bit of the PAC port control register is set high, then
pin PA0 can still be used as an input even though the
configuration option has configured it as a BZ buzzer
output.
In te r n a l C lo c k S o u r c e
P A 0 D a ta
B Z O u tp u t a t P A 0
P A 1 D a ta
B Z O u tp u t a t P A 1
Buzzer Output Pin Control
Note:
The above drawing shows the situation where both pins PA0 and PA1 are selected by configuration option to
be BZ and BZ buzzer pin outputs. The Port Control Register of both pins must have already been setup as output. The data setup on pin PA1 has no effect on the buzzer outputs.
Rev. 1.00
54
October 20, 2009
HT45R37V
Interrupts
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.
Interrupts are an important part of any microcontroller
system. When an external event or an internal function
such as a Timer/Event Counter or an A/D converter requires microcontroller attention, their corresponding interrupt will enforce a temporary suspension of the main
program allowing the microcontroller to direct attention
to their respective needs. The device contains several
external interrupt and internal interrupts functions. The
external interrupts are controlled by the action of the external INT0 and INT1 pins, while the internal interrupts
are controlled by functions such as the Timer/Event
Counter overflows, the Time Base interrupt, the RTC interrupt, the SPI/I2C interrupt, C/R to F converter interrupt and the A/D converter interrupt etc.
Interrupt Priority
Interrupts, occurring in the interval between the rising
edges of two consecutive T2 pulses, will be serviced on
the latter of the two T2 pulses, if the corresponding interrupts are enabled. In case of simultaneous requests,
the following table shows the priority that is applied.
Interrupt Registers
Overall interrupt control, which means interrupt enabling
and request flag setting, is controlled by the INTC0,
INTC1, MFIC0, and MFIC1 registers, which are located
in the Data Memory. By controlling the appropriate enable bits in these registers each individual interrupt can
be enabled or disabled. Also when an interrupt occurs,
the corresponding request flag will be set by the
microcontroller. The global enable flag if cleared to zero
will disable all interrupts.
Interrupt Source
Interrupt Operation
A Timer/Event Counter overflow, Time Base, RTC overflow, SPI/I2C data transfer complete, C/R to F converter
interrupt, an end of A/D conversion or the external interrupt line being triggered are some of the events which
will generate an interrupt request by setting their corresponding request flag. When this happens and if their
appropriate interrupt enable bit is set, 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 statement which will
jump to another section of program which is known as
the interrupt service routine. Here is located the code to
control the appropriate interrupt. The interrupt service
routine must be terminated with a RETI statement,
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.
Vector
1
04H
External Interrupt 1
2
08H
Timer/Event Counter 0 Overflow
3
0CH
Timer/Event Counter 1 Overflow
4
10H
Multi Function 0 Interrupt
5
14H
Multi Function 1 Interrupt
6
18H
The SPI/I2C interrupt, C/R to F converter interrupt share
the same vector which is Multi Function 0 Interrupt vector at location 14H. The A/D converter interrupt, Real
Time clock interrupt and Time Base interrupt share the
same vector which is the Multi Function 1 Interrupt vector at location 18H. Each interrupt has its own interrupt
flag but share the global MF0F or MF1F Multi Function
interrupt flag. The MF0F and MF1F flags will be cleared
by hardware once the Multi-function interrupt is serviced, however the individual interrupts that have triggered the Multi-function interrupt need to be cleared by
the application program
External Interrupt
For an external interrupt to occur, the global interrupt
enable bit, EMI, and external interrupt enable bits, EEI0
and EEI1, must first be set. Additionally the correct
interrupt edge type must be selected using the
INTEDGE register to enable the external interrupt
function and to choose the trigger edge type. An actual
external interrupt will take place when the external
interrupt request flag, EIF0 or EIF1, is set, a situation
that will occur when a transition, whose type is chosen
by the edge select bit, appears on the INT0 or INT1 pin.
The external interrupt pins are pin-shared with the I/O
pins PA6 and PA7 and can only be configured as
external interrupt pins if their corresponding external
interrupt enable bit in the INTC0 register has been set.
The various interrupt enable bits, together with their associated request flags, are shown in the accompanying
diagram with their order of priority.
Once an interrupt subroutine is serviced, all the other interrupts will be blocked, as the EMI bit will be cleared automatically. This will prevent any further interrupt nesting
Rev. 1.00
Priority
External Interrupt 0
55
October 20, 2009
HT45R37V
b 7
b 0
T 0 F
E IF 1
E IF 0
E T 0 I E E I1
E E I0
E M I
IN T C 0 R e g is te
M a s te r in te r r u p t g lo b a l e n a b le
1 : g lo b a l e n a b le
0 : g lo b a l d is a b le
E x te r n a l in te r r u p t 0 e n a b le
1 : e n a b le
0 : d is a b le
E x te r n a l in te r r u p t 1 e n a b le
1 : e n a b le
0 : d is a b le
T im e r /E v e n t C o u n te r 0 in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
E x te r n a l in te r r u p t 0 r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
E x te r n a l in te r r u p t 1 r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
T im e r /E v e n t C o u n te r 0 in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
N o t im p le m e n te d , r e a d a s " 0 "
Interrupt Control Register INTC0
b 7
b 0
M F 1 F
M F 0 F
T 1 F
E M F I1
E M F I0
E T 1 I
IN T C 1 R e g is te r
T im e r /E v e n t C o u n te r 1 in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
M u lti- F u n c tio n in te r r u p t 0 e n a b le
1 : e n a b le
0 : d is a b le
M u lti- fu n c tio n in te r r u p t 1 e n a b le
1 : e n a b le
0 : d is a b le
N o t im p le m e n te d , r e a d a s " 0 "
T im e r /E v e n t C o u n te r 1 in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
M u lti- F u n c tio n in te r r u p t 0 r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
M u lti- fu n c tio n in te r r u p t 1 r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
N o t im p le m e n te d , r e a d a s " 0 "
Interrupt Control Register INTC1
Rev. 1.00
56
October 20, 2009
HT45R37V
b 7
b 0
R C O C F
S IM F
E R C O C I E S IM
M F IC 0 R e g is te r
S P I/I2 C in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
C /R to F c o n v e r te r in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
N o t im p le m e n te d , r e a d a s " 0 "
S P I/I2 C in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
C /R to F c o n v e r te r in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
N o t im p le m e n te d , r e a d a s " 0 "
Interrupt Control Register - MFIC0
b 7
U n d e fin e d
b 0
T B F
R T F
A D F
R e s e rv e d
E T B I E R T I E A D I
M F IC 1 R e g is te r
A /D c o n v e r te r in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
R e a l T im e C lo c k in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
T im e B a s e in te r r u p t e n a b le
1 : e n a b le
0 : d is a b le
R e s e r v e d b it
1 : u n p r e d ic a b le o p e r a tio n - b it m u s t N O T b e s e t to " 1 "
0 : c o r r e c t le v e l - b it m u s t b e s e t to " 0 " fo r c o r r e c t o p e r a tio n
A /D c o n v e r te r in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
R e a l T im e C lo c k in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
T im e B a s e in te r r u p t r e q u e s t fla g
1 : a c tiv e
0 : in a c tiv e
U n d e fin e d b it
Interrupt Control Register - MFIC1
Rev. 1.00
57
October 20, 2009
HT45R37V
A u to m a tic a lly C le a r e d b y IS R
e x c e p t
fo r A D F , T B F , R T F , P E F , S IM F a n d R C O C F
M a n u a lly S e t o r C le a r e d b y S o ftw a r e
A u to m a tic a lly D is a b le d b y IS R
C a n b e E n a b le d M a n u a lly
P r io r ity
E M I
E x te rn a l In te rru p t
R e q u e s t F la g E IF 0
E E I0
E x te rn a l In te rru p t
R e q u e s t F la g E IF 1
E E I1
T im e r /E v e n t C o u n te r 0
In te r r u p t R e q u e s t F la g T 0 F
E T 0 I
T im e r /E v e n t C o u n te r 1
In te r r u p t R e q u e s t F la g T 1 F
E T 1 I
M u lti- F u n c tio n
In te r r u p t 0 R e q u e s t F la g M F 0 F
E M F I0
M u lti- fu n c tio n
In te r r u p t 1 R e q u e s t F la g M F 1 F
E M F I1
A /D C o n v e rte r
In te r r u p t R e q u e s t F la g A D F
E A D I
R e a l T im e C lo c k
In te r r u p t R e q u e s t F la g R T F
E R T I
T im e B a s e
In te r r u p t R e q u e s t F la g T B F
E T B I
S P I/I2C
In te r r u p t R e q u e s t F la g S IM F
E S IM
C /R to F C o n v e rte r
In te r r u p t R e q u e s t F la g R C O C F
H ig h
In te rru p t
P o llin g
L o w
E R C O C I
Interrupt Structure
The external interrupt pins are connected to an internal
filter to reduce the possibility of unwanted external interrupts due to adverse noise or spikes on the external interrupt input signal. As this internal filter circuit will
consume a limited amount of power, a configuration option is provided to switch off the filter function, an option
which may be beneficial in power sensitive applications,
but in which the integrity of the input signal is high. Care
must be taken when using the filter on/off configuration
option as it will be applied not only to both the external
interrupt pins but also to the Timer/Event Counter external input pins. Individual external interrupt or
Timer/Event Counter pins cannot be selected to have a
filter on/off function.
The pin must also be setup as an input by setting the
corresponding PAC.6 and PAC.7 bits in the port control
register. When the interrupt is enabled, the stack is not
full and the correct transition type appears on the
external interrupt pin, a subroutine call to the external
interrupt vector at location 04H or 08H, will take place.
When the interrupt is serviced, the external interrupt
request flags, EIF0 or EIF1, will be automatically reset
and the EMI bit will be automatically cleared to disable
other interrupts. Note that any pull-high resistor
selections on this pin will remain valid even if the pin is
used as an external interrupt input.
The INTEDGE register is used to select the type of active
edge that will trigger the external interrupt. A choice of either rising and falling edge types can be chosen along
with an option to allow both edge types to trigger an external interrupt. Note that the INTEDGE register can also be
used to disable the external interrupt function.
Rev. 1.00
58
October 20, 2009
HT45R37V
b 7
b 0
IN T 1 S 1 IN T 1 S 0 IN T 0 S 1 IN T 0 S 0
IN T E D G E R e g is te r
IN T 0 E d g e S e
IN T 0 S 1
IN
0
0
1
1
le c t
T 0 S 0
0
1
0
1
d is a b le
r is in g e d g e tr ig g e r
fa llin g e d g e tr ig g e r
d u a l e d g e tr ig g e r
IN T 1 E D g e S e le c t
IN T 1 S 1
IN T 1 S 0
0
0
1
0
0
1
1
1
d is a b le
r is in g e d g e tr ig g e r
fa llin g e d g e tr ig g e r
d u a l e d g e tr ig g e r
N o t im p le m e n te d , r e a d a s " 0 "
Interrupt Active Edge Register - INTEDGE
Timer/Event Counter Interrupt
For a Multi-function interrupt to occur, the global interrupt
enable bit, EMI, and the Multi-function interrupt enable
bit, EMF0I or EMF1I, must first be set. An actual
Multi-function interrupt will take place when the
Multi-function interrupt request flag, MF0F, or MF1F is
set. This will occur when either a Time Base overflow, a
Real Time Clock overflow, an A/D conversion completion,
C/R to F converter counters, Timer A or Timer B overflow
or SIM data transfer or I2C address match occurs. When
the interrupt is enabled and the stack is not full, and either
one of the interrupts contained within the Multi-function
interrupts occurs, a subroutine call to one of the
Multi-function interrupt vector at location 014H or 018H
will take place. When the interrupt is serviced, the
Multi-Function request flag, MF0F or MF1F, will be automatically reset and the EMI bit will be automatically
cleared to disable other interrupts. However, it must be
noted that the request flags from the original source of the
Multi-function interrupt, namely the Time-Base interrupt,
Real Time Clock interrupt, A/D Converter interrupt, SIM
Interface or C/R to F converter Interrupt will not be automatically reset and must be manually reset by the application program.
For a Timer/Event Counter 0 or Timer/Event Counter 1
interrupt to occur, the global interrupt enable bit, EMI,
and the corresponding timer interrupt enable bit, ET0I or
ET1I must first be set. An actual Timer/Event Counter interrupt will take place when the Timer/Event Counter request flag, T0F or T1F is set, a situation that will occur
when the Timer/Event Counter overflows. When the interrupt is enabled, the stack is not full and a Timer/Event
Counter overflow occurs, a subroutine call to the timer
interrupt vector at location 0CH or 10C, will take place.
When the interrupt is serviced, the timer interrupt request flag, T0F or T1F, will be automatically reset and
the EMI bit will be automatically cleared to disable other
interrupts.
A/D Interrupt
The A/D Interrupt is contained within the Multi-function
Interrupt 1.
For an A/D Interrupt to be generated, the global interrupt
enable bit, EMI, A/D Interrupt enable bit, EADI, and
Multi-function Interrupt 1 enable bit, EMF1I, must first be
set. An actual A/D Interrupt will take place when the A/D
Interrupt request flag, ADF, is set, a situation that will occur when the A/D conversion process has finished.
When the interrupt is enabled, the stack is not full and
the A/D conversion process has ended, a subroutine
call to the Multi-function Interrupt 1 vector at
location18H, will take place. When the A/D Interrupt is
serviced, the EMI bit will be cleared to disable other interrupts, however only the MF1F interrupt request flag
will be reset. As the ADF flag will not be automatically reset, it has to be cleared by the application program.
SPI/I2C Interface Interrupt
The SPI/I2C interface Interrupt is contained within the
Multi-function Interrupt 0.
For an /I2C interrupt to occur, the global interrupt enable
bit, EMI, the corresponding interrupt enable bit, ESIM
and Multi-function Interrupt 0 enable bit, EMF0I, must be
first set. An actual SPI/I2C interrupt will take place when
the SPI/I2C reset function interface request flag, SIMF, is
set, a situation that will occur when a byte of data has
been transmitted or received by the SPI/I2C interface or
when an I2C address match occurs. When the interrupt
is enabled, the stack is not full and a byte of data has
been transmitted or received by the SPI/I2C interface or
an I2C address match occurs, a subroutine call to the
Multi-function Interrupt 0 vector at location 14H, will take
place. When the interrupt is serviced, the Multi-function
Interrupt 0 request flag, MF0F, will be automatically reset and the EMI bit will be automatically cleared to dis-
Multi-function Interrupts
Additional interrupts known as the Multi-function interrupts are provided. Unlike the other interrupts, these interrupts have no independent source, but rather are
formed from other existing interrupt sources, namely the
A/D Converter interrupt, Time Base interrupt, Real Time
Clock interrupt, SIM Interface Interrupt and the C/R to F
interrupt.
Rev. 1.00
59
October 20, 2009
HT45R37V
flag will not be automatically reset, it has to be cleared
by the application program.
able other interrupts. As the SIMF flag will not be
automatically reset it has to be cleared by the application program.
Similar in operation to the Time Base interrupt, the purpose of the RTC interrupt is also to provide an interrupt
signal at fixed time periods. The RTC interrupt clock
source originates from the internal clock source fS. This
fS input clock first passes through a divider, the division
ratio of which is selected by programming the appropriate bits in the RTCC register to obtain longer RTC interrupt periods whose value ranges from 28/fS~215/fS. The
clock source that generates fS, which in turn controls the
RTC interrupt period, can originate from three different
sources, the 32768Hz oscillator, 32K_INT oscillator or
the System oscillator/4, the choice of which is determine
by the fS clock source configuration option.
C/R to F Converter Interrupt
The C/R to converter Interrupt is contained within the
Multi-function Interrupt 0.
For a C/R to F converter interrupt to be generated, the
global interrupt enable bit, EMI, the corresponding interrupt enable bit, ERCOCI and Multi-function Interrupt 0
enable bit, EMF0I, must be first set. An actual C/R to F
converter interrupt will take place when the C/R to F
converter interrupt request flag, RCOCF, is set, a situation that will occur when one of the C/R to F converter
counters, Timer A or Timer B, overflows. When the interrupt is enabled, the stack is not full and a C/R to F converter counter overflow occurs, a subroutine call to the
Multi-function Interrupt 0 vector at location 14H, will take
place. When the interrupt is serviced, the Multi-function
Interrupt 0 request flag, MF0F, will be automatically reset and the EMI bit will be automatically cleared to disable other interrupts. As the RCOCF flag will not be
automatically reset it has to be cleared by the application program.
Note that the RTC interrupt period is controlled by both
configuration options and an internal register RTCC. A
configuration option selects the source clock for the internal clock fS, and the RTCC register bits RT2, RT1 and
RT0 select the division ratio. Note that the actual division ratio can be programmed from 28 to 215.
Essentially operating as a programmable timer, when
the Real Time Clock overflows it will set a Real Time
Clock interrupt flag which will in turn generate an Interrupt request via the Multi-function Interrupt 1 vector.
Real Time Clock Interrupt
The Real Time Clock Interrupt is contained within the
Multi-function Interrupt 1.
Time Base Interrupt
The Time Base Interrupt is contained within the
Multi-function Interrupt 1.
For a Real Time Clock interrupt to be generated, the
global interrupt enable bit, EMI , Real Time Clock interrupt enable bit, ERTI, and Multi-function Interrupt 1 enable bit, EMF1I, must first be set. An actual Real Time
Clock interrupt will take place when the Real Time Clock
request flag, RTF, is set, a situation that will occur when
the Real Time Clock overflows. When the interrupt is enabled, the stack is not full and the Real Time Clock overflows, a subroutine call to the Multi-function Interrupt 1
vector at location18H, will take place. When the Real
Time Clock interrupt is serviced, the EMI bit will be
cleared to disable other interrupts, however only the
MF1F interrupt request flag will be reset. As the RTF
fS
Y S
/4
3 2 7 6 8 H z
3 2 K _ IN T
fS S o u rc e
C o n fig u r a tio n
O p tio n
fS
For a Time Base Interrupt to be generated, the global interrupt enable bit, EMI,Time Base Interrupt enable bit,
ETBI, and Multi-function Interrupt enable 1 bit, EMF1I,
must first be set. An actual Time Base Interrupt will take
place when the Time Base Interrupt request flag, TBF, is
set, a situation that will occur when the Time Base overflows. When the interrupt is enabled, the stack is not full
and the Time Base overflows, a subroutine call to the
Multi-function Interrupt 1 vector at location18H, will take
place. When the Time Base Interrupt is serviced, the
EMI bit will be cleared to disable other interrupts, how-
D iv id e b y 2 8 ~ 2
S e t b y R T C C
R e g is te r
R T 2
R T 1
1 5
R T C In te rru p t
2 12/fS ~ 2 15/fS
R T 0
RTC Interrupt
fS
Y S
/4
3 2 7 6 8 H z
3 2 K _ IN T
fS S o u rc e
C o n fig u r a tio n
O p tio n
fS
C o n fig u r a tio n O p tio n
D iv id e b y 2 1 2 ~ 2 1 5
T im e B a s e In te r r u p t
2 12/fS ~ 2 15/fS
Time Base Interrupt
Rev. 1.00
60
October 20, 2009
HT45R37V
b 7
L V D O
Q O S C
L V D C
R T 2
R T 1
b 0
R T 0
R T C C
R T C
R T 2
0
0
0
0
1
1
1
1
R e g is te r
In te r r u p t P e r io d
R T 0
R T 1
0
0
1
0
0
1
1
1
0
0
1
0
0
1
1
1
P e
2 8
2 9
2 1
2 1
2 1
2 1
2 1
2 1
r io d
/fS
/fS
0
/fS
1
/fS
2
/fS
3
/fS
4
/fS
5
/fS
L o w V o lta g e D e te c to r C o n tr o l
1 : e n a b le
0 : d is a b le
R T C O s c illa to r Q u ic k - s ta r t
1 : d is a b le
0 : e n a b le
L o w V o lta g e D e te c to r O u tp u t
1 : lo w v o lta g e d e te c te d
0 : n o r m a l v o lta g e
N o t im p le m e n te d , r e a d a s " 0 "
Real Time Clock Control Register - RTCC
condition in the INTC0, INTC1, MFIC0 and MFIC1 registers until the corresponding interrupt is serviced or until the request flag is cleared by the application program.
Note that if a specific interrupt uses a Multi-function Interrupt vector then its interrupt request flag will not be
automatically reset when the program enters the interrupt service routine. Only the Multi-function interrupt request flag will be automatically reset.
ever only the MF1F interrupt request flag will be reset.
As the TBF flag will not be automatically reset, it has to
be cleared by the application program.
The purpose of the Time Base function is to provide an
interrupt signal at fixed time periods. The Time Base interrupt clock source originates from the Time Base interrupt clock source originates from the internal clock
source fS. This fS input clock first passes through a divider, the division ratio of which is selected by configuration options to provide longer Time Base interrupt
periods. The Time Base interrupt time-out period ranges
from 212/fS~215/fS. The clock source that generates fS,
which in turn controls the Time Base interrupt period,
can originate from three different sources, the 32768Hz
oscillator, the 32K_INT internal oscillator or the System
oscillator/4, the choice of which is determine by the fS
clock source configuration option.
It is recommended that programs do not use the ²CALL
subroutine² instruction within the interrupt subroutine.
Interrupts often occur in an unpredictable manner or
need to be serviced immediately in some applications. 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.
All of these interrupts have the capability of waking up
the processor when in the Power Down Mode.
Essentially operating as a programmable timer, when
the Time Base overflows it will set a Time Base interrupt
flag which will in turn generate an Interrupt request via
the Multi-function Interrupt 1 vector.
Only the Program Counter is pushed onto the stack. If
the contents of the status or other registers are altered
by the interrupt service program, which may corrupt the
desired control sequence, then the contents should be
saved in advance.
Programming Considerations
By disabling the 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
Rev. 1.00
61
October 20, 2009
HT45R37V
Reset and Initialisation
the RES pin, whose additional time delay will ensure
that the RES pin remains low for an extended period
to allow the power supply to stabilise. As the RES pin
is shared with an I/O pin its function must be selected
using a configuration option. During this time delay,
normal operation of the microcontroller will be inhibited. After the RES line reaches a certain voltage
value, the reset delay time tRSTD is invoked to provide
an extra delay time after which the microcontroller will
begin normal operation. The abbreviation SST in the
figures stands for System Start-up Timer.
A reset function is a fundamental part of any
microcontroller ensuring that the device can be set to
some predetermined condition irrespective of outside
parameters. The most important reset condition is after
power is first applied to the microcontroller. In this case,
internal circuitry will ensure that the microcontroller, after a short delay, will be in a well defined state and ready
to execute the 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.
V D D
0 .9 V
R E S
tR
S T D
S S T T im e - o u t
In addition to the power-on reset, situations may arise
where it is necessary to forcefully apply a reset condition
when the microcontroller is running. One example of this
is where after power has been applied and the
microcontroller is already running, the RES line is forcefully pulled low. In such a case, known as a normal operation reset, some of the microcontroller registers remain
unchanged allowing the microcontroller to proceed with
normal operation after the reset line is allowed to return
high. 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.
C h ip R e s e t
Power-On Reset Timing Chart
For most applications a resistor connected between
VDD and the RES pin and a capacitor connected between VSS and the RES pin will provide a suitable external reset circuit. Any wiring connected to the RES
pin should be kept as short as possible to minimise
any stray noise interference.
For applications that operate within an environment
where more noise is present the Enhanced Reset Circuit shown is recommended.
V
Another reset exists in the form of a Low Voltage Reset,
LVR, where a full reset, similar to the RES reset is implemented in situations where the power supply voltage
falls below a certain threshold.
D D
0 .0 1 m F * *
1 N 4 1 4 8 *
There are five ways in which a microcontroller reset can
occur, through events occurring both internally and externally:
V D D
1 0 k W ~
1 0 0 k W
Reset Functions
P C 0 /R E S
3 0 0 W *
0 .1 ~ 1 m F
V S S
· Power-on Reset
The most fundamental and unavoidable reset is the
one that occurs after power is first applied to the
microcontroller. As well as ensuring that the Program
Memory begins execution from the first memory address, a power-on reset also ensures that certain
other registers are preset to known conditions. All the
I/O port and port control registers will power up in a
high condition ensuring that all pins will be first set to
inputs.
Although the microcontroller has an internal RC reset
function, if the VDD power supply rise time is not fast
enough or does not stabilise quickly at power-on, the
internal reset function may be incapable of providing
proper reset operation. For this reason it is recommended that an external RC network is connected to
Rev. 1.00
D D
Note:
²*² It is recommended that this component is
added for added ESD protection
²**² It is recommended that this component is
added in environments where power line noise
is significant
External RES Circuit
More information regarding external reset circuits is
located in Application Note HA0075E on the Holtek
website.
62
October 20, 2009
HT45R37V
· RES Pin Reset
W D T T im e - o u t
tS
This type of reset occurs when the microcontroller is
already running and the RES pin is forcefully pulled
low by external hardware such as an external switch.
In this case as in the case of other reset, the Program
Counter will reset to zero and program execution initiated from this point. The RES pin is shared with an I/O
pin so its function must be first selected using a configuration option.
R E S
0 .4 V
0 .9 V
WDT Time-out Reset during Power Down
Reset Initial Conditions
The 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
Power Down function or Watchdog Timer. The reset
flags are shown in the table:
D D
D D
tR
S T D
S S T T im e - o u t
C h ip R e s e t
TO PDF
RES Reset Timing Chart
0
· Low Voltage Reset - LVR
The microcontroller contains a low voltage reset circuit
in order to monitor the supply voltage of the device,
which is selected via a configuration option. If the supply
voltage of the device drops to within a range of
0.9V~VLVR such as might occur when changing the battery, the LVR will automatically reset the device internally. The LVR includes the following specifications: For
a valid LVR signal, a low voltage, i.e., a voltage in the
range between 0.9V~VLVR must exist for greater than the
value tLVR specified in the A.C. characteristics. If the low
voltage state does not exceed 1ms, the LVR will ignore it
and will not perform a reset function. One of a range of
specified voltage values for VLVR can be selected using
configuration options. The VLVR value will be selected as
a pair in conjunction with a Low Voltage Detect value.
0
RESET Conditions
RES reset during power-on
u
u
RES or LVR reset during normal operation
1
u
WDT time-out reset during normal operation
1
1
WDT time-out reset during Power Down
Note: ²u² stands for unchanged
The following table indicates the way in which the various components of the microcontroller are affected after
a power-on reset occurs.
Item
L V R
tR
S T
S S T T im e - o u t
S T D
Condition After RESET
Program Counter
Reset to zero
Interrupts
All interrupts will be disabled
WDT
Clear after reset, WDT begins
counting
Timer/Event Counter Timer Counter will be turned off
S S T T im e - o u t
C h ip R e s e t
Low Voltage Reset Timing Chart
· Watchdog Time-out Reset during Normal Operation
Prescaler
The Timer Counter Prescaler
will be cleared
Input/Output Ports
I/O ports will be setup as inputs
Stack Pointer
Stack Pointer will point to the
top of the stack
The Watchdog time-out Reset during normal operation is the same as a hardware RES pin reset except
that the Watchdog time-out flag TO will be set to ²1².
W D T T im e - o u t
tR
S T D
S S T T im e - o u t
C h ip R e s e t
WDT Time-out Reset during Normal Operation
Timing Chart
· Watchdog Time-out Reset during Power Down
The Watchdog time-out Reset during Power Down 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 A.C.
Characteristics for tSST details.
Rev. 1.00
63
October 20, 2009
HT45R37V
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.
Reset
(Power-on)
RES Reset
(Normal Operation)
WDT Time-out
(Normal Operation)
WDT Time-out
(HALT)
MP0
xxxx xxxx
uuuu uuuu
uuuu uuuu
uuuu uuuu
MP1
xxxx xxxx
uuuu uuuu
uuuu uuuu
uuuu uuuu
ACC
xxxx xxxx
uuuu uuuu
uuuu uuuu
uuuu uuuu
PCL
0000 0000
0000 0000
0000 0000
0000 0000
TBLP
xxxx xxxx
uuuu uuuu
uuuu uuuu
uuuu uuuu
TBLH
-xxx xxxx
-uuu uuuu
-uuu uuuu
-uuu uuuu
RTCC
--00 0111
--00 0111
--00 0111
--uu uuuu
STATUS
--00 xxxx
--uu uuuu
--1u uuuu
--11 uuuu
INTC0
-000 0000
-000 0000
-000 0000
-uuu uuuu
TMR0
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
TMR0C
00-0 1000
00-0 1000
00-0 1000
uu-u uuuu
PA
1111 1111
1111 1111
1111 1111
uuuu uuuu
PAC
1111 1111
1111 1111
1111 1111
uuuu uuuu
PB
--11 1111
--11 1111
--11 1111
--uu uuuu
PBC
--11 1111
--11 1111
--11 1111
--uu uuuu
PC
---1 1111
---1 1111
---1 1111
---u uuuu
PCC
---1 1111
---1 1111
---1 1111
---u uuuu
PD
1111 1111
1111 1111
1111 1111
uuuu uuuu
PDC
1111 1111
1111 1111
1111 1111
uuuu uuuu
PWM0L
0000 ---0
0000 ---0
0000 ---0
uuuu ---u
PWM0H
0000 0000
0000 0000
0000 0000
uuuu uuuu
PWM1L
0000 ---0
0000 ---0
0000 ---0
uuuu ---u
PWM1H
0000 0000
0000 0000
0000 0000
uuuu uuuu
INTC1
-000 -000
-000 -000
-000 -000
-uuu -uuu
MFIC0
--00 --00
--00 --00
--00 --00
--uu --uu
MFIC1
0000 0000
0000 0000
0000 0000
uuuu uuuu
ASCR0
1111 1111
1111 1111
1111 1111
uuuu uuuu
ASCR1
---- ---1
---- ---1
---- ---1
---- ---u
ASCR2
---- --11
---- --11
---- --11
---- --uu
ADRL
xxxx ----
xxxx ----
xxxx ----
uuuu ----
Register
ADRH
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
ADCR
0100 0000
0100 0000
0100 0000
uuuu uuuu
ACSR
10--
10--
10--
uu--
CLKMOD
0000 0x11
0000 0x11
0000 0x11
uuuu uuuu
PAWU
0000 0000
0000 0000
0000 0000
uuuu uuuu
Rev. 1.00
-000
-000
64
-000
-uuu
October 20, 2009
HT45R37V
Reset
(Power-on)
RES Reset
(Normal Operation)
WDT Time-out
(Normal Operation)
WDT Time-out
(HALT)
PAPU
0000 0000
0000 0000
0000 0000
uuuu uuuu
PBPU
--00 0000
--00 0000
--00 0000
--uu uuuu
PCPU
---0 000-
---0 000-
---0 000-
---u uuu-
PDPU
0000 0000
0000 0000
0000 0000
uuuu uuuu
INTEDGE
---- 0000
---- 0000
---- 0000
---- uuuu
MISC
0000 1010
0000 1010
0000 1010
uuuu uuuu
TMRAH
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
TMRAL
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
RCOCCR
0000 1---
0000 1---
0000 1---
uuuu u---
TMRBH
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
TMRBL
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
RCOCR
1xxx --00
1xxx --00
1xxx --00
uuuu --uu
SIMCTL0
1110 000-
1110 000-
1110 000-
uuuu uuu-
SIMCTL1
1000 0001
1000 0001
1000 0001
uuuu uuuu
Register
SIMDR
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
SIMAR/SIMCTL2
0000 0000
0000 0000
0000 0000
uuuu uuuu
TMR1
xxxx xxxx
xxxx xxxx
xxxx xxxx
uuuu uuuu
TMR1C
00-0 1000
00-0 1000
00-0 1000
uu-u uuuu
Note:
²u² stands for unchanged
²x² stands for unknown
²-² stands for unimplemented
Rev. 1.00
65
October 20, 2009
HT45R37V
Oscillator
More information regarding oscillator applications is located on the Holtek website.
Various oscillator options offer the user a wide range of
functions according to their various application requirements. Five types of system clocks can be selected
while various clock source options for the Watchdog
Timer are provided for maximum flexibility. All oscillator
options are selected through the configuration options.
External System RC Oscillator
After selecting the correct configuration option, using
the external system RC oscillator requires that a resistor, with a value between 47kW and 1.5MW, is connected between OSC1 and VDD, and a 470pF capacitor
is connected to ground. Although this is a cost effective
oscillator configuration, the oscillation frequency can
vary with VDD, temperature and process variations and
is therefore not suitable for applications where timing is
critical or where accurate oscillator frequencies are required. For the value of the external resistor ROSC refer
to the Appendix section for typical RC Oscillator vs.
Temperature and VDD characteristics graphics.
System Clock Configurations
There are six methods of generating the system clock,
three high oscillators, two low oscillators and an externally supplied clock. The three high oscillators are the
external crystal/ceramic oscillator, internal RC oscillator
and the external RC network. The two low oscillators are
the fully integrated 32K_INT oscillator and the external
32768Hz oscillator. Selecting whether the low or high
oscillator is used as the system oscillator is implemented using the HLCLK bit in the CLKMOD register.
The source clock for the high and low oscillators is chosen via configuration options. The frequency of the slow
o s c illa t o r i s a l s o d e t e r m i n e d u s i n g t h e
SLOWC0~SLOWC2 bits in the CLKMOD register.
Note that an internal capacitor together with the external
resistor, ROSC, are the components which determine the
frequency of the oscillator. The external capacitor
shown on the diagram does not influence the frequency
of oscillation. Note that if this external system RC oscillation option is selected, as it requires OSC1 external
pin for its operation, the PC2/OSC2 pin is free for use as
normal I/O pin.The internal oscillator circuit contains a
filter circuit to reduce the possibility of erratic operation
due to noise on the oscillator pins.
System Crystal/Ceramic Oscillator
After selecting the external crystal configuration option,
the simple connection of a crystal across OSC1 and
OSC2, is normally all that is required to create the necessary phase shift and feedback for oscillation, without
requiring external capacitors. However, for some crystal
types and frequencies, to ensure oscillation, it may be
necessary to add two small value capacitors, C1 and
V
R
D D
O S C
O S C 1
C 1
O S C 1
4 7 0 p F
R 1
P C 2
O S C 2
C 2
RC Oscillator
Crystal/Ceramic Oscillator
Internal RC Oscillator
C2. Using a ceramic resonator will usually require two
small value capacitors, C1 and C2, to be connected as
shown for oscillation to occur. The values of C1 and C2
should be selected in consultation with the crystal or
resonator manufacturer¢s specification. In most applications, resistor R1 is not required, however for those applications where the LVR function is not used, R1 may
be necessary to ensure the oscillator stops running
when VDD falls below its operating range. The internal
oscillator circuit contains a filter circuit to reduce the
possibility of erratic operation due to noise on the oscillator pins. An additional configuration option must be
setup to configure the device according to whether the
oscillator frequency is high, defined as equal to or above
1MHz, or low, which is defined as below 1 MHz.
Rev. 1.00
The internal RC oscillator is a fully integrated system oscillator requiring no external components. The internal
RC oscillator has three fixed frequencies of either
4MHz, 8MHz or 12MHz, the choice of which is indicated
by the configuration options. Note that if this internal
system clock option is selected, as it requires no external pins for its operation, the OSC1 and OSC2 pins are
free for use as normal I/O pins. Refer to the Appendix
section for more information on the actual internal oscillator frequency vs. Temperature and VDD characteristics graphics.
66
October 20, 2009
HT45R37V
Internal 32K_INT Oscillator
condition the QOSC bit is set to, the 32768Hz oscillator
will always function normally, only there is more power
consumption associated with the quick start-up function.
When the device enters the Sleep, Slow or Idle Mode, its
high frequency clock is switched off to reduce activity
a n d t o c ons e r v e pow er. H o w e v er, i n m a n y
microcontroller applications it may be necessary to keep
some internal functions operational even when the
microcontroller is in the Power-down mode. To do this,
the device has a 32K_INT oscillator, which is a fully integrated free running RC oscillator with a typical period of
31.2ms at 5V, requiring no external components. It is selected via configuration option.
In te rn a l
3 2 K _ IN T
fR
Note that if this external 32768Hz oscillation option is
not selected, the PC3/OSC3 and PC4/OSC4 pins are
free for use as normal I/O pins.
External Oscillator
The system clock can also be supplied by an externally
supplied clock giving users a method of synchronising
their external hardware to the microcontroller operation.
This is selected using a configuration option and supplying the clock on pin OSC1. Note that if this external system clock option is selected, as it requires OSC1
external pin for its operation, the PC2/OSC2 pin is free
for use as normal I/O pin. The internal oscillator circuit
contains a filter circuit to reduce the possibility of erratic
operation due to noise on the oscillator pin.
C 3 2 K
Internal 32K_INT Oscillator
External 32768Hz Oscillator
System Operating Modes
With a function similar to the internal 32K-INT 32KHz oscillator, that is to keep some device functions operational during power down, this device also has an
external 32768Hz oscillator. This clock source has a
fixed frequency of 32768Hz and requires a 32768Hz
crystal to be connected between pins OSC3 and OSC4.
The devices have the ability to operate in several different modes. This range of operating modes, known as
Normal Mode, Slow Mode, Idle Mode and Sleep Mode,
allow the devices to run using a wide range of different
slow and fast clock sources. The devices also possess
the ability to dynamically switch between different clocks
and operating modes. With this choice of operating
functions, and a HALT instruction, users are provided
with a high degree of flexibility to ensure they obtain optimal performance from the device, in terms of operating
The external resistor and capacitor components connected to the 32768Hz crystal are not necessary to provide oscillation. For applications where precise
frequencies are essential, these components may be
required to provide frequency compensation due to different crystal manufacturing tolerances.
speed and power requirements.
Operating Mode Clock Sources
A configuration option selects whether the external
32768Hz oscillator or the internal 32K_INT oscillator is
selected. Selecting low frequency oscillators for use as
a system oscillator is implmented using bits in the
CLKMOD register.
In discussing the system clocks for the devices, they
can be seen as having a dual clock mode. These dual
clocks are what are known as a High Oscillator and the
other as a Low Oscillator. The High and Low Oscillator
are the system clock sources and can be selected dynamically using the HLCLK bit in the CLKMOD register.
During power-up there is a time delay associated with
the 32768Hz oscillator waiting for it to start-up. To minimise this time delay, bit 4 of the RTCC register, known
as the QOSC bit, is provided to have a quick start-up
function. During a power-up condition, this bit will be
cleared to zero which will initiate the 32768Hz oscillator
quick start-up function. However, as there is additional
power consumption associated with this quick start-up
function, to reduce power consumption after start-up
takes place, it is recommended that the application program should set the QOSC bit high for about 2 seconds
after power-on. It should be noted that, no matter what
C 1
3 2 7 6 8 H z
The High Oscillator has the internal name fM whose source
is selected using a configuration option from a choice of either an external crystal/resonator, external RC oscillator,
internal RC oscillator or external clock source.
The Low Oscillator clock source, has the internal name
fSL, whose source is also selected by configuration option from a choice of either an external 32768Hz oscillator or the internal 32K_INT oscillator. This internal fSL, fM
clock, is further modified by the SLOWC0~SLOWC2
bits in the CLKMOD register to provide the low frequency clock source fSLOW.
O S C 3
An additional sub internal clock, with the internal name
fSUB, is a 32kHz clock source which can be sourced from
either the internal 32K_INT oscillator or an external
32768Hz crystal, selected by configuration option. To-
3 2 7 6 8 H z
R 1
O S C 4
C 2
External 32768Hz Oscillator
Rev. 1.00
67
October 20, 2009
HT45R37V
b 7
S L O W C 2 S L O W C 1 S L O W C 0 S IM ID L E
b 0
L T O
H T O
ID L E N
H L C L K
C L K M O D
R e g is te r
fS Y S s e le c t
1 : fM
0 : fS L O W
Id le m o d e
1 : e n a b le
0 : d is a b le
H ig h o s c illa to r r e a d y fla g
1 : tim e - o u t
0 : n o n - tim e - o u t
L o w o s c illa to r r e a d y fla g
1 : tim e - o u t
0 : n o n - tim e - o u t
S P I/I2 C c o n tin u e s r u n n in g in Id le m o d e
1 :e n a b le
0 :d is a b le
fS L O W s e le c tio n
S L O W W C 2 S L O W W C 1
0
0
0
0
1
0
1
0
0
1
0
1
1
1
1
1
S L O W W C 0
0
1
0
1
0
1
0
1
fS
L O W
fS
fM
fM
fM
fM
fM
fM
fS
L
L
/6 4
/3 2
/1 6
/8
/4
/2
Clock Control Register - CLKMOD
· Slow Mode1
gether with fSYS/4, it is used as a clock source for certain
internal functions such as the Watchdog Timer, Buzzer,
RTC Interrupt and Time Base Interrupt. The internal
clock fS, is simply a choice of either fSUB or fSYS/4, using a
configuration option.
fM on, fSLOW=fM/2~fM/64, fSYS=fSLOW, CPU on, fS on, fWDT
on/off depending upon the WDT configuration option
and WDT control register.
· Idle Mode
fM, fSLOW, fSYS off, CPU off; fSUB on, fS on/off by selecting
fSUB or fSYS/4, fWDT on/off depending upon the WDT
configuration option and WDT control register.
Operating Modes
After the correct clock source configuration selections
are made, overall operation of the chosen clock is
achieved using the CLKMOD register. A combination of
the HLCLK and IDLEN bits in the CLKMOD register and
use of the HALT instruction determine in which mode the
device will be run. The devices can operate in the following Modes.
· Sleep Mode
fM, fSLOW, fSYS, fS, CPU off; fSUB, fWDT on/off depending
upon the WDT configuration option and WDT control
register.
Switching Between Modes
The device switches between the different operating
modes using a combination of the HALT instruction and
the IDLEN bit in the CLKMOD register. Switching to one
of the lower power modes enables the normal operating
current to be reduced to a lower operating level or to a
very low standby current level, a feature which is very
important in low power battery applications.
· Normal Mode
fM on, fSLOW on, fSYS=fM, CPU on, fS on, fWDT on/off depending upon the WDT configuration option and WDT
control register.
· Slow Mode0
fM off, fSLOW=32K_INT oscillator or the 32768Hz oscillator, fSYS=fSLOW, CPU on, fS on, fWDT on/off depending
upon the WDT configuration option and WDT control
register.
Rev. 1.00
68
October 20, 2009
HT45R37V
N o rm a l M o d e
-u p
k e
w a
L T
H A
fM O n ,
3 2 7 6 8 H z o r 3 2 K _ IN T O n ,
fS Y S = fM
0
" =
E N
L
"ID
&
S e t "H L C K "
fM O ff,
3 2 7 6 8 H z o r 3 2 K _ IN T O n * ,
fS Y S = O ff
H A
L T
w a
ke
-u
&
"ID
L E
N "
=
p
S lo w
0
&
"ID
w a
ke
-u
p
L E
N "
=
1
Id le M o d e
R e s e t "H L C L K "
S le e p M o d e
H A
L T
fM O ff,
3 2 7 6 8 H z o r 3 2 K _ IN T O n #,
fS Y S = O ff
-u p
k e
w a
M o d e
fM O n /O
3 2 7 6 8 H z o r 3 2 K
fS Y S = fM /2 ~
o r 3 2 7 6 8 H z o r
&
L T
H A
ff,
_ IN T O n ,
fM /6 4
3 2 K _ IN T
" * " D e p e n d s th e W D T e n a b le /d is a b le c o n d itio n .
if W D T is e n a b le d , fS U B = 3 2 K _ IN T , th e n 3 2 K _ IN T O n
1
" =
EL N
"ID
" # " E ith e r th e 3 2 7 6 8 H z o r 3 2 K _ IN T m u s t b e O N .
If fS U B = 3 2 K _ IN T , th e n 3 2 K _ IN T is O N .
Dual Clock Mode Operation
H ig h O s c illa to r
O S C 1
E x te rn a l
C lo c k
O S C 1
E x te rn a l
R C
O S C 1
H ig h F r e q u e n c y O s c illa to r
C o n fig u r a tio n O p tio n
H L C L K B it
E x te rn a l
X T A L
O S C 2
fM
M U X
In te rn a l
R C
fM
E x te rn a l
3 2 7 6 8 H z
C ry s ta l
O S C 3
O S C 4
In te rn a l
3 2 K _ IN T
L o w
3 2 7 6 8 H z
fS
M U X
3 2 K _ IN T
M U X
fS
U B
M U X
fS L a n d fS U B
C o n fig u r a tio n
O p tio n
Y S
fM /2 , ... fM /6 4 , fS
Y S
L O W
L
S L O W C 0
S L O W C 1
S L O W C 2
O s c illa to r
fS
fS
S lo w
C lo c k
C o n tro l
L
fS
M U X
fS
R T C in te r r u p t,
T im e B a s e in te r r u p t,
B u z z e r, W D T
fS
C o n fig u r a tio n O p tio n
/4
Dual Clock Mode Structure
Rev. 1.00
69
October 20, 2009
HT45R37V
Power Down Mode and Wake-up
Executing the HALT Instruction
Wake-up
If the device is running in the Normal Mode and the
HALT instruction is executed then the system clock will
stop to conserve power. Depending upon the condition
of the IDLEN bit in the CLKMOD register, the system
will enter either the Sleep or Idle Mode. In these Modes
the system clock will stop running to conserve power,
however as either the 32K_INT or the external 32KHz
oscillator may continue to operate, certain internal functions may remain operational.
After the system enters the Sleep or Idle Mode, it can be
woken up from one of various sources listed as follows:
· An external reset
· An external falling edge on Port A
· A system interrupt
· A WDT overflow
If the system is woken up by an external reset, the device will experience a full system reset, however, if the
device is woken up by a WDT overflow, a Watchdog
Timer reset will be initiated. Although both of these
wake-up methods will initiate a reset operation, the actual source of the wake-up can be determined by examining the TO and PDF flags. The PDF flag is cleared by a
system power-up or executing the clear Watchdog
Timer instructions and is set when executing the ²HALT²
instruction. 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, the other flags remain in
their original status.
When the HALT instruction is executed in the Normal
Mode, the following will occur:
· The system oscillator will stop running.
· The system will enter either the Sleep or Idle Mode.
· The Data Memory contents and registers will maintain
their present condition.
· The WDT will be cleared and resume counting if the
WDT clock source is selected to come from the
32K_INT or external 32KHz oscillator. The WDT will
stop if its clock source originates from the system
clock.
· The I/O ports will maintain their present condition.
Each pin on Port A can be setup, using the PAWU register, to permit a negative transition on the pin to wake-up
· In the status register, the Power Down flag, PDF, will
be set and the Watchdog time-out flag, TO, will be
cleared.
the system. When a Port A pin wake-up occurs, the program will resume execution at the instruction following
the ²HALT² instruction.
Standby Current Considerations
As the main reason for entering the Sleep or Idle Mode
is to keep the current consumption of the MCU to as low
a value as possible, perhaps only in the order of several
micro-amps, there are other considerations which must
also be taken into account by the circuit designer if the
power consumption is to be minimized. 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 devices which
have different package types, as there may be
unbonbed pins, which must either be setup as outputs
or if setup 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 setup 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 configuration options have enabled the
Watchdog Timer internal oscillator.
Rev. 1.00
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 to ²1² before entering the Sleep or Idle Mode, the wake-up function of the related interrupt will be disabled.
No matter what the source of the wake-up event is, once
a wake-up situation occurs, a time period equal to tSST
system clock periods will be required before normal system operation resumes. However, if the wake-up has
originated due to an interrupt, the actual interrupt subroutine execution will be delayed by an additional one or
more cycles. If the wake-up results in the execution of
the next instruction following the ²HALT² instruction, this
will be executed immediately after the tSST system clock
period delay has ended.
70
October 20, 2009
HT45R37V
Fast Wake-Up
gram can therefore determine the presence of a low
voltage condition.
To minimise power consumption the device can enter
the SLEEP or IDLE Mode, where the clock source to the
device will be stopped. However when the device is
woken up again, it can take a considerable time for the
original system oscillator to restart, stabilise and allow
normal operation to resume. To ensure the device is up
and running as fast as possible a Fast Wake-Up function
is provided, which allows fSUB, namely either the RTC or
LIRC oscillator, to act as a temporary clock to first drive
the system until the original system oscillator has stabilised. As the clock source for the Fast Wake-Up function
is the Watchdog Timer clock, the Watchdog Timer must
be enabled for this function to operate. If the Watchdog
Timer is not enabled then the Fast Start-up function cannot be used. The Fast Wake-Up enable/disable function
is controlled using the configuration option.
After power-on, or after a reset, the LVD will be switched
off by clearing the LVDC bit in the RTCC register to zero.
Note that if the LVD is enabled there will be some power
consumption associated with its internal circuitry, however, by clearing the LVDC bit to zero the power can be
minimised. It is important not to confuse the LVD with
the LVR function. In the LVR function an automatic reset
will be generated by the microcontroller, whereas in the
LVD function only the LVDO bit will be affected with no
influence on other microcontroller functions.
There are a range of voltage values, selected using a
configuration option, which can be chosen to activate
the LVD.
Watchdog Timer
If the Crystal oscillator is selected as the NORMAL
Mode system clock, and if the Fast Wake-Up function is
enabled, then it will take one to two tSUB clock cycles of
the LIRC or RTC oscillator for the system to wake-up.
The system will then initially run under the fSUB clock
source until 1024 Crystal clock cycles have elapsed, at
which point the HTO flag will switch high and the system
will switch over to operating from the Crystal oscillator.
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. It operates by providing a device reset when the Watchdog Timer counter overflows.
Watchdog Timer Operation
The Watchdog Timer clock source is provided by the internal clock, fS, which is in turn supplied by one of two
sources selected by configuration option: fSUB or fSYS/4.
Note that if the Watchdog Timer configuration option
has been disabled, then any instruction relating to its operation will result in no operation.
If the ERC or HIRC oscillators or LIRC oscillator is used
as the system oscillator then it will take 1~2 clock cycles
of the ERC, HIRC or LIRC to wake up the system from
the SLEEP or IDLE Mode.
Note that if the Watchdog Timer is disabled, which
means that the RTC and LIRC are all both off, then there
will be no Fast Wake-Up function available when the device wakes-up from the SLEEP Mode.
LVD Operation
Most of the Watchdog Timer options, such as enable/disable, Watchdog Timer clock source and clear instruction type are selected using configuration options.
In addition to a configuration option to enable the Watchdog Timer, there are four bits, WDTEN3~ WDTEN0, in
the MISC register to offer an additional enable control of
the Watchdog Timer. These bits must be set to a specific
value of 1010 to disable the Watchdog Timer. Any other
values for these bits will keep the Watchdog Timer enabled. After power on these bits will have the disabled
value of 1010.
The LVD function must be first enabled via a
configuration option after which bits 3 and 5 of the RTCC
register are used to control the overall function of the
LVD. Bit 3 is the enable/disable control bit and is known
as LVDC, when set low the overall function of the LVD
will be disabled. Bit 5 is the LVD detector output bit and
is known as LVDO. Under normal operation, and when
the power supply voltage is above the specified VLVD
value in the DC characteristic section, the LVDO bit will
remain at a zero value. If the power supply voltage
should fall below this VLVD value then the LVDO bit will
change to a high value indicating a low voltage condition. Note that the LVDO bit is a read-only bit. By polling
the LVDO bit in the RTCC register, the application pro-
One of the WDT clock sources is the internal fSUB, which
can be sourced from either the 32K_INT internal oscillator or the 32768Hz oscillator. The 32K_INT internal oscillator has an approximate period of 31.2ms at a supply
voltage of 5V. However, it should be noted that this
specified internal clock period can vary with VDD, temperature and process variations. The 32768Hz oscillator
is supplied by an external 32768Hz crystal. The other
Watchdog Timer clock source option is the fSYS/4 clock.
Whether the Watchdog Timer clock source is its own internal 32K_INT, the 32768Hz oscillator or fSYS/4, it is divided by 213~216, using configuration option to obtain the
required Watchdog Timer time-out period. The max time
out period is when the 216 option is selected. This
Low Voltage Detector - LVD
The Low Voltage Detect internal function provides a
means for the user to monitor when the power supply
voltage falls below a certain fixed level as specified in
the DC characteristics.
Rev. 1.00
71
October 20, 2009
HT45R37V
Clearing the Watchdog Timer
time-out period may vary with temperature, VDD and
process variations. As the clear instruction only resets
the last stage of the divider chain, for this reason the actual division ratio and corresponding Watchdog Timer
time-out can vary by a factor of two. The exact division
ratio depends upon the residual value in the Watchdog
Timer counter before the clear instruction is executed.
There are two methods of using software instructions to
clear the Watchdog Timer, one of which must be chosen
by configuration option. The first option is to use the single ²CLR WDT² instruction while the second is to use the
two commands ²CLR WDT1² and ²CLR WDT2². For the
first option, a simple execution of ²CLR WDT² will clear
the WDT while for the second option, both ²CLR WDT1²
and ²CLR WDT2² must both be executed to successfully
clear the Watchdog Timer. Note that for this second option, if ²CLR WDT1² is used to clear the Watchdog Timer,
successive executions of this instruction will have no effect, only the execution of a ²CLR WDT2² instruction will
clear the Watchdog Timer. Similarly after the ²CLR
WDT2² instruction has been executed, only a successive
²CLR WDT1² instruction can clear the Watchdog Timer.
If the fSYS/4 clock is used as the Watchdog Timer clock
source, it should be noted that when the system enters
the Power Down Mode, then the instruction clock is
stopped and the Watchdog Timer will lose its protecting
purposes. For systems that operate in noisy environments, using the 32K_INT RC oscillator is strongly recommended.
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 Power Down 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 an external hardware reset, which
means a low level on the RES pin, the second is using
the watchdog software instructions and the third is via a
²HALT² instruction.
C L R W D T 1 F la g
C o n tro l
L o g ic
C L R W D T 2 F la g
1 o r 2 In s tr u c tio n s
fS
Y S
/4
3 2 K _ IN T O s c illa to r
R T C O s c illa to r
W D T S o u rc e
C o n fig u r a tio n
O p tio n
C L R
fS
8 - b it D iv id e r
fS /2
8
¸
7 - b it P r e s c a le r
2
W D T T im e - o u t
(2 13/fS , 2 14/fS , 2 15/fS o r 2
1 6
/fS )
C o n fig O p tio n
fS /2
1 2
, fS /2
1 3
, fS /2
1 4
o r fS /2
1 5
Watchdog Timer
b 7
O D E 3
O D E 2
O D E 1
O D E 0
W D T E N 3
W D T E N 2
W D T E N 1
b 0
W D T E N 0
M IS C
R e g is te r
W a tc h d o g T im e r E n a b le C o n tr o l
W D T E N 3 W D T E N 2 W D T E N 1 W D T E N 0
1
1
0
0
a ll o th e r v a lu e s
d is a b le
e n a b le
P A 0 ~ P A 3 O p e n D r a in C o n tr o l
- d e s c r ib e d e ls e w h e r e
Watchdog Timer Software Control - MISC
Rev. 1.00
72
October 20, 2009
HT45R37V
Configuration Options
Configuration options refer to certain options within the MCU that are programmed into the device during the programming process. During the development process, these options are selected using the HT-IDE software development
tools. As these options are programmed into the device using the hardware programming tools, once they are selected
they cannot be changed later as the application software has no control over the configuration options. All options must
be defined for proper system function, the details of which are shown in the table.
No.
Options
Oscillator Options
1
High Frequency Oscillator type selection
1. External Crystal Oscillator
2. External RC Oscillator
3. Internal RC Oscillator
4. Externally supplied clock
2
fSL and fSUB clock selection (Low frequency oscillator type selection)
1. 32768Hz External Oscillator
2. 32K_INT Internal Oscillator
3
Internal RC Oscillator frequency select:
4MHz, 8MHz or 12MHz
4
fS clock selection: fSUB or fSYS/4
5
XTAL mode selection: 455kHz or 1M~12MHz
6
Fast wake-up from HALT mode (Only for external crystal oscillator): enable/disable
Reset Option
7
Rest pin Function: PC0 or Reset Pin
PFD Options
8
PA3: normal I/O or PFD output
9
PFD clock selection: Timer/Event Counter 0 or Timer/Event Counter 1
Buzzer Options
10
PA0/PA1: normal I/O or BZ/BZ or PA0=BZ and PA1 as normal I/O
11
Buzzer frequency: fS/22, fS/23, fS/24, fS/25, fS/26, fS/27, fS/28, fS/29
Time Base Option
12
Time base time-out period: 212/fS, 213/fS, 214/fS, 215/fS
Watchdog Options
13
Watchdog Timer function: enable or disable
14
CLRWDT instructions: 1 or 2 instructions
15
WDT time-out period: 212/fS~213/fS, 213/fS~214/fS, 214/fS~215/fS, 215/fS~216/fS
LVD/LVR Options
16
LVD function: enable or disable
17
LVR function: enable or disable
18
LVR/LVD voltage: 2.1V/2.2V or 3.15V/3.3V or 4.2V/4.4V
SPI Options
19
SIM interface enable/disable
20
SPI_WCOL: enable/disable
21
SPI_CSEN: enable/disable, used to enable/disable (1/0) software CSEN function
2
I C Option
22
Rev. 1.00
I2C debounce Time: no debounce, 1 system clock debounce, 2 system clock debounce
73
October 20, 2009
HT45R37V
No.
Options
Timer/Event Counter and External Interrupt Pins Filter Option
23
Interrupt and Timer/Event Counter input pins internal filter On/Off control - applies to all pins
C/R to F Converter Option
24
I/O pins or C/R to F converter inputs
Application Circuits
C/R to F Application Circuit 1
V C C
1 0 m F
V
P B 0 /A N 0
P B 1 /A N 1
D D
V O
0 .0 1 m F
0 .1 m F
V F D 0 ~
V F D 2 3
V D D
1 0 k W ~
1 0 0 k W
1 N 4 1 4 8
3 0 0 W
0 .1 ~ 1 m F
F 1
B Z
B Z
B
R e s e t
C ir c u it
O
O
O
Z I
I/O
P C 0 /R E S
R
s e n s o r
0
R
s e n s o r
1
R
s e n s o r
8
R C 0
V S S
R C 1
O S C
C ir c u it
P C 1 /O S C 1
R C 8
P C 2 /O S C 2
S e e O s c illa to r
S e c tio n
O S C
C ir c u it
*R
R R E F
R C O U T /IN
P C 3 /O S C 3
*C
C R E F
P C 4 /O S C 4
S e e O s c illa to r
S e c tio n
H T 4 5 R 3 7 V
C/R to F Application Circuit 2
V C C
1 0 m F
V
V O
0 .0 1 m F
0 .1 m F
P B 0 /A N 0
P B 1 /A N 1
D D
V F D 0 ~
V F D 2 3
V D D
R e s e t
C ir c u it
1 0 k W ~
1 0 0 k W
1 N 4 1 4 8
0 .1 ~ 1 m F
3 0 0 W
P C 0 /R E S
F 1
B Z
B Z
B
O
O
O
Z I
I/O
R C 0
V S S
R C 1
O S C
C ir c u it
P C 1 /O S C 1
S e e O s c illa to r
S e c tio n
O S C
C ir c u it
S e e O s c illa to r
S e c tio n
Rev. 1.00
R C 8
P C 2 /O S C 2
C
C
C
s e n s o r
0
s e n s o r
1
s e n s o r
8
*R
R R E F
R C O U T /IN
P C 3 /O S C 3
C R E F
*C
P C 4 /O S C 4
H T 4 5 R 3 7 V
74
October 20, 2009
HT45R37V
C/R to F Application Circuit 3
V C C
1 0 m F
V
V D D
R e s e t
C ir c u it
1 0 k W ~
1 0 0 k W
1 N 4 1 4 8
0 .1 ~ 1 m F
V F D 0 ~
V F D 2 3
V O
0 .0 1 m F
0 .1 m F
P B 0 /A N 0
P B 1 /A N 1
D D
3 0 0 W
P C 0 /R E S
F 1
B Z
B Z
B
O
O
O
Z I
I/O
C
R C 0
V S S
O S C
C ir c u it
R C 1
P C 1 /O S C 1
R C 8
C
s e n s o r
0
s e n s o r
1
s e n s o r
8
P C 2 /O S C 2
S e e O s c illa to r
S e c tio n
R R E F
O S C
C ir c u it
C
P C 3 /O S C 3
R C O U T /IN
P C 4 /O S C 4
C R E F
*R
*C
S e e O s c illa to r
S e c tio n
H T 4 5 R 3 7 V
Note: 1. The ²*R² resistance and ²*C² capacitance should be consideration for the frequency of RC OSC.
2. Rsensor0 ~ Rsensor8 are the resistance sensors.
3. Csensor0 ~ Csensor8 are the capacitance sensors.
Rev. 1.00
75
October 20, 2009
HT45R37V
Instruction Set
Introduction
sure 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.
C e n t ra l t o t he s uc c es s f ul oper a t i on o f a n y
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.
Logical and Rotate Operations
The 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 where rotate data
operations are used is to implement multiplication and
division calculations.
For easier understanding of the various instruction
codes, they have been subdivided into several functional groupings.
Instruction Timing
Most instructions are implemented within one instruction cycle. The exceptions to this are branch, call, or table read instructions where two instruction cycles are
required. One instruction cycle is equal to 4 system
clock cycles, therefore in the case of an 8MHz system
oscillator, most instructions would be implemented
within 0.5ms and branch or call instructions would be implemented within 1ms. 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.
Branches and Control Transfer
Program 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.
Moving and Transferring Data
The 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 Operations
The ability to perform certain arithmetic operations and
data manipulation is a necessary feature of most
microcontroller appl i c a t i ons . W i t hi n t he H o l t e k
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 en-
Rev. 1.00
76
October 20, 2009
HT45R37V
Bit Operations
Other Operations
The ability to provide single bit operations on Data Memory is an extremely flexible feature of all Holtek
microcontrollers. This feature is especially useful for
output port bit programming where individual bits or port
pins can be directly set high or low using either the ²SET
[m].i² or ²CLR [m].i² instructions respectively. The feature removes the need for programmers to first read the
8-bit output port, manipulate the input data to ensure
that other bits are not changed and then output the port
with the correct new data. This read-modify-write process is taken care of automatically when these bit operation instructions are used.
In addition to the above functional instructions, a range
of other instructions also exist such as the ²HALT² instruction for Power-down operations and instructions to
control the operation of the Watchdog Timer for reliable
program operations under extreme electric or electromagnetic environments. For their relevant operations,
refer to the functional related sections.
Instruction Set Summary
The 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 Read Operations
Table conventions:
Data 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 setup 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.
Mnemonic
x: Bits immediate data
m: Data Memory address
A: Accumulator
i: 0~7 number of bits
addr: Program memory address
Description
Cycles
Flag Affected
1
1Note
1
1
1Note
1
1
1Note
1
1Note
1Note
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
Z, C, AC, OV
C
1
1
1
1Note
1Note
1Note
1
1
1
1Note
1
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
Z
1
1Note
1
1Note
Z
Z
Z
Z
Arithmetic
ADD A,[m]
ADDM A,[m]
ADD A,x
ADC A,[m]
ADCM A,[m]
SUB A,x
SUB A,[m]
SUBM A,[m]
SBC A,[m]
SBCM A,[m]
DAA [m]
Add Data Memory to ACC
Add ACC to Data Memory
Add immediate data to ACC
Add Data Memory to ACC with Carry
Add ACC to Data memory with Carry
Subtract immediate data from the ACC
Subtract Data Memory from ACC
Subtract Data Memory from ACC with result in Data Memory
Subtract Data Memory from ACC with Carry
Subtract Data Memory from ACC with Carry, result in Data Memory
Decimal adjust ACC for Addition with result in Data Memory
Logic Operation
AND A,[m]
OR A,[m]
XOR A,[m]
ANDM A,[m]
ORM A,[m]
XORM A,[m]
AND A,x
OR A,x
XOR A,x
CPL [m]
CPLA [m]
Logical AND Data Memory to ACC
Logical OR Data Memory to ACC
Logical XOR Data Memory to ACC
Logical AND ACC to Data Memory
Logical OR ACC to Data Memory
Logical XOR ACC to Data Memory
Logical AND immediate Data to ACC
Logical OR immediate Data to ACC
Logical XOR immediate Data to ACC
Complement Data Memory
Complement Data Memory with result in ACC
Increment & Decrement
INCA [m]
INC [m]
DECA [m]
DEC [m]
Rev. 1.00
Increment Data Memory with result in ACC
Increment Data Memory
Decrement Data Memory with result in ACC
Decrement Data Memory
77
October 20, 2009
HT45R37V
Mnemonic
Description
Cycles
Flag Affected
Rotate Data Memory right with result in ACC
Rotate Data Memory right
Rotate Data Memory right through Carry with result in ACC
Rotate Data Memory right through Carry
Rotate Data Memory left with result in ACC
Rotate Data Memory left
Rotate Data Memory left through Carry with result in ACC
Rotate Data Memory left through Carry
1
1Note
1
1Note
1
1Note
1
1Note
None
None
C
C
None
None
C
C
Move Data Memory to ACC
Move ACC to Data Memory
Move immediate data to ACC
1
1Note
1
None
None
None
Clear bit of Data Memory
Set bit of Data Memory
1Note
1Note
None
None
Jump unconditionally
Skip if Data Memory is zero
Skip if Data Memory is zero with data movement to ACC
Skip if bit i of Data Memory is zero
Skip if bit i of Data Memory is not zero
Skip if increment Data Memory is zero
Skip if decrement Data Memory is zero
Skip if increment Data Memory is zero with result in ACC
Skip if decrement Data Memory is zero with result in ACC
Subroutine call
Return from subroutine
Return from subroutine and load immediate data to ACC
Return from interrupt
2
1Note
1note
1Note
1Note
1Note
1Note
1Note
1Note
2
2
2
2
None
None
None
None
None
None
None
None
None
None
None
None
None
Read table (current page) to TBLH and Data Memory
Read table (last page) to TBLH and Data Memory
2Note
2Note
None
None
No operation
Clear Data Memory
Set Data Memory
Clear Watchdog Timer
Pre-clear Watchdog Timer
Pre-clear Watchdog Timer
Swap nibbles of Data Memory
Swap nibbles of Data Memory with result in ACC
Enter power down mode
1
1Note
1Note
1
1
1
1Note
1
1
None
None
None
TO, PDF
TO, PDF
TO, PDF
None
None
TO, PDF
Rotate
RRA [m]
RR [m]
RRCA [m]
RRC [m]
RLA [m]
RL [m]
RLCA [m]
RLC [m]
Data Move
MOV A,[m]
MOV [m],A
MOV A,x
Bit Operation
CLR [m].i
SET [m].i
Branch
JMP addr
SZ [m]
SZA [m]
SZ [m].i
SNZ [m].i
SIZ [m]
SDZ [m]
SIZA [m]
SDZA [m]
CALL addr
RET
RET A,x
RETI
Table Read
TABRDC [m]
TABRDL [m]
Miscellaneous
NOP
CLR [m]
SET [m]
CLR WDT
CLR WDT1
CLR WDT2
SWAP [m]
SWAPA [m]
HALT
Note:
1. For skip instructions, if the result of the comparison involves a skip then two cycles are required,
if no skip takes place only one cycle is required.
2. Any instruction which changes the contents of the PCL will also require 2 cycles for execution.
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.
Rev. 1.00
78
October 20, 2009
HT45R37V
Instruction Definition
ADC A,[m]
Add Data Memory to ACC with Carry
Description
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] + C
Affected flag(s)
OV, Z, AC, C
ADCM A,[m]
Add ACC to Data Memory with Carry
Description
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] + C
Affected flag(s)
OV, Z, AC, C
ADD A,[m]
Add Data Memory to ACC
Description
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 ACC
Description
The contents of the Accumulator and the specified immediate data are added. The result is
stored in the Accumulator.
Operation
ACC ¬ ACC + x
Affected flag(s)
OV, Z, AC, C
ADDM A,[m]
Add ACC to Data Memory
Description
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 ACC
Description
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 ACC
Description
Data in the Accumulator and the specified immediate data perform a bitwise logical AND
operation. The result is stored in the Accumulator.
Operation
ACC ¬ ACC ²AND² x
Affected flag(s)
Z
ANDM A,[m]
Logical AND ACC to Data Memory
Description
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
Rev. 1.00
79
October 20, 2009
HT45R37V
CALL addr
Subroutine call
Description
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 ¬ addr
Affected flag(s)
None
CLR [m]
Clear Data Memory
Description
Each bit of the specified Data Memory is cleared to 0.
Operation
[m] ¬ 00H
Affected flag(s)
None
CLR [m].i
Clear bit of Data Memory
Description
Bit i of the specified Data Memory is cleared to 0.
Operation
[m].i ¬ 0
Affected flag(s)
None
CLR WDT
Clear Watchdog Timer
Description
The TO, PDF flags and the WDT are all cleared.
Operation
WDT cleared
TO ¬ 0
PDF ¬ 0
Affected flag(s)
TO, PDF
CLR WDT1
Pre-clear Watchdog Timer
Description
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 Timer
Description
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 ¬ 0
Affected flag(s)
TO, PDF
Rev. 1.00
80
October 20, 2009
HT45R37V
CPL [m]
Complement Data Memory
Description
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
CPLA [m]
Complement Data Memory with result in ACC
Description
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 Memory
Description
Convert the contents of the Accumulator value to a BCD ( Binary Coded Decimal) value resulting from the previous addition of two BCD variables. If the low nibble is greater than 9 or
if AC flag is set, then a value of 6 will be added to the low nibble. Otherwise the low nibble
remains unchanged. If the high nibble is greater than 9 or if the C flag is set, then a value of
6 will be added to the high nibble. Essentially, the decimal conversion is performed by adding 00H, 06H, 60H or 66H depending on the Accumulator and flag conditions. Only the C
flag may be affected by this instruction which indicates that if the original BCD sum is
greater than 100, it allows multiple precision decimal addition.
Operation
[m] ¬ ACC + 00H or
[m] ¬ ACC + 06H or
[m] ¬ ACC + 60H or
[m] ¬ ACC + 66H
Affected flag(s)
C
DEC [m]
Decrement Data Memory
Description
Data in the specified Data Memory is decremented by 1.
Operation
[m] ¬ [m] - 1
Affected flag(s)
Z
DECA [m]
Decrement Data Memory with result in ACC
Description
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] - 1
Affected flag(s)
Z
HALT
Enter power down mode
Description
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 ¬ 1
Affected flag(s)
TO, PDF
Rev. 1.00
81
October 20, 2009
HT45R37V
INC [m]
Increment Data Memory
Description
Data in the specified Data Memory is incremented by 1.
Operation
[m] ¬ [m] + 1
Affected flag(s)
Z
INCA [m]
Increment Data Memory with result in ACC
Description
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] + 1
Affected flag(s)
Z
JMP addr
Jump unconditionally
Description
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 ¬ addr
Affected flag(s)
None
MOV A,[m]
Move Data Memory to ACC
Description
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 ACC
Description
The immediate data specified is loaded into the Accumulator.
Operation
ACC ¬ x
Affected 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] ¬ ACC
Affected flag(s)
None
NOP
No operation
Description
No operation is performed. Execution continues with the next instruction.
Operation
No operation
Affected flag(s)
None
OR A,[m]
Logical OR Data Memory to ACC
Description
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
Rev. 1.00
82
October 20, 2009
HT45R37V
OR A,x
Logical OR immediate data to ACC
Description
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² x
Affected flag(s)
Z
ORM A,[m]
Logical OR ACC to Data Memory
Description
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 subroutine
Description
The Program Counter is restored from the stack. Program execution continues at the restored address.
Operation
Program Counter ¬ Stack
Affected flag(s)
None
RET A,x
Return from subroutine and load immediate data to ACC
Description
The Program Counter is restored from the stack and the Accumulator loaded with the
specified immediate data. Program execution continues at the restored address.
Operation
Program Counter ¬ Stack
ACC ¬ x
Affected flag(s)
None
RETI
Return from interrupt
Description
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 ¬ 1
Affected flag(s)
None
RL [m]
Rotate Data Memory left
Description
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].7
Affected flag(s)
None
RLA [m]
Rotate Data Memory left with result in ACC
Description
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].7
Affected flag(s)
None
Rev. 1.00
83
October 20, 2009
HT45R37V
RLC [m]
Rotate Data Memory left through Carry
Description
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].7
Affected flag(s)
C
RLCA [m]
Rotate Data Memory left through Carry with result in ACC
Description
Data in the specified Data Memory and the carry flag are rotated left by 1 bit. Bit 7 replaces
the Carry bit and the original carry flag is rotated into the bit 0. The rotated result is stored in
the Accumulator and the contents of the Data Memory remain unchanged.
Operation
ACC.(i+1) ¬ [m].i; (i = 0~6)
ACC.0 ¬ C
C ¬ [m].7
Affected flag(s)
C
RR [m]
Rotate Data Memory right
Description
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].0
Affected flag(s)
None
RRA [m]
Rotate Data Memory right with result in ACC
Description
Data in the specified Data Memory and the carry flag are 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].0
Affected flag(s)
None
RRC [m]
Rotate Data Memory right through Carry
Description
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].0
Affected flag(s)
C
RRCA [m]
Rotate Data Memory right through Carry with result in ACC
Description
Data in the specified Data Memory and the carry flag are rotated right by 1 bit. Bit 0 replaces the Carry bit and the original carry flag is rotated into bit 7. The rotated result is
stored in the Accumulator and the contents of the Data Memory remain unchanged.
Operation
ACC.i ¬ [m].(i+1); (i = 0~6)
ACC.7 ¬ C
C ¬ [m].0
Affected flag(s)
C
Rev. 1.00
84
October 20, 2009
HT45R37V
SBC A,[m]
Subtract Data Memory from ACC with Carry
Description
The contents of the specified Data Memory and the complement of the carry flag are subtracted from the Accumulator. The result is stored in the 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] - C
Affected flag(s)
OV, Z, AC, C
SBCM A,[m]
Subtract Data Memory from ACC with Carry and result in Data Memory
Description
The contents of the specified Data Memory and the complement of the carry flag are subtracted from the Accumulator. The result is stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is
positive or zero, the C flag will be set to 1.
Operation
[m] ¬ ACC - [m] - C
Affected flag(s)
OV, Z, AC, C
SDZ [m]
Skip if decrement Data Memory is 0
Description
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] = 0
Affected flag(s)
None
SDZA [m]
Skip if decrement Data Memory is zero with result in ACC
Description
The contents of the specified Data Memory are first decremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not
0, the program proceeds with the following instruction.
Operation
ACC ¬ [m] - 1
Skip if ACC = 0
Affected flag(s)
None
SET [m]
Set Data Memory
Description
Each bit of the specified Data Memory is set to 1.
Operation
[m] ¬ FFH
Affected flag(s)
None
SET [m].i
Set bit of Data Memory
Description
Bit i of the specified Data Memory is set to 1.
Operation
[m].i ¬ 1
Affected flag(s)
None
Rev. 1.00
85
October 20, 2009
HT45R37V
SIZ [m]
Skip if increment Data Memory is 0
Description
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 ACC
Description
The contents of the specified Data Memory are first incremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not
0 the program proceeds with the following instruction.
Operation
ACC ¬ [m] + 1
Skip if ACC = 0
Affected flag(s)
None
SNZ [m].i
Skip if bit i of Data Memory is not 0
Description
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 ¹ 0
Affected flag(s)
None
SUB A,[m]
Subtract Data Memory from ACC
Description
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
SUBM A,[m]
Subtract Data Memory from ACC with result in Data Memory
Description
The specified Data Memory is subtracted from the contents of the Accumulator. The result
is stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will
be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1.
Operation
[m] ¬ ACC - [m]
Affected flag(s)
OV, Z, AC, C
SUB A,x
Subtract immediate data from ACC
Description
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 - x
Affected flag(s)
OV, Z, AC, C
Rev. 1.00
86
October 20, 2009
HT45R37V
SWAP [m]
Swap nibbles of Data Memory
Description
The low-order and high-order nibbles of the specified Data Memory are interchanged.
Operation
[m].3~[m].0 « [m].7 ~ [m].4
Affected flag(s)
None
SWAPA [m]
Swap nibbles of Data Memory with result in ACC
Description
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].0
Affected flag(s)
None
SZ [m]
Skip if Data Memory is 0
Description
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] = 0
Affected flag(s)
None
SZA [m]
Skip if Data Memory is 0 with data movement to ACC
Description
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] = 0
Affected flag(s)
None
SZ [m].i
Skip if bit i of Data Memory is 0
Description
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 = 0
Affected flag(s)
None
TABRDC [m]
Read table (current page) to TBLH and Data Memory
Description
The low byte of the program code (current 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
TABRDL [m]
Read table (last page) to TBLH and Data Memory
Description
The low byte of the program code (last page) addressed by the table pointer (TBLP) is
moved to the specified Data Memory and the high byte moved to TBLH.
Operation
[m] ¬ program code (low byte)
TBLH ¬ program code (high byte)
Affected flag(s)
None
Rev. 1.00
87
October 20, 2009
HT45R37V
XOR A,[m]
Logical XOR Data Memory to ACC
Description
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 Memory
Description
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 ACC
Description
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² x
Affected flag(s)
Z
Rev. 1.00
88
October 20, 2009
HT45R37V
Package Information
52-pin QFP (14mm´14mm) Outline Dimensions
C
H
D
3 9
G
2 7
I
2 6
4 0
F
A
B
E
1 4
5 2
K
J
1
Symbol
Rev. 1.00
1 3
Dimensions in mm
Min.
Nom.
Max.
A
17.3
¾
17.5
B
13.9
¾
14.1
C
17.3
¾
17.5
D
13.9
¾
14.1
E
¾
1
¾
F
¾
0.4
¾
G
2.5
¾
3.1
H
¾
¾
3.4
I
¾
0.1
¾
J
0.73
¾
1.03
K
0.1
¾
0.2
a
0°
¾
7°
89
October 20, 2009
HT45R37V
Holtek Semiconductor Inc. (Headquarters)
No.3, Creation Rd. II, Science Park, Hsinchu, Taiwan
Tel: 886-3-563-1999
Fax: 886-3-563-1189
http://www.holtek.com.tw
Holtek Semiconductor Inc. (Taipei Sales Office)
4F-2, No. 3-2, YuanQu St., Nankang Software Park, Taipei 115, Taiwan
Tel: 886-2-2655-7070
Fax: 886-2-2655-7373
Fax: 886-2-2655-7383 (International sales hotline)
Holtek Semiconductor Inc. (Shenzhen Sales Office)
5F, Unit A, Productivity Building, No.5 Gaoxin M 2nd Road, Nanshan District, Shenzhen, China 518057
Tel: 86-755-8616-9908, 86-755-8616-9308
Fax: 86-755-8616-9722
Holtek Semiconductor (USA), Inc. (North America Sales Office)
46729 Fremont Blvd., Fremont, CA 94538, USA
Tel: 1-510-252-9880
Fax: 1-510-252-9885
http://www.holtek.com
Copyright Ó 2009 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.tw.
Rev. 1.00
90
October 20, 2009