Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

The Microcontroller Idea Book (Jan Axelson, 1994)

.pdf
Скачиваний:
247
Добавлен:
12.08.2013
Размер:
2.85 Mб
Скачать

Running BASIC-52 from External Memory

14-1 for longer delays between writes. To do so, between lines 30 and 40, add this or a similar “do-nothing” loop: FOR J=1 to 10:NEXT J.

For EPROM storage, you can copy the ROM into RAM and then use Listing 13-8 to program an EPROM. For this method, use a 32K RAM at U7 in Figure 3-1. You’ll also need an unprogrammed 8K EPROM accessed as data or code/data memory. Set MTOP to 5FFFh or lower to ensure that BASIC-52 won’t overwrite the area from 6000h to 7FFFh. In Listing 14-1, lines 10, 30, and 80, change 8000h to 6000h. Run the revised program to copy the 8052-BASIC’s ROM into RAM at 6000h-7FFFh. You then can upload or enter Listing 13-8 to copy BASIC-52 into your EPROM, at the starting address you specify.

Another option is to use an EPROM programmer to copy BASIC-52. If your programmer has an adapter for 8051s, you can copy the 8052-BASIC’s ROM directly into the programmer’s buffer and then program an EPROM, EEPROM, or NV RAM with the buffer’s contents. If you don’t have an adapter, you can use the technique described above to copy BASIC-52 into NV RAM or EEPROM, and then read the device into your programmer.

To read a DS1225 into an EPROM programmer’s buffer, configure the programmer for a DS1225 or 2764 EPROM, since the pinouts for reading these devices are the same. Place the DS1225 in the programming socket and read the contents into the programmer’s buffer. Be sure not to subject the DS1225 to any EPROM programming voltages (by trying to program the device as an EPROM, for example), since this could be lethal to it.

After reading the DS1225, insert a 2764 EPROM into the programming socket, and program the EPROM with the buffer’s contents. You now have an EPROM with the same contents as your NV RAM.

System Requirements

To run BASIC-52 from external memory, your circuit must include the following:

Any 8052, 8032, 80C52, or 80C32 chip, with pin 31 tied low.

BASIC-52 stored in non-volatile memory (NVRAM, EEPROM, or EPROM), beginning at 0 in code memory.

At least 1K of read/write memory (RAM), beginning at 0 in data memory (required for all BASIC-52 systems).

For permanent storage of BASIC-52 programs, non-volatile memory beginning at 8000h in data or code/data memory.

One limitation to running BASIC-52 from external memory is that you can’t use PROG, FPROG, or PGM. This is because during programming, BASIC-52 accesses the address bus as ports, but when BASIC-52 runs from external memory, the 8032 needs the address bus

The Microcontroller Idea Book

241

Chapter 14

to access BASIC-52. But you can store programs in NV RAM or EEPROM, using a BASIC-52 program presented later in this chapter.

For the external-BASIC-52 system, you can use the same circuits as in Figures 3-1 and 4-3, plus Figure 14-1, which adds the chip containing BASIC-52.

Figure 14-1. Added circuits for storing BASIC-52 in external code memory.

242

The Microcontroller Idea Book

Running BASIC-52 from External Memory

In Figure 3-1, tie pin 31 of U2 (EA) to ground instead of +5V, so that the 8032 boots to external memory instead of internal ROM.

Since you aren’t using the programming functions, you can eliminate some components and free up three port pins for other uses. First, you don’t need an AND gate to combine ALE and ALEDIS, so you can wire ALE (U2, pin 30) directly to LE (U4, pin 11). You can also eliminate R2-R9. Plus, in Figure 4-3, you can eliminate AND gate U3C, and wire WRITE (U2, pin 16) directly to WE (U8, pin 27).

If you make these changes, bits 4 and 5 of Port 1 are free for any use you want. And, since NVRAM requires no programming voltage, bit 3 of Port 1 is also free for other uses. If you don’t make the changes, you can still run BASIC-52 from external memory, but if you try to use PROG, FPROG, or PGM, the system will crash. (You can also make these changes in a circuit that uses an 8052-BASIC, to free up some port pins if you use the program described below instead of the programming commands.)

U2 can be any 80(C)32 or 80(C)52. U7 can be an 8K or 32K static RAM, addressed beginning at 0 in data memory.

Figure 14-1 shows the wiring for NVRAM, EPROM, or EEPROM that contains BASIC-52. This chip is accessed from 0 to 1FFFh in external code memory.

U8 is NVRAM accessed from 8000h to 9FFFh in combined code/data memory, for storing BASIC-52 programs and assembly-language routines.

Storing BASIC-52 Programs

With BASIC-52 in external memory, you can’t use the built-in programming functions, but there is another way to store programs. Using the circuits described above, write and test your BASIC-52 programs as usual. When you want to store a program permanently, append the code in Listing 14-2 to your program. The code is shown beginning at line 9000, but it can begin at any line number after the END statement in the program you want to save.

