AT89C52

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

4-61

Features
• Compatible with MCS-51™ Products
• 8K Bytes of In-System Reprogrammable Flash Memory
– Endurance: 1,000 Write/Erase Cycles
• Fully Static Operation: 0 Hz to 24 MHz
• Three-Level Program Memory Lock
• 256 x 8-Bit Internal RAM
• 32 Programmable I/O Lines
• Three 16-Bit Timer/Counters
• Eight Interrupt Sources
• Programmable Serial Channel
• Low Power Idle and Power Down Modes

Description

applications.

Pin Configurations
(T2

PQFP/TQFP

4-62 AT89C52
AT89C52

Block Diagram

4-63
The AT89C52 provides program and data
the following standard memory. In this mode, P0
features: 8K bytes of has internal pullups.
Flash, 256 bytes of RAM, Port 0 also receives the
32 I/O lines, three 16-bit code bytes during Flash
timer/counters, a six- programming and outputs
vector two-level interrupt the code bytes during
architecture, a full duplex program verification.
serial port, on-chip External pullups are
oscillator, and clock required during program
circuitry. In addition, the verification.
AT89C52 is designed with
Port 1
static logic for operation
Port 1 is an 8-bit
down to zero frequency
bidirectional I/O port with
and supports two
internal pullups. The Port
software selectable power
1 output buffers can
saving modes. The Idle
sink/source four TTL
Mode stops the CPU
inputs. When 1s are
while allowing the RAM,
written to Port 1 pins, they
timer/counters, serial port,
are pulled high by the
and interrupt system to internal pullups and can
continue functioning. The be used as inputs. As
Power Down Mode saves inputs, Port 1 pins that are
the RAM contents but externally being pulled low
freezes the oscillator, will source current (IIL)
disabling all other chip because of the internal
functions until the next pullups.
hardware reset.
In addition, P1.0 and P1.1
can be configured to be
Pin Description the timer/counter 2
external count input
VCC
(P1.0/T2) and the
Supply voltage.
timer/counter 2 trigger
GND input (P1.1/T2EX),
Ground. respectively, as shown in
Port 0 the following table.
Port 0 is an 8-bit open Port 1 also receives the
drain bidirectional I/O low-order address bytes
port. As an output port, during Flash
each pin can sink eight programming and
TTL inputs. When 1s are verification.
written to port 0 pins, the
Port Pin Alternate Functions
pins can be used as
highimpedance inputs. P1.0 T2 (external count input to Timer/Counter 2),
Port 0 can also be clock-out
configured to be the P1.1 T2EX (Timer/Counter 2 capture/reload trigger
multiplexed loworder and direction control)
address/data bus during
accesses to external

4-64 AT89C52
AT89C52
Port 2 inputs, Port 3 pins that are
Port 2 is an 8-bit externally being pulled low
bidirectional I/O port with will source current (IIL)
internal pullups. The Port because of the pullups.
2 output buffers can Port 3 also serves the
sink/source four TTL functions of various
inputs. When 1s are special features of the
written to Port 2 pins, they AT89C51, as shown in
are pulled high by the the following table.
internal pullups and can
be used as inputs. As Port 3 also receives some
inputs, Port 2 pins that are control signals for Flash
externally being pulled low programming and
will source current (IIL) verification.
because of the internal Port Pin Alternate Functions
pullups.
P3.0 RXD (serial input port)
Port 2 emits the high-
P3.1 TXD (serial output port)
order address byte during
fetches from external P3.2
program memory and INT0 (external interrupt 0)
during accesses to P3.3
external data memory that
INT1 (external interrupt 1)
use 16-bit addresses
(MOVX @ DPTR). In this P3.4 T0 (timer 0 external input)
application, Port 2 uses P3.5 T1 (timer 1 external input)
strong internal pullups
P3.6
when emitting 1s. During
accesses to external data WR (external data memory write strobe)
memory that use 8-bit P3.7
addresses (MOVX @ RI), RD (external data memory read strobe)
Port 2 emits the contents RST
of the P2 Special Reset input. A high on
Function Register. this pin for two machine
Port 2 also receives the cycles while the oscillator
high-order address bits is running resets the
and some control signals device.
during Flash
programming and ALE/PROG
verification. Address Latch Enable is
Port 3 an output pulse for
Port 3 is an 8-bit latching the low byte of
bidirectional I/O port with the address during
internal pullups. The Port accesses to external
3 output buffers can mem-
sink/source four TTL
inputs. When 1s are ory. This pin is also the
written to Port 3 pins, they program pulse input
are pulled high by the (PROG) during Flash
internal pullups and can programming.
be used as inputs. As

4-65
In normal operation, ALE instruction. Otherwise, the
is emitted at a constant pin is weakly pulled high.

pulse is skipped during each access to external data mem- EA/VPP

rate of 1/6 the oscillator Setting the ALE-disable


frequency and may be bit has no External
used for external timing or Access Enable. EA must
clocking purposes. Note, be strapped to GND in
however, that one ALE order to enable the device
ory. to fetch code from
If desired, ALE operation external program memory
can be disabled by setting locations starting at
bit 0 of SFR location 8EH. 0000H up to FFFFH.
With the bit set, ALE is Note, however, that if lock
active only during a bit 1 is programmed, EA
MOVX or MOVC will be internally latched
on reset.
effect if the programming when 12-
microcontroller is in volt programming is
external execution mode. selected.
PSEN XTAL1
Program Store Enable is Input to the inverting
the read strobe to oscillator amplifier and
external program input to the internal clock
memory. operating circuit.
When the AT89C52 is XTAL2
executing code from
external program
memory, PSEN is
activated twice each
machine cycle, except
that two PSEN activations
are skipped during each
access to external data
memory.

Table 1. AT89C52 SFR


Map and Reset Values
EA should be strapped to
VCC for internal program
executions.
This pin also receives the
12-volt programming
enable voltage (VPP)
during Flash

4-66 AT89C52
AT89C52

B
00000000

ACC
00000000

PSW
00000000

T2CON T2MOD RCAP2L RCAP2H TL2 TH2


00000000 XXXXXX00 00000000 00000000 00000000 00000000

IP
XX000000

P3
11111111

IE
0X000000

P2
11111111

SCON SBUF
00000000 XXXXXXXX

P1
11111111

TCON TMOD TL0 TL1 TH0 TH1


00000000 00000000 00000000 00000000 00000000 00000000

P0 SP DPL DPH PCON


11111111 00000111 00000000 00000000 0XXX0000
0F8H0FFH 0F0H0F7H

0E8H0EFH 0E0H0E7H

0D8H0DFH

0D0H0D7H

0C8H0CFH 0C0H0C7H

0B8H0BFH

0B0H0B7H

0A8H0AFH 0A0H0A7H

98H9FH

90H97H

4-67
88H8FH

80H87H
Output from the inverting
oscillator amplifier.

4-68 AT89C52
AT89C52

Special Function be used in future products


to invoke Table 2.
Registers
T2CON—Timer/Counter 2
A map of the on-chip
memory area called the Control Register
Special Function Register new features. In that
(SFR) space is shown in case, the reset or inactive
Table 1. values of the new bits will
Note that not all of the always be 0.
addresses are occupied, Timer 2 Registers:
and unoccupied Control and status bits
addresses may not be are contained in registers
implemented on the chip. T2CON (shown in Table
Read accesses to these 2) and T2MOD (shown in
addresses will in general Table 4) for Timer 2. The
return random data, and register pair (RCAP2H,
write accesses will have RCAP2L) are the
an indeterminate effect. Capture/Reload registers
User software should not for Timer 2 in 16-bit
write 1s to these unlisted capture mode or 16-bit
auto-reload mode.
locations, since they may
T2CON Address = 0C8H Reset Value = 0000 0000B

Bit Addressable

Bit TF2 EXF2 RCLK TCLK EXEN2 TR2


C/T2 CP/RL2
7 6 5 4 3 2 1 0
Symbol Function
TF2 Timer 2 overflow flag set by a Timer 2 overflow and must be cleared by software. TF2 will not be set when either
RCLK = 1 or TCLK = 1.
EXF2 Timer 2 external flag set when either a capture or reload is caused by a negative transition on T2EX and EXEN2 =
1. When Timer 2 interrupt is enabled, EXF2 = 1 will cause the CPU to vector to the Timer 2 interrupt routine. EXF2
must be cleared by software. EXF2 does not cause an interrupt in up/down counter mode (DCEN = 1).
RCLK Receive clock enable. When set, causes the serial port to use Timer 2 overflow pulses for its receive clock in serial
port Modes 1 and 3. RCLK = 0 causes Timer 1 overflow to be used for the receive clock.
TCLK Transmit clock enable. When set, causes the serial port to use Timer 2 overflow pulses for its transmit clock in
serial port Modes 1 and 3. TCLK = 0 causes Timer 1 overflows to be used for the transmit clock.
EXEN2 Timer 2 external enable. When set, allows a capture or reload to occur as a result of a negative transition on T2EX
if Timer 2 is not being used to clock the serial port. EXEN2 = 0 causes Timer 2 to ignore events at T2EX.
TR2 Start/Stop control for Timer 2. TR2 = 1 starts the timer.

C/T2 Timer or counter select for Timer 2. C/T2 = 0 for timer function. C/T2 = 1 for external event counter (falling edge
triggered).

CP/RL2 Capture/Reload select. CP/RL2 = 1 causes captures to occur on negative transitions at T2EX if EXEN2 = 1.
CP/RL2
= 0 causes automatic reloads to occur when Timer 2 overflows or negative transitions occur at T2EX when EXEN2
= 1. When either RCLK or TCLK = 1, this bit is ignored and the timer is forced to auto-reload on Timer 2 overflow.

4-69
Interrupt Registers: The for each of the six
individual interrupt enable interrupt sources in the IP
bits are in the IE register. register.
Two priorities can be set
Data Memory addressing, so the upper
128 bytes of data RAM
The AT89C52 implements
are available as stack
256 bytes of on-chip
space.
RAM. The upper 128
bytes occupy a parallel Timer 0 and 1
address space to the Timer 0 and Timer 1 in
Special Function the AT89C52 operate the
Registers. That means same way as Timer 0 and
the upper 128 bytes have Timer 1 in the AT89C51.
the same addresses as
the SFR space but are
physically separate from Timer 2
SFR space. Timer 2 is a 16-bit
When an instruction Timer/Counter that can
accesses an internal operate as either a timer
location above address or an event counter. The
7FH, the address mode type of operation is
used in the instruction
specifies whether the selected by bit C/T2 in the
CPU accesses the upper SFR T2CON (shown in
128 bytes of RAM or the Table 2). Timer 2 has
SFR space. Instructions three operating modes:
that use direct addressing capture, auto-reload (up
access SFR space. or down counting), and
For example, the baud rate generator. The
following direct modes are selected by
addressing instruction bits in T2CON, as shown
accesses the SFR at in Table 3.
location 0A0H (which is Timer 2 consists of two 8-
P2). bit registers, TH2 and
MOV 0A0H, #data TL2. In the Timer
Instructions that use function, the TL2 register
indirect addressing is incremented every
access the upper 128 machine cycle. Since a
bytes of RAM. For machine cycle consists of
example, the following 12 oscillator periods, the
indirect addressing count rate is 1/12 of the
instruction, where R0 oscillator frequency.
contains 0A0H, accesses Table 3. Timer 2
the data byte at address Operating Modes
0A0H, rather than P2
(whose address is 0A0H). RCLK +TCLK CP/RL2 TR2 MODE
MOV @R0, #data 0 0 1 16-Bit Auto-Reload
Note that stack operations 0 1 1 16-Bit Capture
are examples of indirect

4-70 AT89C52
AT89C52

1 X at least once before it


changes, the level should
X X be held for at least one
In the Counter function, full machine cycle.
the register is
incremented in response Capture Mode
to a 1-to-0 transition at its In the capture mode, two
corresponding external options are selected by bit
input pin, T2. In this EXEN2 in T2CON. If
function, the external EXEN2 = 0, Timer 2 is a
input is sampled during 16-bit timer or counter
S5P2 of every machine which upon overflow sets
cycle. When the samples bit TF2 in T2CON. This bit
can then be used to
Figure 1. Timer in generate an interrupt. If

OSC ÷12
C/T2 = 0

TH2 TL2 TF2

OVERFLOW
CONTROL
TR2
C/T2 = 1

T2 PIN CAPTURE
RCAP2H RCAP2L
TRANSITION
DETECTOR TIMER 2
INTERRUPT
T2EX PIN EXF2

CONTROL
EXEN2
Capture Mode EXEN2 = 1, Timer 2
show a high in one cycle performs the same
and a low in the next operation, but a 1to-0
cycle, the count is transition at external input
incremented. The new T2EX also causes the
count value appears in current value in TH2 and
the register during S3P1 TL2 to be captured into
of the cycle following the RCAP2H and RCAP2L,
one in which the transition respectively. In addition,
was detected. Since two the transition at T2EX
machine cycles (24 causes bit EXF2 in
oscillator periods) are T2CON to be set. The
required to recognize a 1- EXF2 bit, like TF2, can
to-0 transition, the generate an interrupt. The
maximum count rate is capture mode is
1/24 of the oscillator illustrated in Figure 1.
frequency. To ensure that
a given level is sampled

4-71
Auto-Reload (Up or sets the EXF2 bit. Both
Down Counter) the TF2 and EXF2 bits
can generate an interrupt
Timer 2 can be
if enabled.
programmed to count up
or down when configured Setting the DCEN bit
in its 16-bit auto-reload enables Timer 2 to count
mode. This feature is up or down, as shown in
invoked by the DCEN
Figure 3. In this mode, the
(Down Counter Enable)
bit located in the SFR T2EX pin controls Figure
T2MOD (see Table 4). 2. Timer 2 Auto Reload
Upon reset, the DCEN bit Mode (DCEN = 0)
is set to 0 so that timer 2
will default to count up. the direction of the count.
When DCEN is set, Timer A logic 1 at T2EX makes
2 can count up or down, Timer 2 count up. The
depending on the value of timer will overflow at
the T2EX pin. 0FFFFH and set the TF2
bit. This overflow also
Figure 2 shows Timer 2 causes the 16-bit value in
automatically counting up RCAP2H and RCAP2L to
when DCEN = 0. In this be reloaded into the timer
mode, two options are registers, TH2 and TL2,
selected by bit EXEN2 in respectively.
T2CON. If EXEN2 = 0,
Timer 2 counts up to A logic 0 at T2EX makes
0FFFFH and then sets Timer 2 count down. The
the TF2 bit upon overflow. timer underflows when
The overflow also causes TH2 and TL2 equal the
the timer registers to be values stored in RCAP2H
reloaded with the 16-bit and RCAP2L. The
value in RCAP2H and underflow sets the TF2 bit
RCAP2L. The values in and causes 0FFFFH to be
Timer in Capture reloaded into the timer
ModeRCAP2H and registers.
RCAP2L are preset by The EXF2 bit toggles
software. If EXEN2 = 1, a whenever Timer 2
16-bit reload can be overflows or underflows
triggered either by an and can be used as a
overflow or by a 1-to-0 17th bit of resolution. In
transition at external input this operating mode,
T2EX. This transition also EXF2 does not flag an
interrupt.

4-72 AT89C52
AT89C52

OSC ÷12
C/T2 = 0

TH2 TL2

OVERFLOW
CONTROL
TR2
C/T2 = 1
RELOAD

T2 PIN TIMER 2
INTERRUPT
RCAP2H RCAP2L

TF2
TRANSITION
DETECTOR

T2EX PIN EXF2

CONTROL
EXEN2

Table 4. T2MOD—Timer 2 Mode Control Register


T2MOD Address = 0C9H Reset Value = XXXX XX00B

Not Bit Addressable

— — — — — — T2OE DCEN

Bit 7 6 5 4 3 2 1 0

Symbol Function
— Not implemented, reserved for future
T2OE Timer 2 Output Enable bit.
DCEN When set, this bit allows Timer 2 to be configured as an up/down counter.
Figure 3. Timer 2 Auto Reload Mode (DCEN = 1)

4-73
(DOWN COUNTING RELOAD VALUE
) TOGGLE

0FFH 0FFH
EXF2

OSC ÷12 OVERFLOW


C/T2 = 0

TH2 TL2 TF2

CONTROL
TR2
C/T2 = 1 TIMER 2
INTERRUPT
T2 PIN
RCAP2H RCAP2L
COUNT
(UP COUNTING RELOAD VALUE
) DIRECTION
1=UP
0=DOWN

T2EX PIN

Figure 4. Timer 2 in Baud Rate Generator Mode


TIMER 1 OVERFLOW

÷2
"0" "1"
NOTE:OSC.FREQ.IS DIVIDED BY 2, NOT 12
SMOD1

OSC ÷2 C/T2 = 0
"1" "0"
TH2 TL2
RCLK
Rx
CONTROL CLOCK
TR2 ÷ 16
C/T2 = 1
"1" "0"
T2 PIN
TCLK
RCAP2H RCAP2L Tx
CLOCK
TRANSITION
DETECTOR
÷ 16

TIMER 2
T2EX PIN EXF2 INTERRUPT

CONTROL
EXEN2

4-74 AT89C52
AT89C52

Baud Rate it is used as a baud rate


generator. Normally, as a
Generator timer, it increments every
Timer 2 is selected as the machine cycle (at 1/12
baud rate generator by the oscillator frequency).
setting TCLK and/or As a baud rate generator,
RCLK in T2CON (Table however, it
2). Note that the baud
rates for transmit and
receive can be different if
Timer 2 is used for the
receiver or transmitter
and Timer 1 is used for
the other function. Setting
RCLK and/or TCLK puts
Timer 2 into its baud rate
generator mode, as
shown in Figure 4.
The baud rate generator
mode is similar to the
auto-reload mode, in that
a rollover in TH2 causes
the Timer 2 registers to
be reloaded with the 16-
bit value in registers
RCAP2H and RCAP2L,
which are preset by
software.
The baud rates in Modes
1 and 3 are determined
by Timer 2’s overflow rate
according to the following
equation.
Timer 2 Overflow Rate
Modes 1 and 3 Baud Rates
=
--------------------------------------
---------------------
1
6

The Timer can be


configured for either timer
or counter operation. In
most applications, it is
configured for timer

operation (CP/T2 = 0).


The timer operation is
different for Timer 2 when

4-75
Figure 5. Timer 2 in TCLK = 1 in T2CON. Note

TL2 TH2
OSC ÷2
(8-BITS) (8-BITS)

TR2

RCAP2L RCAP2H
C/T2 BIT

P1.0
÷2
(T2)

T2OE (T2MOD.1)

TRANSITION
DETECTOR

P1.1 TIMER 2
(T2EX) EXF2
INTERRUPT

EXEN2
Clock-Out Mode that a rollover in TH2
increments every state does not set TF2 and will
time (at 1/2 the oscillator not generate an interrupt.
frequency). The baud rate Note too, that if EXEN2 is
formula is given below. set, a 1-to-0 transition in
T2EX will set EXF2 but
Modes 1 and 3
will not cause a reload
Oscillator Frequency
from (RCAP2H, RCAP2L)
--------------------------------------
-= to (TH2, TL2). Thus when
------------------------------------- Timer 2 is in use as a
------------------------------------- baud rate generator,
------------------- T2EX can be used as an
Baud Rate32 × extra external interrupt.
[65536 – (RCAP2H RCAP2L, Note that when Timer 2 is
)] running (TR2 = 1) as a
timer in the baud rate
where (RCAP2H, generator mode, TH2 or
RCAP2L) is the content of TL2 should not be read
RCAP2H and RCAP2L from or written to. Under
taken as a 16-bit these conditions, the
unsigned integer. Timer is incremented
Timer 2 as a baud rate every state time, and the
generator is shown in results of a read or write
Figure 4. This figure is may not be accurate. The
valid only if RCLK or RCAP2 registers may be

4-76 AT89C52
AT89C52
read but should not be
written to, because a write
might overlap a reload
and cause write and/or
reload errors. The timer
should be turned off (clear
TR2) before accessing
the Timer 2 or RCAP2
registers.

4-77
Programmable is possible to use Timer 2
as a baud-rate generator
Clock Out and a clock generator
A 50% duty cycle clock simultaneously. Note,
can be programmed to however, that the baud-
come out on P1.0, as rate and clock-out
shown in Figure 5. This frequencies cannot be
pin, besides being a determined independently
regular I/O pin, has two from one another since
alternate functions. It can they both use RCAP2H
be programmed to input and RCAP2L.
the external clock for
Timer/Counter 2 or to
output a 50% duty cycle UART
clock ranging from 61 Hz The UART in the
to 4 MHz at a 16 MHz AT89C52 operates the
operating frequency. same way as the UART in
To configure the the AT89C51.
Timer/Counter 2 as a
clock generator, bit Interrupts
The AT89C52 has a total
C/T2 (T2CON.1) must be of six interrupt vectors:
cleared and bit T2OE two exter-
(T2MOD.1) must be set.
Bit TR2 (T2CON.2) starts
nal interrupts (INT0 and
and stops the timer.
INT1), three timer
The clock-out frequency interrupts (Timers 0, 1,
depends on the oscillator and 2), and the serial port
frequency and the reload interrupt. These interrupts
value of Timer 2 capture are all shown in Figure 6.
registers (RCAP2H,
Each of these interrupt
RCAP2L), as shown in
sources can be
the following equation.
individually enabled or
Oscill
disabled by setting or
ator
Fequ
clearing a bit in Special
encyFunction Register IE. IE
Clock-Out Frequency= also contains a global
-------------------------------------- disable bit, EA, which
-------------------------------------- disables all interrupts at
-------------- once.
4 Note that Table 5 shows
RCAP2L, that bit position IE.6 is
unimplemented. In the
In the clock-out mode,
AT89C51, bit position IE.5
Timer 2 roll-overs will not
is also unimplemented.
generate an interrupt.
User software should not
This behavior is similar to
write 1s to these bit
when Timer 2 is used as
positions, since they may
a baud-rate generator. It

4-78 AT89C52
AT89C52
be used in future AT89 Table 5. Interrupt Enable
products. (IE) Register
Timer 2 interrupt is
generated by the logical
OR of bits TF2 and EXF2
in register T2CON.
Neither of these flags is
cleared by hardware
when the service routine
is vectored to. In fact, the
service routine may have
to determine whether it
was TF2 or EXF2 that
generated the interrupt,
and that bit will have to be
cleared in software.
The Timer 0 and Timer 1
flags, TF0 and TF1, are
set at S5P2 of the cycle in
which the timers overflow.
The values are then
polled by the circuitry in
the next cycle. However,
the Timer 2 flag, TF2, is
set at S2P2 and is polled
in the same cycle in which
the timer overflows.

(MSB)
(LSB)
EA — ET2 ES ET1 EX1 ET0 EX0
Enable Bit = 1 enables the interrupt.

Enable Bit = 0 disables the interrupt.

Symbol Position Function


EA IE.7 Disables all interrupts. If EA = 0,
no interrupt is acknowledged. If
EA = 1, each interrupt source is
individually enabled or disabled
by setting or clearing its enable
bit.
— IE.6 Reserved.
ET2 IE.5 Timer 2 interrupt enable bit.
ES IE.4 Serial Port interrupt enable bit.
ET1 IE.3 Timer 1 interrupt enable bit.
EX1 IE.2 External interrupt 1 enable bit.
ET0 IE.1 Timer 0 interrupt enable bit.
EX0 IE.0 External interrupt 0 enable bit.
User software should never write 1s to unimplemented bits,
because they may be used in future AT89 products.

4-79
Figure 6. Interrupt maximum voltage high

Sources and low time


specifications must be
Oscillator observed.
Characteristics
XTAL1 and XTAL2 are
the input and output,
Idle Mode
respectively, of an In idle mode, the CPU
inverting amplifier that puts itself to sleep while
can be configured for use all the onchip peripherals
as an on-chip oscillator, remain active. The mode
as shown in Figure 7. is invoked by software.
Either a quartz crystal or The content of the on-chip
ceramic resonator may be RAM and all the special
used. To drive the device functions registers remain
from an external clock unchanged during this
source, XTAL2 should be mode. The idle mode can
left unconnected while be terminated by any
XTAL1 is driven, as enabled interrupt or by a
shown in Figure 8. There hardware reset.
are no requirements on Note that when idle mode
the duty cycle of the is terminated by a
external clock signal, hardware reset, the
since the input to the device normally resumes
internal clocking circuitry program execution from
is through a divide-by-two where it left off, up to two
flip-flop, but minimum and machine cycles before the

4-80 AT89C52
AT89C52
internal reset algorithm oscillator to restart and
takes control. On-chip stabilize.
hardware inhibits access
Figure 7. Oscillator
to internal RAM in this
Connections
event, but access to the
port pins is not inhibited. C2
To eliminate the XTAL2
possibility of an
unexpected write to a port
pin when idle mode is
terminated by a reset, the C1
instruction following the XTAL1
one that invokes idle
mode should not write to
a port pin or to external
memory. GND

Power Down
Mode
In the power down mode,
the oscillator is stopped, Note: C1, C2 = 30 pF
pF for Crystals
and the instruction that
invokes power down is = 40 pF ±
10 pF for
the last instruction
Ceramic
executed. The on-chip Resonator
RAM and Special s
Function Registers retain
their values until the Figure 8. External Clock
power down mode is Drive Configuration
terminated. The only exit
from power down is a
hardware reset. Reset
redefines the SFRs but
does not change the on-
chip RAM. The reset
should not be activated
before VCC is restored to
its normal operating level
and must be held active
long enough to allow the
Status of External Pins During Idle and Power Down Modes
Mode Program Memory ALE PSEN PORT0 PORT1 PORT2 PORT3
Idle Internal 1 1 Data Data Data Data
Idle External 1 1 Float Data Address Data
Power Down Internal 0 0 Data Data Data Data
Power Down External 0 0 Float Data Data Data

4-81
When lock bit 1 is
NC programmed,
XTAL2 the logic
level at the EA pin is
sampled and latched
during reset. If the device
is powered up without a
EXTERNAL
reset, XTAL1
the latch initializes
OSCILLATOR
SIGNAL to a random value and
holds that value until reset
is activated. The
GND
latched value of EA must
agree with the current
logic level at that pin in
Program Memory order for the device to
Lock Bits function properly.
The AT89C52 has three
lock bits that can be left
unprogrammed (U) or can
Programming the
be programmed (P) to Flash
obtain the additional The AT89C52 is normally
features listed in the shipped with the on-chip
following table. Flash memory array in the
erased state (that is,
contents = FFH) and
Lock Bit ready to be programmed.
Protection The programming
interface accepts either a
Modes high-voltage (12-volt) or a
Program Lock Bits low-voltage (VCC) program
enable signal. The low
LB1 LB2 LB3 voltage programming
mode provides a
1 U U U
convenient way to
2 P U U program the AT89C52
inside the user’s system,
while the high-voltage
programming mode is
compatible with
conventional thirdparty
Flash or EPROM
programmers.
The AT89C52 is shipped
with either the high-
3 P P U voltage or low-voltage
programming mode
enabled. The respective
4 P P P top-side marking and
device signature codes

4-82 AT89C52
AT89C52
are listed in the following The byte-write cycle
table. is self-timed and
typically takes no
VPP = 12V more than 1.5 ms.
Repeat steps 1
Top-Side Mark AT89C52 through 5, changing
xxxx the address and data
yyww for the entire array or
until the end of the
Signature (030H)=1EH
object file is reached.
(031H)=52H
(032H)=FFH
Data Polling: The
The AT89C52 code AT89C52 features Data
memory array is Polling to indicate the end
programmed byte-bybyte of a write cycle. During a
in either programming write cycle, an attempted
mode. To program any read of the last byte
nonblank byte in the on- written will result in the
chip Flash Memory, the complement of the written
entire memory must be data on PO.7. Once the
erased using the Chip write cycle has been
Erase Mode. completed, true data is
Programming valid on all outputs, and
Algorithm: Before
programming the the next cycle may begin.
AT89C52, the address, Data Polling may begin
data and control signals any time after a write
should be set up cycle has been initiated.
according to the Flash
programming mode table Ready/Busy: The
and Figures 9 and 10. To progress of byte
program the AT89C52, programming can also
take the following steps.
1. Input the desired be monitored by the
memory location on RDY/BSY output signal.
the address lines. P3.4 is pulled low after
2. Input the appropriate ALE goes high during
data byte on the data programming to indicate
lines.
3. Activate the correct BUSY. P3.4 is pulled high
combination of control again when programming
signals. is done to indicate
READY.
4. Raise EA/VPP to 12V
for the high-voltage Program Verify: If lock
programming mode. bits LB1 and LB2 have
not been programmed,
5. Pulse ALE/PROG
the programmed code
once to program a
data can be read back via
byte in the Flash
the address and data
array or the lock bits.

4-83
lines for verification. The Flash
lock bits cannot be
verified directly. Programming
Verification of the lock bits Modes
is achieved by observing
that their features are
enabled.
Chip Erase: The entire
Flash array is erased
electrically by using the
proper combination of
control signals and by

holding ALE/PROG low


for 10 ms. The code array
is written with all 1s. The
chip erase operation must
be executed before the
code memory can be
reprogrammed.
Reading the Signature
Bytes: The signature
bytes are read by the
same procedure as a
normal verification of Programming
locations 030H, 031H, Interface
and 032H, except that
Every code byte in the
P3.6 and P3.7 must be
Flash array can be
pulled to a logic low. The
written, and the entire
values returned are as
array can be erased, by
follows.
using the appropriate
(030H) = 1EH combination of control
indicates signals. The write
manufactured by operation cycle is
Atmel selftimed and once
(031H) = 52H initiated, will automatically
indicates 89C52 time itself to completion.
(032H) = FFH All major programming
indicates 12V vendors offer worldwide
programming support for the Atmel
(032H) = 05H microcontroller series.
indicates 5V Please contact your local
programming programming vendor for
the appropriate software
revision.

Mode RST PSEN ALE/PROG EA/VPP P2.6 P2.7 P3.6 P3.7

4-84 AT89C52
AT89C52

Write Code Data H L H/12V L H H H

Read Code Data H L H H L L H H

Write Lock Bit - 1 H L H/12V H H H H

Bit - 2 H L H/12V H H L L

Bit - 3 H L H/12V H L H L

Chip Erase H L (1) H/12V H L L L

Read Signature H L H H L L L L
Byte
Note: 1. Chip Erase requires a 10-ms PROG pulse.
Figure 9. Programming the Flash Memory
Verifying the Flash Memory
+5V +5V

4-85
Flash Programming and Verification
Characteristics
TA = 0°C to 70°C, VCC = 5.0 ± 10%
Symbol Parameter Min Max Units
VPP(1) Programming Enable Voltage 11.5 12.5 V
IPP(1) Programming Enable Current 1.0 mA

/t Oscillator Frequency 3 24 MHz


1 CLCL

t
tAVGL Address Setup to PROG Low 48 CLCL

t
tGHAX Address Hold After PROG 48 CLCL

t
tDVGL Data Setup to PROG Low 48 CLCL

t
tGHDX Data Hold After PROG 48 CLCL

t
tEHSH P2.7 (ENABLE) High to VPP 48 CLCL

10 µs
tSHGL VPP Setup to PROG Low
tGHSL(1) 10 µs
VPP Hold After PROG
1 110 µs
tGLGH PROG Width
Address to Data Valid t
tAVQV 48 CLCL

t
tELQV ENABLE Low to Data Valid 48 CLCL

0
t
tEHQZ Data Float After ENABLE 48 CLCL

1.0 µs
tGHBL PROG High to BUSY Low
Byte Write Cycle Time 2.0 ms
tWC
Note: 1. Only used in 12-volt programming mode.

4-86 AT89C52
AT89C52

Flash Programming and Verification


Waveforms - High Voltage Mode
(VPP=12V)
PROGRAMMING VERIFICATION
P1.0-P1.7
ADDRESS ADDRESS
P2.0-P2.4
tAVQV
PORT0 DATAIN DATAOUT
tDVGL tGHDX
tAVGL tGHAX
ALE/PROG
tSHGL tGHSL
tGLGH
VPP LOGIC1
EA/VPP LOGIC0
(2)
tEHSH tEHQZ
tELQV
P2.7
(ENABLE)
tGHBL
P3.4
(RDY/BSY) BUSY READY
tWC

4-87
Flash Programming and Verification
Waveforms - Low Voltage Mode
(VPP=5V)
PROGRAMMING VERIFICATION
P1.0-P1.7
ADDRESS ADDRESS
P2.0-P2.4
tAVQV
PORT0 DATAIN DATAOUT
tDVGL tGHDX
tAVGL tGHAX
ALE/PROG
tSHGL
tGLGH
LOGIC1
EA/VPP LOGIC0

tEHSH tEHQZ
tELQV
P2.7
(ENABLE)
tGHBL
P3.4
(RDY/BSY) BUSY READY
tWC
Absolute Maximum Ratings*
Operating Temperature.................................. -55°C to

+125°C Storage Temperature..................................... -65°C

to +150°C

Voltage on Any Pin


with Respect to Ground.....................................-1.0V to +7.0V

Maximum Operating Voltage.............................................


6.6V

DC Output Current...................................................... 15.0 mA


*NOTICE: Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent dam-
age to the device. This is a stress rating only and functional
operation of the device at these or any other conditions beyond
those indicated in the operational sections of this specification
is not implied. Exposure to absolute maximum rating
conditions for extended periods may affect device reliability.

4-88 AT89C52
AT89C52

DC Characteristics
The values shown in this table are valid for T A = -40°C to
85°C and VCC = 5.0V ± 20%, unless otherwise noted.
Symbol Parameter Condition Min Max Units

Input Low Voltage -0.5 0.2 VCC-0.1 V


VIL (Except EA)
-0.5 0.2 VCC-0.3 V
VIL1 Input Low Voltage (EA)

VIH Input High Voltage (Except XTAL1, RST) 0.2 VCC+0.9 VCC+0.5 V

VIH1 Input High Voltage (XTAL1, RST) 0.7 VCC VCC+0.5 V

Output Low Voltage(1) (Ports 1,2,3) IOL = 1.6 mA 0.45 V


VOL

Output Low Voltage(1) IOL = 3.2 mA 0.45 V


VOL1
(Port 0, ALE, PSEN)
VOH Output High Voltage IOH = -60 µA, VCC = 5V ± 10% 2.4 V

(Ports 1,2,3, ALE, PSEN) V


IOH = -25 µA 0.75 VCC

IOH = -10 µA 0.9 VCC V

VOH1 Output High Voltage IOH = -800 µA, VCC = 5V ± 10% 2.4 V
(Port 0 in External Bus Mode)

IOH = -300 µA 0.75 VCC V

IOH = -80 µA 0.9 VCC V

Logical 0 Input Current (Ports 1,2,3) VIN = 0.45V -50 µA


IIL
Logical 1 to 0 Transition Current VIN = 2V, VCC = 5V ± 10% -650 µA
ITL
(Ports 1,2,3)

0.45 < VIN < VCC ±10 µA


ILI Input Leakage Current (Port 0, EA)
RRST Reset Pulldown Resistor 50 300 KΩ

Pin Capacitance Test Freq. = 1 MHz, TA = 25°C 10 pF


CIO
ICC Power Supply Current Active Mode, 12 MHz 25 mA

Idle Mode, 12 MHz 6.5 mA

Power Down Mode(1) VCC = 6V 100 µA

4-89
VCC = 3V 40 µA

Notes: 1. Under
steady state
(non-
transient)
conditions, IOL
must be
externally
limited as
follows:
Maximum IOL
per port pin:
10 mA
Maximum IOL
per 8-bit port:
Port 0: 26 mA Ports 1, 2, 3: 15 mA
Maximum total IOL for all output pins: 71 mA
If IOL exceeds the test condition, VOL may exceed
the related specification. Pins are not guaranteed
to sink current greater than the listed test
conditions.
2. Minimum VCC for Power Down is 2V.
AC Characteristics
Under operating conditions, load capacitance for Port 0,
ALE/PROG, and PSEN = 100 pF; load capacitance for
all other outputs = 80 pF.

External Program and Data Memory


Characteristics
Symbol Parameter 12 MHz Oscillator Variable Oscillator Units
Min Max Min Max

/t Oscillator Frequency 0 24 MHz


1 CLCL

ALE Pulse Width 127 2tCLCL-40 ns


tLHLL
Address Valid to ALE Low 43 ns
tAVLL tCLCL-13
Address Hold After ALE Low 48 ns
tLLAX tCLCL-20
ALE Low to Valid Instruction In 233 4tCLCL-65 ns
tLLIV

4-90 AT89C52
AT89C52

43 ns
tLLPL ALE Low to PSEN Low tCLCL-13
205 3tCLCL-20 ns
tPLPH PSEN Pulse Width
145 3tCLCL-45 ns
tPLIV PSEN Low to Valid Instruction In
0 0 ns
tPXIX Input Instruction Hold After PSEN
59 ns
tPXIZ Input Instruction Float After PSEN tCLCL-10
75 ns
tPXAV PSEN to Address Valid tCLCL-8
Address to Valid Instruction In 312 5tCLCL-55 ns
tAVIV
10 10 ns
tPLAZ PSEN Low to Address Float
400 6tCLCL-100 ns
tRLRH RD Pulse Width
400 6tCLCL-100 ns
tWLWH WR Pulse Width
252 5tCLCL-90 ns
tRLDV RD Low to Valid Data In
0 0 ns
tRHDX Data Hold After RD
97 2tCLCL-28 ns
tRHDZ Data Float After RD
ALE Low to Valid Data In 517 8tCLCL-150 ns
tLLDV
Address to Valid Data In 585 9tCLCL-165 ns
tAVDV
200 300 3tCLCL-50 3tCLCL+50 ns
tLLWL ALE Low to RD or WR Low
203 4tCLCL-75 ns
tAVWL Address to RD or WR Low
23 ns
tQVWX Data Valid to WR Transition tCLCL-20
433 7tCLCL-120 ns
tQVWH Data Valid to WR High
33 ns
tWHQX Data Hold After WR tCLCL-20

4-91
0 0 ns
tRLAZ RD Low to Address Float
43 123 ns
tWHLH RD or WR High to ALE High tCLCL-20 tCLCL+25
External Program Memory Read
Cycle
tLHLL
ALE
tPLPH
tAVLL tLLIV
tLLPL
PSEN tPLIV
tPXAV
tPLAZ
tPXIZ
tLLAX
tPXIX
PORT0 A0-A7 INSTRIN A0-A7

tAVIV

PORT2 A8-A15 A8-A15

External Data Memory Read Cycle


tLHLL
ALE
tWHLH

PSEN
tLLDV
tRLRH
tLLWL

RD tLLAX
tRLDV tRHDZ
tAVLL
tRLAZ
tRHDX

PORT 0 A0 - A7 FROM RI OR DPL DATA IN A0 - A7 FROM PCL INSTR IN

tAVWL
tAVDV
PORT 2 P2.0 - P2.7 OR A8 - A15 FROM DPH A8 - A15 FROM PCH

4-92 AT89C52
AT89C52

External Data Memory Write Cycle


tLHLL
ALE
tWHLH

PSEN
tLLWL tWLWH

WR tLLAX
tAVLL tQVWX tWHQX
tQVWH

PORT 0 A0 - A7 FROM RI OR DPL DATA OUT A0 - A7 FROM PCL INSTR IN

tAVWL

PORT 2 P2.0 - P2.7 OR A8 - A15 FROM DPH A8 - A15 FROM PCH

External Clock Drive Waveforms


tCHCX
tCHCX tCLCH tCHCL
VCC - 0.5V
0.7 VCC

0.2 VCC - 0.1V


0.45V
tCLCX
tCLCL

External Clock Drive


Symbol Parameter Min Max Units

/t Oscillator Frequency 0 24 MHz


1 CLCL

Clock Period 41.6 ns


tCLCL

High Time 15 ns
tCHCX

Low Time 15 ns
tCLCX

4-93
Rise Time 20 ns
tCLCH

Fall Time 20 ns
tCHCL
Serial Port Timing: Shift Register
Mode Test Conditions
The values in this table are valid for VCC = 5.0V ± 20%
and Load Capacitance = 80 pF.
Symbol Parameter 12 MHz Osc Variable Oscillator Units

Min Max Min Max

Serial Port Clock Cycle Time 1.0 t µs


tXLXL 12 CLCL

Output Data Setup to Clock Rising Edge 700 10tCLCL-133 ns


tQVXH
Output Data Hold After Clock Rising Edge 50 2tCLCL-117 ns
tXHQX
Input Data Hold After Clock Rising Edge 0 0 ns
tXHDX
Clock Rising Edge to Input Data Valid 700 10tCLCL-133 ns
tXHDV
Shift Register Mode Timing
Waveforms
INSTRUCTION 0 1 2 3 4 5 6 7 8
ALE
tXLXL
CLOCK
tQVXH
tXHQX
WRITETOSBUF 0 1 2 3 4 5 6 7
tXHDX
OUTPUTDATA tXHDV SETTI
CLEARRI VALID VALID VALID VALID VALID VALID VALID VALID

INPUTDATA SETRI

AC Testing Input/Output Waveforms(1) Float Waveforms(1)


V - 0.5VCC

4-94 AT89C52
AT89C52
0.2 VCC + 0.9V V LOAD+0.1 V V OL -0.1 V

TEST POINTS Timing Reference


Points
0.2 VCC - 0.1V V LOAD -0.1 V V OL +0.1 V
V
LOAD 0.45V

Note: 1. AC Inputs during testing are driven at VCC - 0.5V for Note: 1. For timing purposes, a port pin is no longer floating
a logic 1 and 0.45V for a logic 0. Timing mea- when a 100 mV change from load voltage occurs. A
surements are made at VIH min. for a logic 1 and
VIL port pin begins to float when a 100 mV
change from max. for a logic 0. the loaded
VOH/VOL level occurs.
Ordering Information
Speed Power
(MHz) Supply Ordering Code Package Operation Range

12 5V ± 20% AT89C52-12AC 44A Commercial


AT89C52-12JC 44J (0°C to 70°C)
AT89C52-12PC 40P6
AT89C52-12QC 44Q

AT89C52-12AI 44A Industrial (-


AT89C52-12JI 44J 40°C to 85°C)
AT89C52-12PI 40P6
AT89C52-12QI 44Q

AT89C52-12AA 44A Automotive (-


AT89C52-12JA 44J 40°C to 105°C)
AT89C52-12PA 40P6
AT89C52-12QA 44Q

16 5V ± 20% AT89C52-16AC 44A Commercial


AT89C52-16JC 44J (0°C to 70°C)
AT89C52-16PC 40P6
AT89C52-16QC 44Q

AT89C52-16AI 44A Industrial (-


AT89C52-16JI 44J 40°C to 85°C)
AT89C52-16PI 40P6
AT89C52-16QI 44Q

AT89C52-16AA 44A Automotive (-


AT89C52-16JA 44J 40°C to 105°C)
AT89C52-16PA 40P6
AT89C52-16QA 44Q

20 5V ± 20% AT89C52-20AC 44A Commercial


AT89C52-20JC 44J (0°C to 70°C)
AT89C52-20PC 40P6
AT89C52-20QC 44Q

AT89C52-20AI 44A Industrial (-

4-95
AT89C52-20JI 44J 40°C to 85°C)
AT89C52-20PI 40P6
AT89C52-20QI 44Q

Ordering Information
Speed Power Supply
(MHz) Ordering Code Package Operation Range
24 5V ± 20% AT89C52-24AC 44A Commercial
AT89C52-24JC 44J (0°C to 70°C)
AT89C52-24PC 40P6
AT89C52-24QC 44Q
AT89C52-24AI 44A Industrial (-40°C to
AT89C52-24JI 44J 85°C)
AT89C52-24PI 40P6
AT89C52-24QI 44Q
Package Type

44A 44 Lead, Thin Plastic Gull Wing Quad Flatpack (TQFP)


44J 44 Lead, Plastic J-Leaded Chip Carrier (PLCC)
40P6 40 Lead, 0.600" Wide, Plastic Dual Inline Package (PDIP)
44Q 44 Lead, Plastic Gull Wing Quad Flatpack (PQFP)

4-96 AT89C52

You might also like