i~.
MCS@-51 ARCHITECTURAL OVERVIEW
Table 9. Conditions Jumps in MCS@-51 Devioes
Mnemonic
Operation
Addressing Modes
Execution
Dir
ind
Rag imm
Time (ps)
JZ rei
Jump if A = O
Accumulator oniy
2
JNZ rel
Jumpif A+O
Accumulator oniy
2
DJNZ <byte>
,rel
Deorement and jump if not zero x
x
2
CJNE A, <byte> ,rei
Jumpif A # <byte>
x
x
2
CJNE <byte> ,#data,rei
Jumpif <byte> # #data
x x
2
There is no Zero bit in the PSW. The JZ and JNZ
instructions test the Accumulator data for thst ccmdi-
tion.
The DJNZ instruction (Dezrement and Jump if Not
Zero) is for loop control. To execute a loop N times,
load a counter byte with N and tersnina
te the loop with
a DJNZ to the beginning of the loop, as shown below
for N = 10:
MOV
com~#lo
LOOP: (begin loop)
●
*
(;d Imp)
DJNZ
COUNTER,LOOP
(continue)
The CJNE instruction (Compare and Jump if Not
Equal) can also be used for loop control as in Figure 12.
Two bytes are specified in the operand field of the in-
struction. The jump is executed only if the two bytes
are not equal. In the example of Figure 12, the two
bytes were the data in R1 and the constant 2AH. The
initial data in R1 was 2EH. Every time the loop was
executed, R 1 was decresnertted,and the looping was to
continue until the R1 &ta reached 2AH.
Another application of this instruction is in “great=
than, less than” comparisons. The two bytes in the op
erand field are taken as unsigned integers. If the first is
less than the second, then the Carry bit is set (l). If the
first is greater than or equal to the second, then the
Carry bit is cleared.
CPU TIMING
All
MCS-51 microcontrollers have an on-chip oscillator
which can be used if desired as the clock source for the
CPU. To use the on-chip oscillator, connect a crystal or
ceramic resonator between the XTAL1 and XTAL2
pins of the microcontroller, and capacitors to ground as
shown in Figure 13.
@
‘4-J
Mes-51
HIAOS
ORCHMOS
STAL7.
OUART&&~WA; > Cl
RrsONAmR
57.
S-TAL1
Vss
=
270251-11
Figure 13. Using the On-Chip Oeciilator
-4-I
w’%
HMOS
ORCnuos
SmLS
CLOCK STAL1
SIGNAL
=
270251-12
A. HMOS or CHMOS
-i-l
Mcs”-51
HMOS
EilSRNAL
ONLY
CLOCK
STAL2
STAL1
Vss
=
B. HMOS Only
u
Mm%!
CHMOS
ONLY
(w) STU.2
WRNAL
nut
L=
Vss
s
C. CHMOS only
270251-13
270251-14
Figure 14. Using an Externai Ciock
1-17