ATMEL 2051/1051 PROGRAMMER The Atmel 2051/1051 processors are extremely useful and versatile microcontrollers. These processors contain Flash Programmable and Erasable Read Only Memory (PEROM). They can be reprogrammed over 1000 times. Reprogramming takes seconds without the time consuming erasure step associated with EPROM based Microcontrollers. This article describes a simple programmer for programming these devices. The programmer is designed to operate from the parallel port of a PC. These associated software is DOS. based allowing the programmer to be used with almost any PC. The hardware and software for this project is loosely based around that described in the Atmel Application Note (see the data book, data CD or WEB site). Although the implementation is different (particularly that of the hardware) the hardware and software should be interchangeable with that described in the Application Note. The 40 pin devices (89C51/52) are not supported by this hardware. Programming Devices The devices can be programmed in various modes, as described below. These programming modes are selected by applying the correct control signals to P3.3 to P3.7, as shown in Diagram 1 and Table 1. . . Read Signature Bytes. The device has 3 pre-programmed bytes which are used to identify the device. Byte 1 : This identifies the manufacturer. 1EH signifies ATMEL Byte 2 : This is the device type. 21H for 2051 and 11H for a 1051. Byte 3 : This is the Programming voltage. FFH for 12V devices. Write Code Data This process fills the internal PEROM with the code. Before this process can begin the contents of the PEROM must be erased (in the erased state all the internal location will read back FF). During programming an internal counter keeps track of the current address. When the sequence is started the counter is reset to 0000H, after a location has been programmed the internal counter is advanced by 1, until the complete array is filled. Chip Erase The entire PEROM array and the two lock bits are erased. Previously programmed locations require to be erased before they can be reprogrammed. The entire array should read back FFH if the device is blank. Read Code The contents of the PEROM can be read back from the device, providing the Lock Bit 2 is not set. Reading back the contents of the device is useful for copy devices (when you do not have the programming file). It is also useful for verifying the contents of a device. Write Lock Bits The contents of the PEROM array can be protected by programming the lock bits. Lock bit 1 prevents further programming of the device. Lock bit 2 prevents the contents of the Array being read from the device Therefore preventing copying of devices or disassembling the code. Circuit Description The hardware for the programmer provides the interface between the PC parallel port and the device being programmed, as well as the correct programming voltage for the device. The timing for each of the programming cycles is controlled by the software running on PC. The circuit for the programmer is shown in Diagram 2. All of the decoding and control is done inside U3, (Lattice LSI2032). This is a Programmable Logic Device (PLD) which greatly simplifies the board layout enabling the complete programmer to measure only 4 x 2 inches. A LS245 transceiver is used to buffer the data signals, some PC I/O cards have strong pull-ups on the parallel port therefore the programmer needs to be able to source a reasonable amount of current. The HCT240 buffer is required to isolate the control signals to the device being programmed (this is required during the power up sequence). The programming voltage requires to switch between 0-5-12V. These voltages are provided by an LM317 adjustable regulator. Two transistors are used to switch between the voltages. Software description The software runs under DOS and should work with any PC. The timing for all of the programming cycles is done in software. In order for the software to be system independent, the PC timer (PIC) is used to generate all of the software delays. The software is based on the software described in Atmel Application Note. However a number of changes and improvements have been made. Most notably the software can read both Binary and INTEL.HEX file formats. (Note the software can support INTEL.HEX files with out of order address, unlike some of HEX to Bin conversion utilities). The software gives the following facilities: ? ERASE DEVICE: Erase the entire contents of device, including lock bytes ? READ SIGNATURE: Displays the device identity bytes ? PROGRAM: Programs the device with specified program file (Intel HEX or binary) ? PROGRAM LOCK: Disables programming and reading of the device ? VERIFY: Reads device and verifies against specified file ? SAVE: Reads device and saves as a binary file Construction Diagram 3 shows the component overlay for the programmer. The PCB is single sided, using the Lattice PLD greatly simplifies the board layout. The PCB contains some small tracks and pads, therefore take care when drilling the holes for the components. Use the correct drill size for each component (0.8mm for ICs, transistors etc. 1.2mm for the regulators & 1mm for the connectors). If you have to de-solder any components use the minimum amount of heat as tracks will lift easily. Make sure you populate the links before any other components, as one of the links goes under the socket for U3. Do not forget this link. The layout contains two sizes of resistors, the standard size and the miniature 0.125W type. Refer to the parts list to determine the correct size. If you have trouble finding the miniature resistors, you could mount a standard resistor vertically. Make sure the orientation of the SIL resistor is correct Pin 1 is denoted by a dot on the package. J2 is a ZIF socket, you should make sure there is enough space for it, as it is larger than a normal 20 Pin socket. You may have to mount it in a socket or use one with longer legs to ensure it is clear of the other components. The two regulators should be mounted vertically and the metal tab should face in towards the board. A small heatsink may be required on the 5V regulator U2. Make sure that the Case for the 25 way D-Type is grounded at one of the mounting points. U3 is a pre-programmed device. If you are able to program this device yourself the programming file can be obtained via the PE web site. Alternatively contact the author for a pre-programmed device or a programming service. You can contact the author directly via email at colin.meikle@virgin.net or via Practical Electronics. Take care when soldering the socket for U3 as the pads and tracks are very close together. Also note the orientation of the socket (with the D-Type socket at the L.H.S of the board the slanting corner on the socket should be at the bottom R.H.S.). The programmer requires 15-18V DC @ 200mA, it is probably best to use a small wall mounted PSU. Connection to the PC is made via a standard 25-way cable with male D-Type plugs at both ends. Housing the programmer in a suitable enclosure has been left up to the reader. Note however you can get a ZIF socket with long leads, which could allow the socket to protrude through the top of the box. Testing Before attempting to program any devices, perform the following checks. ? All polarised components are orientated correctly ? All links are in place. ? There are no solder shorts on the bottom of the board. ? Check the orientation of U3 (the dot on the package is pin 1). If everything look fines apply power to the board, without a device in J2 or cable to PC attached. Measure the current, it should be approximately 100mA. If not, power off and recheck. Using the programmer Before you use the programmer you will need to obtain the programming software that runs on the PC. This can be obtained from the PE WEB site. There is one executable called PROG51.exe, that can be used to program both AT89C1051 and AT89C2051 devices. For the programmer to work correctly your parallel port requires to be set-up for 8 bit bi-directional mode (sometimes called PS/2 mode). You can normally change the setting via the PC’s BIOS settings (i.e. the set-up during the PC power up). If your parallel port is a plug-in IO card, you may have to change the jumper or switch setting on the card. If your card can not be set-up for bi–directional mode, you can still program devices, but the read back (verify & read signature) functions will not work. IO cards are cheap, so you could buy a new card. Once you have setup your port you are ready to program your device. Plug-in the cable to a free parallel port on your PC (LPT1 and LPT2 are supported). From a DOS prompt run the PROG51 program. You will have to tell the program which port to use, either LPT1 or LPT2 e.g. type for LPT1. Now plug the cable into the programmer and apply power to the programmer. The program should be run before plugging in the programmer, so that the port is reset into an inactive state. You can now put the device you want to programme into the ZIF socket. When you run PROG51, you should be presented with the following screen: By default a 2051 device is selected. You can change manually by selecting ‘1’ for 1051 or ‘2’ for 2051, the first line of the menu will change accordingly. If you have a device in the socket then the type can be automatically selected by performing a "Read signature". This will display the signature bytes, device type and automatically set the correct device type. To program a device select P. you will now be prompted for a filename and file type. The type can be either binary or INTEL HEX. INTEL HEX files are ASCII files and normally have the extension .HEX. If possible you should use INTEL.HEX files. The software will do more checking on an INTEL.HEX file. The device will be erased before programming, you cannot program over part of the device. To verify a device select ‘V’ again you will be prompted for a filename and type. If there are any discrepancies between the device and the file , they will be shown. Problems and Error Messages When you first test your programmer you should try reading the signature bytes. If you get back FFH, FFH, FFH for the signature there are a number of possible causes. ? Check cables and power to the board. ? Check you are using the correct port. ? Check your board for errors. ? Check your BIOS setting, (You need the port to be bi-directional). If you are convinced that everything is OK. Try programming a device and testing it in your application. If it works, your parallel port is not bi-directional (it may not support bi-directional mode or is incorrectly set-up). When using INTEL.HEX files you may receive one of the following messages: ? "Address out of range" Your programming file contains addresses outwith the 1K or 2K limit. E.G. Your program is too big. (Note; most assemblers/compilers will not warn you when you exceed the limits of a device). ? "Check Sum Error" Your file is corrupt. You have the option of ignoring these errors but your device probably will not work as expected. For binary files there is no checking. If you receive errors during a verify option, you should check the supply voltage to the programmer, it requires to between 14.5V and 18V. You should also check your cable is not too long. You may also want to try a different 245 transceiver (e.g. 74F245 or 74ALS245). Altering the characteristics of the transceiver may help the signal integrity, alternatively you could try a different IO card. Note if you do experience noise problems e.g. with long cables, corruption is more probable when reading data back. Therefore the device will probably program OK. PARTS LIST Used PartType Designators Description 1 10K RP1 SIL Resistor 1 1k R12 Miniature 0.125W Resistor 1 100K R8 Miniature 0.125W Resistor 1 100R R13 0.25W Resistor 1 270R R7 0.25W Resistor 2 1K R6 R9 0.25W Resistor 2 2K2 R5 R11 0.25W Resistor 1 4K7 R10 0.25W Resistor 4 10K R1 R2 R3 R4 Miniature 0.125W Resistor 2 47uF C4 10V Electrolytic 1 47uF C5 25V Electrolytic 1 74HCT240 U5 Buffer 1 74LS245 U3 Transceiver 1 82nF C1 Ceramic (0.1in pitch) 5 100nF C2 C3 Ceramic Capacitor(0.2in pitch) C6 C7 C8 1 DB25 J1 25Way Dtype Connector (Female) 1 LM317T U4 Adjustable regulator 1 MC78L05CP U2 5V Regulator + Small "Clip" Heatsink 1 BC549 T1 NPN Transistor 1 BC557 T2 PNP Transistor 1 ZIF20 J2 Zero Force 20 pin socket 1 44SOCKET U3 44 pin PLCC Socket + Programmed isp2032 (see text) 1 14.5-18V PSU Power supply 16V, 200mA 1 Parallel Cable 25 Way Male to 25 Way Male Cable