Elektor_ ATMEL_AVR_Micro_Programmer_2001.pdf

(2592 KB) Pobierz
010005-UK Atmel-programmer
MICRO PROCESSOR
Atmel AVR Micro
for 89Cx051 with up to 4k of program memory
Design by A. Oyrer
This programmer is suitable for programming the three popular 20-pin
Atmel processors, the 89C1051, 89C2051 and the new 89C4051 with
4 k of program memory.
There is a new arrival in the Atmel family of
powerful yet inexpensive MCS51-compatible
microcontrollers with flash memory (PEROM):
the 89C4051 boasts 4 kBytes of program
memory. Besides the program memory capac-
ity all members of the family have
the following features:
– 128 bytes RAM
– 15 I/O port bits
– 2 16-bit timer/counters
– Interrupt architecture with two
priorities and five vectors
– Programmable full-duplex serial
port
– Precision analogue comparator
52
Elektor Electronics
9/2001
Programmer
38144861.050.png
MICRO PROCESSOR
– Integrated clock/oscillator circuit
Flash memory pr ogr amming modes
Modus
The AT89Cx051 family operates at
a clock frequency between 0 (sta-
tic) and 24 MHz and features two
software-selectable power-saving
modes: Idle (CPU only stopped)
and Power down (RAM contents
are preserved, but all functions are
disabled).
RST/VPP P3.2/PROG
P3.3 P3.4 P3.5 P3.7
Write program data 12 V
1.2 ms negative-going pulse L
H
H
H
Read program data
H
H
L
L
H
H
Write lockbit 1
12 V
1.2 ms negative-going pulse H
H
H
H
Write lockbit 2
12 V
1.2 ms negative-going pulse H
H
L
L
Erase memory
12 V
10 ms negative-going pulse
H
L
L
L
Read signature bits
H
H
L
L
L
L
Programming the flash
The programming characteristics of
the flash memory are of course cru-
cial to the design of a programmer.
When the Atmel microcontroller
leaves the factory the program mem-
ory array is filled with FFs and is
ready to be written, byte by byte.
Once the array is programmed, a
byte that has been written can only
be rewritten after first erasing the
entire memory. The AT89Cx051
includes a PEROM address counter ,
which is reset to 00H on a positive-
going edge of RST and incremented
on each clock pulse on XTAL1.
The logical values on port pins P3.1
to P3.7 determine the programming
mode, as shown in Table 1 .
In order to write a program into
the PEROM, Atmel recommends the
following programming algorithm .
PORT 1
DATA IN
DATA OUT
µ
s
1
µ
s
P3.2
(PROG)
10 µ s
10 µ s
1 ... 110
µ
s
RST
(V PP )
V PP
LOGIC1
LOGIC0
1 µ s
1
µ
s
µ
s
P3.4
(ENABLE)
50ns
P3.1
(RDY/BSY)
XTAL1
(INCREMENT
ADDRESS)
BUSY
READY
2 00n s
2ms
1 µ s
010005 - 12
Figure 1.Timing diagram for a write/read cycle.
7. To read data, the voltage on RST
is taken down to a normal logic
high level and port pins P3.3 are
set to the appropriate levels. The
byte stored in the current address
appears on port P1.
begin a new cycle before the end of the pre-
vious one, pin P3.1 is taken low (BUSY) for a
maximum of 2 ms, while writing is taking
place. Only when P3.1 returns high (READY)
can a new write cycle be initiated.
As can be seen from the timing diagram,
verification of the write process can be car-
ried out either byte by byte during the BUSY
period during write (compare) or all in one go,
as long as the lock bits have not been set
(read). The latter is carried out as follows:
1. Power up by applying the supply
voltage to VCC and GND, and
hold RST/VPP and XTAL1 to
ground.
8. When the byte has been written
or read, the address counter is
incremented by a rising edge on
XTAL1. The new byte is put on
P1.
2. Take RST/VPP and P3.2 high.
3. Set port pins P3.3 through P3.7
according to the table.
1. Take RST from low to high to reset the
internal address counter to 000H.
9. Steps 5 to 8 are repeated until the
whole memory is programmed or
until the end of the programming
data is reached.
To write and read programming data
the next steps are as follows:
2. Set up the appropriate control signals on
pins P3.3 through P3.7 and the data byte
appears on P1.
4. Apply the first byte to be pro-
grammed (into memory address
00H) to pins P1.0 through P1.7.
10.To finish the programming
process, set XTAL1 and RST low
and remove the supply voltage
from VCC and GND.
3. Apply a pulse to XTAL1 to increment the
address counter by one place, and the
next data byte appears on P1.
5. Take RST to 12 V to being the pro-
gramming process.
6. Apply a negative-going pulse,
with a duration of between 1 and
100 µs, to P3.2 in order to write
the byte into the PEROM array or
into the lock bits. The write cycle
completes automatically after
about 1.2 ms.
A complete write/read cycle is illus-
trated in Figure 1 . P ort pin P3.1,
which signals READY/BUSY , is not
shown. The data sheet gives the
duration of the programming pulse
at between 1 and 100 µs. Since a
programming cycle lasts about
1.2 ms and it is not permitted to
4. Repeat step 3 until the entire memory is
read.
The lock bits cannot be directly verified,
but they can be identified by the effect they
produce.
The entire memory, along with the lock bits,
9/2001
Elektor Electronics
53
1
1
38144861.052.png
MICRO PROCESSOR
JP1
+5V
+5V
R4
C13
20
C14
R2
T1
C1
IC3
100n
10
100n
10µ
63V
R5
BC557B
R1
D1
C12
K3
100n
AD0
AD1
AD2
AD3
AD4
AD5
AD6
AD7
12
13
14
15
16
17
18
19
20
R14
2
IC3
1N4148
24
+5V
20
11
23
D 6
C1
1
1
22
EN
RST
IC1
21
1
R3
9
8
7
6
5
4
3
2
AD0
AD1
AD2
AD3
AD4
AD5
AD6
AD7
AD0
AD1
AD2
AD3
AD4
AD5
AD6
AD7
12
13
14
15
16
17
18
19
2
3
7
2
3
4
7
8
AD3
P10/IN+
P11/IN–
RXD/P30
TXD/P31
1D
9
5
AD2
6
7
8
9
4
8
6
AD1
P12
P13
P14
P15
P16
P17
INT0/P32
INT1/P33
3
11
9
AD0
5
6
1
12
13
T0/P34
T1/P35
10
15
14
17
18
89C2051
16
19
AD4
11
P37
8x 10k
74HC373
X1
X0
10
5
4
IC6
R13
1k5
D5
+5V
LM317
C3
C2
BC557B
X1
R12
1k5
22p
22p
R7
R9
11,059MHz
D4
T3
C5
10µ
R6
63V
+5V
R15
2
K1
T2
R10
1
V+
16
C7
C1+
R8
D3
R11
1
C11
IC4
D7
6
10µ
63V
3
C1–
BS170
25V
2
14
11
4V7
500mW
T1OUT
T2OUT
T1IN
T2IN
7
7
10
3
13
12
R1IN
R2IN
R1OUT
R2OUT
8
8
9
K2
IC5
3
4
4
C4
C8
C2+
D2
7805
+5V
18V
9
MAX232
1
10µ
63V
5
10µ
63V
5
15
C2–
1N4001
V-
C9
C10
2
6
DB9
C6
10µ
63V
10µ
63V
10µ
63V
010005 - 11
Figure 2. Circuit diagram of the Atmel Programmer with master controller and ZIF socket for the device to be programmed.
is electrically erased when the correct com-
bination is applied to P3.3-P3.7, and P3.2 is
held low for at least 10 ms. All memory loca-
tions are then filled with ones. This chip
erase procedure is required before repro-
gramming an already-programmed memory
or in order to erase the lock bits.
The signature bytes give manufacturer
and device type information. They can be
read in the same way as the program mem-
ory locations, but with P3.5 and P3.7 held low.
Possible values are as follows:
Programmer hardware
– Program lock bits
– Erase
– Read signature
Since, apart from the size of the pro-
gram memory, all the functions and
features of the three microcontrollers
are identical, the programmer is not
complicated. It must simply read the
signature bytes at the start of any
operation to identify the type of
microcontroller.
The programmer presented here
implements all the programming
modes described:
In write mode the signature bytes
are checked to ensure that the
amount of data to be programmed
will fit in the processor. In read
mode, the data file generated can be
in Intel Hex or in binary format.
Reading the signature bytes is
optional and can if required (for
example in the case of a faulty micro-
controller) be disabled via the menu.
In this case the programmer
assumes that it is dealing with an
89C4051.
000H 1EH: manufacturer code for Atmel
001H 11H: 89C1051
21H: 89C2051
41H: 89C4051
– Write
– Read
– Compare
54
Elektor Electronics
9/2001
38144861.053.png 38144861.054.png 38144861.001.png 38144861.002.png 38144861.003.png 38144861.004.png 38144861.005.png 38144861.006.png 38144861.007.png 38144861.008.png 38144861.009.png 38144861.010.png 38144861.011.png 38144861.012.png 38144861.013.png 38144861.014.png 38144861.015.png 38144861.016.png 38144861.017.png 38144861.018.png 38144861.019.png 38144861.020.png
MICRO PROCESSOR
As can be seen from Figure 2 , the
programmer hardware is relatively
straightforward and consists essen-
tially of a master microcontroller,
which needs to contain just 865
bytes of program code. IC1, naturally
enough an 89C2051, carries out
everything required for program-
ming: it sets up the programming
mode requested by the user, con-
verts into parallel form the program
code sent from the PC over the
RS232 interface, sends the contents
of an already-programmed memory
(and other information) back to the
PC, and switches the voltages (0 V,
5 V and 12 V) as required by the tim-
ing diagrams. However, even with
the best will in the world, all this is
not so easy to achieve with just the
15 I/O port bits offered by the
89C2051.
Communication with the PC is
handled via port pins P3.0 and P3.1.
Data transfer is indicated by LEDs
D4 and D5 flashing. Port pin P3.3
(interrupt 1) is used as an input to
monitor the BUSY/READY signal of
the microcontroller being pro-
grammed (‘processor under pro-
gramming’, or PUP). The individual
programming pulses are provided by
a further port pin, P3.5, while P3.4 is
used to provide the edges on XTAL1
to increment the address counter of
the PUP.
Now, the remaining ten port pins
must provide five control signals and
eight data bits, and here some inge-
nuity is required. The whole of port
1 of IC1 is connected to its counter-
part on the PUP, but the five port
pins P1.0-P1.4 are also connected to
IC3, an 8-bit latch type 74HC373.
The microcontroller first applies the
control signals to the five latch
inputs. The latch enable input (pin
11) is taken high and so the latches
are transparent: control signal out-
puts AD1, AD2, AD3 go directly to
the PUP (as can be seen from
Table 1, P3.5 and P3.7 always have
the same value), AD0 turns on the
+5 V supply to the microcontroller
via T1 (indicated by LED D6), and
AD4 controls the application of the
programming voltage to RST/VPP.
Once these values are set up, the
latch enable input is taken low
again, and the values are stored.
The Atmel programmer uses an
adjustable voltage regulator to pro-
vide the voltage on RST/VPP. For
reading, when 5 V is required, FET
T2 conducts and the two resistors R6
and R8 are effectively in parallel. If
12 V is required, the FET is turned
off and only R8 is in circuit. The
BS170 is switched by a separate port pin of
IC1, P3.7.
In order that the voltage on VPP/RST is at
ground potential after the programming or
reading process (and so the PUP can safely
be removed from its socket) the LM317 is first
switched to 5 V. Then AD4 (from the latch) is
set, to make the potential at the junction of
R10 and D3 equal to 5 V. This turns off tran-
sistor T3 and R11 pulls RST/VPP to ground.
This accounts for all the port pins of the
89Cx051.
Software
The companion diskette for this project, order
code 010005-11 , which is available from
Readers’ Services, includes an assembler pro-
gram called Atmelpr.asm for the master
microcontroller, as well as the microcontroller
object code in the form of a Atmelpr.hex file.
Ready-programmed microcontrollers are also
available (order code 010005-41 ). This soft-
ware is complemented by
Programmer_eng.exe ,
a program written in Delphi which controls all
the operations of the Atmel programmer such
as reading, writing, and erasing. The Delphi
source code source_eng.zip is also available.
The printed circuit board layout is avail-
able for free download from our Internet site
www.elektor-electronics.co.uk . There is no
download for the above mentioned software
because of contractual agreements with the
authors.
Serial port COM2 is used by default. When
the program starts up a window appears,
divided into two ( Figure 3 ). On the left the
operations are selected from a menu while on
the right the operations are confirmed, for
example as follows:
reading signature byte ok
programming lock bit 1 ok
error: file too large!
and so on.
Figure 3. Control panel for the PC program Programmer_eng.exe.
If Read is selected, all other operations are
disabled and a window appears to allow the
user to choose the name of the file in which
the contents of the processor’s memory are to
be written out. If the file extension is given as
hex , then an Intel Hex file is automatically
generated; if bin is specified, a binary file is
read.
The Select file button allows the user to
choose the name of the file that will be writ-
ten. Here also hex and bin are possible.
The file size is shown below the microcon-
troller type. Below that a bar indicates
progress of the individual actions. In the area
9/2001
Elektor Electronics
55
38144861.021.png 38144861.022.png
 