To store a program in U8, type GOTO 9000, where 9000 is the line number where Listing 14-2 begins, and follow the on-screen instructions.

Listing 14-2 has all of the abilities of PROG1-PROG6, including auto-execute on power-up, setting the baud rate, and saving MTOP. Line 8990 indicates the end of the program you want to save. Lines 9000-9040 prompt you to press P to copy the current BASIC-52 program to NVRAM at U8, or press Q to quit. Line 9050 writes 55h to NVRAM, which indicates to the interpreter that a BASIC program follows. Lines 9060-9080 copy the current BASIC-52 program, which is stored beginning at 200h in external data memory (U7), to NV RAM (U8) beginning at 8011h. Listing 14-2 is also copied as part of the current program. Lines

The Microcontroller Idea Book

243

Chapter 14

Listing 14-2. Simulates BASIC-52’s PROG and PROG1-6 commands, for systems with BASIC-52 in external memory or systems that do not use the PGM PULSE signal. Adapted and reprinted with permission from Micromint.

8990 END

9000 PRINT “Press ’P’ to copy the current BASIC program to RAM at 8000h.”

9010 PRINT “Press ’Q’ to quit.”

9020 G=GET

9030 G=GET : IF G=0 THEN 9030

9040 IF (G<>80.AND.G<>112) THEN END

9050 XBY(8010H)=55H

9060 FOR X=200H TO (200H+LEN)

9070 XBY(X+7E11H)=XBY(X)

9080 NEXT X

9090 PRINT “Press a number from 1 to 6 to do PROG1-PROG6.” 9100 PRINT “Press ’Q’ to quit.”

9110 G=GET

9120 G=GET : IF G=0 THEN 9120

9130 IF (G<49.OR.G>54) THEN END

9140 XBY(8000H)=G

9150 XBY(8001H)=INT(RCAP2/256)

9160 XBY(8002H)=RCAP2-(XBY(8001H)*256)

9170 IF G<50 THEN END

9180 XBY(8003H)=INT(MTOP/256)

9190 XBY(8004H)=MTOP-(XBY(8003H)*256)

9200 END

9090-9130 prompt you to press a number from 1 to 6 to simulate a PROG1-PROG6 command, or to press Q to quit. Lines 9140-9190 store the PROG value (1-6), RCAP2 (for saving the baud rate), and MTOP, as requested.

Listing 14-2 stores only the current program, not multiple programs like the PROG command. But you can store a new program whenever you wish by writing over the previously stored program. And you don’t have to worry about removing and erasing an EPROM when it’s filled.

If you have a 32K RAM at 0, remember to set MTOP to 7FFFh and use Listing 14-2 to execute a PROG3, to ensure that your NV RAM won’t be overwritten on bootup.

You can use EEPROM with Listing 14-2, if you add a delay loop after each write operation using XBY, as described for Listing 14-1.

244

The Microcontroller Idea Book

Related Products

15

Related Products

Because of the popularity of the 8052-BASIC chip, many companies have developed products to simplify the tasks of designing, building, and testing BASIC-52 systems. This chapter describes some of the offerings in these areas.

Enhanced BASIC-52

The BASIC-52 interpreter contained in the original 8052-BASIC is a good, full-featured and easy-to-use programming language. However, Intel hasn’t updated the program since version 1.1. Fortunately, other programmers have taken on the task of improving and enhancing the language.

MDL Labs’ MDL-BASIC is an EPROM that contains an enhanced version of BASIC-52. It includes new operators that set and clear individual bits in memory, increment and decrement values, and return the remainder in integer division. MDL-BASIC also has improvements for faster loading and running of programs, and fixes many of BASIC-52’s bugs, such as the problem with variable names beginning with F (see Chapter 5). It requires a system that can operate with BASIC in external memory, as described in Chapter 14.

Other vendors, including Blue Earth Research and Micromint, have improved and added to the BASIC-52 interpreter as well.

The Microcontroller Idea Book

245

Chapter 15

BASIC compilers

A BASIC compiler offers a middle ground between the BASIC-52 interpreter and assem- bly-language programming. With a BASIC compiler, you write your programs using the familiar keywords and syntax rules of BASIC, but the compiled programs run on their own, without requiring the BASIC-52 interpreter. Binary Technology, Systronix, and Blue Earth are three vendors of BASIC compilers for the 8052.

As with assembly language, to use a BASIC compiler, you first write a source file, using any text editor. But instead of using assembly-language mnemonics, you write the source file using the BASIC compiler’s keywords and conventions. When the program is complete, the compiler program translates your program lines into the machine codes required by the 8052 chip. The compilers will create an object file, usually in Intel Hex format, for uploading or programming into EPROM, plus a listing file for documentation and debugging use. When the object file is stored in the 8052’s code memory, the 8052 can run the program directly, without having to use the BASIC-52 interpreter.

Using a compiler has several advantages:

