• No results found

Operational modes

In document ep25-ElectronicsProjectsVol25.pdf (Page 53-59)

The programmer can operate in any of the following two modes:

1. Direct keyboard-entry mode 2. Serial-port interface mode

Direct keyboard-entry mode. In this mode, the programmer is connected to an IBM PC keyboard. The program data is entered byte by byte and the same gets programmed into the microcontroller which is inserted into the appropriate ZIF socket on the programmer board. The bit-wise contents of any given location of an already programmed microcontroller can also be read and displayed on an 8-LED display provided on the programmer.

There is also a provision for erasing the contents of an already programmed device.

This mode is useful for developing simple applications by users who do not have ready access to a PC and want the code to be manually entered without the hassle of a computer.

Serial-port interface mode. The

programming board can be con-nected to Com port of a PC, us-ing a 3-wire cable, terminatus-ing on a 9-pin D connector on the board. A simple serial port pro-gram run on the PC starts the dialogue and you can program an 89C51, 89C52 or 89C2051 microcontroller in this program-ming mode by using program data in an ASCII file on the PC as well as byte-by-byte from the PC’s keyboard. The locking of the entered code in the micro-Fig. 1: Pin assignments for 89C51/52

Fig. 2: Pin assignments for 89C2051 Fig. 3: Authors' working model of programming board

Parts List Semiconductors:

IC1 - 89C51 microcontroller IC2 - MAX232 RS-232 level

converter

IC3 - 74LS04 hex inverter IC4 - 7805 +5V regulator T1, T2 - BC548 npn transistor T3 - 2N2907 pnp transistor T4 - BC557 pnp transistor D1 - 1N4148 switching diode ZD1 - 5V zener diode LED1-LED8 - Red LED

LED9 - Yellow LED

LED10 - Green LED Resistors (all ¼-watt, ±5% carbon, unless stated otherwise):

R1, R5, R8, R9 - 4.7-kilo-ohm R2-R4, R6, R12 - 10-kilo-ohm

R7 - 390-ohm

R10 - 1-kilo-ohm

R11 - 330-ohm

RNW1 - 4.7-kilo-ohm x 8-resistor network

RNW2 - 1-kilo-ohm x 8-resistor net-work

Capacitors:

C1 - 1µF, 16V electrolytic C2 - C5 - 22µF, 16V electrolytic C6- C9 - 22pF ceramic disk C10 - 0.1µF ceramic disk Miscellaneous:

XTAL1 - 3.57MHz Crystal XTAL2 - 12MHz Crystal S1, S2 - Push-to-on switch ZIF Socket 1 - 40-pin ZIF socket ZIF Socket 2 - 20-pin ZIF socket - 9-pin ‘D’ connector - 5-pin keyboard connector

Fig. 4: Circuit diagram of the programming board

controller is also feasible.

Circuit description

Figs 3 and 4 show the authors' working model and the schematic circuit diagram of the programmer board, respectively.

In Fig. 4, microcontroller 89C51 (IC1) is preprogrammed for programming other microcontrollers inserted into the

appro-priate ZIF socket on the right—either into a 40-pin or a 20-40-pin IC to the socket at a time. The 40-pin ZIF socket-1 and 20-pin ZIF socket-2 are used for inserting an 89C51 (or 89C52) and 89C2051, respectively. IC MAX232 (IC2) is the voltage level converter, which converts TTL-level signals into RS-232C compatible sig-nals and vice-versa. The power-on-reset signal is generated by R1-C1 com-bination in conjunction with NOT gate 74LS04 (IC3), which provides a high-going reset pulse to pin 9 of IC1. Manual to be programmed via ZIF socket-1 or ZIF socket-2.

This port needs pull-up resistors. Therefore pin numbers 39 down to 32 of port 0 are pulled up to +5V through a (4.7k×8) resistor network RNW-1.

