architecture with an 8032 microcontroller core.
The uPSD321X Devices of Flas h PSDs feat ure
dual banks of Flash memory, SRAM, general
purpose I/O and programmable logic, supervisory functions and access via I
PWM channels, and an on-board 8032 microcontroller core, with two UARTs, three 16-bit
Timer/Counters and two External Interrupts. As
with other Flash PSD families, the uPSD321X
Devices are also in-system programmable (ISP)
via a JTAG ISP interface.
■ Large 2KByte SRAM with battery back-up
option
■ Dual bank Flash memories
– 64KByte ma in Flash me mory
– 16KByte secondary Flash memory
PA035I/OGeneral I/O port pin
PA134I/OGeneral I/O port pin
PA232I/OGeneral I/O port pin
PA328I/OGeneral I/O port pin
PA426I/OGeneral I/O port pin
PA524I/OGeneral I/O port pin
PA622I/OGeneral I/O port pin
PA721I/OGeneral I/O port pin
PB080I/OGeneral I/O port pin
PB178I/OGeneral I/O port pin
PB276I/OGeneral I/O port pin
PB374I/OGeneral I/O port pin
PB473I/OGeneral I/O port pin
PB572I/OGeneral I/O port pin
PB667I/OGeneral I/O port pin
PB766I/OGeneral I/O port pin
1. PLD Macro-cell outputs
2. PLD inputs
3. Latched Address Out (A0-A7)
4. Peripheral I/O Mode
1. PLD Macro-cell outputs
2. PLD inputs
3. Latched Address Out (A0-A7)
15/152
UPSD3212C, UPSD3212CV
Port Pin
PC0TMS20IJTAG pin
PC1TCK16IJTAG pin
PC2
PC3TSTAT14I/OGeneral I/O port pin
PC4TERR9I/OGeneral I/O port pin
PC5TDI7IJTAG pin
PC6TDO6OJTAG pin
PC75I/OGeneral I/O port pin
PD1CLKIN3I/OGeneral I/O port pin
PD2CSI1I/OGeneral I/O port pin
Vcc12
Vcc50
GND13
GND29
GND69
NC10
Signal
Name
V
STBY
Pin No.In/Out
15I/OGeneral I/O port pin
Function
BasicAlternate
1. PLD Macro-cell outputs
2. PLD inputs
3. SRA M stand by voltage input
4. SRAM battery-on indicator
5. JTAG pins are dedicated pins
1. PLD I/O
2. Clock input to PLD and APD
1. PLD I/O
2. Chip select to PSD Module
(V
STBY
(PC4)
)
NC11
NC17
NC71
52 PIN PACKAGE I/O PORT
The 52-pin package members of the uPSD321X
Devices have the same port pins as those of the
80-pin package except:
■ Port 0 (P0.0-P0.7, external address/data bus
AD0-AD7)
■ Port 2 (P2.0-P2.3, external address bus A8-
A11)
■ Port A (PA0-PA7)
■ Port D (PD2)
■ Bus control signal (RD,WR,PSEN,ALE)
Pin 5 requires a pull-up resistor (2kΩ for 3V devices, 7.5kΩ for 5V devices) for all devices.
16/152
ARCHITECTURE OVERVIEW
Memory Organization
The uPSD321X Devices’s standard 8032 Core
has separate 64KB address spac es for Program
memory and Data Memory. Program memory is
where the 8032 executes in structions from. Data
memory is used to hold data variables. Flash
memory can be mapped in either program or data
space. The Flash memory consists of two flash
memory blocks: the main Flash (512Kbit) and the
Secondary Flash (128Kbit). Except during flash
memory programming or update, Flash memory
can only be read, not written to. A Page Register
is used to access memory beyond t he 64K bytes
Figure 5. Memory Map and Address Space
MAIN
FLASH
UPSD3212C, UPSD3212CV
address space. Refer to the PSD Module for details on mapping of the Flash memory.
The 8032 core h as t wo ty pes of data m em ory (internal and external) that can be read and written.
The internal SRAM cons ists of 256 byte s, and includes the stack area.
The SFR (Special Function Registers) occupies
the upper 128 bytes of the internal SRAM, the registers can be accessed by Direct addressing only.
Another 2K bytes resides in the PSD Modul e that
can be mapped to any address space defined by
the user.
EXT. RAM
SECONDARY
FLASH
16KB
Flash Memory Space
64KB
INT. RAM
FF
Indirect
Addressing
7F
Indirect
Direct
Addressing
0
Internal RAM Space
(256 Bytes)
SFR
Direct
Addressing
or
2KB
External RAM Space
(MOVX)
AI07425
17/152
UPSD3212C, UPSD3212CV
Registers
The 8032 has several registers; these are the Program Counter (PC), Accumulator (A), B Register
(B), the Stack Pointer (SP), the Program Status
Word (PSW), General purpose registers (R0 to
R7), and DPTR (Data Pointer register).
Accumulator. The Ac cumulator is the 8-bit general purpose register, used for data operation such
as transfer, temporary saving, and conditional
tests. The Accumulator can be used as a 16-bit
register with B Register as shown in Figure 6.
B Register. The B Register is the 8-bit general
purpose register, used f or an arithmetic operation
such as multiply, division with the Accumulator
(see Figure 7).
Stack Pointer. The Stack Pointer Register is 8
bits wide. It is incremented before data is stored
during PUSH and CALL executions. While the
stack may reside anywhere in on-chip RAM, the
Stack Po inter is initi alize d to 07h af ter reset. Th is
causes the stack to begin at location 08h (see Figure 8).
Program Counter. The Program Counter is a 16bit wide which consists of two 8-bit registers, PCH
and PCL. This counter indicates the address of the
next instruction to be executed. In RESET
the program counter has reset routine address
(PCH:00h, PCL:00h).
Program Status Word. The Program Status
Word (PSW) contains several bits that reflect the
current state of the CPU and select Internal RAM
(00h to 1Fh: Bank0 to Bank3). The PSW is described in Figure 9, page 19. It contains the Carry
Flag, the Auxiliary Carry Flag, the Half Carry (for
BCD operation), the general purpose flag, the
Register Bank Select Flags, the Overflow Flag,
and Parity Flag.
[Carry Flag, CY]. This flag stores any carry or not
borrow from the ALU of CPU after an arithmetic
operation and is also changed by the Shift Instruction or Rotate Instruction.
[Auxiliary Carry Flag, AC]. After operation, this is
set when there is a carry from Bit 3 of ALU or there
is no borrow from Bit 4 of ALU.
[Register Bank Select Flags, RS0, RS1]. This flags
select one of four bank(00~07H:bank0,
08~0Fh:bank1, 10~17h: bank2, 17~1Fh:bank3) in
Internal RAM.
[Overflow Flag, OV]. This flag is set to '1' when an
overflow occurs as the result of an arithmetic operation involving signs. An overflow occurs when the
result of an addition or subtraction exceeds +127
(7Fh) or -128 (80h). The CLRV instruction clears
the overflow flag. There is no set instruction. When
state,
the BIT instruction is executed, Bit 6 of memory is
copied to this flag.
[Parity Flag, P]. This flag reflects on number of Accumulator’s “1.” If the number of Accumulator’s 1
is odd, P=0. otherwise, P=1. The sum of adding
Accumulator’s 1 to P is always even.
R0~R7. General purpose 8-bit registers that are
locked in the lower portion of internal data area.
Data Pointer Register. Data Pointer Register is
16-bit wide which consists of two-8bit registers,
DPH and DPL. This register is used as a data
pointer for the data transmission with external data
memory in the PSD Module.
Figure 6. 8032 MCU Registers
Accumulator
B Register
Stack Pointer
Program Counter
Program Status Word
General Purpose
Register (Bank0-3)
Data Pointer Register
AI06636
PCH
DPTR(DPH)
A
B
SP
PCL
PSW
R0-R7
DPTR(DPL)
Figure 7. Configuration of BA 16-bit Registers
B
AB
A
Two 8-bit Registers can be used as a "BA" 16-bit Registers
AI06637
Figure 8. Stack Pointer
Stack Area (30h-FFh)
Bit 15Bit 0Bit 8 Bit 7
Hardware Fixed
SP (Stack Pointer) could be in 00h-FFh
SP00h
00h-FFh
AI06638
18/152
Figure 9. PSW (Program Status Word) Registe r
UPSD3212C, UPSD3212CV
MSB
CY
PSW
Carry Flag
Auxillary Carry Flag
General Purpose Flag
AC FO RS1 RS0 OVP
Register Bank Select Flags
(to select Bank0-3)
Program Memory
The program memory consists of two Flash memory: 64KByte Main Flash and 16KByte of Secondary Flash. The Flash mem ory can be mapped to
any address space as define d by the user in the
PSDsoft Tool. It can also be mapped to Data
memory space during Flash memory update or
programming.
After reset, the CPU begins execution from location 0000h. As shown in Figure 10, each interrupt
is assigned a fixed location in Program Memory.
The interrupt causes the CPU to jump to t hat location, where it commences execution of the service
routine. External Interrupt 0, for example, is assigned to location 0003h. If External Interrupt 0 is
going to be used, its service routine must begin at
location 0003h. If the interrupt is not going to be
used, its service location is available as gen eral
purpose Program Memory.
The interrupt service locations are spaced at 8byte intervals: 0003h for External Interrupt 0,
000Bh for Timer 0, 0013 h for E xternal I nterrupt 1,
001Bh for Timer 1 and so forth. If an interrupt service routine is short enough (as is often the c ase
in control applications), it can reside entirely within
that 8-byte interval (see Figure 10). Longer service
routines can use a jump instruction to s kip over
subsequent interrupt locat ions, if other interrupts
are in use.
Data memory
The internal data memory is divided into four physically separate d blocks: 256 bytes of internal RAM,
128 bytes of Special Function Registers (SFRs)
areas and 2K bytes (XRAM-PSD) in the PSD Module.
LSB
Reset Value 00h
Parity Flag
Bit not assigned
Overflow Flag
AI06639
RAM
Four register banks, each 8 registers wide, occupy
locations 0 through 31 in the lower RAM area.
Only one of these banks may be enabled at a time.
The next 16 bytes, locations 32 through 47, contain 128 directly addressable bit locations. The
stack depth is only limited by the available internal
RAM space of 256 bytes.
XRAM-PSD
The 2K bytes of XRAM-P SD resides in the PSD
Module and can be mapped to any address space
through the DPLD (Decoding PLD) as defined by
the user in PSDsoft Development tool. The XRAMPSD has a battery backup feature that allow the
data to be retained in t he event of a power lost.
The battery is connected t o the Port C PC2 pin.
This pin must be configured in PSDSoft to be battery back-up.
Figure 10. Inte rru pt Lo c atio n of P rog ra m
Memory
008Bh
•
•
•
•
0013h
000Bh
0003h
0000hReset
8 Bytes
AI06640
Interrupt
Location
•
•
•
•
•
19/152
UPSD3212C, UPSD3212CV
SFR
The SFRs can only be addressed directly in the
address range from 80h to FFh. Table 15, page 32
gives an overview of the Speci al Function Registers. Sixteen address in the SFRs space are bothbyte and bit-addressable. The bit-addressable
SFRs are those whose address ends in 0h and 8h.
The bit addresses in this area are 80h to FFh.
Table 3. RAM Address
Byte Address
(in Hexadecimal)
↓↓
FFh255
30h48
Byte Address
(in Decimal)
Addressing Modes
The addressing modes in uPSD321 X Devices instruction set are as follows
■ Direct addressing
■ Indirect addressing
■ Register addressing
■ Register-specific addressing
■ Immediate constants addressing
■ Indexed addressing
(1) Direct addressing. I n a direct addressing t he
operand is specified by an 8-bit address field in the
instruction. Only internal Data RAM and SFRs
(80~FFH RAM) can be directly addressed.
(2) Indirect addressing. In indirect addressing
the instruction specifies a register which contains
the address of the operand. Both internal and external RAM can be indirectly addressed. The address register for 8-bit addresses can be R0 or R1
of the selected register bank, or the Stack Pointer.
The address register for 16-bit addresses can only
be the 16-bit “data pointer” register, DPTR.
Example:
mov @R1, #40 H ;[R1] <-----40H
Figure 12. Indirect Addressing
Program Memory
55h
7
R1
40h
55
AI06642
20/152
UPSD3212C, UPSD3212CV
(3) Register addressing. The register banks,
containing registers R0 through R7, can be accessed by certain instructions which carry a 3-bit
register specification within the opc ode of the instruction. Instructions that access the registers
this way are code efficient, since t his mode eliminates an address byte. When the instruction is executed, one of four banks is selected at execution
time by the two bank select bits in the PSW.
Example:
mov PSW, #0001000B ; select Bank0
mov A, #30H
mov R1, A
(4) Register-specific addressing. Some instructions are specific to a certain register. For example, some instructions always operate on the
Accumulator, or Data Pointer, etc., so no address
byte is needed to point it. The opcode it self does
that.
(5) Immediate constants addressing. The value of a constant can follow the opcode in Program
memory.
Example:
mov A, #10H.
(6) Indexed addressing. Only Program memory
can be accessed with indexed addressing, a nd it
can only be read. This addressing mode is intended for reading look-up tables in Program memory.
A 16-bit base register (either DPTR or PC) points
to the base of the table, and the Accumulator is set
up with the table entry number. The address of the
table entry in Program memory is formed by adding the Accumulator data to the bas e p ointer (see
Figure 13).
Example:
movc A, @A+DPTR
Figure 13. Indexed Addressing
Arithmetic Instructions
The arithmetic instructions is listed in Table 4,
page 22. The table indicates the addressing
modes that can be used with each ins truction to
access the <byte> operand. For example, the
ADD A, <byte> instruction can be written as:
ADD a, 7FH (direct addressing)
ADD A, @R0 (indirect addressing)
ADD a, R7 (register addressing)
ADD A, #127 (immediate constant)
Note: Any byte in the internal Data Memory space
can be incremented without going through the Accumulator.
One of the INC instructions operates on the 16-bit
Data Pointer. The Data Pointer is used to generate
16-bit addresses for external memory, so being
able to increment it in one 16-bit operations is
a useful feature.
The MUL A B instruc tion mul tiplies the Accum ula-
tor by the data in the B register and puts the 16-bit
product into the concatenated B and Accumulator
registers.
The DIV AB instruction divides the Accumulator by
the data in the B register and leaves the 8-bit quotient in the Accumulator, and the 8-bit remainder in
the B regi s ter.
In shift operations, dividing a num ber by 2n s hifts
its “n” bits to the right. Using DIV AB t o perform the
division completes the shift in 4?s and leaves the
B register holding the b its that were shifted out.
The DAA instruction is for BCD arithmetic operations. In BCD arithmetic, ADD and ADDC instructions should always be followed by a DAA
operation, to ensure that the result is also in BCD.
Note: DAA will not convert a binary number to
BCD. The DAA operation produces a meaningful
result only as the second step in the addition of
two BCD bytes.
ACCDPTR
3Ah1E73h
Program Memory
3Eh
AI06643
21/152
UPSD3212C, UPSD3212CV
Table 4. Arithmetic Instructions
MnemonicOperation
ADD A,<byte>A = A + <byte>XXXX
ADDC A,<byte>A = A + <byte> + CXXXX
SUBB A,<byte>A = A – <byte> – CXXXX
INCA = A + 1Accumulator only
INC <byte><byte> = <byte> + 1XXX
INC DPTRDPTR = DPTR + 1Data Pointer only
DECA = A – 1Accumulator only
DEC <byte><byte> = <byte> – 1XXX
MUL ABB:A = B x AAccumulator and B only
DIV AB
DA ADecimal AdjustAccumulator only
A = Int[ A / B ]
B = Mod[ A / B ]
Dir.Ind.Reg.Imm
Logical Instructions
Table 5, page 23 shows list of uPSD321X Devices
logical instructions. The instructions that perform
Boolean operations (AND, OR, Exclusive OR,
NOT) on bytes perform the operation on a bit-bybit basis. That is, if the Accumulator contains
00110101B and byte contains 01010011B, then:
ANL A, <byte>
will leave the Accumulat or holding 00010001B.
The addressing modes that can be used to access
the <byte> operand are listed in Table 5.
The ANL A, <byte> instruction may take any of the
forms:
ANL A,7FH(direct addressing)
ANL A, @R1 (indirect addressing)
ANL A,R6 (register addressing)
ANL A,#53H (immediate constant)
Note: Boolean operations can be performed on
any byte in the internal Data Mem ory space without going through the Accumulator. The XRL
<byte>, #data instruction, for example, offers a
quick and easy way to invert port bits, as in
If the operation is in response to an interrupt, not
using the Accumulator saves the time and effort to
push it onto the stack in the service routine.
The Rotate instructions (RL A , RLC A, etc.) shift
the Accumulator 1 bit to the left or right. For a left
rotation, the MSB rolls into the LSB position. For a
right rotation, the LSB rolls into the MSB position.
The SWAP A instruction interchanges the high
and low nibbles within the Accumulator. This is a
useful operation in BCD manipulations. For example, if the Accumulator contains a b inary number
which is known to be less than 100, it can be quickly converted to BCD by the following code:
MOVE B,#10
DIV AB
SWAP A
ADD A,B
Dividing the number by 10 leaves the tens digit in
the low nibble of the Acc umulator, and the ones
digit in the B register. The SWAP and ADD instructions move the tens digit to the high nibble of the
Accumulator, and the ones digit to the low nibble.
CRL AA = 00hAccumulator only
CPL AA = .NOT. AAccumulator only
RL ARotate A Left 1 bitAccumulator only
RLC ARotate A Left through CarryAccumulator only
RR ARotate A Right 1 bitAccumulator only
Addressing Modes
RRC ARotate A Right through CarryAccumulator only
SWAP ASwap Nibbles in AAccumulator only
23/152
UPSD3212C, UPSD3212CV
Data Transfers
Internal RAM. Table 6 shows the menu of in-
structions that are available for moving data
around within the internal memory spaces, and the
addressing modes that can be used with each
one. The MOV <dest>, <src> instruction allows
data to be transferred between any two internal
RAM or SFR locations without going through t he
Accumulator. Remember, the Uppe r 128 b ytes of
data RAM can be access ed only by indirect addressing, and SFR space only by di rect addressing.
Note: In uPSD321X Devices, the stack resides in
on-chip RAM, and grows upwards . The PUSH instruction first increments the St ack Pointer (SP),
then copies the byte into the stack. PUSH and
POP use only direct addressing to identify the byte
being saved or restored, but the stack itself is accessed by indirect addressing us ing the S P register. This means the stack can go into the Upper
128 bytes of RAM, if they are implemented, but not
into SFR space.
The Data Transfer instructions include a 16-bit
MOV that can be used to initialize the Data Pointer
(DPTR) for look-up tables in Program Memory.
The XCH A, <byte> instruction causes the Accumulator and ad-dressed byte to exchange data.
The XCHD A, @Ri instruction is similar, but only
the low nibbles are involved in the exchange. To
see how XCH and XCHD can be used to facilitate
data manipulations, cons ider first the problem of
shifting and 8-digit BCD number two digits to the
right. Table 8 shows how this can be done using
XCH instructions. To aid in understanding how the
code works, the contents of the regist ers that are
holding the BCD number and t he content of the
Accumulator are shown alongside each instruction
to indicate their status after the instruction has
been executed.
After the routine has been executed, the Accumulator contains the two digits that were shifted out
on the right. Doing the routine with direct MOVs
uses 14 code bytes. The same operation with
XCHs uses only 9 bytes and executes almost
twice as fast. To right-shift by an odd number of
digits, a one-digit must be executed. Table 9
shows a sample of code that will right-shift a BCD
number one digit, using the XCHD instruction.
Again, the contents of the registers holding the
number and of the accumulator are shown alongside each instruction.
Table 6. Data Transfer Instructions that Access Internal Data Memory Space
MnemonicOperation
Dir.Ind.Reg.Imm
MOV A,<src>A = <src>XXXX
MOV <dest>,A<dest> = AXXX
MOV <dest>,<src><dest> = <src>XXXX
MOV DPTR,#data16DPTR = 16-bit immediate constantX
PUSH <src>INC SP; MOV “@SP”,<src>X
POP <dest>MOV <dest>,”@SP”; DEC SPX
XCH A,<byte>Exchange contents of A and <byte>XXX
XCHD A,@RiExchange low nibbles of A and @RiX
Addressing Modes
24/152
UPSD3212C, UPSD3212CV
First, pointers R1 and R0 are set up to point to the
two bytes containing the last four BCD digits. Then
Table 7. Shifting a BCD Number Two Digits to
the Right (using direct MOVs: 14 bytes)
a loop is executed which leaves the last byte, location 2EH, holding the l ast two dig its of the shi fted
number. The pointers are decremented, and the
loop is repeated for location 2DH. The CJNE instruction (Compare and Jump if Not equal) is a
loop control that will be described later. The l oop
executed from LOOP to CJNE for R1 = 2EH, 2DH,
2CH, and 2BH. At that point the digit that was originally shifted out on the right has propagated to location 2AH. Since that location should be left with
MOV 2Ch,2 Bh001212345678
MOV 2Bh,# 0000012345678
0s, the lost digit is moved to the Accumulator.
Table 8. Shifting a BCD Number Two Digits to
the Right (using direct XCHs: 9 bytes)
; loop for R1 = 2Dh001238456745
; loop for R1 = 2Ch001823456723
; loop for R1 = 2Bh080123456701
CLRA0801234567 00
XCHA,2Ah000123456708
25/152
UPSD3212C, UPSD3212CV
External RAM. Table 10 shows a l ist of t he Data
Transfer instructions that access external Data
Memory. Only indirect addressing can be used.
The choice is whether t o use a one-byte address,
@Ri, where Ri can be either R0 or R1 of the s elected register bank, or a two-byte
address, @DTPR.
Note: In all external Data RAM accesses, the Accumulator is always either the destination or
source of the data.
Lookup Tables. Ta ble 1 1 shows t he tw o instructions that are available for reading lookup tables in
Program Memory. Since these instructions access
only Program Memory, the lookup tables can only
be read, not updated.
The mnemonic is MOVC for “move constant.” The
first MOVC instruction in Table 11 can accommodate a table of up to 256 entries numbered 0
through 255. The number of th e desired entry is
loaded into the Accumulator, and the Data Pointer
is set up to point to the beginning of the table.
Then:
MOVC A, @A+DPTR
copies the desired table entry into the Accumula-
tor.
The other MOVC instruction works the same way,
except the Program Counter (PC) is used as the
table base, and the table is accessed through a
subroutine. First the num ber of the desired en-try
is loaded into the Accumulator, and the subroutine
is called:
MOV A , ENTRY NUMBER
CALL TABLE
The subroutine “TABLE” would look like this:
TABLE: MOVC A , @A+PC
RET
The table itself immediately follows the RET (return) instruction is Program Memory. This type of
table can have up to 255 entries, numbered 1
through 255. Number 0 cannot b e used, because
at the time the MOVC instruction is execute d, the
PC contains the address of the RET instruction.
An entry numbered 0 would be the RET opcode itself.
Table 10. Data Transfer Instruction that Access External Data Memory Space
The uPSD323X Devices contain a complete Boolean (single-bit) processor. One page o f the internal RAM contains 128 address able bits, and the
SFR space can support up to 128 addressable bits
as well. All of the port lines are bit-addressable,
and each one can be treated as a separate singlebit port. The instructions that access these bits are
not just conditional branches, but a complete
menu of move, set, clear, complement, OR and
AND instructions. These kinds of bit operations
are not easily obtained in other architectures with
any amount of byte-oriented software.
The instruction set for the Boolean processor is
shown in Table 12. All bit s acc esse s are by di rect
addressing.
Bit addresses 00h through 7Fh are in the Lower
128, and bit addresses 80h through FFh are in
SFR space.
Note how easily an internal flag can be moved to
a port pin:
MOV C,FLAG
MOV P1.0,C
In this example, FLAG is the name of any addressable bit in the Lower 128 or SFR space. An I/O
line (the LSB of Port 1, in this case) is set or
cleared depending on whether the Flag Bit is '1' or
'0.'
The Carry Bit in the PSW is used as the single-bit
Accumulator of the Boolean processor. Bit instructions th at re fer to th e Ca rry B it as C as se mbl e a s
Carry-specific instructions (CLR C, etc.). The Carry Bit also has a direct address, since it resides in
the PSW register, which is bit-addressable.
Note: The Boolean instruction set includes ANL
and ORL operations, but not the XRL (Exclusive
OR) operation. An XRL operation is simple to implement in software. Suppose, for example, it is required to form the Exclusive OR of two bits:
C = bit 1 .XRL. bit2
The software to do that could be as follows:
MOV C , bit1
JNB bit2, OVER
CPL C
OVER: (continue)
First, Bit 1 is moved to the Carry. If bit2 = 0, then
C now contains the correct result. That i s, Bit 1
.XRL. bit2 = bit1 if bit2 = 0. On the o ther hand, if
bit2 = 1, C now contains the complement of the
correct result. It need only be inverted (CPL C) to
complete the operation.
This code uses the JNB instruction, one of a series
of bit-test instructions which execute a jump if the
UPSD3212C, UPSD3212CV
addressed bit is set (JC, JB, JBC) or if the addressed bit is not set (JNC, JNB). In the above
case, Bit 2 is being tested, and if bit2 = 0, the CPL
C instruction is jumped over.
JBC executes the jump if the addressed bit is set,
and also clears the bit. Thus a flag can be tested
and cleared in one operation. All the PSW bits are
directly addressable, so the Parity Bit, or the general-purpose flags, for example, are also available
to the bit-test instructions.
Relative Offset
The destination address for thes e jumps is specified to the assembler by a label or by an actual address in Program memory. How-ever, the
destination address assembl es to a relative of fset
byte. This is a signed (two’s complement) offset
byte which is added to the PC in two’s complement
arithmetic if the jump is executed.
The range of the jump is therefore -128 to +127
Program Memory bytes relative to the first byte following the instruction.
Table 12. Boolean Instructions
MnemonicOperation
ANL C,bitC = A .AND. bit
ANL C,/bitC = C .AND. .NOT. bit
ORL C,bitC = A .OR. bit
ORL C,/bitC = C .OR. .NOT. bit
MOV C,bitC = bit
MOV bit,Cbit = C
CLR CC = 0
CLR bitbit = 0
SETB CC = 1
SETB bitbit = 1
CPL CC = .NOT. C
CPL bitbit = .NOT. bit
JC relJump if C =1
JNC relJump if C = 0
JB bit,relJump if bit =1
JNB bit,relJump if bit = 0
JBC bit,relJump if bit = 1; CLR bit
27/152
UPSD3212C, UPSD3212CV
Jump Instructions
Table 13 shows the list of unconditional jump instructions. The table lists a single “JMP add” instruction, but in fact there a re th ree S JMP, LJMP,
and AJMP, which differ in the format of the destination address. JMP is a generic mnemonic which
can be used if the programmer does not care
which way the jump is en-coded.
The SJMP instruction encodes the destination address as a relative offset, as described above. The
instruction is 2 bytes long, consisting of the opcode and the relative offset byte. The jump distance is limited to a range of -128 to +127 bytes
relative to the instruction following the SJMP.
The LJMP instruction encodes the destination address as a 16-bit constant. The instruction is 3
bytes long, consistin g of the op code and two address bytes. The des tination address can be anywhere in the 64K Program Memory space.
The AJMP instruction encodes the destination address as an 11-bit constant. The instruction is 2
bytes long, consisting of the opcode, which itself
contains 3 of the 11 address bits, followed by another byte containing the low 8 bits of the destination address. When the instruction is executed,
these 11 bits are simply substituted for the low 11
bits in the PC. The high 5 bits stay the same.
Hence the destination has to be within the same
2K block as the instruction following the AJMP.
In all cases the programmer specifies the destination address to the assembler in the same way: as
a label or as a 16-bit constant. The assembler will
put the destination address into the correct format
for the given instruction. If the format required by
the instruction will not support t he distance t o the
specified destination address, a “Destination out
of range” message is written into the List file.
The JMP @A+DPTR instruction supports case
jumps. The destination address is computed at execution time as the sum of the 16-bit DPTR register and the Accumulator. Typically. DPTR is set up
with the address of a jump table. In a 5-way
branch, for ex-ample, an integer 0 through 4 is
loaded into the Accum ulator. The code t o be executed mi ght be as follows:
MOV DPTR, # J U MP TABLE
MOV A,INDEX_ NU MBER
RL A
JMP @A+DPTR
The RL A instruction converts the index number (0
through 4) to an even number on the range 0
through 8, because each entry in the jump table is
2 bytes long:
JUMP TABLE:
AJMP CASE 0
AJMP CASE 1
AJMP CASE 2
AJMP CASE 3
AJMP CASE 4
Table 13 shows a single “CALL a ddr” instruction,
but there are two of them, LCALL and ACALL,
which differ in the format in which the subroutine
address is given to the CPU. CALL is a generic
mnemonic which can b e used if the progra mmer
does not care which way the address is encoded.
The LCALL instruction uses the 16-bit address format, and the subroutine can be anywh ere in the
64K Program Memory space. The ACALL instruction uses the 11-bit format, and the subroutine
must be in the same 2K block as the instruction following the ACALL.
In any case, the programmer specifies the subroutine address to the assembler in the same way: as
a label or as a 16-bit constant. The assembler will
put the address into the correct format for the given instructions.
Subroutines should end with a RET instruction,
which returns execution to the instruction following
the CALL.
RETI is used to return from an interrupt service
routine. The only difference between RET and
RETI is that RET I tells the interrupt control system
that the interrupt in progress is done. If there is no
interrupt in progress at the time RETI is executed,
then the RETI is functionally identical to RET.
Table 13. Unconditional Jump Instructions
MnemonicOperation
JMP addrJump to addr
JMP @A+DPTRJump to A+DPTR
CALL addrCall Subroutine at addr
RETReturn from subroutine
RETIReturn from Interrupt
28/152
NOPNo operation
UPSD3212C, UPSD3212CV
Table 14 shows the list of conditional jumps available to the uPSD321X Devices user. All of these
jumps specify the destination address by the relative offset method, and so are limited to a jump distance of -128 to +127 bytes from the instruction
following the conditional jump instruction. Important to note, however, the user specifies to the assembler the actual destination address the sam e
way as the other jumps: as a label or a 16-bit constant.
There is no Zero Bit in the PSW. The JZ and JNZ
instructions test the Accumulator data for that condition.
The DJNZ instruction (Decrement and Jump if Not
Zero) is for loop control. To execute a loop N
times, load a counter byte with N and terminate the
loop with a DJNZ to the b eginning of t he loop, as
shown below for N = 10:
MOV COUNTER,#10
LOOP: (begin loop)
•
•
•
(end loop)
DJNZ COUNTER, LOOP
(continue)
The CJNE instruction (Compare and Jump if Not
Equal) can also be used f or loo p cont rol a s in Table 9. Two bytes are specified in the operand field
of the instruction. The jump is executed only if the
two bytes are not equal. In the example of Table 9
Shifting a BCD Numb er One Digits to the Right,
the two bytes were data in R1 and the constant
2Ah. The initial data in R1 was 2Eh.
Every time the loop was executed, R1 was decremented, and the looping was to continue until the
R1 data reached 2Ah.
Another application of this instruction is in “greater
than, less than” comparisons. The two bytes in the
operand field are taken as unsigned integers. If the
first is less than the second, then the Carry Bit is
set (1). If the first is greater than or equal to the
second, then the Carry Bit is cleared.
Machine Cycles
A machine cycle consists of a sequence of six
states, numbered S1 through S6. Each state time
lasts for t wo oscillator peri ods. Thus, a ma chine
cycle takes 12 oscillator periods or 1µs if the oscillator frequency is 12MHz. Refer to Figure 14, page
30.
Each state is divided into a Phase 1 half and a
Phase 2 half. State Sequence i n uPSD321X Devices shows that retrieve/execute sequences in
states and phases for various kinds of instructions.
Normally two program retrievals are generated
during each machine cycle, even if the instruction
not
being executed does
require it. If the instruction being executed does not need more code
bytes, the CPU simply ig nores the e xtra retrieval,
and the Program Counter is not incremented.
Execution of a one-cycle instruction (Figure 14,
page 30) begins during State 1 of the machine cycle, when the opcode is latched into the Instruction
Register. A second retrieve occurs during S4 of
the same machine cycle. Execution is complete at
the end of State 6 of this machine cycle.
The MOVX instructions take two machine cycles
to execute. No program retrieval is generated during the second cycle of a MOVX instruction. This
is the only time program retrievals are skipped.
The retrieve/execute sequence for MOVX instruction is shown in Figure 14, page 30 (d).
Table 14. Conditional Jump Instructions
Addressing Modes
MnemonicOperation
Dir.Ind.Reg.Imm
JZ relJump if A = 0Accumulator only
JNZ relJump if A ≠ 0Accumulator only
DJNZ <byte>,relDecrement and jump if not zeroXX
CJNE A,<byte>,relJump if A ≠ <byte>XX
CJNE <byte>,#data,relJump if <byte> ≠ #dataXX
29/152
UPSD3212C, UPSD3212CV
Figure 14. State Sequence in uPSD321X Devices
Osc.
(XTAL2)
a. 1-Byte, 1-Cycle Instruction, e.g. INC A
b. 2-Byte, 1-Cycle Instruction, e.g. ADD A, adrs
c. 1-Byte, 2-Cycle Instruction, e.g. INC DPTR
S1S2S3S4S5S6S1S2S3S4S5S6
p1p1p1p1p1p1p1p1p1p1p1p1p2p2p2p2p2p2p2p2p2p2p2p2
Read next
Read opcode
S1S2S3S4S5S6
Read opcode
S1S2S3S4S5S6
Read opcode
S1S2S3S4S5S6
Read opcode
(MOVX)
opcode and
discard
Read 2nd
Byte
Read next
opcode and
discard
Read next
opcode and
discard
Read next
opcode
Read next
opcode
Read next
opcode and
discard
S1S2S3S4S5S6
No Fetch
No ALE
Read next
opcode and
discard
No Fetch
Read next
opcode
Read next
opcode
S1S2S3S4S5S6S1S2S3S4S5S6
d. 1-Byte, 2-Cycle MOVX Instruction
AddrData
Access External Memory
AI06822
30/152
Loading...
+ 122 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.