Unlike with assembly language, the syntax used with BASIC compilers is similar to BASIC-52. This means that you don’t have to learn a new programming language. In fact, you can usually use the BASIC-52 interpreter to test your code before you compile it. You can also use BASIC-52 for loading and debugging your compiled programs, as described in Chapter 13.

A compiled BASIC program will run faster than an interpreted BASIC-52 program. The speed increase depends on the program, but programs that run 20 to 50 percent faster are typical.

Because a compiler doesn’t limit you to the 8052-BASIC chip, you can develop programs for other members of the 8051 family. For example, Systronix’s BASIC compiler has optional language extensions for Dallas Semiconductor’s DS5000 8051-compatible microcontroller.

A disadvantage to using a compiler rather than an interpreter is that you have the extra steps of compiling and uploading programs before you can run them. But because the BASIC-52 language is so similar to the compilers, you can do a lot of your testing with the interpreter, and use the compiled version for final testing only.

There’s also the added expense of buying the compiler. But if you develop many different projects, or if you need many copies of a single project, the compiler can end up saving you money, since you can use 8032 chips instead of the more expensive 8052-BASICs.

246

The Microcontroller Idea Book

Related Products

Finally, a compiled BASIC program usually requires more memory than an interpreted one, but you do gain 8 kilobytes of code memory because you no longer need the BASIC-52 interpreter.

Programming Environments

If you like the convenience of the BASIC-52 interpreter, but would like features that make it easier to write, edit, and store your programs, there are alternatives here as well.

MDL Labs and MicroFuture are two sources for development environments, which are programs that typically include communications and program-editing abilities. Most run on IBM-compatible host computers. Figure 15-1 shows a typical screen.

The environments include features like these:

Block editing, or the ability to move, delete, or copy blocks of text in one operation.

The ability to refer to subroutines by name, rather than by line number.

Figure 15-1. MDL Labs’ Basikit includes communications and program-editing abilities.

The Microcontroller Idea Book

247

Chapter 15

Elimination of the need to use line numbers at all.

Automatic stripping of comments, to save memory and execution time in uploaded programs.

On-line help for BASIC-52.

Debugging tools, such as setting of breakpoints or watch variables for program testing.

Conversion of BASIC-52 programs to hex files for EPROM programming.

Screening of variable names for duplicates or embedded keywords.

Pc Boards

If you’d rather not build your own 8052-BASIC system from scratch, a variety of sources are ready to help here as well, with fabricated pc boards ready for use with the 8052-BASIC chip. The boards contain all of the components required to get an 8052-BASIC system up and running. Most come with complete schematics, to make it easy to add to the included circuits. A few boards are available as kits or bare boards, if you’d rather build your own.

I’ll describe just a few of the available products here; see Appendix A for a more complete listing of sources.

Figure 15-2. Prologic’s BASCOM1 is available as a low-cost bare pc board with an instruction manual for construction and use.

248

The Microcontroller Idea Book

Related Products

Figure 15-3. Blue Earth’s Micro440 board has BASIC-52 and a monitor program in a tiny package.

Micromint offers a variety of 8052-BASIC boards and other products. Both the BCC52 and RTC52 are single-board systems that can also serve as the base of an expanded system. The BCC52 uses edge connectors and a backplane, while the RTC52 is a stackable design. A variety of expansion boards are available, including interfaces to displays, keypads, relays, infrared control, and A/D converters. The BRUTE-52 is a single board with many expansion options on-board.

Micromint’s Domino is a complete Basic-52 system in a 20-pin encapsulated package that’s about the size and shape of a domino. It has a surface-mount 80C52-BASIC chip, 32 kilobytes each of RAM and EEPROM, and twelve I/O pins, two of which may be analog inputs. The Domino’s BASIC-52 interpreter adds functions for measuring frequency and period and for reading the analog inputs.

Prologic Designs offers an inexpensive bare pc board (Figure 15-2) and detailed manual for 8052-BASIC systems, for those who prefer building their own.

Blue Earth Research’s Micro-440e is a complete system on a tiny pc board, just 1.9" x 2.25" (Figure 15-3). The system uses a surface-mount 83C51FB chip with both Blue Earth’s version of BASIC-52 and a monitor program in ROM. A case and expansion boards are also available. The Micro-485 adds an analog-to-digital converter, clock and calendar, and an RS-485 interface for networking.

The Microcontroller Idea Book

249

Chapter 15

To speed up program execution, you can use Dallas Semiconductor’s DS80C520 high-speed microcontrollers, which are compatible with the 8051 family. MDL Labs and Photronics Research offer variations of BASIC-52 designed for use with these chips.

BASIC-52 Source Code

If you’re interested in seeing the source code for the BASIC-52 interpreter, look for it on Intel’s or Philips’ BBS or on the Internet (Appendix A). To modify the code, you’ll need Intel’s ASM51 or a compatible 8051 assembler.

250

The Microcontroller Idea Book