Chapter 5 Appendix 5.1 DESCRIPTION OF AT89c2051
Chapter 5 Appendix 5.1 DESCRIPTION OF AT89c2051
Chapter 5 Appendix 5.1 DESCRIPTION OF AT89c2051
GND: Ground
pull-ups. P1.0 and P1.1 also serve as the positive input (AIN0) and the negative
input (AIN1)
Port 1:
Port 1 is an 8-bit bi-directional I/O port. Port pins P1.2 toP1.7 provides internal
pull-ups. P1.0 and P1.1 require external put (AIN1), respectively, of the on-chip
precision analog comparator. The Port 1 output buffers can sink 20 m A and can
drive LED displays directly. When 1s are written to Port 1 pins, they can be used as
inputs. When pins P1.2 to P1.7 are used as inputs and are externally pulled low, they
will source current (IIL) because of the internal pull-ups. Port 1 also receives code
data during Flash programming and verification.
Port 3:
Port 3 pins P3.0 to P3.5, P3.7 are seven bi-directional I/O pins with internal pull-
ups. P3.6 is hard-wired as an input to the output of the on-chip comparator and is
not accessible as a general purpose I/O pin. The Port 3 output buffers can sink 20
MA. When 1s are written to Port 3 pins they are pulled high by the internal pull-ups
and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low
will source current (IIL) because of the pull-ups.
Port 3 also serves the functions of various special features of theAT89C2051 as listed
below: Port 3 also receives some control signals for Flash programming and
verification.
RST:
Reset input. All I/O pins are reset to 1s as soon as RST goes high. Holding the RST
pin high for two machine cycles while the oscillator is running resets the device.
Each machine cycle takes 12 oscillator or clock cycles.
XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
XTAL2:
A map of the on-chip memory area called the Special Function Register SFR) pace is
shown in the table below.
Note that not all of the addresses are occupied, and unoccupied addresses ay not be
implemented on the chip. Read accesses to these addresses will in general return random
data, and write accesses will have an indeterminate
effect. User software should not write 1s to these unlisted locations, since they may be used
in future products to invoke new features. In that case, the reset or inactive values of the
new bits will always be 0.
INCLUDE 89c2051.mc
CLR p3.1
CLR buzzer
l :
a
1
:
l
a
2
:
l
a
3
NBp1.6,la3 SETB p3.0 CLR p3.1
J CLR buzzer
N
B CLR p3.0
p CLR p3.1
1 SETB buzzer JMPmainloop
.
5
,
l
a
2
C
L
R
p
3
.
0
S
E
T
B
p
3
.
1
C
L
R
b
u
z
z
e
r
J
5.3 PROGRAMMING THE FLASH
The AT89C2051 is shipped with the 2K bytes of on-chip PEROM code memory
array in the erased state (i.e., contents= FFH) and ready to be programmed. The
code Memory array is programmed one byte at a time. Once the array is
programmed, to re-program any non-blank byte the entire memory array needs to
be erased electrically.
4. To verify the programmed data, lower RST from 12V to logic “H” level and set
pins P3.3 to P3.7 to the appropriate levels. Output data can be read at the port P1
pin.
5. To program a byte at the next address location, pulseXTAL1 pin once to advance
the internal address
6. Repeat steps 5 through 8, changing data and advancing the counter. Apply new
data to the port P1 pins. Address counter for the entire 2K bytes array or until
the end of the object file is reached.
7. Power-off sequence: Set XTAL1 to “L”
Set RST to “L”
Turn VCC power off
DATA POLLING : The AT89C2051 features Data Polling to indicate the end of a
write cycle. During a write cycle, an attempted read of the last byte written will
result in the complement of the written data on P1.7. Once the write cycle has been
completed, true data is valid on all outputs, and the next cycle may begin. Data
Polling may begin any time after a write cycle has been initiated.
PROGRAM VERIFY : If lock bits LB1 and LB2 have not been programmed code
data can be read back via the data lines for verification:
1. Reset the internal address counter to 000H by bringing RST from “L” to “H”.
2. Apply the appropriate control signals for Read Code data and read the
output data at the port P1 pins.
3. Pulse pin XTAL1 once to advance the internal address counter.
4. Read the next code data byte at the port P1 pins.
5. Repeat steps 3 and 4 until the entire array is read .The lock bits cannot be
verified directly. Verification of the lock bits is achieved by observing that their
features are enabled.
CHIP ERASE : The entire PEROM array (2K bytes) and the two Lock Bits are
erased electrically by using the proper combination of control signals and by
holding P3.2 low for 10 ms. The code array is written with all “1”s in the Chip.
Erase operation and must be executed before any nonblank memory byte can be re-
programmed.
READING THE SIGNATURE BYTES : The signature bytes are read by the same
procedure as a normal verification of locations 000H, 001H, and 002H, except that
P3.5 and P3.7 must be pulled to logic low. The values returned are as follows.
(000H) = 1EH indicates manufactured by Atmel (001H) = 21H indicates 89C2051
Programming Interface:
Every code byte in the Flash array can be written and using the appropriate
combination of control signals can erase the entire array. The write operation cycle is
self timed and once initiated, will automatically time itself to completion.
All major programming vendors offer worldwide support for the Atmel micro
controller series. Please contact your local programming vendor for the appropriate
software revision.
FLASH PROGRAMMING MODES
Notes:
1. The internal PEROM address counter is reset to 000H on the rising edge of RST
and is advanced by a positive pulse at XTAL 1 pin.
2.Chip Erase requires a 10 ms PROG pulse.
3.P3.1 is pulled Low during programming to indicate RDY/BS
Figure 3. Programming the Flash Memory
where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-
bit unsigned integer. Timer 2 as a baud rate generator is shown in Figure 4. This
figure is valid only if RCLK or TCLK = 1 in T2CON. Note that a rollover in TH2
does not set TF2 and will not generate an interrupt. Note too, that if EXEN2 is set, a
1-to-0 transition in T2EX will set EXF2 but will not cause a reload from (RCAP2H,
RCAP2L) to (TH2, TL2). Thus when Timer 2 is in use as a baud rate generator,
T2EX can be used as an extra external interrupt.
Note that when Timer 2 is running (TR2 = 1) as a timer in the baud rate generator
mode, TH2 or TL2 should not be read from or written to. Under these conditions,
the Timer is incremented every state time, and the results of a read or write may not
be accurate. The RCAP2 registers may be 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.
Figure 5.5 :Timer 2 in Clock-out Mode
A 50% duty cycle clock can be programmed to come out on P1.0, as shown in Figure
5. This pin, besides being a regular I/O pin, has two alternate functions. It can be
programmed to input the external clock for Timer/Counter 2 or to output a 50%
duty cycle clock ranging from 61 Hz to 4 MHz at a 16 MHz operating frequency. To
configure the Timer/Counter 2 as a clock generator, bit C/T2 (T2CON.1) must be
cleared and bit T2OE (T2MOD.1) must be set. Bit TR2 (T2CON.2) starts and stops
the timer. The clock-out frequency depends on the oscillator frequency and the
reload value of Timer 2 capture registers (RCAP2H, RCAP2L), as shown in the
following equation.
In the clock-out mode, Timer 2 roll-overs will not generate an interrupt. This
behavior is similar to when Timer 2 is used as a baud-rate generator. It is possible to
use Timer 2 as a baud-rate generator and a clock generator simultaneously. Note,
however, that the baud-rate and clock-out Frequencies cannot be determined
independently from one another since they both use RCAP2H and RCAP2L.
UART
The UART in the AT89C52 operates the same way as the UART in the AT89C51.