– 8051 Pin and Instruction Compatible
– Four 8-bit I/O Ports
– Three 16-bit Tim er/Counters
– 256 Bytes Scratch Pad RAM
– 9 Interrupt Sourc es with 4 Priority Levels
– Dual Data Pointer
• Variable Length MOVX for Slow RAM/Peripherals
• ISP (In-system Programming) Using Standard V
• Boot ROM Contains Low Level Fla sh Programming Routines and a Default Serial
Loader
• High-speed Archit ecture
– In Standard Mode:
40 MHz (Vcc 2.7V to 5.5V, both Inter nal and external code execution)
60 MHz (Vcc 4.5V to 5.5V and Internal Code execution only)
– In X2 mode (6 Clocks/machine cycle)
20 MHz (Vcc 2.7V to 5.5V, both Inter nal and external code execution)
30 MHz (Vcc 4.5V to 5.5V and Internal Code execution only)
– 16K/32K Bytes On-chip Flash Program/Data Memor y
– Byte and Page (128 Bytes) Erase and Write
– 100K Write Cycles
• On-chip 1024 Bytes Expanded RAM (XRAM)
– Software Selectable Size (0 , 256, 512, 768, 1024 Bytes)
– 256 Bytes Selected at Reset for TS87C51RB2/RC2 Compatibility
• Keyboard Interrupt Interface on Port P1
• SPI Interface (Ma ster/Slave Mode)
• 8-bit Clock Prescaler
• Improved X2 Mode with Independent Selection for CPU and Each Peripheral
• Hardware Watchdog Timer (One-time Enabled with Reset-out)
• Power Control Modes
– Idle Mode
– Power-down Mode
– Power-off Flag
• Power Supply:
– 2.7 to 3.6 (3V Version)
– 2.7 to 5.5V (5V Version)
• T em p erature Ranges: Commercial (0 to +70°C) and Industrial (-40°C to +85°C)
• Packages: PDIL40, PLCC44, VQFP44
Power Supply
CC
8-bit
Microcontroller
with 16K/
32K Bytes Flash
AT89C51RB2
AT89C51RC2
Description
The AT89C51RB2/RC2 is a high-performance Flash version of the 80C51 8-bit microcontrollers. It contains a 16K or 32K Bytes Flash memory block for program and data.
The Flash mem ory c an be programmed e ither i n parallel mode or in serial mo de with
the ISP c apability o r wi th software . Th e prog ramm ing voltage i s intern ally g enerat ed
from the standard VCC pin.
Rev. 4180E–8051–10/06
AT89C51RB2/RC2
The AT89C51R B2/RC2 retains all features of the 80C52 with 256 Bytes of internal
RAM, a 9-source 4-level interrupt controller and three timer/counters.
In addition, the AT89C51RB2/RC2 has a Programmable Counter Array, an XRAM of
1024 Bytes, a Hardware Watchdog Timer, a Keyboard Interface, an SPI Interface, a
more versatile serial channel that facilitates multiprocessor communication (EUART)
and a speed improvement mechanism (X2 mode).
The Pinout is the standard 40/44 pins of the C52.
The fully static design reduces system power consumption of the AT89C51RB2/ RC2 by
allowing it to bring the clock frequency down to any value, even DC, without loss of data.
The AT 89C5 1RB 2/RC 2 has 2 soft ware -selec tabl e mo des of redu ced acti vity an d 8 -bit
clock prescaler for further reduction in power consumption. In Idle mode, the CPU is frozen while the peripherals and the interrupt system are still operating. In power-down
mode, the RAM is saved and all other functions are inoperative.
The added features of the AT89C51RB2/RC2 make it more powerful for applications
that need pulse width modulation, high speed I/O and counting capabilities such as
alarms, motor control, corded phones, and smart card readers.
Table 1. Memory Size
TOTAL RAM
Part NumberFlash (Bytes)XRAM (B ytes)
AT89C51RB2 16K1024128032
AT89C51RC2 32K1024128032
AT89C51IC2 32K1024128032
(Bytes)I/O
2
4180E–8051–10/06
Block Diagram
Figure 1. Block Diagram
AT89C51RB2/RC2
CC
Vss
RxD
TxD
V
PCA
ECI
T2EX
T2
XTAL1
XTAL2
ALE/
PROG
PSEN
EA
(2)
RD
(2)
WR
Notes: 1. Alternate functi on of Por t 1.
2. Alternate function of Port 3.
CPU
RESET
(2)(2)
EUART
BRG
Timer 0
Timer 1
(2) (2)(2) (2)
T0
RAM
+
256x8
C51
CORE
INT
Ctrl
T1
INT0
Flash
32Kx8 or
16Kx8
IB-bus
Parallel I/O Ports & Ext. Bus
Port 0
INT1
Port 1
P0
XRAM
Port 2 Port 3
P1
1Kx8
P2
Boot
ROM
2Kx8
P3
(1)(1)
PCA
Watch
Dog
(1) (1)
Timer2
Key
Board
SPI
(1)(1) (1)
MISO
(1)
SS
MOSI
SCK
4180E–8051–10/06
3
AT89C51RB2/RC2
SFR MappingThe Specia l Function Registers (SFRs) o f the AT89C 51RB2 /RC2 fall into t he follo wing
•Interrupt system registers: IEN0, IPL0, IPH0, IEN1, IPL1, IPH1
•Keyb oard Interface registers: KBE, KBF, KBLS
•SPI registers: SPCON, SPST R , SPDAT
•BRG (Baud Rate Generator) registers: BRL, BDRCON
•Flash register: FCON
•Clock Prescaler register: CKRL
•Others: AUXR, AUXR1, CKCON0, CKCON1
4
4180E–8051–10/06
AT89C51RB2/RC2
Table 2. C51 Core SFRs
MnemonicAddName76543210
ACCE0h Accumulator
BF0h B Register
PSWD0h Program Status WordCYACF0RS1RS0OVF1P
SP81hStack Pointer
DPL82h Data Pointer Low Byte
DPH83h Data Pointer High Byte
Table 3. System Management SFRs
MnemonicAddName76543210
PCON87h Power ControlSMOD1SMOD0-POFGF1GF0PD IDL
AUXR8Eh Auxiliary Register 0DPU-M0XRS2XRS1XRS0EXTRAMAO
AUXR1A2h Auxiliary Register 1--ENBOOT-GF30-DPS
CKRL97h Clock Reload Register CKRL7CKRL6CKRL5CKRL4CKRL3CKRL2CKRL1CKRL0
CKCKON08Fh Clock Control Register 0-WDTX2PCAX2SIX2T2X2T1X2T0X2X2
CKCKON1AFhClock Control Register 1-------SPIX2
Table 4. Interrupt SFRs
MnemonicAddName76543210
IEN0A8h Interrupt Enable Control 0EAECET2ESET1EX1ET0EX0
IEN1B1hInterrupt Enable Control 1 -----ESPIEI2CKBD
IPH0B7h Interrupt Priority Control High 0-PPCHPT2HPHSPT1HPX1HPT0HPX0H
IPL0B8h Interrupt Priority Control Low 0-PPCLPT2LPLSPT1LPX1LPT0LPX0L
IPH1B3hInterrupt Priority Control High 1-----SPIHIE2CHKBDH
IPL1B2hInterrupt Priority Control Low 1-----SPILIE2CLKBDL
Table 5. Port SFRs
MnemonicAddName76543210
P080h 8-bit Port 0
P190h 8-bit Port 1
P2A0h 8-bit Port 2
P3B0h 8-bit Port 3
4180E–8051–10/06
5
AT89C51RB2/RC2
Table 6. Timer S FR s
MnemonicAddName76543210
TCON88hTimer/C o un te r 0 and 1 Co nt rolTF1TR1TF0TR0IE1IT1IE0 IT0
TMOD89hTimer/Coun te r 0 and 1 Mo de sGATE1C/ T1 #M11M0 1GATE0C/T0#M10 M00
Table 12. Pin Description for 40 - 44 Pin Packages
Pin Number
Mnemonic
V
SS
V
CC
P0.0 - P0.739 - 3243 - 3637 - 30I/OPort 0: Por t 0 is an open-drain, bi-directional I/O port. Port 0 pi ns that have 1s
P1.0 - P1.71 - 82 - 940 - 44
202216IGround: 0V reference
404438I
1 - 3
1240I/OP1.0: Input/Output
2341I/OP1.1: Input/Output
TypeName and FunctionDILLCCVQFP44 1.4
Power Supply: This is the power supply voltage for normal, idle and power-down
operation
written to them float and can be used as high impedance inputs. Port 0 must be
polarize d t o V
is also the multiplexed low-order address and data bus during access to external
program and data memory. In this application, it uses strong internal pull-up when
emitting 1s. Port 0 also inputs the code Bytes during Flash programming. External
pull-ups are required during program verification during which P0 outputs th e code
Bytes.
I/OPo rt 1 : Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. Port 1 pins that
have 1s written to them are pulled high by the internal pull-ups and can be used as
inputs. As inputs, Port 1 pins that are externally pulled low will source current
because of the internal pull-ups. Port 1 also receives the low-order address Byte
during memory programming and verification.
Alternate functi on s for AT89C51RB2 /RC2 Port 1 include:
P1.0 - P1.7I/OMOSI: SPI Master Output Slave Input line
XTAL1192115I
XTAL2182014OCry stal 2: Output from the inverting oscillator amplifier
P2.0 - P2.721 - 2824 - 3118 - 25I/OPort 2 : Port 2 is an 8-bit bi-directional I/O port with internal pull-ups. Port 2 pins that
P3.0 - P3.710 - 1711,
13 - 19
5,
7 - 13
TypeName and FunctionDILLCCVQFP44 1.4
I/OCEX4: Capture/Compare External I/O for PCA Module 4
When SPI is in master mode, MOSI o utputs data to the slave peripheral. When SPI
is in sla v e mode, MOSI receives data from the master contro ller .
Crystal 1: Input to the inverting oscillator amplifier and input to the internal clock
generator circuits.
have 1s written to them are pulled high by the internal pull-ups and can be used as
inputs. As inputs, Port 2 pins that are externally pulled low will source current
because of the internal pull-ups. Port 2 emits the high - order address Byte during
fetches from external program memory and during accesses to external data
memory that use 16-bit addresses (MOVX @DPTR). In this applicat ion, it uses
strong internal pull-ups emitting 1s. During accesses to external data memory that
use 8-bit addresses (MOVX @Ri ), port 2 emits the contents of the P2 SF R. Some
Port 2 pi ns receive the high order address bits during EPROM programming and
verification:
P2.0 to P2.5 for 16 KB devices
P2.0 to P2.6 for 32KB devices
I/OPo rt 3: Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. Port 3 pins that
have 1s written to them are pulled high by the internal pull-ups and can be used as
inputs. As inputs, Port 3 pins that are externally pulled low will source current
because of the internal pull-ups. Port 3 also serves the special features of the
80C51 family, as listed below.
10115IRXD (P3.0): Serial in pu t por t
11137OTXD (P3.1): Serial output port
12148IINT0
13159IINT1
141610IT 0 (P3.4): Timer 0 external input
151711IT 1 (P3.5): Timer 1 external input
161812OWR
171913ORD
RST9104I/O
ALE/PROG
303327O (I)Address Latch Enable/Program Pulse: Output pulse for latchin g the low Byt e of
(P3.2): Ex te rna l interrupt 0
(P3.3): Ex te rna l interrupt 1
(P3.6): External data memory write strobe
(P3.7): External data memory read strobe
Reset: A high on t his pin for two machine cycles while the oscillator is running,
resets the device. An internal diffused resistor to V
only an external capacitor to V
watchdog forces a system reset.
the address during an access to external memory. In normal operation, ALE is
emitted at a constant rate of 1/6 (1/3 in X2 mode) the oscillator frequency, and can
be used for external timing or clocki ng. Note that one ALE pulse is skipped during
each access to external data memory. This pin is also the program pulse input
(PROG
) duri ng Flas h p rogr a mming . ALE can be di sa bl ed by s ett in g SF R’ s AU XR. 0
bit. With this bit set, ALE will be inactive during internal fetches.
PSEN293226OProgram Strobe Enable: The read strobe to external program memory. When
EA313529IExternal Access Enable: EA
TypeName and FunctionDILLCCVQFP44 1.4
executing code from the external program memory, PSEN
machine cycle, except that two PSEN
external data memory. PSEN
memory.
fetch code from external program memory locations 0000H to FFFFH (RD). If
security level 1 is programmed, EA
activ atio ns are sk ip pe d d uri ng ea ch ac ces s t o
is not activated during fetches from internal program
must be externally held low to enable the device to
will be internally latched on Reset.
is activa te d t wic e each
12
4180E–8051–10/06
AT89C51RB2/RC2
Port TypesAT89C51RB2 /RC2 I/O ports (P1, P2, P3) imp lement the quasi-bid irectional o utput that
is com mon on the 8 0C 51 and mos t of its d eriva tive s. This o utp ut ty pe ca n b e used as
both an i nput and ou tput w ithout the need to rec onfigure the port. This is p ossible
because when the port outputs a logic high, it is weakly driven, allowing an external
device to pull the pin low. When the pin is pulled low, it is dri ven strongly and able to sink
a fairly large current. These features are somew hat similar to an open drain output
except that there are three pull-up transistors in the quasi-bidirectional output that serve
different purposes. One of these pul l-ups, called the "weak " pull-up, is turned on whenever the port latch for the pin contains a logic 1. The weak pull-up sources a very small
current that will pull the pin high if it is left floating. A second pull-up, called the "medium"
pull-up, is turned on when the port latch for the pin contains a logic 1 and the pin itself is
also at a logic 1 level. This pull-up provides the primary s ource current for a quas i-bidirectional pin that is outputting a 1. If a pin that has a logic 1 on it is pulled low by an
external device, the medi um pull-up turn s off, and only the we ak pull-up remains on . In
order to pull the pin low under these conditions, the external device has to sink enough
current to overpow er the me dium pull -up and take the voltage on the port pi n below its
input threshold.
The third pull-up is referred to as the "strong" pull-up. This pull-up is used to speed up
low-to-high transitions on a quasi-bidirectional port pin when the port latch changes from
a logic 0 to a logic 1. When this occurs, the strong pu ll-up turns on for a brief time, two
CPU clocks, in order to pull the port pin high quickly. Then it turns off again.
The DPU bit (bit 7 in AUXR register) allows to disable the perman ent we ak pull up of all
ports when latch data is logical 0.
The quasi-bidirectional port configuration is shown in Figure 3.
Figure 3. Quasi-Bidire ction al Output
Port Latch
Data
2 CPU
Clock Delay
Input
Data
P
N
Strong
PP
Weak
DPU
AUXR.7
Medium
Pin
4180E–8051–10/06
13
AT89C51RB2/RC2
OscillatorTo optim ize t he p ower c onsu mpti on an d e xecu tion ti me n eede d fo r a sp ecific task, an
internal, prescaler feature has been implemented between the oscillator and the CPU
and peripherals.
RegistersTable 13. CKRL Register
CKRL – Clock Reload Register (97h)
76543210
CKRL7CKRL6CKRL5CKRL4CKRL3CKRL2CKRL1CKRL0
Bit Number MnemonicDescription
7:0CKRL
Clock Reload Register
Prescaler value
Reset Value = 1111 1111b
Not bit addressable
Table 14. PCON Register
PCON – Power Control Register (87h)
76543210
SMOD1SMOD0-POFGF1GF0PDIDL
Bit NumberBit MnemonicDescription
7SMOD1
6SMOD0
5-
4POF
Serial Port Mode bit 1
Set to select double baud rate in mode 1, 2 or 3.
Serial Port Mode bit 0
Clear ed to sel ec t SM0 bi t in SC ON r e gist er.
Set to select FE bit in SCON register.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Power-off Flag
Cleared to recognize next reset type.
Set by har dwa re wh en V
also be set by software.
rises fr om 0 to it s nomi na l volt a ge . Can
CC
14
General-pu r pos e Flag
3GF1
2GF0
1PD
0IDL
Cleared by software for general-purpose usage.
Set by software f o r ge ne r al- pu rpos e usa ge .
General-pu r pos e Flag
Cleared by software for general-purpose usage.
Set by software f o r ge ne r al- pu rpos e usa ge .
Power-down Mode bit
Cleared by hardware when reset occurs.
Set to enter power-down mode.
Idle Mode bit
Cleared by hardware when interrupt or reset occurs.
Set to enter idle mode.
Reset Value = 00X1 0000b Not bit addressable
4180E–8051–10/06
Funct ional Block
F
F
---
F
F
---
Diagram
Figure 4. Functional Oscillator Block Diagram
AT89C51RB2/RC2
Reload
8-bit
Prescaler-Divider
1
0
CKRL = 0xFF?
CLK
PERIPH
CLK
CPU
Idle
Xtal1
Xtal2
Osc
Reset
CKRL
F
OSC
1
:2
0
X2
CKCON0
Prescaler Divider•A hardware RESET puts the prescaler divider in the following state:
•CKRL = FFh: F
CLK CPU
= F
CLK PERIPH
= F
/2 (Standard C51 feature)
OSC
•Any value between F Fh down to 00h can be written by software into CKRL register
in order to divide frequency of the selected osc illator:
Enhanced FeaturesIn comparison to the original 80C52, the AT89C51RB 2/RC2 im plement s some new fea-
tures, which are
•X2 option
•Dual Data Pointer
•Extended RAM
•Programmable Counter Array (PCA)
•Hardware Watchdog
•SPI interface
•4-level interrupt priority system
•power-off flag
•ONCE mode
•AL E disabling
•Some enha nc ed features are also located in the UART and the timer 2
X2 Feature The AT89C51RB2/RC2 core needs only 6 clock periods per machine cycle. This feature
called ‘X2’ provides the following advantages:
•Divide frequency crystals by 2 (cheaper crystals) while keeping same CPU power.
•Save power consumption while keeping same CPU power (oscillator power saving).
•Sa ve power consum ption by dividing dynam ical ly the operating frequency by 2 in
operating and idle modes.
•Increase CPU power by 2 while keeping same crystal frequency.
:
In order to keep the original C51 compatibility, a divider by 2 is inserted between the
XTAL1 signal and the main clock input of the core (phase generator). This divider m ay
be disabled by software.
DescriptionThe clock for the w hole ci rcuit a nd peri pherals i s first divi ded by 2 before being used by
the CPU core and the peripherals.
This allows any cyclic ratio to be accepted on XTAL1 input. In X2 mode, as this divider is
bypassed, the signals on XTAL1 must have a cyclic ratio between 40 to 60%.
Figure 5 shows the clock generation block diagram. X2 bit is validated on the rising edge
of the XTAL1÷2 to avoid g litches whe n swi tching f rom X2 t o X1 mod e. Figure 6 show s
the switching mode waveforms.
Figure 5. Clock Generation Diagram
CKRL
F
X2
OSC
0
1
8 bit Pre scaler
F
CLK CPU
F
CLK PER IP H
XTAL1
FXTAL
XTAL1:2
2
CKCON0
16
4180E–8051–10/06
Figure 6. Mode Switching Waveforms
XTAL1
XTAL1:2
X2 Bit
CPU Clock
The X2 bit in the CKCON0 register (see Table 15) allows a switch from 12 clock periods
per instruction to 6 clo ck periods and vice versa. At reset , t he speed is set according to
X2 bit of Hardware Security Byte (HSB). By default, Standard mode is active. Setting the
X2 bit activates the X2 feature (X2 mode).
The T0X2, T1X2, T2X2, UARTX2, PCAX2, and WDX 2 bits in the CKCON0 register
(Table 15) and SPIX2 bit in the CKCON1 register (see Table 16) allow a switch from
standard peri phera l spee d ( 12 clo ck p eriod s per p eriph eral clock cyc le) to fa st pe ripheral speed (6 clock periods per peripheral clock cycle). These bits are active only in X2
mode.
AT89C51RB2/RC2
F
OSC
X2 Modex1 ModeX1 Mode
4180E–8051–10/06
17
AT89C51RB2/RC2
Table 15. CKCON0 Register
CKCON0 - Clock Control Register (8Fh)
76543210
-WDX2PCAX2SIX2T2X2T1X2T0X2X2
Bit
Number
7Reserved
6WDX2
5PCAX2
4SIX2
3T2X2
Bit
Mnemonic Description
Watchdog Clock
(This con tr ol bi t is va li da ted when t he CP U cl ock X2 i s s et ; whe n X2 is lo w, this bit
has no effect).
Cleared to select 6 clock periods per peripheral clock cycle.
Set to select 12 clock periods per peripheral clock cycle.
Programmable Counter Array Clock
(This con tr ol bi t is va li da ted when t he CP U cl ock X2 i s s et ; whe n X2 is lo w, this bit
has no effect).
Cleared to select 6 clock periods per peripheral clock cycle. Set to select 12 clock
periods per peripheral clock cycl e.
Enhanced UART Clock (Mode 0 and 2)
(This con tr ol bi t is va li da ted when t he CP U cl ock X2 i s s et ; whe n X2 is lo w, this bit
has no effect).
Cleared to select 6 clock periods per peripheral clock cycle. Set to select 12 clock
periods per peripheral clock cycl e.
Timer 2 Clock
(This con tr ol bi t is va li da ted when t he CP U cl ock X2 i s s et ; whe n X2 is lo w, this bit
has no effect).
Cleared to select 6 clock periods per peripheral clock cycle.
Set to select 12 clock periods per peripheral clock cycle.
Timer 1 Clock
2T1X2
1T0X2
0X2
(This con tr ol bi t is va li da ted when t he CP U cl ock X2 i s s et ; whe n X2 is lo w, this bit
has no effect).
Cleared to select 6 clock periods per peripheral clock cycle. Set to select 12 clock
periods per peripheral clock cycl e.
Timer0 Clock
(This con tr ol bi t is va li da ted when t he CP U cl ock X2 i s s et ; whe n X2 is lo w, this bit
has no effect).
Cleared to select 6 clock periods per peripheral clock cycle. Set to select 12 clock
periods per peripheral clock cycl e.
CPU Clock
Cleared to select 12 clock periods per machine cycle (STD, X1 mode) for CPU
and all the peripherals. Set to select 6 clock periods per machine cycle (X2
mode) and to enable the individual peripherals’X2’ bits . Programmed by
hardware after Power-up regarding Hardware Security Byte (HSB), Default
setting, X2 is cleared.
Reset Value = 0000 000’HSB. X2’b (see Table 65 “Hardware Security Byte”)
Not bit addressable
SPI (This control bit is validated when the CPU clock X2 is set; when X2 is low,
this bit has no effect).
Clear to select 6 clock periods per peripheral clock cycle.
Set to select 12 clock periods per peripheral clock cycle.
Reset Value = XXXX XXX0b
Not bit addressable
4180E–8051–10/06
19
AT89C51RB2/RC2
Dual Data Pointer
External Data Memory
Register (DPTR)
Figure 7. Use of Dual Pointer
AUXR1(A2H)
The addi tion al da ta poin ter ca n be u sed t o spe ed up code exe cuti on and reduc e cod e
size.
The dual D PT R st ru c tur e is a way by w h ic h the c hip will s p e c if y the address of an exter nal data memory location. There are two 16-bit DPTR registers that address the external
memory, and a single bit called DPS = AUXR1.0 (see Table 17) that allows the program
code to switch between them (see Figure 7).
07
DPS
DPTR1
DPTR0
DPH(83H) DPL(82H)
20
4180E–8051–10/06
AT89C51RB2/RC2
Table 17. AUXR1 register
AUXR1- Auxiliary Register 1(0A2h)
76543210
--ENBOOT-GF30-DPS
Bit
Number
7-
6-
5ENBOOT
4-
3GF3This bit is a general-purpose user flag.
20Al ways Cleared
1-
0DPS
Bit
Mnemonic Description
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Enable Boot Flash
Cleare d to disa ble bo ot ROM.
Set to map the boot ROM between F800h - 0FFFFh.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
(1)
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Data Pointer Selection
Cleared to select DPTR0.
Set to select DPTR1.
Reset Value = XXXX XX0X0b
Not bit addressable
Note:1. Bit 2 stuck at 0; this allows using INC AUXR1 to toggle DPS without chan ging GF3.
4180E–8051–10/06
ASSEMBLY LANGUAGE
; Block move using dual data pointers
; Modifies DPTR0, DPTR1, A and PSW
; note: DPS exits opposite of entry state
; unles s an extra INC AUXR1 is added
;
00A2 AUXR1 EQU 0A2H
;
0000 909000MOV DPTR,#SOURCE ; address of SOURCE
0003 05 A2 INC AUXR1 ; switch data pointers
0005 90 A000 MOV DPTR,#DEST ; address of DEST
0008 LOOP:
0008 05 A2 INC AUXR1 ; switch data pointers
000A E0 MOVX A,@DPTR ; get a Byte from SOURCE
000B A3 INC DPTR ; increment SOURCE address
000C 05A2 INC AUXR1 ; switch data pointers
000E F0 MOVX @DPTR,A ; write the Byte to DEST
000F A3 INC DPTR ; increment DEST address
0010 70 F6JNZ LOOP ; check for 0 t erminator
0012 05A2 INC AUXR1 ; (optional) restore DPS
21
AT89C51RB2/RC2
INC is a short (2 Bytes) a nd fast (12 clocks) way to manipulate the DPS bit in the
AUXR1 SFR. However, note t hat the I NC i nstruction does not directly force the DPS bit
to a particular state, but simply toggles it. In simple routines, such as the block move
example, only the fact that DPS is toggled in the proper sequence matters, not its actual
value. In other words, the block move routine works the same whether DPS is '0' or '1'
on entry. Observe that without the last instruction (INC AUXR 1), the routine will ex it with
DPS in the opposite state.
22
4180E–8051–10/06
AT89C51RB2/RC2
Expanded RAM
(XRAM)
The AT89C51RB2/RC2 provides additional bytes of random access memory (RAM)
space for increased data parameter handling and high-level language usage.
AT89C51RB2/RC2 devices have expanded RAM in external data space; maximu m size
and location are described in Table 18.
Table 18. Expanded RAM
Address
Part NumberXRAM Size
AT89C51RB2/RC2102400h3FFh
StartEnd
The AT89C51RB2/RC2 has internal data memory that is mapped into four separate
segments.
The four segments are:
1. The Lower 128 Bytes of RAM (addresses 00h to 7Fh) are directly and indirectly
addressable.
2. The Upper 128 Bytes of RAM (addresses 80h to FFh) are indirectly addressable
only.
3. The Special Function Registers, SFRs, (addresses 80h to FFh) are directly
addressable only.
4. The expanded RAM Bytes are indirectly accessed by MOVX instructions, and
with the EXTRAM bit cleared in the AUXR register (see Table 18).
The lower 128 Bytes can be accessed by either direct or indirect addressing. The Upper
128 Bytes can be accessed by indirect addressing only. The Upper 128 Bytes occupy
the same address sp ace as the S FR. Th at means they have the same addres s, but are
physically separate from SFR space.
Figure 8. Internal and External Data Memory Address
0FFh or 3FFh
XRAM
00
0FFh
128 Bytes
Indirect Accesses
80h80h
7Fh
128 Bytes
Direct or Indirect
00
Accesses
When an instruction ac cesses an i nternal location ab ove addres s 7Fh, the CPU knows
whether the access is to the upper 128 Byte s of data RAM or to SFR space by the
addressing mode used in the instruction.
•Instructions that use direct addressing access SFR space. For example:
MOV 0A0H, # data, accesses the SFR at location 0A0h (which is P2).
Upper
Internal
RAM
Lower
Internal
RAM
0FFh
Special
Function
Register
Direct Accesses
00FFh up to 03FFh
0FFFFh
0000
External
Data
Memory
4180E–8051–10/06
23
AT89C51RB2/RC2
•Instruc tions that use indirect addressing access the Upper 128 Bytes of data RAM.
For example: MOV @R0, # data where R0 contains 0A0h, accesses the data Byte
at address 0A0h, rather than P2 (whose address is 0A0h).
•The XRAM Bytes can be accessed by indirect addressing, with EXTRAM bit cleared
and MOVX instructions. This part of memory that is physically located on-chip,
logically occupies the first Bytes of external data memory. The bits XRS0 and XRS1
are used to hide a part of the available XRAM as explained in Table 18. This can be
useful if external peripherals are mapped at addresses already used by the internal
XRAM.
•With EXTRAM = 0,
combination with any of the registers R0, R1 of the selected bank or DPTR. An
access to XRAM will not af fect ports P0, P2, P3 .6 (WR) and P3 .7 (R D) . For
example, with EXTRAM = 0, MOVX @R0, # data where R0 contains 0A0H,
accesses the XRAM at address 0A0H rather than external memory. An access to
external data memory locations higher than the accessible size of the XRAM will be
performed with the MOVX DPTR instructions in the same way as in the standard
80C51, with P0 and P2 as data/address busses, and P3.6 and P3.7 as write and
read timing signals. Accesses to XRAM above 0FFH can only be done by the use of
DPTR.
•With EXTRAM = 1
80C51. MOVX @ Ri will provide an eight-bit address multiplexed with data on Port0
and any output port pins can be used to output higher order address bits. This is to
provide the external pag ing c apa b ili ty. MOVX @ D PTR w ill ge nerate a sixteen-bit
address. Port2 outputs the high-order eight address bits (the contents of DPH) while
Port0 multiplexes the low-order eight address bits (DPL) with data. MOVX @ RI and
MOVX @DPTR will generate either read or write signals on P3.6 (WR
(RD
).
the XRAM is indirectly addressed, using the MOVX instruction in
, MOVX @RI and MOVX @DPTR will be similar to the standard
) and P3.7
The stack pointer (SP) may be located anywhere in the 256 Bytes RAM (lower and
upper RAM) internal data memory. The stack may not be located in the XRAM.
The M0 bit allows to stretc h the XRAM tim ings; if M0 is set, the r ead and wr ite pulses
are extended from 6 to 30 clock periods. This is useful to access externa l slow
peripherals.
24
4180E–8051–10/06
RegistersTable 19. AUXR Register
AUXR - Auxiliary Register (8Eh)
76543210
DPU-M0-XRS1XRS0EXTRAMAO
AT89C51RB2/RC2
Bit
Number
7DPU
6-
5M0
4-
3XRS1XRAM Size
2XRS0
1EXTRAM
Bit
Mnemonic Description
Disable Weak Pull-up
Cleared to activate the permanent weak pull up when latch data is logical 1
Set to disactive the weak pull-up (reduce power consumption)
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Pulse Length
Cleared to stretch MOVX control: the RD
periods (default).
Set to stretch MOVX control: the RD
periods.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
XRS1
00256 Bytes (default)
01512 Bytes
10768 Bytes
111024 Bytes
EXTRAM Bit
Cleared to access internal XRAM using movx @ Ri/ @ DPTR.
Set to access external memory.
Programmed by hardware after Power-up regarding Hardware Security Byte
(HSB), default setting, XRAM selecte d.
and the WR pulse length is 6 clock
and the WR pulse length is 30 clock
XRS0 XRAM size
4180E–8051–10/06
ALE Output Bit
0AO
Clear ed , ALE is em itt e d at a c onst a nt rat e of 1/6 t he osci lla to r freq ue nc y (or 1/3 if
X2 mode is used). (default) Set, ALE is active only during a MOVX or MOVC
instruc tio n is use d.
Reset Value = XX0X 00’HSB. XRAM’0b (see Table 65)
Not bit addressable
25
AT89C51RB2/RC2
Timer 2The Timer 2 in the AT89C51RB2/RC2 is the standard C52 Timer 2.
It is a 16-bit timer/counter: t he count is maintained by two e ight-bit timer registe rs, TH 2
and TL2 are cascaded. It is controlled by T2CON (Table 20) and T2MOD (Table 21)
registers. Timer 2 operation is similar to Timer 0 and Timer 1C/T2
operation) or external pin T2 (counter operation) as the timer clock input. Setting TR2
allows TL2 to increment by the selected input.
Timer 2 has 3 operating modes: capture, autoreload and Ba ud Rate Generator. These
modes are selected by the combination of RCLK, TCLK and CP/RL2
see the Atm el 8-bit Micro control ler Hardw are d escription f or the des criptio n of Cap ture
and Baud Rate Generator Modes.
Timer 2 includes the following enhancements:
•Auto-reload mode with up or down counter
•Programmable clock-output
selects F
(T2CON).
Auto-reload ModeThe auto-re load mod e configu res T imer 2 as a 16 -bit time r or eve nt coun ter with aut o-
matic reload . If DCEN b it in T2MOD i s cleared, Timer 2 behaves as in 8 0C52 (see the
Atmel C51 Microcontroller Hardware d escription). If DCEN bit is s et, Timer 2 acts a s an
Up/down timer/counter as shown in Figure 9. In this mode the T2EX pin controls the
direction of count.
When T2EX is hi gh, Timer 2 c ounts up. T im er overf low occurs at F FF Fh which set s t he
TF2 flag and generat es an interrupt reque st. The overflow also caus es the 16-bit val ue
in RCAP2H and RCAP2L registers to be loaded into the timer registers TH2 and TL2.
/12 (timer
OSC
When T2EX is low, Timer 2 counts down. Timer underflow occurs when the count in the
timer registers TH2 and TL2 equals the value stored in RCAP2H and RCAP2L registers.
The underflow sets TF2 flag and reloads FFFFh into the timer registers.
The EXF2 bit toggles when Timer 2 overflows or underflows according to the direction of
the count. EXF2 does not generate any interrupt . This bit can be used to provide 17-bit
resolution.
T2EX:
if DCEN = 1, 1 = UP
if DCEN = 1, 0 = DOWN
if DCEN = 0, up countin
TOGGLE
TF2
T2CON
T2CON
EXF2
TIMER 2
INTERRUP
In the clock-out mode, Timer 2 operates as a 50% duty-cycle, programmable clock generator (see Fi gure 10). The input clock incr emen ts TL2 at freq uenc y F
CLK PERIPH
/2. The
timer repeatedly counts to overflow from a loaded value. At overflow, the contents of
RCAP2H and RCAP2L registers are loaded into TH2 and TL2. In this mode, Timer 2
overflows do not generate interrupts. The formula gives the clock-out frequency as a
function of the system oscillator frequency and the value in the RCAP2H and RCAP2L
registers:
For a 16 MHz system clock, Timer 2 has a programmable frequency range of 61 Hz
(F
CLK PERIPH
16
/2
) to 4 M H z (F
CLK PERIPH
/4). The generated clock signal is brought out to
T2 pin (P1.0).
Timer 2 is programmed for the clock-out mode as follows:
•Set T2OE bit in T2MOD register.
•Clear C/T 2
bit in T2CON register.
•Determine the 16-bit reload value from the formula and enter it in RCAP2H/RCAP2L
registers.
•Enter a 16-bit initial value in timer registers TH2/TL2. It can be the same as the
reload value or a different one depending on the application.
•T o start the timer, set TR2 run control bit in T2CON register.
It is possible to use Timer 2 as a baud rate generator and a clock generator simulta-
neously. For this configuration, the baud rates and clock frequencies are not
independent since both functions use the values in the RCAP2H and RCAP2L registers.
27
AT89C51RB2/RC2
Figure 10. Clock-Out Mode C/T2 = 0
FCLK PERIPH
:6
TR2
T2CON
TL2
(8-bit)
TH2
(8-bit)
OVERFLOW
T2EX
T2
Toggle
QD
EXEN2
T2CON
RCAP2L
(8-bit)
T2MOD
EXF2
T2CON
RCAP2H
(8-bit)
T2OE
TIMER 2
INTERRUPT
28
4180E–8051–10/06
RegistersTable 20. T 2CON Register
T2CON – Timer 2 Control Register (C8h)
76543210
TF2EXF2RCLKTCLKEXEN2TR2C/T2#CP/RL2#
AT89C51RB2/RC2
Bit
Number
7TF2
6EXF2
5RCLK
4TCLK
3EXEN2
2TR2
Bit
Mnemonic Description
Timer 2 Overflow Flag
Must be cleared by software.
Set by hardware on Timer 2 overflow, if RCLK = 0 and TCLK = 0.
Timer 2 External Flag
Set whe n a captur e or a reload is caused by a negative transiti on on T2EX pin if
EXEN2 = 1.
When set, causes the CPU to vector to Timer 2 interrupt routine when Timer 2
interrupt is enabled.
Must be cleared by software. EXF2 doesn’t cause an interr upt in Up/down
counter mode (DCEN = 1).
Receive Clock Bit
Cleared to use timer 1 overflow as receive clock for serial port in mode 1 or 3.
Set to use Timer 2 overflow as receive clock for serial port in mode 1 or 3.
Transmit Clock Bit
Cleare d to use time r 1 overflow as tran smit clock f or serial port in mode 1 or 3.
Set to use Timer 2 overflow as transmit clock for serial port in mode 1 or 3.
Timer 2 External Enable Bit
Cleared to ignore events on T2EX pin for Timer 2 operation.
Set to cause a capture or reload when a negative transition on T2EX pin is
detected, if Timer 2 is not used to clock the serial port.
Timer 2 Run Control Bit
Cleared to turn off Timer 2.
Set to turn on Timer 2.
4180E–8051–10/06
Timer/Coun ter 2 Select B it
1C/T2#
0CP/RL2#
Cleare d for timer operati on (input fr om inter nal clock system: F
Set for count er oper at ion (i np ut fr o m T2 inp ut pi n, fa ll i ng edg e tr igg er ). Mus t be 0
for clock out mode.
Timer 2 Capture/Reload Bit
If RCLK = 1 or TCLK = 1, CP/RL2# is ignored and timer is forced to auto-reload
on Timer 2 overflow.
Cleare d to auto-reload on Timer 2 overf lows or negative transitions on T2EX pin
if EXEN2 = 1.
Set to capture on negative transitions on T 2EX pin if EXEN2 = 1.
Reset Value = 0000 0000b
Bit addressable
CLK PERIPH
).
29
AT89C51RB2/RC2
Table 21. T2MOD Register
T2MOD – Timer 2 Mode Control Register (C9h)
76543210
------T2OEDCEN
Bit
Number
7-
6-
5-
4-
3-
2-
1T2OE
0DCEN
Bit
Mnemonic Description
Reserved
The value rea d fro m thi s bit is ind et erm in at e. D o no t set this bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. D o no t set this bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. D o no t set this bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. D o no t set this bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. D o no t set this bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. D o no t set this bit.
Timer 2 Output Enable Bitt
Cleared to program P1.0/T2 as clock input or I/O port.
Set to program P1.0/T2 as clock output.
Down Counter Enable Bit
Cleare d to disable Timer 2 as up/down counter.
Set to enable Timer 2 as up/down counter.
Reset Value = XXXX XX00b
Not bit addressable
30
4180E–8051–10/06
Loading...
+ 96 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.