These pins are also con-nected to LED1 to LED8 via current-limiting re-sistors (1k×8) of RNW-2.

Thus, port-0 data can be viewed on these eight LEDs as complement of the actual data, at a spe-cific memory location. A 3.57 MHz crystal (XTAL1) is connected to pins 18 and 19 of IC1, which provides a low baud rate of 1200 for this application. However, a 12MHz crystal (XTAL2) is used for the 89C51/52 IC (being programmed) in ZIF socket-1, to meet its internal timing requirements.

The address bus, data bus and control signals are required for programming a new microcontroller IC. Port 0 and Port 1 pins of IC1 provide 8-bit data bus and eight low-order address lines (A0 through A7), respectively. Four higher-order ad-dress lines (A8 through A11) are taken from pins 21 through 24 of port 2 (P2.0

through P2.3). To get A12 address line needed for the 89C52 higher memory IC, pin P3.5 (pin 15) is connceted to pin 25 of ZIF socket-1.

Pins 25 through 28 of IC1 (P2.4 through P2.7) are used for program control functions for the new IC (to be programmed in ZIF 1 or ZIF socket-2). The program control signals are given in Table.

When the programming (write) mode is invoked, control pin P2.4 is at logic 0, while pins P2.5 through P2.7 of IC1 are at logic 1 (0111H). During programming mode, the data received from the serial port is routed through the accumulator to the port pins 39 down to 32 of IC1 and hence given to the data pins of the sockets.

Data lines D0 through D7 of IC1 are con-nected to pins 39 down to 32 of the ZIF socket-1 and to pins 19 down to 12 of ZIF socket-2. Pin 30 (PROG) of ZIF socket-1 or pin 6 (INT0) of ZIF socket-2 is required to be pulsed low for about 100 microseconds during the programming operation. Also, VPP pin 31 of ZIF socket-1 or VPP pin-1 of ZIF socket-2 gets a pulsed 12V supply a few microseconds before the PROG pin goes low, which lasts for 2 milliseconds (ms) after PROG pin goes high again. This timing is needed by the internal logic of the microcontroller to keep the voltage applied to the oxide gate of the memory for suitable duration, thereby writing into the flash memory by turning a 1 into 0.

(Erasing does the opposite of turning a 0 into a 1 bit). The memory bits, after being programmed, will remain non volatile, until the same is erased, which can be done only totally for the entire chip's flash memory.

However, the entire flash memory (and not any one location individually) can be erased by using a proper combination (1000H) of control signals via pins P2.4 through P2.7 by holding PROG pin low for about 10 ms, with 12V applied to VPP pin.

For reading of the signature byte by IC1, control pins P2.4 through P2.7 are at logic 0 (0000H). The signature is present at address 30H of 89C51 (or 89C52) and address 00H of 89C2051 microcontroller.

Transistors T1 through T3 are used for generating the pulsed 12V supply using pins 13 (P3.3) and 17 (P3.7) of IC1. When pin 17 (P3.7) goes low, npn transistor T1 is cut off and its collector voltage rises to drive npn transistor T2 into conduction.

As a result the base of pnp transistor T3 goes low, thereby transistor T3 conducts and its collector voltage rises to around Fig. 5: Interface circuit between an 89C51 microcontroller and

LCD module

Fig. 6: Interface circuit between an 89C2051 microcontroller and LCD module

12V. The collector of transistor T3 is con-nected to VPP pins of the ZIF sockets 1 and 2. A green LED (LED10) connected to the collector of transistor T3 via current-limiting resistor R7 and zener diode ZD1 lights up to provide a visual indication of the programming voltage.

A voltage of 5V initially and 12V during erasing/programming is applied to VPP pin of the microcontroller IC to be programmed. The availability of 5V at VPP pins of ZIF sockets in absence of program-ming/erasing pulse period is ensured by circuitry around Transistor T4, in conjunc-tion with pin 13 (P3.3) of IC1. When pin 13 goes low, transistor T4 conducts to provide nearly 5V at VPP pin. LED9 gives visual indication of 5V at VPP pins of sockets 1