MICRO PROCESSOR
010005-1
C13
COMPONENTS LIST
IC5
IC6
H2
C11
Resistors:
R1 = 8k
2
R2 = 100
R3 = 8-way 10k
C9 C10
T3
T1
SIL array
K2
R1
D7
D6
C14
T2
R4,R5 = 1k
R6 = 1210
D1
D2
C1
C12
R7 = 274
R8 = 2260
D4
R2
JP1
R12
R13
R9,R10 = 10k
R11 = 4k
D5
C4
7
R12,R13,R14 = 1k 5
R15 = 2k
X1
C2 C3
C5
2
IC4
IC1
R3
IC3
Capacitors:
C1,C4-C10 = 10
K1
µ
F 63V radial
C2,C3 = 22pF
C11 = 1
H4
C7 C8
C6
K3
F 25V radial
C12,C13,C14 = 100nF
Semiconductors:
D1 = 1N4148
D2 = 1N4001
D3 = zener diode 4V7, 500 mW
D4,D5,D6 = LED, green, high effi-
ciency
T1,T3 = BC557B
T2 = BS170
IC1 = AT89C2051-12PC (order
code 010005-41 )*
IC2 (K3) = 24-way zero-insertion
force (ZIF) socket
IC3 = 74HC373
IC4 = MAX232
IC5 = 7805
IC6 = LM317T
Miscellaneous:
JP1 = jumper
K1 = 9-way Sub-D socket
(female), PCB mount, angled pins
K2 = mains adaptor socket
X1 = 11.0592MHz quartz crystal
Enclosure, size 137x
95x
* (see Readers Services page or
www.elektor-electronics.co.uk )
010005
at the bottom the filename and path
are shown.
In the menu under Read signature
byte the user can choose whether
the signature bytes are initially read
or not. This option should always be
activated unless the programmer is
unable to read the signature bytes.
The information in the signature
bytes is shown below the microcon-
Figure 4. Layout and component mounting plan for the double-sided printed circuit board.
56
Elektor Electronics
9/2001
µ
25 mm
(e.g., Pactec type WM46)
PCB, order code 010005-1 *
Disk, project software, order code
010005-11 *
38144861.023.png 38144861.024.png 38144861.025.png 38144861.026.png 38144861.027.png 38144861.028.png 38144861.029.png 38144861.030.png 38144861.031.png 38144861.032.png 38144861.033.png 38144861.034.png 38144861.035.png 38144861.036.png 38144861.037.png 38144861.038.png 38144861.039.png 38144861.040.png 38144861.041.png 38144861.042.png 38144861.043.png 38144861.044.png 38144861.045.png 38144861.046.png 38144861.047.png 38144861.048.png 38144861.049.png 38144861.051.png
Zgłoś jeśli naruszono regulamin