HT46R47
HT46R47
HT46R47
8-Bit OTP Battery Charger Controller
Features
· Operating voltage: · Up to 0.5ms instruction cycle with 8MHz
fSYS=4MHz: 3.3V~5.5V system clock at VDD=5V
fSYS=8MHz: 4.5V~5.5V · Six-level subroutine nesting
· 13 bidirectional I/O lines (max.) · 4 channels 9-bit resolution (8-bit accuracy)
· 1 interrupt input shared with an I/O line A/D converter
· 8-bit programmable timer/event counter with · 1 channel (6+2)-bit PWM output shared
overflow interrupt and 7-stage prescaler with an I/O line
· On-chip crystal and RC oscillator · Bit manipulation instruction
· Watchdog Timer · 14-bit table read instruction
· 2048´14 program memory PROM · 63 powerful instructions
· 64´8 data memory RAM · All instructions in one or two machine
· Supports PFD for sound generation cycles
· HALT function and wake-up feature reduce · Low voltage reset function
power consumption · 18-pin DIP/SOP package
General Description
The device is an 8-bit high performance The program and option memories can be elec-
RISC-like microcontroller designed for multi- trically programmed, making the microcontrol-
ple I/O product applications. The device is par- ler suitable for use in product development.
ticularly suitable for use in products such as
battery charger controllers and A/D applica-
tions. A HALT feature is included to reduce
power consumption.
Block Diagram
P A 5 /IN T
In te rru p t
C ir c u it M P r e s c a le r fS Y S
T M R U
S T A C K X P A 4 /T M R
P ro g ra m P ro g ra m IN T C T M R C
R O M C o u n te r
P A 4
P A 3 /P F D
S Y S C L K /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 R T D
P D 0 /P W M
P D
In s tr u c tio n M U X
D e c o d e r 4 -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 R T B
T im in g S h ifte r P B 0 /A N 0 ~ P B 3 /A N 3
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 O R T A P A 3 /P F D
O p tio n
P A 4 /T M R
O S C 2 O S C 1 A C C L V R P R O M P A
P A 5 /IN T
R E S P A 6 , P A 7
V D D
V S S
Pin Assignment
P A 3 /P F D 1 1 8 P A 4 /T M R
P A 2 2 1 7 P A 5 /IN T
P A 1 3 1 6 P A 6
P A 0 4 1 5 P A 7
P B 3 /A N 3 5 1 4 O S C 2
P B 2 /A N 2 6 1 3 O S C 1
P B 1 /A N 1 7 1 2 V D D
P B 0 /A N 0 8 1 1 R E S
V S S 9 1 0 P D 0 /P W M
H T 4 6 R 4 7
1 8 D IP -A /S O P -A
Pin Description
ROM Code
Pin No. Pin Name I/O Description
Option
Bidirectional 8-bit input/output port. Each bit can be
4~2 PA0~PA2 configured as wake-up input by ROM code option.
1 PA3/PFD Pull-high Software instructions determine the CMOS output or
18 PA4/TMR I/O Wake-up Schmitt trigger input with or without pull-high resistor
17 PA5/INT PA3 or PFD (determined by pull-high options: bit option). The PFD,
16, 15 PA6, PA7 TMR and INT are pin-shared with PA3, PA4 and PA5,
respectively.
Bidirectional 4-bit input/output port. Software in-
structions determine the CMOS output, Schmitt trig-
8 PB0/AN0 ger input with or without pull-high resistor
7 PB1/AN1 (determined by pull-high options: bit option) or A/D in-
I/O Pull-high
6 PB2/AN2 put.
5 PB3/AN3 Once a PB line is selected as an A/D input (by using
software control), the I/O function and pull-high
resistor are disabled automatically.
9 VSS ¾ ¾ Negative power supply, ground.
Bidirectional I/O line. Software instructions deter-
Pull-high mine the CMOS output, Schmitt trigger input with or
10 PD0/PWM I/O PD0 or without a pull-high resistor (determined by pull-high
PWM options: bit option). The PWM output function is
pin-shared with PD0 (dependent on PWM options).
11 RES I ¾ Schmitt trigger reset input. Active low.
12 VDD ¾ ¾ Positive power supply
OSC1, OSC2 are connected to an RC network or a
13 OSC1 I Crystal Crystal (determined by ROM code option) for the in-
14 OSC2 O or RC ternal system clock. In the case of RC operation, OSC2
is the output terminal for 1/4 system clock.
Note: These are stress ratings only. Stresses exceeding the range specified under ²Absolute Maxi-
mum 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 expo-
sure to extreme conditions may affect device reliability.
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
VDD1 Operating Voltage ¾ fSYS=4MHz 3.3 ¾ 5.5 V
VDD2 Operating Voltage ¾ fSYS=8MHz 4.5 ¾ 5.5 V
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
3.3V ¾ 40 60 80 kW
RPH Pull-high Resistance
5V ¾ 10 30 50 kW
EAD A/D Conversion Error 5V ¾ ¾ ±0.5 ±1 LSB
Test Conditions
Symbol Parameter Min. Typ. Max. Unit
VDD Conditions
Note: *tSYS=1/fSYS
Functional Description
When executing a jump instruction, conditional
Execution flow
skip execution, loading PCL register, subrou-
The system clock for the microcontroller is de- tine call, initial reset, internal interrupt, exter-
rived from either a crystal or an RC oscillator. nal interrupt or return from subroutine, the PC
The system clock is internally divided into four manipulates the program transfer by loading
non-overlapping clocks. One instruction cycle the address corresponding to each instruction.
consists of four system clock cycles.
The conditional skip is activated by instruc-
Instruction fetching and execution are tions. Once the condition is met, the next in-
pipelined in such a way that a fetch takes an in- struction, fetched during the current
struction cycle while decoding and execution instruction execution, is discarded and a
takes the next instruction cycle. However, the dummy cycle replaces it to get the proper in-
pipelining scheme causes each instruction to ef- struction. Otherwise proceed with the next in-
fectively execute in a cycle. If an instruction struction.
changes the program counter, two cycles are re-
The lower byte of the program counter (PCL) is
quired to complete the instruction.
a readable and writeable register (06H).
Moving data into the PCL performs a short
Program counter - PC jump. The destination will be within 256 loca-
The program counter (PC) controls the se- tions.
quence in which the instructions stored in pro- When a control transfer takes place, an addi-
gram PROM are executed and its contents tional dummy cycle is required.
specify full range of program memory.
After accessing a program memory word to fetch Program memory - PROM
an instruction code, the contents of the program
The program memory is used to store the pro-
counter are incremented by one. The program
gram instructions which are to be executed. It
counter then points to the memory word contain-
also contains data, table, and interrupt entries,
ing the next instruction code.
and is organized into 2048´14 bits, addressed
by the program counter and table 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
*10 *9 *8 *7 *6 *5 *4 *3 *2 *1 *0
Initial Reset 0 0 0 0 0 0 0 0 0 0 0
External Interrupt 0 0 0 0 0 0 0 0 1 0 0
Timer/Event Counter Overflow 0 0 0 0 0 0 0 1 0 0 0
A/D Converter Interrupt 0 0 0 0 0 0 0 1 1 0 0
Skip PC+2
Loading PCL *10 *9 *8 @7 @6 @5 @4 @3 @2 @1 @0
Jump, Call Branch #10 #9 #8 #7 #6 #5 #4 #3 #2 #1 #0
Return from Subroutine S10 S9 S8 S7 S6 S5 S4 S3 S2 S1 S0
Program counter
Note: *10~*0: Program counter bits S10~S0: Stack register bits
#10~#0: Instruction code bits @7~@0: PCL bits
well-defined, the other bits of the table word a subroutine or an interrupt routine, signaled
are transferred to the lower portion of TBLH, by a return instruction (RET or RETI), the pro-
and the remaining 2 bits are read as "0". The gram counter is restored to its previous value
Table Higher-order byte register (TBLH) is from the stack. After a chip reset, the SP will
read only. The table pointer (TBLP) is a point to the top of the stack.
read/write register (07H), which indicates the If the stack is full and a non-masked interrupt
table location. Before accessing the table, the takes place, the interrupt request flag will be
location must be placed in TBLP. The TBLH recorded but the acknowledgment will be inhib-
is read only and cannot be restored. If the ited. When the stack pointer is decremented (by
main routine and the ISR (Interrupt Service RET or RETI), the interrupt will be serviced.
Routine) both employ the table read instruc- This feature prevents stack overflow allowing
tion, the contents of the TBLH in the main the programmer to use the structure more eas-
routine are likely to be changed by the table ily. In a similar case, if the stack is full and a
read instruction used in the ISR. Errors can "CALL" is subsequently executed, stack over-
occur. In other words, using the table read in- flow occurs and the first entry will be lost (only
struction in the main routine and the ISR si- the most recent 6 return addresses are stored).
multaneously should be avoided. However, if
the table read instruction has to be applied in
Data memory - RAM
both the main routine and the ISR, the inter-
rupt is supposed to be disabled prior to the ta- The data memory is designed with 85´8 bits.
ble read instruction. It will not be enabled The data memory is divided into two func-
until the TBLH has been backed up. All table tional groups: special function registers and
related instructions require two cycles to com- general purpose data memory (64´8). Most are
plete the operation. These areas may function read/write, but some are read only.
as normal program memory depending upon The special function registers include the indi-
the requirements. rect addressing register (00H), timer/event
counter (TMR;0DH), timer/event counter con-
Stack register - STACK trol register (TMRC;0EH), program counter
This is a special part of the memory which is lower-order byte register (PCL;06H), memory
used to save the contents of the program coun- pointer register (MP;01H), accumulator
ter (PC) only. The stack is organized into 6 lev- (ACC;05H), table pointer (TBLP;07H), table
els and is neither part of the data nor part of the higher-order byte register (TBLH;08H), status
program space, and is neither readable nor register (STATUS;0AH), interrupt control reg-
writeable. The activated level is indexed by the ister (INTC;0BH), PWM data register
stack pointer (SP) and is neither readable nor (PWM;1AH), the A/D result lower-order byte
writeable. At a subroutine call or interrupt ac- register (ADRL;20H), the A/D result
knowledgment, the contents of the program higher-order byte register (ADRH;21H), the
counter are pushed onto the stack. At the end of A/D control register (ADCR;22H), the A/D
Table Location
Instruction
*10 *9 *8 *7 *6 *5 *4 *3 *2 *1 *0
TABRDC [m] P10 P9 P8 @7 @6 @5 @4 @3 @2 @1 @0
TABRDL [m] 1 1 1 @7 @6 @5 @4 @3 @2 @1 @0
Table location
Note: *10~*0: Table location bits P10~P8: Current program counter bits
@7~@0: Table pointer bits
clock setting register (ACSR;23H), I/O regis- All of the data memory areas can handle arith-
ters (PA;12H, PB;14H, PD;18H) and I/O con- metic, logic, increment, decrement and rotate
trol registers (PAC;13H, PBC;15H, PDC;19H). operations directly. Except for some dedicated
The remaining space before the 40H is re- bits, each bit in the data memory can be set and
served for future expanded usage and reading reset by "SET [m].i" and "CLR [m].i". They are
these locations will get "00H". The general also indirectly accessible through memory
purpose data memory, addressed from 40H to pointer register (MP;01H).
7FH, is used for data and control information
under instruction commands. Indirect addressing register
status information and controls the operation ternal timer/event counter interrupt and A/D
sequence. converter interrupts. The Interrupt Control
With the exception of the TO and PD flags, Register (INTC;0BH) contains the interrupt
bits in the status register can be altered by control bits to set the enable/disable and the in-
instructions like most other registers. Any terrupt request flags.
data written into the status register will not Once an interrupt subroutine is serviced, all
change the TO or PD flag. In addition opera- the other interrupts will be blocked (by clearing
tions related to the status register may give the EMI bit). This scheme may prevent any fur-
different results from those intended. The ther interrupt nesting. Other interrupt re-
TO flag can be affected only by system quests may happen during this interval but
power-up, a WDT time-out or executing the only the interrupt request flag is recorded. If a
"CLR WDT" or "HALT" instruction. The PD certain interrupt requires servicing within the
flag can be affected only by executing the service routine, the EMI bit and the correspond-
"HALT" or "CLR WDT" instruction or a sys- ing bit of INTC may be set to allow interrupt
tem power-up. nesting. If the stack is full, the interrupt request
The Z, OV, AC and C flags generally reflect the will not be acknowledged, even if the related in-
status of the latest operations. terrupt is enabled, until the SP is decremented.
If immediate service is desired, the stack must
In addition, on entering the interrupt sequence be prevented from becoming full.
or executing the subroutine call, the status reg-
ister will not be pushed onto the stack automat- All these kinds of interrupts have a wake-up ca-
ically. If the contents of the status are pability. As an interrupt is serviced, a control
important and if the subroutine can corrupt the transfer occurs by pushing the program counter
status register, precautions must be taken to onto the stack, followed by a branch to a sub-
save it properly. routine at specified location in the program
memory. Only the program counter is pushed
Interrupt onto the stack. If the contents of the register or
status register (STATUS) are altered by the in-
The device provides an external interrupt, in- terrupt service program which corrupts the de-
Labels Bits Function
C is set if the operation results in a carry during an addition operation or if a bor-
C 0 row 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 the operation results in a carry out of the low nibbles in addition or no
AC 1 borrow from the high nibble into the low nibble in subtraction; otherwise AC is
cleared.
Z is set if the result of an arithmetic or logic operation is zero; otherwise Z is
Z 2
cleared.
OV is set if the operation results in a carry into the highest-order bit but not a
OV 3
carry out of the highest-order bit, or vice versa; otherwise OV is cleared.
PD is cleared by system power-up or executing the "CLR WDT" instruction. PD
PD 4
is set by executing the "HALT" instruction.
TO is cleared by system power-up or executing the "CLR WDT" or "HALT" in-
TO 5
struction. TO is set by a WDT time-out.
¾ 6, 7 Unused bit, read as "0"
Status register
sired control sequence, the contents should be cleared to disable further interrupts.
saved in advance. During the execution of an interrupt subroutine,
External interrupts are triggered by a high to other interrupt acknowledgments are held until
low transition of INT and the related interrupt the "RETI" instruction is executed or the EMI
request flag (EIF; bit 4 of INTC) will be set. bit and the related interrupt control bit are set to
When the interrupt is enabled, the stack is not 1 (of course, if the stack is not full). To return
full and the external interrupt is active, a sub- from the interrupt subroutine, "RET" or "RETI"
routine call to location 04H will occur. The in- may be invoked. RETI will set the EMI bit to en-
terrupt request flag (EIF) and EMI bits will be able an interrupt service, but RET will not.
cleared to disable other interrupts. Interrupts, occurring in the interval between
The internal timer/event counter interrupt is the rising edges of two consecutive T2 pulses,
initialized by setting the timer/event counter will be serviced on the latter of the two T2
interrupt request flag (TF; bit 5 of INTC), pulses, if the corresponding interrupts are en-
caused by a timer overflow. When the interrupt abled. In the case of simultaneous requests the
is enabled, the stack is not full and the TF bit is following table shows the priority that is ap-
set, a subroutine call to location 08H will occur. plied. These can be masked by resetting the
The related interrupt request flag (TF) will be EMI bit.
reset and the EMI bit cleared to disable further
No. Interrupt Source Priority Vector
interrupts.
a External Interrupt 1 04H
The A/D converter interrupt is initialized by
setting the A/D converter request flag (ADF; bit Timer/event
b 2 08H
6 of INTC), caused by an end of A/D conversion. Counter Overflow
When the interrupt is enabled, the stack is not A/D Converter
full and the ADF is set, a subroutine call to loca- c 3 0CH
Interrupt
tion 0CH will occur. The related interrupt re-
quest flag (ADF) will be reset and the EMI bit The timer/event counter interrupt request flag
(TF), external interrupt request flag (EIF), A/D
Register Bit No. Label Function
Controls the master (global) interrupt
0 EMI
(1= enabled; 0= disabled)
Controls the external interrupt
1 EEI
(1= enabled; 0= disabled)
Controls the timer/event counter interrupt
2 ETI
(1= enabled; 0= disabled)
Controls the A/D converter interrupt
INTC 3 EADI
(1= enabled; 0= disabled)
(0BH)
External interrupt request flag
4 EIF
(1= active; 0= inactive)
Internal timer/event counter request flag
5 TF
(1= active; 0= inactive)
A/D converter request flag
6 ADF
(1= active; 0= inactive)
7 ¾ Unused bit, read as "0"
INTC register
S y s te m C lo c k /4
R O M W D T P r e s c a le r
C o d e fs W D T T im e - o u t
8 - b it C o u n te r 7 - b it C o u n te r T T 1 5 1 6
O p tio n fs/2 ~ fs/2
W D T S e le c t
O S C C L R W D T
Watchdog Timer
Timer can be disabled by a ROM code option. If · The contents of the on chip RAM and regis-
the Watchdog Timer is disabled, all the execu- ters remain unchanged.
tions related to the WDT result in no operation. · WDT will be cleared and recounted again (if
Once the internal oscillator (RC oscillator with the WDT clock is from the WDT oscillator).
a period of 72ms/5V normally) is selected, it is · All of the I/O ports maintain their original sta-
first divided by 256 (8-stage) to get the nominal tus.
time-out period of approximately 18.6ms/5V. · The PD flag is set and the TO flag is cleared.
This time-out period may vary with tempera-
tures, VDD and process variations. By invoking The system can leave the HALT mode by means
the WDT prescaler, longer time-out periods can of an external reset, an interrupt, an external
be realized and the maximum time-out period falling edge signal on port A or a WDT overflow.
is 2.3s/5V~4.7s/5V seconds. If the WDT oscilla- An external reset causes a device initialization
tor is disabled, the WDT clock may still come and the WDT overflow performs a ²warm re-
from the instruction clock and operate in the set². After the TO and PD flags are examined,
same manner except that in the HALT state the the reason for chip reset can be determined.
WDT may stop counting and lose its protecting The PD flag is cleared by system power-up or
purpose. In this situation the logic can only be executing the ²CLR WDT² instruction and is
restarted by external logic. set when executing the ²HALT² instruction.
If the device operates in a noisy environment, us- The TO flag is set if the WDT time-out occurs,
ing the on-chip RC oscillator (WDT OSC) is and causes a wake-up that only resets the PC
strongly recommended, since the HALT will stop and SP; the others keep their original status.
the system clock. The port A wake-up and interrupt methods can
The WDT overflow under normal operation will be considered as a continuation of normal exe-
initialize ²chip reset² and set the status bit cution. Each bit in port A can be independently
²TO². But in the HALT mode, the overflow will selected to wake up the device by the ROM code
initialize a ²warm reset², and only the PC and option. Awakening from an I/O port stimulus,
SP are reset to zero. To clear the contents of the program will resume execution of the next
WDT, three methods are adopted; external re- instruction. If it is awakening from an inter-
set (a low level to RES), software instruction rupt, two sequences may happen. If the related
and a "HALT" instruction. The software in- interrupt is disabled or the interrupt is enabled
struction include ²CLR WDT² and the other set but the stack is full, the program will resume
- ²CLR WDT1² and ²CLR WDT2². Of these two execution at the next instruction. If the inter-
types of instruction, only one can be active de- rupt is enabled and the stack is not full, the reg-
pending on the ROM code option - ²CLR WDT ular interrupt response takes place. If an
times selection option². If the ²CLR WDT² is se- interrupt request flag is set to ²1² before enter-
lected (i.e. CLRWDT times equal one), any exe- ing the HALT mode, the wake-up function of
cution of the ²CLR WDT² instruction will clear the related interrupt will be disabled. Once a
the WDT. In the case that ²CLR WDT1² and wake-up event occurs, it takes 1024 tSYS (sys-
²CLR WDT2² are chosen (i.e. CLRWDT times tem clock period) to resume normal operation.
equal two), these two instructions must be exe- In other words, a dummy period will be inserted
cuted to clear the WDT; otherwise, the WDT after wake-up. If the wake-up results from an
may reset the chip as a result of time-out. interrupt acknowledgment, the actual inter-
rupt subroutine execution will be delayed by
one or more cycles. If the wake-up results in the
Power down operation - HALT
next instruction execution, this will be executed
The HALT mode is initialized by the ²HALT² immediately after the dummy period is fin-
instruction and results in the following... ished.
· The system oscillator will be turned off but To minimize power consumption, all the I/O
the WDT oscillator keeps running (if the pins should be carefully managed before enter-
WDT oscillator is selected). ing the HALT status.
Reset V D D
V D D
R E S
tS S T
S S T T im e - o u t
C h ip R e s e t
TMRC register
P W M
(6 + 2 ) c o m p a re to P D 0 c ir c u it
fS Y S 8 - s ta g e p r e s c a le r
f IN T D a ta B u s
8 -1 M U X
T M 1
T M 0 T im e r /E v e n t C o u n te r R e lo a d
P S C 2 ~ P S C 0 T M R P r e lo a d R e g is te r
T E
P u ls e W id th T im e r /E v e n t O v e r flo w
T M 1 M e a s u re m e n t C o u n te r
T M 0 to In te rru p t
M o d e C o n tro l
T O N
1 /2 P F D
Timer/Event Counter
The TM0, TM1 bits define the operating mode. counter is turned on, data written to it will only
The event count mode is used to count external be kept in the timer/event counter preload reg-
events, which means the clock source comes from ister. The timer/event counter will still operate
an external (TMR) pin. The timer mode functions until overflow occurs. When the timer/event
as a normal timer with the clock source coming counter (reading TMR) is read, the clock will be
from the fINT clock. The pulse width measurement blocked to avoid errors. As clock blocking may re-
mode can be used to count the high or low level du- sults in a counting error, this must be taken into
ration of the external signal (TMR). The counting consideration by the programmer.
is based on the fINT. The bit0~bit2 of the TMRC can be used to de-
In the event count or timer mode, once the fine the pre-scaling stages of the internal clock
timer/event counter starts counting, it will count sources of timer/event counter. The definitions
from the current contents in the timer/event are as shown. The overflow signal of
counter to FFH. Once overflow occurs, the coun- timer/event counter can be used to generate the
ter is reloaded from the timer/event counter PFD signal. The timer prescaler is also used as
preload register and generates the interrupt re- the PWM counter.
quest flag (TF; bit 5 of INTC) at the same time.
In the pulse width measurement mode with Input/output ports
the TON and TE bits equal to one, once the There are 13 bidirectional input/output lines in
TMR has received a transient from low to high the microcontroller, labeled as PA, PB and PD,
(or high to low if the TE bits is ²0²) it will start which are mapped to the data memory of [12H],
counting until the TMR returns to the original [14H] and [18H] respectively. All of these I/O
level and resets the TON. The measured result ports can be used for input and output opera-
will remain in the timer/event counter even if tions. For input operation, these ports are
the activated transient occurs again. In other non-latching, that is, the inputs must be ready at
words, only one cycle measurement can be the T2 rising edge of instruction ²MOV A,[m]²
done. Until setting the TON, the cycle measure- (m=12H, 14H or 18H). For output operation, all
ment will function again as long as it receives the data is latched and remains unchanged until
further transient pulse. Note that, in this oper- the output latch is rewritten.
ating mode, the timer/event counter starts Each I/O line has its own control register (PAC,
counting not according to the logic level but ac- PBC, PDC) to control the input/output configu-
cording to the transient edges. In the case of ration. With this control register, CMOS output
counter overflows, the counter is reloaded from or Schmitt trigger input with or without
the timer/event counter preload register and is- pull-high resistor structures can be reconfig-
sues the interrupt request just like the other ured dynamically (i.e. on-the-fly) under soft-
two modes. To enable the counting operation, ware control. To function as an input, the
the timer ON bit (TON; bit 4 of TMRC) should corresponding latch of the control register must
be set to 1. In the pulse width measurement write ²1². The input source also depends on the
mode, the TON will be cleared automatically af- control register. If the control register bit is ²1²,
ter the measurement cycle is completed. But in the input will read the pad state. If the control
the other two modes the TON can only be reset register bit is ²0², the contents of the latches
by instructions. The overflow of the timer/event will move to the internal bus. The latter is pos-
counter is one of the wake-up sources. No mat-
sible in the ²read-modify-write² instruction.
ter what the operation mode is, writing a 0 to
ETI can disable the interrupt service. For output function, CMOS is the only configu-
ration. These control registers are mapped to
In the case of timer/event counter OFF condi-
locations 13H, 15H and 19H.
tion, writing data to the timer/event counter
preload register will also reload that data to After a chip reset, these input/output lines re-
the timer/event counter. But if the timer/event main at high levels or floating state (dependent
on pull-high options). Each bit of these in- erated by timer/event counter overflow signal.
put/output latches can be set or cleared by ²SET The input mode always remaining its original
[m].i² and ²CLR [m].i² (m=12H, 14H or 18H) in- functions. Once the PFD option is selected, the
structions. PFD output signal is controlled by PA3 data
Some instructions first input data and then fol- register only. Writing ²1² to PA3 data register
low the output operations. For example, ²SET will enable the PFD output function and writ-
[m].i², ²CLR [m].i², ²CPL [m]², ²CPLA [m]² read ing ²0² will force the PA3 to remain at ²0². The
the entire port states into the CPU, execute the I/O functions of PA3 are shown below.
defined operations (bit-operation), and then I/O I/P O/P I/P O/P
write the results back to the latches or the accu- Mode (Normal) (Normal) (PFD) (PFD)
mulator. Logical Logical Logical PFD
PA3
Each line of port A has the capability of wak- Input Output Input (Timer on)
ing-up the device. The highest 4-bit of port B and
7 bits of port D are not physically implemented; Note: The PFD frequency is the timer/event
on reading them a ²0² is returned whereas writ- counter overflow frequency divided by 2.
ing then results in a no-operation. See Applica- The PA5 and PA4 are pin-shared with INT and
tion note. TMR pins respectively.
Each I/O line has a pull-high option. Once the The PB can also be used as A/D converter in-
pull-high option is selected, the I/O line has a puts. The A/D function will be described later.
pull-high resistor, otherwise, there¢s none. There is a PWM function shared with PD0. If
Take note that a non-pull-high I/O line operat- the PWM function is enabled, the PWM signal
ing in input mode will cause a floating state. will appear on PD0 (if PD0 is operating in out-
The PA3 is pin-shared with the PFD signal. If put mode). The I/O functions of PD0 are as
the PFD option is selected, the output signal in shown.
output mode of PA3 will be the PFD signal gen-
V D D
C o n tr o l B it P U
D a ta B u s D Q
W r ite C o n tr o l R e g is te r C K Q B
C h ip R e s e t S P A 0 ~ P A 2
P A 3 /P F D
P A 4 /T M R
R e a d C o n tr o l R e g is te r P A 5 /IN T
D a ta B it P A 6 , P A 7
D Q P B 0 /A N 0 ~ P B 3 /A N 3
P D 0 /P W M
W r ite D a ta R e g is te r C K Q B
S
M
P A 3 U
(P D 0 o r P W M ) X
P F D
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
I/O I/P O/P I/P O/P In a PWM cycle, the duty cycle of each modula-
Mode (Normal) (Normal) (PWM) (PWM) tion cycle is shown in the table.
Logical Logical Logical Parameter AC (0~3) Duty Cycle
PD0 PWM
Input Output Input DC + 1
i<AC
It is recommended that unused or not bonded Modulation cycle i 64
out I/O lines should be set as output pins by (i=0~3) DC
software instruction to avoid consuming power i³AC
64
under input floating state.
The modulation frequency, cycle frequency and
PWM cycle duty of the PWM output signal are sum-
The microcontroller provides 1 channel (6+2) marized in the following table.
bits PWM output shared with PD0. The PWM PWM
channel has its data register denoted as PWM PWM Cycle PWM Cycle
Modulation
(1AH). The frequency source of the PWM coun- Frequency Duty
Frequency
ter comes from fSYS. The PWM register is an
eight bits register. The waveforms of PWM out- fSYS/64 fSYS/256 [PWM]/256
put are as shown. Once the PD0 is selected as
the PWM output and the output function of A/D converter
PD0 is enabled (PDC.0=²0²), writing 1 to PD0 The 4 channels and 9-bit resolution A/D (8-bit
data register will enable the PWM output func- accuracy) converter are implemented in this
tion and writing ²0² will force the PD0 to stay microcontroller. The reference voltage is VDD.
at ²0². The A/D converter contains 4 special registers
A PWM cycle is divided into four modulation cy- which are; ADRL (20H), ADRH (21H), ADCR
cles (modulation cycle 0~modulation cycle 3). (22H) and ACSR (23H). The ADRH and ADRL
Each modulation cycle has 64 PWM input clock are A/D result register higher-order byte and
period. In a (6+2) bit PWM function, the con- lower-order byte and are read-only. After the
tents of the PWM register is divided into two A/D conversion is completed, the ADRH and
groups. Group 1 of the PWM register is denoted ADRL should be read to get the conversion re-
by DC which is the value of PWM.7~PWM.2. sult data. The ADCR is an A/D converter con-
The group 2 is denoted by AC which is the value trol register, which defines the A/D channel
of PWM.1~PWM.0. number, analog channel select, start A/D con-
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
P W M c y c le : 2 5 6 /fS Y S
PWM
version control bit and the end of A/D conver- PB line is selected as an analog input, the I/O
sion flag. If the users want to start an A/D functions and pull-high resistor of this I/O line
conversion, define PB configuration, select the are disabled, and the A/D converter circuit is
converted analog channel, and give START bit power on. The EOC bit (bit6 of the ADCR) is
a raising edge and a falling edge (0®1®0). At end of A/D conversion flag. Check this bit to
the end of A/D conversion, the EOC bit is know when A/D conversion is completed. The
cleared and an A/D converter interrupt occurs START bit of the ADCR is used to begin the
(if the A/D converter interrupt is enabled). The conversion of A/D converter. Give START bit a
ACSR is A/D clock setting register, which is raising edge and falling edge that means the
used to select the A/D clock source. A/D conversion has started. In order to ensure
The A/D converter control register is used to the A/D conversion is completed, the START
control the A/D converter. The bit2~bit0 of the should stay at ²0² until the EOC is cleared to
ADCR are used to select an analog input chan- ²0² (end of A/D conversion).
nel. There are a total of four channels to select. The bit 7 of the ACSR is used for testing pur-
The bit5~bit3 of the ADCR are used to set PB pose only. It can not be used for the users. The
configurations. PB can be an analog input or as bit1 and bit0 of the ACSR are used to select A/D
digital I/O line decided by these 3 bits. Once a clock sources.
Bits Function
ADCS1, ADCS0: Select the A/D converter clock source.
0, 0: fSYS/2
ADCS0 0
0, 1: fSYS/8
ADCS1 1
1, 0: fSYS/32
1, 1: Undefined, cannot be used.
¾ 2~6 Unused bit, read as ²0².
TEST 7 For internal test only.
When the A/D conversion is completed, the A/D · The LVR uses the ²OR² function with the exter-
interrupt request flag is set. The EOC bit is set nal RES signal to perform chip reset.
to ²1² when the START bit is set from ²0² to ²1². The relationship between VDD and VLVR is
Bit Bit Bit Bit Bit Bit Bit Bit shown below.
Register
7 6 5 4 3 2 1 0
V D D V O P R
ADRL D0 ¾ ¾ ¾ ¾ ¾ ¾ ¾ 5 .5 V 5 .5 V
ADRH D8 D7 D6 D5 D4 D3 D2 D1
3 .3 V
Low voltage reset - LVR
3 .0 V
The microcontroller provides low voltage reset
circuit in order to monitor the supply voltage of
the device. If the supply voltage of the device is
within the range 0.9V~3.3V, such as changing a 0 .9 V
battery, the LVR will automatically reset the Note: VOPR is the voltage range for proper chip
device internally. operation at 4MHz system clock.
The LVR includes the following specifications:
· The low voltage (0.9V~3.3V) has to remain in
their original state to exceed 1ms. If the low
voltage state does not exceed 1ms, the LVR
will ignore it and do not perform a reset func-
tion.
S T A R T
E O C
*7 6 T A D *7 6 T A D
P C R 0 ~ P C R 2 0 0 0 B 1 0 0 B 1 0 0 B 0 0 0 B
A C S 0 ~ A C S 2 0 0 0 B 0 1 0 B 0 0 0 B **X X X B
P o w e r S ta rt o f A /D S ta rt o f A /D 1 : A ll P B lin e is d ig ita l in p u t
O n c o n v e r s io n c o n v e r s io n
R e s e t 2 : A /D c o n v e r te r is p o w e r o ff
R e s e t A /D R e s e t A /D to r e d u c e p o w e r c o n s u m p tio n
c o n v e rte r c o n v e rte r
1 : D e fin e P B c o n fig u r a tio n E n d o f A /D E n d o f A /D
2 : S e le c t a n a lo g c h a n n e l c o n v e rte r c o n v e rte r
***3 : S e le c t A D C c lo c k
(E x a m p le : 4 c h a n n e l, A N 2 ,
fS Y S /8 )
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
Application Circuits
P A 0 , P A 1 1 2 V
O S C 1
P A 3 /P F D
O S C
C ir c u it P A 4 /T M R
P A 5 /IN T
O S C 2
S e e b e lo w P A 6 , P A 7
5 V H T 4 6 R 4 7 5 V
P D 0 /P W M
V D D
1 0 0 k W V R t
P B 0 /A N 0
0 .1 m F V b a t
R E S P B 1 /A N 1
0 .1 m F
V S S
P A 2
If
P B 2 /A N 2
P B 3 /A N 3
N o te : T h e r e s is ta n c e a n d c a p a c ita n c e fo r r e s e t c ir c u it s h o u ld b e d e s ig n e d
to e n s u r e th a t th e V D D is s ta b le a n d r e m a in s in a v a lid r a n g e o f th e
o p e r a tin g v o lta g e b e fo r e b r in g in g R E S to h ig h .
V b a t: 3 .6 V ( N iC d , N iM H ) o r 4 .1 V ( L i+ )
1 2 V
O S C 1 P A 0
O S C P A 3 /P F D
C ir c u it P A 4 /T M R
O S C 2 P A 5 /IN T
S e e b e lo w
P D 0 /P W M
5 V
V D D
H T 4 6 R 4 7
1 0 0 k W C H 0
P A 6
0 .1 m F R E S
0 .1 m F C H 1
P A 7
V S S V b a t0
P B 0 /A N 0
V b a t1
P B 1 /A N 1
P B 3 /A N 3 P A 1
P A 2
If
P B 2 /A N 2
V D D
2 7 0 p F
O S C 1 R C s y s te m o s c illa to r
R O S C 3 0 k W < R O S C < 7 5 0 k W
fS Y S /4
O S C 2
O S C 1
C 1 C r y s ta l s y s te m o s c illa to r
C 1 = C 2 = 3 0 0 p F , if fS Y S < 1 M H z
O S C 2 O th e r w is e , C 1 = C 2 = 0
C 2
V b a t0 , V b a t1 : 3 .6 V ( N iC d , N iM H ) o r 4 .1 V ( L i+ )
Instruction Flag
Mnemonic Description
Cycle Affected
Rotate
RRA [m] Rotate data memory right with result in ACC 1 None
RR [m] Rotate data memory right 1(1) None
RRCA [m] Rotate data memory right through carry with result in 1 C
ACC
RRC [m] Rotate data memory right through carry 1(1) C
RLA [m] Rotate data memory left with result in ACC 1 None
RL [m] Rotate data memory left 1(1) None
RLCA [m] Rotate data memory left through carry with result in 1 C
ACC
RLC [m] Rotate data memory left through carry 1(1) C
Data Move
MOV A,[m] Move data memory to ACC 1 None
MOV [m],A Move ACC to data memory 1(1) None
MOV A,x Move immediate data to ACC 1 None
Bit Operation
CLR [m].i Clear bit of data memory 1(1) None
SET [m].i Set bit of data memory 1(1) None
Branch
JMP addr Jump unconditionally 2 None
SZ [m] Skip if data memory is zero 1(2) None
SZA [m] Skip if data memory is zero with data movement to 1(2) None
ACC
SZ [m].i Skip if bit i of data memory is zero 1(2) None
SNZ [m].i Skip if bit i of data memory is not zero 1(2) None
SIZ [m] Skip if increment data memory is zero 1(3) None
SDZ [m] Skip if decrement data memory is zero 1(3) None
SIZA [m] Skip if increment data memory is zero with result in 1(2) None
ACC
SDZA [m] Skip if decrement data memory is zero with result in 1(2) None
ACC
CALL addr Subroutine call 2 None
RET Return from subroutine 2 None
RET A,x Return from subroutine and load immediate data to 2 None
ACC
RETI Return from interrupt 2 None
Instruction Flag
Mnemonic Description
Cycle Affected
Table Read
TABRDC [m] Read ROM code (current page) to data memory and 2(1) None
TBLH
TABRDL [m] Read ROM code (last page) to data memory and TBLH 2(1) None
Miscellaneous
NOP No operation 1 None
CLR [m] Clear data memory 1(1) None
SET [m] Set data memory 1(1) None
CLR WDT Clear Watchdog Timer 1 TO,PD
CLR WDT1 Pre-clear Watchdog Timer 1 TO(4),PD(4)
CLR WDT2 Pre-clear Watchdog Timer 1 TO(4),PD(4)
SWAP [m] Swap nibbles of data memory 1(1) None
SWAPA [m] Swap nibbles of data memory with result in ACC 1 None
HALT Enter power down mode 1 TO,PD
Instruction Definition
CPLA [m] Complement data memory and place result in the accumulator.
Description Each bit of the specified data memory is logically complemented (1's comple-
ment). 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)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ Ö ¾ ¾
DECA [m] Decrement data memory and place result in the accumulator.
Description Data in the specified data memory is decremented by 1, leaving the result in
the accumulator. The contents of the data memory remain unchanged.
Operation ACC ¬ [m]-1
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ Ö ¾ ¾
INCA [m] Increment data memory and place result in the accumulator.
Description Data in the specified data memory is incremented by 1, leaving the result in
the accumulator. The contents of the data memory remain unchanged.
Operation ACC ¬ [m]+1
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ Ö ¾ ¾
NOP No operation.
Description No operation is performed. Execution continues with the next instruction.
Operation PC ¬ PC+1
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
RLA [m] Rotate data memory left and place result in the accumulator.
Description Data in the specified data memory is rotated 1 bit left with bit 7 rotated into
bit 0, leaving the rotated result in the accumulator. The contents of the data
memory remain unchanged.
Operation ACC.(i+1) ¬ [m].i; [m].i:bit i of the data memory (i=0~6)
ACC.0 ¬ [m].7
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
RLCA [m] Rotate left through carry and place result in the accumulator.
Description Data in the specified data memory and the carry flag are rotated 1 bit left. Bit
7 replaces the carry bit and the original carry flag is rotated into bit 0 posi-
tion. The rotated result is stored in the accumulator but the contents of the
data memory remain unchanged.
Operation ACC.(i+1) ¬ [m].i; [m].i:bit i of the data memory (i=0~6)
ACC.0 ¬ C
C ¬ [m].7
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ Ö
RRCA [m] Rotate right through carry and place result in the accumulator.
Description Data of the specified data memory and the carry flag are rotated 1 bit right.
Bit 0 replaces the carry bit and the original carry flag is rotated into the bit 7
position. The rotated result is stored in the accumulator. The contents of the
data memory remain unchanged.
Operation ACC.i ¬ [m].(i+1); [m].i:bit i of the data memory (i=0~6)
ACC.7 ¬ C
C ¬ [m].0
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ Ö
SBC A,[m] Subtract data memory and carry from the accumulator.
Description The contents of the specified data memory and the complement of the carry
flag are subtracted from the accumulator, leaving the result in the accumula-
tor.
Operation ACC ¬ ACC+[m]+C
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ Ö Ö Ö Ö
SBCM A,[m] Subtract data memory and carry from the accumulator.
Description The contents of the specified data memory and the complement of the carry
flag are subtracted from the accumulator, leaving the result in the data
memory.
Operation [m] ¬ ACC+[m]+C
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ Ö Ö Ö Ö
SDZA [m] Decrement data memory and place result in ACC, skip if 0.
Description The contents of the specified data memory are decremented by 1. If the result
is 0, the next instruction is skipped. The result is stored in the accumulator
but the data memory remains unchanged. If the result is 0, the following in-
struction, fetched during the current instruction execution, is discarded and
a dummy cycle is replaced to get the proper instruction (2 cycles). Otherwise
proceed with the next instruction (1 cycle).
Operation Skip if ([m]-1)=0, ACC ¬ ([m]-1)
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
SIZA [m] Increment data memory and place result in ACC, skip if 0.
Description The contents of the specified data memory are incremented by 1. If the result
is 0, the next instruction is skipped and the result is stored in the accumula-
tor. The data memory remains unchanged. If the result is 0, the following in-
struction, fetched during the current instruction execution, is discarded and
a dummy cycle is replaced to get the proper instruction (2 cycles). Otherwise
proceed with the next instruction (1 cycle).
Operation Skip if ([m]+1)=0, ACC ¬ ([m]+1)
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
SWAPA [m] Swap data memory and place result in the accumulator.
Description The low-order and high-order nibbles of the specified data memory are inter-
changed, writing the result to 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)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
TABRDC [m] Move the ROM code (current page) to TBLH and data memory.
Description The low byte of ROM code (current page) addressed by the table pointer
(TBLP) is moved to the specified data memory and the high byte transferred
to TBLH directly.
Operation [m] ¬ ROM code (low byte)
TBLH ¬ ROM code (high byte)
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
TABRDL [m] Move the ROM code (last page) to TBLH and data memory.
Description The low byte of ROM code (last page) addressed by the table pointer (TBLP)
is moved to the data memory and the high byte transferred to TBLH directly.
Operation [m] ¬ ROM code (low byte)
TBLH ¬ ROM code (high byte)
Affected flag(s)
TC2 TC1 TO PD OV Z AC C
¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