and 2. Switch S2 is used for applying 12V pulses to VPP pins of sockets 1 and 2. It protects the IC (to be programmed) from accidentally getting 12V upon power-on and thereby damaging it since 12V should be applied only when control signals are active for erasing or programming func-tions, and that too for limited duration. If 12V is applied for a longer duration, VPP pin internally gets shorted to ground and further programming is not possible.

IC MAX232 (IC2) is used as an RS-232 level converter. Pins 10 (RXD) and 11 (TXD) of IC1 are connected to pins 3 and 2 of 9-pin D connector, respectively via IC2.

The PC keyboard is connected to pins 12 and 14 of IC1.

For compactness, a single 12.6V DC

supply is used for the programmer board.

While Vpp pulse generation circuitry makes use of 12.6V, however all ICs de-ployed on the board need regulated 5V DC for their operation. Regulator IC 7805 (IC4) generates 5V supply from the 12.6V DC to meet this requirement.

Port 0 of IC1 connected to the ZIF socket-1 and ZIF socket-2 serves as a bi-directional port for writing (programming) and reading of data to/from the ICs being programmed.

1. In the direct keyboard-entry mode, data entered via the keyboard has to be output to the LEDs for viewing. During write operation control signal P2.4 would be logic 0 while P2.5 through P2.7 would be at logic 1 (0111H). For reading data from the programmed IC, port 0 is converted into an input port by outputting FF hex before outputting the control signals (0011H) via pins P2.4 through P2.7 respectively. Thus, the function of port 0 is bidirectional.

2. In the serial-port interface mode, data transfer from PC to programming board occurs serially and after two bytes of ASCII code are received at the program-ming board, the same are converted into Fig. 7: Actual-size, single-side PCB for the programming board

Data.bas

open “scrn:” for output as #2

OPEN “CAPTURE.DAT” FOR OUTPUT AS #4 locate ,,1

xoff$=chr$(19):xon$=chr$(17)

510 n$=inkey$: if n$=“s” or n$=“S” then flag=1 : goto 800

IF N$=”Y” THEN FLAG2=1 520 if n$<> “” then print #1,n$;:

if eof(1) then 510

570 if loc(1)>128 then pause=true:print #1, xoff$:

