ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 2104
Скачиваний: 0
Saving Programs
This is the recommended algorithm for older, smaller-capacity EPROMs like the 2-kilobyte 2716 and 4-kilobyte 2732, and some 8-kilobyte 2764s. These typically require a programming voltage of 21 or 25 volts at the EPROM’s VPP input.
Intelligent programming. This algorithm uses much shorter programming pulses, and verifies after each attempt. After each 1-millisecond programming pulse, you read the EPROM location to see if the programming succeeded. If not, you try again, up to 25 times. When the location verifies, you apply a final pulse equal to three times the total amount of programming pulses already applied. For example, if it takes five attempts to verify, you would apply a final 15-millisecond pulse. Finally, when all locations are programmed, you verify each once more.
For Intelligent programming, VPP is typically +12.5 volts, and VCC, the EPROM’s main power supply, is also raised from +5 to +6V during programming.
Intelligent programming is the recommended algorithm for many 8K EPROMs. Intel’s 2764 EPROM uses 21V, 5—millisecond programming, while the 2764A uses 12.5V, Intelligent programming.
Quick-pulse programming. Some CMOS 8K EPROMs (27C64) can use an even faster programming algorithm called Quick-Pulse. In Quick-Pulse programming, VPP is typically 12.75V, VCC is 6.25, and the programming pulses are 100 microseconds. BASIC-52 doesn’t offer Quick-Pulse programming as an option.
Choosing an algorithm. As a rule, you can program an EPROM using a slower algorithm than the recommended one, so you should be able to program any 12.5V EPROM with 50-millisecond programming, with VPP at 12.5V and VCC at +5V. And, any EPROM that can use Quick-Pulse programming should also program with the Intelligent or 50-millisec- ond programming algorithm and voltages. But whatever you do, don’t exceed the recommended programming voltages for the device at VCC and VPP.
EPROM Pinouts
Figure 4-4 shows the pinout for a 2764 8K EPROM. Once again, the pin functions and locations are similar to those in an 8K RAM. During normal operation, the data pins (DQ0-DQ7) are read-only. Pin 27, which is Write Enable (WE) on RAM, is PGM, or program pulse, on the EPROM, and pin 1, which has no connection on RAM, is VPP, or programming voltage, on the EPROM.
EPROM-programming Circuits
Figure 4-5 shows additions to Figure 4-3’s circuits that enable you to program a 12.5V 8K EPROM instead of NVRAM or EEPROM. Table 4-2 is a parts list for Figure 4-5’s circuits.
The Microcontroller Idea Book |
57 |
Chapter 4
Figure 4-4. Pinout for 8K EPROM.
The components continue the numbering sequence begun in Figures 3-1 and 4-4. The additional circuits for the PROG commands are at pin 1 of U8. Jumper J5 allows you to configure the memory site for the type of NV memory you’re using.
On NVRAM or EEPROM, pin 1 has no connection (or, on some EEPROMs, it’s a BUSY output). On the EPROM, it’s VPP, which is +5V during read operations and 12.5V during programming. (pin 6 on the 8052-BASIC) controls the programming voltage by going low during programming operations and otherwise remaining high.
To prevent accidental programming during power up, OR gate U10A’s output remains high until RESET goes low. U10 is not an ordinary OR gate—it’s a 75453 peripheral driver. Unlike ordinary logic gates, U10’s open-collector output can pull up to 30V without damaging the chip. The output also has much greater current-sinking ability than other logic gates (up to 300mA), and can easily provide base current to drive transistor Q1.
When pin 3 of U10A is high, Q1 is off, and VPP connects to +5V through germanium diode D2. The diode’s voltage drop is just 0.3V, so VPP is actually at about 4.7V. Intel’s data sheets specify that read operations require VPP to be at least 3.8V for the 2764A, or VCC-0.7V for the 27C64, so 4.7V is within the specifications.
58 |
The Microcontroller Idea Book |
Saving Programs
Figure 4-5. Additional circuits for programming EPROMs.
The Microcontroller Idea Book |
59 |
Chapter 4
Table 4-2. |
Parts list for Figure 4-5. |
Semiconductors |
|
D2,D3 |
1N270 or similar germanium diode |
Q1,Q2 |
PN2907 or similar PNP general-purpose transistor |
U10 |
75453 dual peripheral OR driver |
Resistors (1/4-watt, 5% tolerance) |
|
R11,R14 |
4,700-ohm |
R12,R13 |
10,000-ohm |
R15,R16 |
10,000-ohm |
Capacitors(16WVDC, 20% tolerance) |
|
C15 |
0.1-microfarad ceramic disc |
Miscellaneous |
|
J5-J6 |
SIP header, 3-terminal, and shorting block |
When BASIC-52 executes a programming command, PGM EN goes low, pin 3 of U10 goes low, and Q1 switches on. This brings VPP to 12.5 volts. Diode D2 prevents current from flowing into the 5V supply. When programming is finished, PGM EN goes high again, and VPP returns to +4.7V.
Resistor R10 limits U10A’s output current, and R11 ensures that pin 3 of U10 pulls up to 12.5V. Capacitor C14 provides power-supply decoupling.
If you happen to have an older 21V EPROM, the circuit should also work with a +21V supply in place of +12.5V.
FPROG Circuits
If you want to use the FPROG commands for faster EPROM programming, additional circuits are required. These are identical to the circuits that switch VPP, except that they instead switch VCC to +6V during programming.
With the FPROG circuits shown in Figure 4-5, during normal (non-programming) operation, VCC is actually slightly less than +5V, due to D3’s voltage drop. This should cause no
60 |
The Microcontroller Idea Book |
Saving Programs
problems with EPROMs that have a 10 percent power-supply tolerance; in other words, ones that are guaranteed to operate from supplies of 4.5 to 5.5V. You do want to be sure that your main supply is a solid +5V, or even a little higher.
The data sheets for some EPROMs specify 5-percent tolerance: the supply must be between 4.75 and 5.25V to guarantee operation within the specifications. In this case, you will be operating near or just below the recommended supply voltage, especially if your main supply is slightly under +5V. When you are not programming the EPROM, you can move J6 to connect pin 28 directly to +5V. But overall, 10-percent-tolerance EPROMs are a better choice for this circuit.
If you are using a NVRAM or EEPROM, set J6 to +5V, since VCC must remain at 5V for these devices.
Power Supplies for Programming
You have several options for creating the programming power supplies of +12.5V and, optionally, +6V.
Benchtop Supply
For occasional use, if you have a benchtop supply that can supply the needed outputs, you can add terminals to the appropriate connections in your BASIC-52 system, and connect the supply leads to them when needed.
Adjustable Regulator
Figure 4-6 shows a circuit that regulates a DC supply of 15 to 18V to 12.5V or 6V. For the 15V supply, you can use a benchtop supply, a wall-transformer AC-to-DC adapter, or even two 9-volt transistor batteries connected in series. The supply must have a DC output, but it doesn’t have to be regulated. You’ll need one LM317 and an R1 and R2 for each output voltage, but you can power both LM317’s from the same supply.
Typical current requirements for programming an NMOS 2764A are 50 milliamperes at 12.5V and 75 milliamperes at 6V, or 125 milliamperes total. For a CMOS 27C64, it’s 30 milliamperes for each, or 60 milliamperes total.
Each regulating circuit uses an LM317 adjustable regulator. You set the output voltage of the LM317 with R1 and R2, using the formula shown. The LM317 creates a constant 1.25V reference across R1. The current through R1 also flows through R2, and the voltage across the pair of resistors is the regulator’s output.
Intel’s EPROM data sheets specify this range for the programming voltages:
The Microcontroller Idea Book |
61 |
Chapter 4
Figure 4-6. Power supply circuit for EPROM-programming voltages.
VPP: 12V to 13V
VCC: 5.75V to 6.25V
If you use 5%-tolerance resistors for R1 and R2, you may have to vary the value of R2 for the proper output, especially to meet the requirement for Vcc. Or, you can use a 5K potentiometer for R2 and adjust for the desired output, or use 1%-tolerance resistors for a more precise output.
You can wire the LM317 circuits to your 8052-BASIC circuit board, and add terminals or jacks for connecting a 15V supply. Wire the LM317’s output to the appropriate connections in Figure 4-5.
Switching Regulators
A third way to generate programming voltages is to use switching regulators like those available from Maxim Semiconductor. These can create the programming voltages from your +5V supply. For example, the MAX633 can create outputs of 6 and 12.5V from a +5V
62 |
The Microcontroller Idea Book |
Saving Programs
supply. The chip requires an additional inductor and capacitor, plus two resistors to set the output voltage. Maxim’s data books have more details about this and similar chips.
Storing Programs on Disk
With BASIC-52’s ability to store programs in on-board memory, disk storage isn’t necessary. But storing programs on the host system’s disk is convenient, since you can save as many programs as you want without worrying about running out of program memory. Since the programs are stored as ASCII text, you can write or edit them with any text editor, and then upload them as needed to the target system.
Most communications software allows you to upload and download files. In Procomm Plus, you use the PGUP and PGDN keys. In the Windows Terminal Accessory, use the Transfers menu.
Uploading to the 8052-BASIC System
When you upload a program to the 8052-BASIC system, you have to ensure that BASIC-52 has enough time to process each line before the next one arrives. If there isn’t enough time, you’ll have missing characters or lines in uploaded programs. There are a couple of ways to ensure that your uploads are complete.
Most software allows you to add delays after each transmitted line or character. You can experiment with different values to find the shortest delays that allow you to upload reliably. If you keep your program lines short, the delays between lines can be shorter.
If these options aren’t available, try using a slower baud rate, which gives BASIC-52 a little more time to process each line before the next one arrives.
Downloading to the Host Computer
To download a BASIC-52 program from the target’s RAM to the host’s disk, type LIST to list the current program, but before you press ENTER to execute the command, set up your host’s software to download, or receive, an ASCII file. When prompted, specify a filename. When the transfer is ready to go, press ENTER to send your program to the host. When you see the READY prompt, end the transfer by whatever means your software requires. (In Procomm Plus, press ESCAPE.) You should now have a file on disk containing the program you just listed.
You can test your download by erasing the program in the 8052-BASIC system’s RAM, and then uploading it back into RAM.
The Microcontroller Idea Book |
63 |
Chapter 4
First, type NEW to erase the program. To restore your program by uploading it from disk, set up your host’s software to upload, or send, an ASCII file, and enter the name of your previously downloaded file. As the file loads, you’ll see each program line on screen. The file will contain a READY prompt after the program listing. This causes BASIC-52 to display an error message, which you can ignore. Type LIST to view the uploaded program, and type RUN to run it.
With BASIC-52 programs on disk, you can use any text editor to view or modify the program. Save the file as pure ASCII text, with no formatting commands added. You can also use your text editor to create a program from scratch, then upload it to BASIC-52, rather than typing the lines using BASIC-52’s line editor.
64 |
The Microcontroller Idea Book |
Programming
5
Programming
When you have your 8052-BASIC system up and running, you’re ready to start writing and running your own programs. This chapter is an introduction to the BASIC-52 programming language. It includes a summary of BASIC-52’s abilities, some examples that illustrate what you can do with it, plus tips for writing and debugging programs.
For a complete reference to BASIC-52, see the BASIC-52 programming manual (either version), which includes many more examples and details about the language and how it works. You can learn a lot about BASIC-52 by browsing through the programming manual and experimenting on your own.
Programming Basics
Like other BASIC programs, BASIC-52 programs are built around a set of keywords, or reserved words. Each keyword has a specific meaning to the BASIC-52 interpreter. or example, the program line PRINT XTAL tells BASIC-52 to find the stored value of the XTAL operator and send it to the console input device (the serial port of the host computer), which will then display the value it receives.
If you’re familiar with BASIC programming, most of BASIC-52’s keywords and conventions will be familiar. If you have little programming experience, or if your experience is with assembly language, C, Pascal, or another language, you’ll have more to learn. But on the whole, BASIC-52 makes it easy to quickly write and test your programs.
The Microcontroller Idea Book |
65 |
Chapter 5
Writing a short BASIC-52 program involves these steps:
Define what you want to do
Write program lines to accomplish it
Test the results
As necessary, revise and retest
Longer programs involve the same basic steps, except that you can divide the program into a series of smaller tasks, or modules, and program and test each individually. Then, when the modules are working, you can combine them in one big program and test the result.
Modular programming can save a lot of headaches by limiting the amount of untested program code you have to work with at one time. A long, untested program almost certainly contains many errors will be hard to find and fix. It’s much easier in the long run to test the pieces first, and BASIC-52 makes this easy to do.
Command and Run Modes
BASIC-52 has two modes of operation: command and run. Command mode refers to anything you type without a line number. BASIC-52 executes these lines immediately after you press ENTER. Run mode refers to running stored programs with the RUN command. A program consists of a series of program lines, with each line beginning with a line number.
BASIC-52 includes some keywords that you can use only in command mode, but not in programs. PROG is an example. Most of BASIC-52’s other keywords are usable in either command or run mode. A few, such as DO...WHILE, are usable in RUN mode only.
Tips for Writing BASIC-52 Programs
The following advice is intended to make your programs easier to write and debug, and to help you avoid some common mistakes:
•Number program lines by 10s. Each line in a BASIC-52 program must begin with a line number. BASIC-52 uses the numbers to order the statements. Traditionally, BASIC programs begin at line 10, and count up in multiples of 10: 20, 30, and so on. This way, if you later discover that you need to add a few lines in the middle, you can, using the unused numbers that remain.
•Divide long programs into modules. Break up big projects. Use subroutines for independent functions. A subroutine is a block of statements that the main program jumps to with a GOSUB statement. At the end of the subroutine, a RETURN statement causes the program to jump back to the program line following the GOSUB statement.
66 |
The Microcontroller Idea Book |