Beruflich Dokumente
Kultur Dokumente
General Description
The HT46R23/HT46C23 are 8-bit, high performance, The advantages of low power consumption, I/O flexibil-
RISC architecture microcontroller devices specifically ity, programmable frequency divider, timer functions,
designed for A/D applications that interface directly to oscillator options, multi-channel A/D Converter, Pulse
analog signals, such as those from sensors. The mask Width Modulation function, I2C interface, HALT and
version HT46C23 is fully pin and functionally compatible wake-up functions, enhance the versatility of these de-
with the OTP version HT46R23 device. vices to suit a wide range of A/D application possibilities
such as sensor signal processing, motor driving, indus-
trial control, consumer products, subsystem controllers,
etc.
Block Diagram
P A 5 /IN T
In te rru p t
M P r e s c a le r fS Y S
C ir c u it T M R C
U
T M R X P A 4 /T M R
S T A C K
P ro g ra m P ro g ra m IN T C
R O M C o u n te r
P A 3 /P F D P A 4
fS Y S /4
In s tr u c tio n M
W D T
R e g is te r W D T U
M P M D A T A P r e s c a le r
X
U M e m o ry
X
P W M R C O S C
P D C P o rt D
P D 0 /P W M 0 ~ P D 1 /P W M 1
P D
In s tr u c tio n M U X
D e c o d e r 8 -C h a n n e l
A /D C o n v e rte r
A L U S T A T U S
P B C P o rt B
T im in g S h ifte r P B 0 /A N 0 ~ P B 7 /A N 7
P B
G e n e ra to r
P A 3 , P A 5
P A 0 ~ P A 2
P A C P A 3 / P F D
P o rt A P A 4 / T M R
O S C 2 O S C 1 A C C L V R P A P A 5 / IN T
P A 6 / S D A
R E S I2 C B u s
V D D P A 7 / S C L
S la v e M o d e
V S S
P C P o rt C
P C 0 ~ P C 4
P C C
Pin Assignment
P B 5 /A N 5 1 2 8 P B 6 /A N 6
P B 4 /A N 4 2 2 7 P B 7 /A N 7
P B 5 /A N 5 1 2 4 P B 6 /A N 6 P A 3 /P F D 3 2 6 P A 4 /T M R
P B 4 /A N 4 2 2 3 P B 7 /A N 7 P A 2 4 2 5 P A 5 /IN T
P A 3 /P F D 3 2 2 P A 4 /T M R P A 1 5 2 4 P A 6 /S D A
P A 2 4 2 1 P A 5 /IN T P A 0 6 2 3 P A 7 /S C L
P A 1 5 2 0 P A 6 /S D A P B 3 /A N 3 7 2 2 O S C 2
P A 0 6 1 9 P A 7 /S C L P B 2 /A N 2 8 2 1 O S C 1
P B 3 /A N 3 7 1 8 O S C 2 P B 1 /A N 1 9 2 0 V D D
P B 2 /A N 2 8 1 7 O S C 1 P B 0 /A N 0 1 0 1 9 R E S
P B 1 /A N 1 9 1 6 V D D V S S 1 1 1 8 P D 1 /P W M 1
P B 0 /A N 0 1 0 1 5 R E S P C 0 1 2 1 7 P D 0 /P W M 0
V S S 1 1 1 4 P D 0 /P W M 0 P C 1 1 3 1 6 P C 4
P C 0 1 2 1 3 P C 1 P C 2 1 4 1 5 P C 3
H T 4 6 R 2 3 /H T 4 6 C 2 3 H T 4 6 R 2 3 /H T 4 6 C 2 3
2 4 S K D IP -A /S O P -A 2 8 S K D IP -A /S O P -A
Pad Description
Pad Name I/O Option Description
PA0~PA2 Bidirectional 8-bit input/output port. Each bit can be configured as wake-up
PA3/PFD Pull-high input by options. Software instructions determine the CMOS output or
PA4/TMR Wake-up Schmitt trigger input with or without pull-high resistor (determined by
I/O
PA5/INT PA3 or PFD pull-high options: bit option). The PFD, TMR and INT are pin-shared with
PA6/SDA I/O or Serial Bus PA3, PA4 and PA5, respectively. Once the I2C Bus function is used, the in-
PA7/SCL ternal registers related to PA6 and PA7 can not be used.
PB0/AN0
PB1/AN1
Bidirectional 8-bit input/output port. Software instructions determine the
PB2/AN2
CMOS output, Schmitt trigger input with or without pull-high resistor (deter-
PB3/AN3
I/O Pull-high mined by pull-high: port option) or A/D input.
PB4/AN4
Once a PB line is selected as an A/D input (by using software control), the
PB5/AN5
I/O function and pull-high resistor are disabled automatically.
PB6/AN6
PB7/AN7
Bidirectional 5-bit input/output port. Software instructions determine the
PC0~PC4 I/O Pull-high CMOS output, Schmitt trigger input with or without pull-high resistor (deter-
mine by pull-high option: port option).
Bidirectional 2-bit input/output port. Software instructions determine the
PD0/PWM0 Pull-high CMOS output, Schmitt trigger input with or without a pull-high resistor (de-
I/O
PD1/PWM1 I/O or PWM termined by pull-high option: port option). The PWM0/PWM1 output func-
tion are pin-shared with PD0/PD1 (dependent on PWM options).
RES I ¾ Schmitt trigger reset input. Active low.
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 reliabil-
ity.
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
Standby Current 3V ¾ ¾ 5 mA
ISTB1 No load, system HALT
(WDT Enabled) 5V ¾ ¾ 10 mA
Standby Current 3V ¾ ¾ 1 mA
ISTB2 No load, system HALT
(WDT Disabled) 5V ¾ ¾ 2 mA
Input Low Voltage for I/O Ports,
VIL1 ¾ ¾ 0 ¾ 0.3VDD V
TMR and INT
Input High Voltage for I/O Ports,
VIH1 ¾ ¾ 0.7VDD ¾ VDD V
TMR and INT
VIL2 Input Low Voltage (RES) ¾ ¾ 0 ¾ 0.4VDD V
VIH2 Input High Voltage (RES) ¾ ¾ 0.9VDD ¾ VDD V
VLVR Low Voltage Reset ¾ ¾ 2.7 3 3.3 V
3V VOL=0.1VDD 4 8 ¾ mA
IOL I/O Port Sink Current
5V VOL=0.1VDD 10 20 ¾ mA
3V VOH=0.9VDD -2 -4 ¾ mA
IOH I/O Port Source Current
5V VOH=0.9VDD -5 -10 ¾ mA
3V ¾ 20 60 100 kW
RPH Pull-high Resistance
5V ¾ 10 30 50 kW
VAD A/D Input Voltage ¾ ¾ 0 ¾ VDD V
EAD A/D Conversion Error ¾ ¾ ¾ ±0.5 ±1 LSB
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
3V ¾ 45 90 180 ms
tWDTOSC Watchdog Oscillator Period
5V ¾ 32 65 130 ms
tRES External Reset Low Pulse Width ¾ ¾ 1 ¾ ¾ ms
tSST System Start-up Timer Period ¾ Wake-up from HALT ¾ 1024 ¾ *tSYS
Connect to external
tIIC I2C Bus Clock Period ¾ 64 ¾ ¾ *tSYS
pull-high resistor 2kW
Note: *tSYS=1/fSYS
Functional Description
Execution Flow When executing a jump instruction, conditional skip ex-
The system clock for the microcontroller is derived from ecution, loading PCL register, subroutine call, initial re-
either a crystal or an RC oscillator. The system clock is set, internal interrupt, external interrupt or return from
internally divided into four non-overlapping clocks. One subroutine, the PC manipulates the program transfer by
instruction cycle consists of four system clock cycles. loading the address corresponding to each instruction.
Instruction fetching and execution are pipelined in such The conditional skip is activated by instructions. Once
a way that a fetch takes an instruction cycle while de- the condition is met, the next instruction, fetched during
coding and execution takes the next instruction cycle. the current instruction execution, is discarded and a
However, the pipelining scheme causes each instruc- dummy cycle replaces it to get the proper instruction.
tion to effectively execute in a cycle. If an instruction Otherwise proceed with the next instruction.
changes the program counter, two cycles are required to The lower byte of the program counter (PCL) is a read-
complete the instruction. able and writeable register (06H). Moving data into the
PCL performs a short jump. The destination will be
Program Counter - PC within 256 locations.
The program counter (PC) controls the sequence in When a control transfer takes place, an additional
which the instructions stored in program PROM are exe- dummy cycle is required.
cuted and its contents specify full range of program
memory. Program Memory - ROM
After accessing a program memory word to fetch an in- The program memory is used to store the program in-
struction code, the contents of the program counter are in- structions which are to be executed. It also contains
cremented by one. The program counter then points to the data, table, and interrupt entries, and is organized into
memory word containing the next instruction code. 4096´15 bits, addressed by the program counter and ta-
ble pointer.
T 1 T 2 T 3 T 4 T 1 T 2 T 3 T 4 T 1 T 2 T 3 T 4
S y s te m C lo c k
O S C 2 (R C o n ly )
P C P C P C + 1 P C + 2
F e tc h IN S T (P C )
E x e c u te IN S T (P C -1 ) 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 )
Execution Flow
Program Counter
Mode
*11 *10 *9 *8 *7 *6 *5 *4 *3 *2 *1 *0
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 1 0 0
Timer/Event Counter Overflow 0 0 0 0 0 0 0 0 1 0 0 0
A/D Converter Interrupt 0 0 0 0 0 0 0 0 1 1 0 0
I2C Bus Interrupt 0 0 0 0 0 0 0 1 0 0 0 0
Skip Program Counter + 2
Loading PCL *11 *10 *9 *8 @7 @6 @5 @4 @3 @2 @1 @0
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
0 0 0 H
Certain locations in the program memory are reserved D e v ic e In itia liz a tio n P r o g r a m
for special usage:
0 0 4 H
· Location 000H E x te r n a l In te r r u p t S u b r o u tin e
This area is reserved for program initialization. After 0 0 8 H
chip reset, the program always begins execution at lo- T im e r /E v e n t C o u n te r In te r r u p t S u b r o u tin e
cation 000H. 0 0 C H
· Location 004H A /D C o n v e r te r In te r r u p t S u b r o u tin e
Table Location
Instruction
*11 *10 *9 *8 *7 *6 *5 *4 *3 *2 *1 *0
TABRDC [m] P11 P10 P9 P8 @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: *11~*0: Table location bits P11~P8: Current program counter bits
@7~@0: Table pointer bits
If the stack is full and a non-masked interrupt takes The memory pointer registers (MP0 and MP1 are 8-bit
place, the interrupt request flag will be recorded but the registers).
acknowledgment will be inhibited. When the stack
pointer is decremented (by RET or RETI), the interrupt Accumulator
will be serviced. This feature prevents stack overflow al- The accumulator is closely related to ALU operations. It
lowing the programmer to use the structure more easily. is also mapped to location 05H of the data memory and
In a similar case, if the stack is full and a ²CALL² is sub- can carry out immediate data operations. The data
sequently executed, stack overflow occurs and the first movement between two data memory locations must
entry will be lost (only the most recent 8 return ad- pass through the accumulator.
dresses are stored).
0 0 H In d ir e c t A d d r e s s in g R e g is te r 0
Data Memory - RAM 0 1 H M P 0
0 2 H In d ir e c t A d d r e s s in g R e g is te r 1
The data memory is designed with 224´8 bits. The
0 3 H M P 1
data memory is divided into two functional groups: spe-
0 4 H
cial function registers and general purpose data mem-
0 5 H A C C
ory (192´8). Most are read/write, but some are read 0 6 H P C L
only. 0 7 H T B L P
The special function registers include the indirect ad- 0 8 H T B L H
dressing registers (00H;02H), timer/event counter 0 9 H
0 A H S T A T U S
higher-order byte register (TMRH;0CH), timer/event
0 B H IN T C 0
counter low-order byte register (TMRL;0DH),
0 C H T M R H
timer/event counter control register (TMRC;0EH), pro-
0 D H T M R L
gram counter lower-order byte register (PCL;06H),
0 E H T M R C
memory pointer registers (MP0;01H, MP1;03H), accu-
0 F H
mulator (ACC;05H), table pointer (TBLP;07H), table 1 0 H
higher-order byte register (TBLH;08H), status register 1 1 H
(STATUS;0AH), interrupt control register 0 (INTC0; 1 2 H P A
0BH), PWM data register (PWM0;1AH, PWM1;1BH), 1 3 H P A C S p e c ia l P u r p o s e
the I2C Bus slave address register (HADR;20H), the I2C 1 4 H P B D a ta M e m o ry
Bus control register (HCR;21H), the I2C Bus status reg- 1 5 H P B C
ister (HSR;22H), the I2C Bus data register (HDR;23H), 1 6 H P C
the A/D result lower-order byte register (ADRL;24H), the 1 7 H P C C
A/D result higher-order byte register (ADRH;25H), the 1 8 H P D
A/D control register (ADCR;26H), the A/D clock setting 1 9 H P D C
1 A H P W M 0
register (ACSR;27H), I/O registers (PA;12H, PB;14H,
1 B H P W M 1
PC;16H, PD;18H) and I/O control registers (PAC;13H,
1 C H
PBC;15H, PCC;17H, PDC;19H). The remaining space
1 D H
before the 40H is reserved for future expanded usage
1 E H IN T C 1
and reading these locations will get ²00H². The general 1 F H
purpose data memory, addressed from 40H to FFH, is 2 0 H H A D R
used for data and control information under instruction 2 1 H H C R
commands. 2 2 H H S R
The internal timer/event counter interrupt is initialized by ²RETI² may be invoked. RETI will set the EMI bit to en-
setting the timer/event counter interrupt request flag able an interrupt service, but RET will not.
(TF; bit 5 of INTC0), caused by a timer overflow. When
Interrupts, occurring in the interval between the rising
the interrupt is enabled, the stack is not full and the TF
edges of two consecutive T2 pulses, will be serviced on
bit is set, a subroutine call to location 08H will occur. The
the latter of the two T2 pulses, if the corresponding inter-
related interrupt request flag (TF) will be reset and the
rupts are enabled. In the case of simultaneous requests
EMI bit cleared to disable further interrupts.
the following table shows the priority that is applied.
The A/D converter interrupt is initialized by setting the These can be masked by resetting the EMI bit.
A/D converter request flag (ADF; bit 6 of INTC0),
caused by an end of A/D conversion. When the interrupt Interrupt Source Priority Vector
is enabled, the stack is not full and the ADF is set, a sub- External Interrupt 1 04H
routine call to location 0CH will occur. The related inter-
Timer/Event Counter Overflow 2 08H
rupt request flag (ADF) will be reset and the EMI bit
cleared to disable further interrupts. A/D Converter Interrupt 3 0CH
Serial bus interrupt 4 10H
Bit No. Label Function
Controls the master (global) interrupt The timer/event counter interrupt request flag (TF), ex-
0 EMI
(1=enabled; 0=disabled) ternal interrupt request flag (EIF), A/D converter request
Controls the external interrupt flag (ADF), the I2C Bus interrupt request flag (HIF), en-
1 EEI able timer/event counter bit (ETI), enable external inter-
(1=enabled; 0=disabled)
rupt bit (EEI), enable A/D converter interrupt bit (EADI),
Controls the timer/event counter
enable I2C Bus interrupt bit (EHI) and enable master in-
2 ETI interrupt
(1=enabled; 0=disabled) terrupt bit (EMI) constitute an interrupt control register 0
(INTC0) and an interrupt control register 1 (INTC1)
Controls the A/D converter interrupt which are located at 0BH and 1EH in the data memory.
3 EADI
(1=enabled; 0=disabled)
EMI, EEI, ETI, EADI, EHI are used to control the en-
External interrupt request flag abling/disabling of interrupts. These bits prevent the re-
4 EIF
(1=active; 0=inactive) quested interrupt from being serviced. Once the
Internal timer/event counter request interrupt request flags (TF, EIF, ADF, HIF) are set, they
5 TF flag will remain in the INTC0 and INTC1 register until the in-
(1=active; 0=inactive) terrupts are serviced or cleared by a software instruc-
tion.
A/D converter request flag
6 ADF
(1=active; 0=inactive) Bit No. Label Function
For test mode used only. Controls the I2C Bus interrupt
0 EHI
7 ¾ Must be written as ²0²; otherwise may (1= enabled; 0= disabled)
result in unpredictable operation.
1~3 ¾ Unused bit, read as ²0²
INTC0 (0BH) Register
I2C Bus interrupt request flag
2 2 4 HIF
The I C Bus interrupt is initialized by setting the I C Bus (1= active; 0= inactive)
interrupt request flag (HIF; bit 4 of INTC1), caused by a 5~7 ¾ Unused bit, read as ²0²
slave address match (HAAS=²1²) or one byte of data trans-
fer is completed. When the interrupt is enabled, the stack INTC1 (1EH) Register
is not full and the HIF bit is set, a subroutine call to location It is recommended that a program does not use the
10H will occur. The related interrupt request flag (HIF) will
²CALL subroutine² within the interrupt subroutine. In-
be reset and the EMI bit cleared to disable further inter-
terrupts often occur in an unpredictable manner or
rupts.
need to be serviced immediately in some applications.
During the execution of an interrupt subroutine, other in- If only one stack is left and enabling the interrupt is not
terrupt acknowledgments are held until the ²RETI² in- well controlled, the original control sequence will be dam-
struction is executed or the EMI bit and the related aged once the ²CALL² operates in the interrupt subrou-
interrupt control bit are set to 1 (of course, if the stack is tine.
not full). To return from the interrupt subroutine, ²RET² or
S y s te m C lo c k /4
8
M a s k fs fs/2
o p tio n D iv id e r W D T P r e s c a le r
s e le c t
W D T
O S C M a s k O p tio n C K T C K T T im e -o u t R e s e t
R R 2 1 5/fS ~ 2 1 6
/fS
2 1 4/fS ~ 2 1 5
/fS
W D T C le a r 2 1 3/fS ~ 2 1 4
/fS
2 1 2/fS ~ 2 1 3
/fS
Watchdog Timer
Power Down Operation - HALT set² that resets only the program counter and stack
pointer, leaving the other circuits in their original state.
The HALT mode is initialized by the ²HALT² instruction
Some registers remain unchanged during other reset
and results in the following...
conditions. Most registers are reset to the ²initial condi-
· The system oscillator will be turned off but the WDT os-
tion² when the reset conditions are met. By examining
cillator keeps running (if the WDT oscillator is selected).
the PDF and TO flags, the program can distinguish be-
· The contents of the on chip RAM and registers remain
tween different ²chip resets².
unchanged.
· WDT will be cleared and recounted again (if the WDT TO PDF RESET Conditions
clock is from the WDT oscillator).
0 0 RES reset during power-up
· All of the I/O ports maintain their original status.
u u RES reset during normal operation
· The PDF flag is set and the TO flag is cleared.
0 1 RES wake-up HALT
The system can leave the HALT mode by means of an ex-
ternal reset, an interrupt, an external falling edge signal on 1 u WDT time-out during normal operation
port A or a WDT overflow. An external reset causes a de- 1 1 WDT wake-up HALT
vice initialization and the WDT overflow performs a ²warm
Note: ²u² means ²unchanged²
reset². After the TO and PDF flags are examined, the rea-
son for chip reset can be determined. The PDF flag is To guarantee that the system oscillator is started and
cleared by system power-up or executing the ²CLR WDT² stabilized, the SST (System Start-up Timer) provides an
instruction and is set when executing the ²HALT² instruc- extra-delay of 1024 system clock pulses when the sys-
tion. The TO flag is set if the WDT time-out occurs, and tem reset (power-up, WDT time-out or RES reset) or the
causes a wake-up that only resets the program counter system awakes from the HALT state.
and stack pointer; the others keep their original status. V D D
The port A wake-up and interrupt methods can be con- R E S
tS S T
sidered as a continuation of normal execution. Each bit
in port A can be independently selected to wake up the S S T T im e - o u t
device by the options. Awakening from an I/O port stim-
C h ip R e s e t
ulus, the program will resume execution of the next in-
struction. If it is awakening from an interrupt, two Reset Timing Chart
sequences may happen. If the related interrupt is dis-
abled or the interrupt is enabled but the stack is full, the V D D V D D
Reset
R E S
There are three ways in which a reset can occur: C o ld
· RES reset during normal operation R e s e t
S S T
· RES reset during HALT O S C 1 1 0 - b it R ip p le
C o u n te r
· WDT time-out reset during normal operation
When a system reset occurs, the SST delay is added Program Counter 000H
during the reset period. Any wake-up from HALT will en-
Interrupt Disable
able the SST delay. The functional unit chip reset status
are shown below. Clear. After master reset, WDT
WDT
begins counting
An extra option load time delay is added during system
reset (power-up, WDT time-out at normal mode or RES Timer/Event Counter Off
reset). Input/Output Ports Input mode
Stack Pointer Points to the top of the stack
Timer/Event Counter In the pulse width measurement mode with the TON and
TE bits equal to one, once the TMR has received a tran-
A timer/event counter (TMR) is implemented in the
microcontroller. The timer/event counter contains an sient from low to high (or high to low if the TE bits is ²0²)
16-bit programmable count-up counter and the clock it will start counting until the TMR returns to the original
may come from an external source or the system clock. level and resets the TON. The measured result will re-
main in the timer/event counter even if the activated
Using the internal system clock, there is only one refer-
transient occurs again. In other words, only one cycle
ence time-base. The internal clock source comes from
measurement can be done. Until setting the TON, the
fSYS. The external clock input allows the user to count
cycle measurement will function again as long as it re-
external events, measure time intervals or pulse widths,
ceives further transient pulse. Note that, in this operat-
or to generate an accurate time base.
ing mode, the timer/event counter starts counting not
There are three registers related to the timer/event according to the logic level but according to the transient
counter; TMRH (0CH), TMRL (0DH), TMRC (0EH). edges. In the case of counter overflows, the counter is
Writing TMRL will only put the written data to an internal
reloaded from the timer/event counter preload register
lower-order byte buffer (8 bits) and writing TMRH will
and issues the interrupt request just like the other two
transfer the specified data and the contents of the
modes. To enable the counting operation, the timer ON
lower-order byte buffer to TMRH and TMRL preload reg-
bit (TON; bit 4 of TMRC) should be set to 1. In the pulse
isters, respectively. The timer/event counter preload
register is changed by each writing TMRH operations. width measurement mode, the TON will be cleared au-
Reading TMRH will latch the contents of TMRH and tomatically after the measurement cycle is completed.
TMRL counters to the destination and the lower-order But in the other two modes the TON can only be reset by
byte buffer, respectively. Reading the TMRL will read the instructions. The overflow of the timer/event counter is
contents of the lower-order byte buffer. The TMRC is the one of the wake-up sources. No matter what the opera-
timer/event counter control register, which defines the tion mode is, writing a 0 to ETI can disable the interrupt
operating mode, counting enable or disable and active service.
edge.
In the case of timer/event counter OFF condition, writing
The TM0, TM1 bits define the operating mode. The data to the timer/event counter preload register will also
event count mode is used to count external events, reload that data to the timer/event counter. But if the
which means the clock source comes from an external timer/event counter is turned on, data written to it will
(TMR) pin. The timer mode functions as a normal timer only be kept in the timer/event counter preload register.
with the clock source coming from the fINT clock. The The timer/event counter will still operate until overflow
pulse width measurement mode can be used to count the occurs. When the timer/event counter (reading TMRH)
high or low level duration of the external signal (TMR). is read, the clock will be blocked to avoid errors. As
The counting is based on the fINT. clock blocking may results in a counting error, this must
In the event count or timer mode, once the timer/event be taken into consideration by the programmer.
counter starts counting, it will count from the current con- The bit0~bit2 of the TMRC can be used to define the
tents in the timer/event counter to FFFFH. Once overflow pre-scaling stages of the internal clock sources of the
occurs, the counter is reloaded from the timer/event coun- timer/event counter. The definitions are as shown. The
ter preload register and generates the interrupt request overflow signal of the timer/event counter can be used
flag (TF; bit 5 of INTC0) at the same time. to generate the PFD signal.
P W M
(6 + 2 ) o r (7 + 1 ) T o P D 0 /P D 1 C ir c u it
C o m p a re
D a ta B u s
fS Y S 8 - s ta g e p r e s c a le r
f IN T
L o w B y te
8 -1 M U X B u ffe r
T M 1
T M 0
P S C 2 ~ P S C 0 T M R
1 6 - B it R e lo a d
P r e lo a d R e g is te r
T E
P u ls e W id th
T M 1 M e a s u re m e n t H ig h B y te L o w B y te O v e r flo w to In te rru p t
T M 0 M o d e C o n tro l
T O N 1 6 - B it T im e r /E v e n t C o u n te r
1 /2 P F D
Timer/Event Counter
V D D
C o n tr o l B it P U
D a ta B u s D Q
P A 0 ~ P A 2
W r ite C o n tr o l R e g is te r C K Q P A 3 /P F D
C h ip R e s e t S P A 4 /T M R
P A 5 /IN T
P A 6 /S D A
R e a d C o n tr o l R e g is te r P A 7 /S C L
D a ta B it P B 0 /A N 0 ~ P B 7 /A N 7
D Q P C 0 ~ P C 4
P D 0 /P W M 0
W r ite D a ta R e g is te r C K Q P D 1 /P W M 1
S
M
(P D 0 o r P W M 0 ) P A 3 U
(P D 1 o r P W M 1 ) P F D X
P F D E N
M (P A 3 )
U
X
R e a d D a ta R e g is te r
S y s te m W a k e -u p
( P A o n ly ) O P 0 ~ O P 7
IN T fo r P A 5 O n ly
T M R fo r P A 4 O n ly
Input/Output Ports
PA3 to remain at ²0². The I/O functions of PA3 are PD0/PD1. The PWM channels have their data registers
shown below. denoted as PWM0 (1AH) and PWM1 (1BH). The fre-
quency source of the PWM counter comes from fSYS.
I/O I/P O/P I/P O/P The PWM registers are two 8-bit registers. The wave-
Mode (Normal) (Normal) (PFD) (PFD)
forms of PWM outputs are as shown. Once the
Logical Logical Logical PFD PD0/PD1 are selected as the PWM outputs and the out-
PA3
Input Output Input (Timer on) put function of PD0/PD1 are enabled (PDC.0/PDC.1
=²0²), writing ²1² to PD0/PD1 data register will enable
Note: The PFD frequency is the timer/event counter
the PWM output function and writing ²0² will force the
overflow frequency divided by 2.
PD0/PD1 to stay at ²0².
The PA4, PA5, PA6 and PA7 are pin-shared with TMR,
INT, SDA and SCL pins respectively. A (6+2) bits mode PWM cycle is divided into four modu-
lation cycles (modulation cycle 0~modulation cycle 3).
The PB can also be used as A/D converter inputs. The Each modulation cycle has 64 PWM input clock period.
A/D function will be described later. There is a PWM In a (6+2) bit PWM function, the contents of the PWM
function shared with PD0/PD1. If the PWM function is register is divided into two groups. Group 1 of the PWM
enabled, the PWM0/PWM1 signal will appear on register is denoted by DC which is the value of
PD0/PD1 (if PD0/PD1 is operating in output mode). PWM.7~PWM.2. The group 2 is denoted by AC which is
Writing ²1² to PD0/PD1 data register will enable the the value of PWM.1~PWM.0.
PWM0/PWM1 output function and writing ²0² will force
In a (6+2) bits mode PWM cycle, the duty cycle of each
the PD0/PD1 to remain at ²0². The I/O functions of
modulation cycle is shown in the table.
PD0/PD1 are as shown.
Parameter AC (0~3) Duty Cycle
I/O I/P O/P I/P O/P
Mode (Normal) (Normal) (PWM) (PWM) DC+1
i<AC
Modulation cycle i 64
PD0 Logical Logical Logical PWM0
PD1 Input Output Input PWM1 (i=0~3) DC
i³AC
64
It is recommended that unused or not bonded out I/O
lines should be set as output pins by software instruction A (7+1) bits mode PWM cycle is divided into two modu-
to avoid consuming power under input floating state. lation cycles (modulation cycle 0 ~ modulation cycle 1).
Each modulation cycle has 128 PWM input clock period.
PWM
In a (7+1) bits PWM function, the contents of the PWM
The microcontroller provides 2 channels (6+2)/(7+1) register is divided into two groups. Group 1 of the PWM
(dependent on options) bits PWM output shared with register is denoted by DC which is the value of
fS Y S /2
[P W M ] = 1 0 0
P W M
2 5 /6 4 2 5 /6 4 2 5 /6 4 2 5 /6 4 2 5 /6 4
[P W M ] = 1 0 1
P W M
2 6 /6 4 2 5 /6 4 2 5 /6 4 2 5 /6 4 2 6 /6 4
[P W M ] = 1 0 2
P W M
2 6 /6 4 2 6 /6 4 2 5 /6 4 2 5 /6 4 2 6 /6 4
[P W M ] = 1 0 3
P W M
2 6 /6 4 2 6 /6 4 2 6 /6 4 2 5 /6 4 2 6 /6 4
P W M m o d u la tio n p e r io d : 6 4 /fS Y S
M o d u la tio n c y c le 0 M o d u la tio n c y c le 1 M o d u la tio n c y c le 2 M o d u la tio n c y c le 3 M o d u la tio n c y c le 0
P W M c y c le : 2 5 6 /fS Y S
fS Y S /2
[P W M ] = 1 0 0
P W M
5 0 /1 2 8 5 0 /1 2 8 5 0 /1 2 8
[P W M ] = 1 0 1
P W M
5 1 /1 2 8 5 0 /1 2 8 5 1 /1 2 8
[P W M ] = 1 0 2
P W M
5 1 /1 2 8 5 1 /1 2 8 5 1 /1 2 8
[P W M ] = 1 0 3
P W M
5 1 /1 2 8 5 2 /1 2 8
5 2 /1 2 8
P W M m o d u la tio n p e r io d : 1 2 8 /fS Y S
P W M c y c le : 2 5 6 /fS Y S
The A/D converter control register is used to control the START should remain at ²0² until the EOCB is cleared
A/D converter. The bit2~bit0 of the ADCR are used to to ²0² (end of A/D conversion).
select an analog input channel. There are a total of eight
channels to select. The bit5~bit3 of the ADCR are used Bit No. Label Function
to set PB configurations. PB can be an analog input or
Selects the A/D converter
as digital I/O line decided by these 3 bits. Once a PB line
clock source
is selected as an analog input, the I/O functions and
0 ADCS0 00= system clock/2
pull-high resistor of this I/O line are disabled and the A/D
1 ADCS1 01= system clock/8
converter circuit is power on. The EOCB bit (bit6 of the
10= system clock/32
ADCR) is end of A/D conversion flag. Check this bit to
11= undefined
know when A/D conversion is completed. The START
bit of the ADCR is used to begin the conversion of the 2~6 ¾ Unused bit, read as ²0²
A/D converter. Giving START bit a rising edge and fall-
ing edge means that the A/D conversion has started. In 7 TEST For test mode used only
order to ensure the A/D conversion is completed, the ACSR (27H) Register
Port B Configuration
Bit 7 of the ACSR register is used for test purposes only by setting the START bit high and then clearing it to zero
and must not be used for other purposes by the applica- within 10 instruction cycles of the Port B channel selec-
tion program. Bit1 and bit0 of the ACSR register are tion bits being modified. Note that if the Port B channel
used to select the A/D clock source. selection bits are all cleared to zero then an A/D initial-
When the A/D conversion has completed, the A/D inter- ization is not required.
rupt request flag will be set. The EOCB bit is set to ²1² Register Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
when the START bit is set from ²0² to ²1². ADRL D1 D0 ¾ ¾ ¾ ¾ ¾ ¾
Important Note for A/D initialization: ADRH D9 D8 D7 D6 D5 D4 D3 D2
Special care must be taken to initialize the A/D con-
Note: D0~D9 is A/D conversion result data bit
verter each time the Port B A/D channel selection bits
LSB~MSB.
are modified, otherwise the EOCB flag may be in an un-
defined condition. An A/D initialization is implemented ADRL (24H), ADRH (25H) Register
The following two programming examples illustrate how to setup and implement an A/D conversion. In the first exam-
ple, 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.
Example: using EOCB Polling Method to detect end of conversion
clr EADI ; disable ADC interrupt
mov a,00000001B
mov ACSR,a ; setup the ACSR register to select fSYS/8 as the A/D clock
mov a,00100000B ; setup ADCR register to configure Port PB0~PB3 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 within 10 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,ADRH ; read conversion result high byte value from the ADRH register
mov adrh_buffer,a ; save result to user defined memory
mov a,ADRL ; read conversion result low byte value from the ADRL register
mov adrl_buffer,a ; save result to user defined memory
:
:
jmp start_conversion ; start next A/D conversion
mov a,00100000B ; setup ADCR register to configure Port PB0~PB3 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 within 10 instruction cycles
:
Start_conversion:
clr START
set START ; reset A/D
clr START ; start A/D
clr ADF ; clear ADC interrupt request flag
set EADI ; enable ADC interrupt
set EMI ; enable global interrupt
:
:
:
; ADC interrupt service routine
ADC_ISR:
mov acc_stack,a ; save ACC to user defined memory
mov a,STATUS
mov status_stack,a ; save STATUS to user defined memory
:
:
mov a,ADRH ; read conversion result high byte value from the ADRH register
mov adrh_buffer,a ; save result to user defined register
mov a,ADRL ; read conversion result low byte value from the ADRL register
mov adrl_buffer,a ; save result to user defined register
clr START
set START ; reset A/D
clr START ; start A/D
:
:
EXIT_INT_ISR:
mov a,status_stack
mov STATUS,a ; restore STATUS from user defined memory
mov a,acc_stack ; restore ACC from user defined memory
reti
S T A R T
P C R 2 ~ 0 0 0 B 1 0 0 B 1 0 0 B 1 0 1 B 0 0 0 B
P C R 0
1 . P B p o rt s e tu p a s I/O s
2 . A /D c o n v e r te r is p o w e r e d o ff
to r e d u c e p o w e r c o n s u m p tio n
A C S 2 ~
A C S 0 0 0 0 B 0 1 0 B 0 0 0 B 0 0 1 B d o n 't c a r e
P o w e r-o n S ta rt o f A /D S ta rt o f A /D S ta rt o f A /D
R e s e t c o n v e r s io n c o n v e r s io n c o n v e r s io n
R e s e t A /D R e s e t A /D R e s e t A /D
c o n v e rte r c o n v e rte r c o n v e rte r
E n d o f A /D E n d o f A /D E n d o f A /D
1 : D e fin e P B c o n fig u r a tio n c o n v e r s io n c o n v e r s io n c o n v e r s io n
2 : S e le c t a n a lo g c h a n n e l
tA D C tA D C tA D C
A /D c o n v e r s io n tim e A /D c o n v e r s io n tim e A /D c o n v e r s io n tim e
N o te : A /D c lo c k m u s t b e fS Y S /2 , fS Y S /8 o r fS Y S /3 2
tA D C S = 3 2 tA D
tA D C = 7 6 tA D
V D D
5 .5 V
V L V R L V R D e te c t V o lta g e
0 .9 V
0 V
R e s e t S ig n a l
R e s e t N o r m a l O p e r a tio n R e s e t
*1 *2
Note: *1: To make sure that the system oscillator has stabilized, the SST provides an extra delay of 1024 system
clock pulses before entering the normal operation.
*2: Since low voltage state has to be maintained in its original state for over 1ms, therefore after 1ms delay,
the device enters the reset mode.
The I2C Bus status register contains 5 bits. The HCF bit ister. At the beginning of the transfer of the I2C Bus, the
is reset to ²0² when one data byte is being transferred. If device must initial the bus, the following are the notes for
one data transfer is completed, this bit is set to ²1². The initialing the I2C Bus.
HASS bit is set ²1² when the address is match, and the Note:
I2C Bus interrupt request flag is set to ²1². If the interrupt
1. Write the I2C Bus address register (HADR) to define
is enabled and the stack is not full, a subroutine call to
its own slave address.
location 10H will occur. Writing data to the I2C Bus con-
trol register clears HAAS bit. If the address is not match, 2. Set HEN bit of I2C Bus control register (HCR) bit 0 to
this bit is reset to ²0². The HBB bit is set to respond the enable the I2C Bus.
I2C Bus is busy. It mean that a START signal is detected. Bit
This bit is reset to ²0² when the I2C Bus is not busy. It Label Function
No.
means that a STOP signal is detected and the I2C Bus is
2~0 ¾ Unused bit, read as ²0²
free. The SRW bit defines the read/write command bit, if
the calling address is match. When HAAS is set to ²1², To enable or disable transmit ac-
the device check SRW bit to determine whether the de- 3 TXAK knowledge (0=acknowledge; 1=don¢t
vice is working in transmit or receive mode. When SRW acknowledge)
bit is set ²1², it means that the master wants to read data To define the transmit/receive mode
4 HTX
from I2C Bus, the slave device must write data to I2C (0= receive mode; 1= transmit)
Bus, so the slave device is working in transmit mode.
5~6 ¾ Unused bit, read as ²0²
When SRW is reset to ²0², it means that the master
wants to write data to I2C Bus, the slave device must To enable or disable I2C Bus function
7 HEN
read data from the bus, so the slave device is working in (0= disable; 1= enable)
receive mode. The RXAK bit is reset ²0² indicates an ac- HCR (21H) Register
knowledges signal has been received. In the transmit
3. Set EHI bit of the interrupt control register 1 (INTC1)
mode, the transmitter checks RXAK bit to know the re-
bit 0 to enable the I2C Bus interrupt.
ceiver which wants to receive the next data byte, so the
transmitter continue to write data to the I2C Bus until the Bit
Label Function
RXAK bit is set to ²1² and the transmitter releases the No.
SDA line, so that the master can send the STOP signal
RXAK is cleared to ²0² when the
to release the bus.
master receives an 8-bit data and ac-
The HADR bit7-bit1 define the device slave address. At 0 RXAK knowledgment at the 9th clock,
the beginning of transfer, the master must select a de- RXAK is set to ²1² means not ac-
vice by sending the address of the slave device. The bit knowledged.
0 is unused and is not defined. If the I2C Bus receives a 1 ¾ Unused bit, read as ²0²
start signal, all slave device notice the continuity of the
8-bit data. The front of 7 bits is slave address and the SRW is set to ²1² when the master
first bit is MSB. If the address is match, the HAAS status wants to read data from the I2C Bus,
so the slave must transmit data to the
bit is set and generate an I2C Bus interrupt. In the ISR,
2 SRW master. SRW is cleared to ²0² when
the slave device must check the HAAS bit to know the
the master wants to write data to the
I2C Bus interrupt comes from the slave address that has I2C Bus, so the slave must receive
match or completed one 8-bit data transfer. The last bit data from the master.
of the 8-bit data is read/write command bit, it responds in
SRW bit. The slave will check the SRW bit to know if the 3~4 ¾ Unused bit, read as ²0²
master wants to transmit or receive data. The device HBB is set to ²1² when I2C Bus is
check SRW bit to know it is as a transmitter or receiver. 5 HBB busy and HBB is cleared to ²0²
means that the I2C Bus is not busy.
Bit7~Bit1 Bit0
HAAS is set to ²1² when the calling
Slave Address ¾
6 HAAS address has matched, and I2C Bus
²¾² means undefined interrupt will occur and HIF is set.
HADR (20H) Register HCF is clear to ²0² when one data
byte is being transferred, HCF is set
The HDR register is the I2C Bus input/output data regis- 7 HCF
to ²1² indicating 8-bit data communi-
ter. Before transmitting data, the HDR must write the
cation has been finished.
data which we want to transmit. Before receiving data,
the device must dummy read data from HDR. Transmit HSR (22H) Register
or Receive data from I2C Bus must be via the HDR reg-
S ta rt
W r ite S la v e
A d d re s s to H A D R
S E T H E N
D is a b le I2C B u s E n a b le
In te rru p t= ?
C L R E H I S E T E H I
P o ll H IF to d e c id e
w h e n to g o to I2C B u s IS R 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
S ta rt
N o H A A S = 1 Y e s
?
N o H T X = 1 Y e s Y e s S R W = 1 N o
? ?
C L R H T X
R e a d fro m H D R S E T H T X
C L R T X A K
D u m m y R e a d
R E T I W r ite to H D R
F ro m H D R
Y e s R X A K = 1
?
R E T I R E T I
N o
C L R H T X
W r ite to H D R
C L R T X A K
D u m m y R e a d
R E T I
fro m H D R
R E T I
S ta rt S la v e A d d r e s s S R W A C K
S C L
1 0 1 1 0 1 0 1 0
S D A
D a ta A C K S to p
S C L
1 0 0 1 0 1 0 0
S D A
S = S ta rt (1 b it)
S A = S la v e A d d r e s s ( 7 b its )
S R = S R W b it ( 1 b it)
M = S la v e d e v ic e s e n d a c k n o w le d g e b it ( 1 b it)
D = D a ta (8 b its )
A = A C K (R 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)
P = S to p (1 b it)
S S A S R M D A D A S S A S R M D A D A P
S C L SRW Bit
The SRW bit means that the master device wants to
S D A
read from or write to the I2C Bus. The slave device
check this bit to understand itself if it is a transmitter or a
Start Bit receiver. The SRW bit is set to ²1² means that the mas-
ter wants to read data from the I2C Bus, so the slave de-
Slave Address vice must write data to a bus as a transmitter. The SRW
is cleared to ²0² means that the master wants to write
The master must select a device for transferring the
data to the I2C Bus, so the slave device must read data
data by sending the slave device address after the
from the I2C Bus as a receiver.
START signal. All device in the I2C Bus will receive the
I2C Bus slave address (7 bits) to compare with its own
slave address (7 bits). If the slave address is matched,
the slave device will generate an interrupt and save the
following bit (8th bit) to SRW bit and sends an acknowl-
edge bit (low level) to the 9th bit. The slave device also
sets the status flag (HAAS), when the slave address is
matched.
Acknowledge Bit byte data. If the transmitter checks and there¢s no ac-
One of the slave device generates an acknowledge signal, knowledge signal, then it release the SDA line, and the
when the slave address is matched. The master device master sends a STOP signal to release the I2C Bus. The
can check this acknowledge bit to know if the slave device data is stored in the HDR register. The transmitter must
accepts the calling address. If no acknowledge bit, the write data to the HDR before transmit data and the re-
master must send a STOP bit and end the communication. ceiver must read data from the HDR after receiving
When the I2C Bus status register bit 6 HAAS is high, it data.
means the address is matched, so the slave must check S C L
SRW as a transmitter (set HTX) to ²1² or as a receiver
(clear HTX) to ²0². S D A
S ta r t b it S to p b it
S C L D a ta D a ta
s ta b le a llo w
c h a n g e
S D A
Data Timing Diagram
Stop Bit
Receive Acknowledge Bit
When the receiver wants to continue to receive the next
Data Byte data byte, it generates an acknowledge bit (TXAK) at
The data is 8 bits and is sent after the slave device has the 9th clock. The transmitter checks the acknowledge
acknowledges the slave address. The first bit is MSB bit (RXAK) to continue to write data to the I2C Bus or
and the 8th bit is LSB. The receiver sends the acknowl- change to receive mode and dummy read the HDR reg-
edge signal (²0²) and continues to receive the next one ister to release the SDA line and the master sends the
STOP signal.
Options
The following table shows all kinds of options in the microcontroller. All of the options must be defined to ensure proper
system function.
No. Options
OSC type selection.
1
This option is to decide if an RC or crystal oscillator is chosen as system clock.
WDT source selection.
2
There are three types of selection: on-chip RC oscillator, instruction clock or disable the WDT.
CLRWDT times selection.
This option defines how to clear the WDT by instruction. ²One time² means that the CLR WDT instruction can
3
clear the WDT. ²Two times² means only if both of the CLR WDT1 and CLR WDT2 instructions have been exe-
cuted, then WDT can be cleared.
Wake-up selection.
4 This option defines the wake-up function activity. External I/O pins (PA only) all have the capability to wake-up
the chip from a HALT.
Pull-high selection.
5 This option is to decide whether a pull-high resistance is visible or not in the input mode of the I/O ports.
PA0~PA7, can be independently selected.
PFD selection.
6
PA3: level output or PFD output
PWM selection: (7+1) or (6+2) mode
7 PD0: level output or PWM0 output
PD1: level output or PWM1 output
WDT time-out period selection.
8
212/fS~213/fS, 213/fS~214/fS, 214/fS~215/fS, 215/fS~216/fS.
9 Low voltage reset selection: Enable or disable LVR function.
I2C Bus selection.
10
PA6 and PA7: I/O or I2C Bus function
Application Circuits
V D D
V D D P A 0 ~ P A 2
P A 3 /P F D
R e s e t V D D
1 0 0 k W P A 4 /T M R
C ir c u it
P A 5 /IN T 4 7 0 p F R C S y s te m O s c illa to r
0 .1 m F O S C 1 2 4 k W < R O S C < 1 M W
R E S P A 6 /S D A
R O S C
0 .1 m F P A 7 /S C L fS Y S /4
O S C 2
P B 0 /A N 0
C 1
~
V S S P B 7 /A N 7 O S C 1 C r y s ta l/R e s o n a to r
S y s te m O s c illa to r
P C 0 ~ P C 4 R 1
O S C O S C 1 P D 0 /P W M 0 F o r R 1 , C 1 , C 2 s e e n o te
O S C 2
C ir c u it O S C 2 P D 1 /P W M 1 C 2
H T 4 6 R 2 3 /H T 4 6 C 2 3 O S C C ir c u it
Instruction Set
Introduction subtract instruction mnemonics to enable the necessary
arithmetic to be carried out. Care must be taken to en-
Central to the successful operation of any
sure correct handling of carry and borrow data when re-
microcontroller is its instruction set, which is a set of pro-
sults exceed 255 for addition and less than 0 for
gram instruction codes that directs the microcontroller to
subtraction. The increment and decrement instructions
perform certain operations. In the case of Holtek
INC, INCA, DEC and DECA provide a simple means of
microcontrollers, a comprehensive and flexible set of
increasing or decreasing by a value of one of the values
over 60 instructions is provided to enable programmers
in the destination specified.
to implement their application with the minimum of pro-
gramming overheads.
Logical and Rotate Operations
For easier understanding of the various instruction
The standard logical operations such as AND, OR, XOR
codes, they have been subdivided into several func-
and CPL all have their own instruction within the Holtek
tional groupings.
microcontroller instruction set. As with the case of most
instructions involving data manipulation, data must pass
Instruction Timing
through the Accumulator which may involve additional
Most instructions are implemented within one instruc- programming steps. In all logical data operations, the
tion cycle. The exceptions to this are branch, call, or ta- zero flag may be set if the result of the operation is zero.
ble read instructions where two instruction cycles are Another form of logical data manipulation comes from
required. One instruction cycle is equal to 4 system the rotate instructions such as RR, RL, RRC and RLC
clock cycles, therefore in the case of an 8MHz system which provide a simple means of rotating one bit right or
oscillator, most instructions would be implemented left. Different rotate instructions exist depending on pro-
within 0.5ms and branch or call instructions would be im- gram requirements. Rotate instructions are useful for
plemented within 1ms. Although instructions which re- serial port programming applications where data can be
quire one more cycle to implement are generally limited rotated from an internal register into the Carry bit from
to the JMP, CALL, RET, RETI and table read instruc- where it can be examined and the necessary serial bit
tions, it is important to realize that any other instructions set high or low. Another application where rotate data
which involve manipulation of the Program Counter Low operations are used is to implement multiplication and
register or PCL will also take one more cycle to imple- division calculations.
ment. As instructions which change the contents of the
PCL will imply a direct jump to that new address, one Branches and Control Transfer
more cycle will be required. Examples of such instruc- Program branching takes the form of either jumps to
tions would be ²CLR PCL² or ²MOV PCL, A². For the specified locations using the JMP instruction or to a sub-
case of skip instructions, it must be noted that if the re- routine using the CALL instruction. They differ in the
sult of the comparison involves a skip operation then sense that in the case of a subroutine call, the program
this will also take one more cycle, if no skip is involved must return to the instruction immediately when the sub-
then only one cycle is required. routine has been carried out. This is done by placing a
return instruction RET in the subroutine which will cause
Moving and Transferring Data
the program to jump back to the address right after the
The transfer of data within the microcontroller program CALL instruction. In the case of a JMP instruction, the
is one of the most frequently used operations. Making program simply jumps to the desired location. There is
use of three kinds of MOV instructions, data can be no requirement to jump back to the original jumping off
transferred from registers to the Accumulator and point as in the case of the CALL instruction. One special
vice-versa as well as being able to move specific imme- and extremely useful set of branch instructions are the
diate data directly into the Accumulator. One of the most conditional branches. Here a decision is first made re-
important data transfer applications is to receive data garding the condition of a certain data memory or indi-
from the input ports and transfer data to the output ports. vidual bits. Depending upon the conditions, the program
will continue with the next instruction or skip over it and
Arithmetic Operations jump to the following instruction. These instructions are
The ability to perform certain arithmetic operations and the key to decision making and branching within the pro-
data manipulation is a necessary feature of most gram perhaps determined by the condition of certain in-
microcontroller applications. Within the Holtek put switches or by the condition of internal data bits.
microcontroller instruction set are a range of add and
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.
Instruction Definition
DAA [m] Decimal-Adjust ACC for addition with result in Data Memory
Description Convert the contents of the Accumulator value to a BCD ( Binary Coded Decimal) value re-
sulting 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 add-
ing 00H, 06H, 60H or 66H depending on the Accumulator and flag conditions. Only the C
flag may be affected by this instruction which indicates that if the original BCD sum is
greater than 100, it allows multiple precision decimal addition.
Operation [m] ¬ ACC + 00H or
[m] ¬ ACC + 06H or
[m] ¬ ACC + 60H or
[m] ¬ ACC + 66H
Affected flag(s) C
NOP No operation
Description No operation is performed. Execution continues with the next instruction.
Operation No operation
Affected flag(s) None
RET A,x Return from subroutine and load immediate data to ACC
Description The Program Counter is restored from the stack and the Accumulator loaded with the
specified immediate data. Program execution continues at the restored address.
Operation Program Counter ¬ Stack
ACC ¬ x
Affected flag(s) None
RLCA [m] Rotate Data Memory left through Carry with result in ACC
Description Data in the specified Data Memory and the carry flag are rotated left by 1 bit. Bit 7 replaces
the Carry bit and the original carry flag is rotated into the bit 0. The rotated result is stored in
the Accumulator and the contents of the Data Memory remain unchanged.
Operation ACC.(i+1) ¬ [m].i; (i = 0~6)
ACC.0 ¬ C
C ¬ [m].7
Affected flag(s) C
RRCA [m] Rotate Data Memory right through Carry with result in ACC
Description Data in the specified Data Memory and the carry flag are rotated right by 1 bit. Bit 0 re-
places the Carry bit and the original carry flag is rotated into bit 7. The rotated result is
stored in the Accumulator and the contents of the Data Memory remain unchanged.
Operation ACC.i ¬ [m].(i+1); (i = 0~6)
ACC.7 ¬ C
C ¬ [m].0
Affected flag(s) C
SBCM A,[m] Subtract Data Memory from ACC with Carry and result in Data Memory
Description The contents of the specified Data Memory and the complement of the carry flag are sub-
tracted from the Accumulator. The result is stored in the Data Memory. Note that if the re-
sult of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is
positive or zero, the C flag will be set to 1.
Operation [m] ¬ ACC - [m] - C
Affected flag(s) OV, Z, AC, C
SDZA [m] Skip if decrement Data Memory is zero with result in ACC
Description The contents of the specified Data Memory are first decremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy in-
struction while the next instruction is fetched, it is a two cycle instruction. If the result is not
0, the program proceeds with the following instruction.
Operation ACC ¬ [m] - 1
Skip if ACC = 0
Affected flag(s) None
SIZA [m] Skip if increment Data Memory is zero with result in ACC
Description The contents of the specified Data Memory are first incremented by 1. If the result is 0, the
following instruction is skipped. The result is stored in the Accumulator but the specified
Data Memory contents remain unchanged. As this requires the insertion of a dummy in-
struction while the next instruction is fetched, it is a two cycle instruction. If the result is not
0 the program proceeds with the following instruction.
Operation ACC ¬ [m] + 1
Skip if ACC = 0
Affected flag(s) None
SUBM A,[m] Subtract Data Memory from ACC with result in Data Memory
Description The specified Data Memory is subtracted from the contents of the Accumulator. The result
is stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will
be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1.
Operation [m] ¬ ACC - [m]
Affected flag(s) OV, Z, AC, C
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
Package Information
24-pin SKDIP (300mil) Outline Dimensions
A A
2 4 1 3 2 4 1 3
B B
1 1 2 1 1 2
H H
C C
D D
E F G I E F G I
Dimensions in mil
Symbol
Min. Nom. Max.
A 1230 ¾ 1280
B 240 ¾ 280
C 115 ¾ 195
D 115 ¾ 150
E 14 ¾ 22
F 45 ¾ 70
G ¾ 100 ¾
H 300 ¾ 325
I ¾ ¾ 430
Dimensions in mil
Symbol
Min. Nom. Max.
A 1160 ¾ 1195
B 240 ¾ 280
C 115 ¾ 195
D 115 ¾ 150
E 14 ¾ 22
F 45 ¾ 70
G ¾ 100 ¾
H 300 ¾ 325
I ¾ ¾ 430
Dimensions in mil
Symbol
Min. Nom. Max.
A 1145 ¾ 1185
B 275 ¾ 295
C 120 ¾ 150
D 110 ¾ 150
E 14 ¾ 22
F 45 ¾ 60
G ¾ 100 ¾
H 300 ¾ 325
I ¾ ¾ 430
2 8 1 5
B
1 1 4
D
I
E F G
Dimensions in mil
Symbol
Min. Nom. Max.
A 1375 ¾ 1395
B 278 ¾ 298
C 125 ¾ 135
D 125 ¾ 145
E 16 ¾ 20
F 50 ¾ 70
G ¾ 100 ¾
H 295 ¾ 315
I ¾ ¾ 375
2 4 1 3
A B
1 1 2
C '
G
D H
E F a
· MS-013
Dimensions in mil
Symbol
Min. Nom. Max.
A 393 ¾ 419
B 256 ¾ 300
C 12 ¾ 20
C¢ 598 ¾ 613
D ¾ ¾ 104
E ¾ 50 ¾
F 4 ¾ 12
G 16 ¾ 50
H 8 ¾ 13
a 0° ¾ 8°
2 8 1 5
A B
1 1 4
C '
G
D H
E F a
· MS-013
Dimensions in mil
Symbol
Min. Nom. Max.
A 393 ¾ 419
B 256 ¾ 300
C 12 ¾ 20
C¢ 697 ¾ 713
D ¾ ¾ 104
E ¾ 50 ¾
F 4 ¾ 12
G 16 ¾ 50
H 8 ¾ 13
a 0° ¾ 8°
D
T 2
A B C
T 1
SOP 24W
Symbol Description Dimensions in mm
A Reel Outer Diameter 330.0±1.0
B Reel Inner Diameter 100.0±1.5
C Spindle Hole Diameter 13.0+0.5/-0.2
F
W
B 0
C
D 1 P
K 0
A 0
R e e l H o le
IC p a c k a g e p in 1 a n d th e r e e l h o le s
a r e lo c a te d o n th e s a m e s id e .
SOP 24W
Symbol Description Dimensions in mm
W Carrier Tape Width 24.0±0.3
P Cavity Pitch 12.0±0.1
E Perforation Position 1.75±0.1
F Cavity to Perforation (Width Direction) 11.5±0.1
D Perforation Diameter 1.55+0.10/-0.00
D1 Cavity Hole Diameter 1.50+0.25/-0.00
P0 Perforation Pitch 4.0±0.1
P1 Cavity to Perforation (Length Direction) 2.0±0.1
A0 Cavity Length 10.9±0.1
B0 Cavity Width 15.9±0.1
K0 Cavity Depth 3.1±0.1
t Carrier Tape Thickness 0.35±0.05
C Cover Tape Width 21.3±0.1
SOP 28W
Symbol Description Dimensions in mm
W Carrier Tape Width 24.0±0.3
P Cavity Pitch 12.0±0.1
E Perforation Position 1.75±0.10
F Cavity to Perforation (Width Direction) 11.5±0.1
D Perforation Diameter 1.5+0.1/-0.0
D1 Cavity Hole Diameter 1.50+0.25/-0.00
P0 Perforation Pitch 4.0±0.1
P1 Cavity to Perforation (Length Direction) 2.0±0.1
A0 Cavity Length 10.85±0.10
B0 Cavity Width 18.34±0.10
K0 Cavity Depth 2.97±0.10
t Carrier Tape Thickness 0.35±0.01
C Cover Tape Width 21.3±0.1