n$=input$(loc(1),#1) lfp=0

630 lfp=instr(lfp+1,n$,chr$(10)) if lfp>0 then mid$(n$,lfp,1)=” “:goto 630 print #2,n$;

IF FLAG2=1 THEN PRINT #4, N$;

if loc(1)>0 then 570

if pause then pause=false: print #1,xon$;

goto 510

800 for kk=1 to 30000:next kk:get #3 print #1,m$; : rem print m$; if lfp>0 then mid$(n$,lfp,1)=” “:goto 850 print #2,n$;

IF N$=”R” THEN PRINT #2, “stopped on error”:

GOTO 9001

IF NUMB>=5 THEN numb=0 :goto 860 855 if eof(1) then 855

goto 835

860 if not eof(3) then 800 end9000 print “err.no:”,err:resume

Note. 1. Chip erase requires a 10ms PROG pulse.

(1)

one hex byte before being programmed into the new IC (in ZIF socket). The pro-grammed data is then verified before send-ing the same, along with its address to the PC for its display on PC monitor. (The data followed by address is output serially to the computer.) The above procedure is repeated for programming and displaying of the next data byte.

Proper handshaking between the PC and programming board is essential for suc-cessful operation. The program (data.bas) for interfacing the PC to the programming board is written in Turbo Basic.(Turbo Basic TB.EXE file is included in current EFY-CD along with other software) The source code of data.bas is given below:

Start the Turbo Basic program (TB.

exe) on the PC, select ‘Key Break–On’ in the Option menu bar, load the program (data.bas) for interfacing the PC and the programming board and run it. The program works in the non-compiled mode also. (Note. At line #800, the maximum value of variable kk may be varied, as necessary, depending on your PC’s speed, so that the program works smoothly)

Programming

We shall discuss programming aspects relating to both the modes of operation

namely, the direct keyboard-entry mode and the serial-port interface mode. For each mode a separate preprogrammed 89C51 microcontroller chip with different codes (for monitor program) is required.

Programming using direct key-board-entry mode. In this configuration, a PC keyboard is connected to the board via keyboard connector provided on the programming board. The preprogrammed (with pgrmod1 data code) 89C51 microcon-troller chip is put into the socket for IC1 and connected to a 12.6V supply. The IC to be programmed is inserted only after ensuring that ‘Program’ LED10 is off and resetting the circuit using push-to-on switch S1. Now programming can be started. Of course, only one of the two ZIF sockets is to be used at a time.

The keyboard is used for entering the address location, program data and commands for programming, verifying (reading) the programmed data bytes and erasing of the entire chip. The ‘on’ and ‘off’

status of the display LEDs indicate low (0) and high (1) logic levels, respectively (i.e.

complement of the data). The software program takes into consideration the keys used for entering hexadecimal numbers 0 through 9 and letters A through F as also the keys used for high-address selection, low-address selection, incrementing,

dec-rementing, programming and erasing as per the following details:

1. enter key is used for incrementing the address.

2. backspace key is used for decre-menting the address.

3. H key is used for making the data field value as the high address.

4. L key is used for making the data field value as the low address.

5. t key is used for programming data at the current location.

6. r key is used for erasing the pro-grammed IC.

7. s key is used for signature verifica-tion. It shows 1E on the LEDs.

When data, say, 75 is entered from the keyboard by first pressing ‘7’ followed by ‘5’ , the display LEDs show the entered data. If a mistake occurs during entry; say,

‘6’ is entered after ‘7’, re-entering ‘7’ and ‘5’

shows 75 Hex on the LED display.

To program this data into the micro-controller at location 0000H, press T key while keeping the 12V supply switch S2 pressed. This results in 75H to be pro-grammed at location 0000H.

To advance to the next location, press Enter key. (To go back, press Backspace key.) Now enter the next byte to be pro-grammed, say, 90H. If needed, correct as before. (Do not press Enter key or keys other than 0 through 9 and A through F.) Then press T key again along with switch S2 to store 90H at location 0001H.

Every time T key is pressed, the 12V LED (green LED) blinks. This shows that the 12V pulse is applied to the EA/VPP pin. In this way data can be entered and programmed into the new IC byte-by-byte.

If data is to be entered at a location other than start address 0000H, the start-ing address can be set by usstart-ing H and L keys as follows:

Supposing that you want to start programming from address 0250H. Enter 0 followed by 2 and then press H key. The high address is set to 02 Hex. Now Enter

‘5’ followed by‘0’ and then press L key.

The low address is set to 50 Hex. Thus, the programming start address is set to 0250H. The data is shown on the eight LEDs. (Please note that in a new good IC, all memory locations should read FF hex.) With an 89C2051 microcontroller (in ZIF socket-2) programming and verification (reading) cannot start from location other than origin (0000H) since 89C2051 has no provision for address input directly, but Fig. 8: Component layout for the PCB

only by counting pulses applied into its pin 5, and the address is advanced by pulsing pin 5 (address line A0).

To read/verify data in an already programmed device starting with address 0000H, press Reset switch S1 and keep on pressing the Enter key to read data on the LED display byte-by-byte.

Erasing is done simply by resetting and pressing 12V switch S2 followed by R key. The 12V LED glows for a fraction of a second. The 12V LED should glow momentarily only when T (Program) key or R (Erase) key is pressed.

Programming using the serial-port interface mode. For this mode of operation the keyboard is not connected to the circuit board, but a 3-core cable is connected to the PC’s spare Com port 1 or Com port 2 from the 9-pin ‘D’ connector on the programming board. Operation in this mode is feasible using DOS or Win-dows operating system. Programming the microcontroller IC in this mode requires ASCII code file (with extension .ASC), or the programming can be done byte-by-byte, using the PC’s keyboard under ‘P’

option as explained later. The ASCII file is developed as follows:

1. The source program file (with exten-sion .ASM) is developed using Assembly language, for which one can use X8051.

exe cross-assembler program. The same program also generates its object code file (with extension .OBJ). (with .ASC extension) using the BIN4ASC.

exe program.

As stated earlier, a different moni-tor program (with pgrmod2 data code), burnt into 89C51 IC is placed in the socket of IC1. Switch on the 12.6 V sup-ply to the circuit board, insert the IC to be programmed in the ZIF socket and connect the programming board to the PC’s Com port. Then, press Reset switch.

If the 12V LED glows inadvertently at power-on, pressing the Reset button will put it out. Ensure that the 12V switch S2 is initially off.

Now you may run the data.bas pro-gram on the PC. This propro-gram sets the Com port for 1200 bauds, 8 bits, no parity.

The program then prompts for the name of the ASCII file that is to be programmed into the fresh IC (in ZIF socket), as fol-lows :

Filename?

Enter the file name interactively. For example, if the ASCII file name is EFY.

ASC, type the same and press Enter key.

(The code in EFY.ASC file contains code to display a message ‘ElectronicForYou’ on a 16X1 LCD module, which uses a Hitachi controller or equivalent that considers the single row as a configuous address from 0 to 15 for its 16 characters.) Now press Re-set switch S1 on the board, momentarily.

The following message should appear on PC monitor via the RS-232 Com port:

READY, Which Device, 8951 Or 52 Or 2051?

If the message doesn’t appear on pressing Reset, check RS-232 connecting wires. Also check whether TXD pin 11 of the preprogrammed IC 89C51 is pulsing, using a logic probe. (It should pulsate.)

Enter 1, 2 or 3 to select the device. If

Make sure that 12V LED is ‘off,’ then press the 12V switch S2 and enter ‘E’

for erasing (if desired) the chip. The 12V Program LED10 glows for a while. You need not press Enter key after ‘E’ key is pressed.

After erasing is over, the following message comes up:

ERASE OVER, Now Send Data For sending data (for programming) to the programming board from the PC, an ASCII file is needed. Simply enter ‘s’

from the PC’s keyboard. Of course, before entering ‘s’ key, you need to ensure that, prior to pressing of the s key, the 12V LED does not glow. Now, keep the 12V switch pressed for the entire programming duration.

The data transfer takes place and the address gets incremented by one after programming each memory location. The 12V LED keeps on blinking during the programming process. The board sends the currently programmed address along with data to the PC for display on the monitor screen and we can watch this programming process.

The address gets incremented until ei-ther the entire chip has been programmed or else the data in the ASCII file has ended. Now open the 12V switch S2 and

press Reset switch S1, on the board.

Data is programmed into the IC cor-rectly, because after each byte is sent and programmed, the same is verified there.

Then the next address is output to the PC to inform at what address programming is proceeding. In case data sent and data verified do not match, the following error message comes up:

ERR AT xxxx (Address)

and the program halts. Press Reset on the programming board to resume programming of the IC.

If the chip is programmed completely, the following message appears:

OVERThe read chip (R) option allows you to read the contents of a programmed mi-crocontroller in the socket. This is useful to read already programmed chips, but if the lock bit is programmed, no data can be read.

In response to the prompt “Want to Erase, or Read or Prog or Lock? (E/R/P/L)”

message, if you press R key, data is output

message, if you press R key, data is output

In document ep25-ElectronicsProjectsVol25.pdf (Page 53-59)