ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 2080
Скачиваний: 0
Chapter 3
required for the programming functions, and are included for future use. You can use eight individual resistors, or a resistor network that contains eight resistors in a SIP or DIP package. In a bussed resistor network, one pin connects to one side of all of the resistors, so you have fewer connections to wire.
The remaining bus is the HIGH ADDRESS BUS (A8-A15), which consists of the upper eight address lines, and is not multiplexed.
Address decoding. U6 is a 74HCT138 3-to-8-line decoder. It functions as an address decoder for the 64K external memory space. Address decoding allows multiple chips to connect to the address and data buses, with each chip enabled only when it is selected.
Figure 3-2 shows a truth table for the decoder. The 8052-BASIC chip uses the three highest address lines (A13-A15) to generate a chip-select signal for each of eight 8K blocks in memory. This is by no means the only way to decode memory, but it’s a common and flexible one. In the schematic, each output is labeled with the base, or bottom, address in the block it controls.
For example, when U2 reads or writes to an address between 0 and 1FFFh in external memory, A13, A14, and A15 are low, so pin 15 of U6 is low. For all other addresses, pin 15 is high. If we connect pin 15 to the chip-select input of an 8K RAM, the RAM will be enabled only when addresses from 0 to 1FFFh are accessed. (Remember that 8K, or 8 kilobytes, is 2000h, or 0 through 1FFFh, in hexadecimal.)
If you use a 32K RAM, you don’t need U6 to decode its addressing. For all of the 32K RAM’s addresses (0 to 7FFFh), A15 is low, and for all other addresses (7FFFh to FFFFh), A15 is high. This means that you can use A15 directly as a chip select, without additional decoding. U6 will come in handy later, however, even if you use a 32K RAM.
RAM choices. The minimal circuit includes just one memory chip, U7, which can be an 8K or 32K static RAM, or SRAM. BASIC-52 requires at least 1K of RAM, but I’ve used the larger capacities, since the extra room is useful and doesn’t cost much more. The pinouts of the two chips are similar, with jumpers J2 and J3 routing the signals that vary.
The 8K chip has 13 address inputs (A0-A12), while the 32K chip has 15 (A0-A14). Eight data I/O pins (I/O1-I/O8) connect to the data bus and hold the bytes to be read or written.
The RAM has three control inputs whose functions match those of the 8052’s control outputs. Pin 20 (CS1, or Chip Select 1) enables U7 whenever the 8052 reads or writes to the chip, with the address decoding determining the address range of the chip.
28 |
The Microcontroller Idea Book |
Powering Up
Jumper J3 chooses the chip select for an 8K or 32K device. Some 8K RAMs have a second chip select (CS2), which is tied high (always selected) by J2. If you limit yourself to either 8K or 32K RAMs, you can eliminate J2 and J3 and wire the appropriate connections directly.
Pin 27 (WE, or Write Enable) is driven by WRITE, and is strobed low during each write to external data memory. Pin 22 (OE, or Output Enable) is driven by READ, and strobes low when either external data or code memory is read.
With an 8K RAM, each write cycle follows this sequence: The 8052 brings ALE high and places the address to be written to on AD0-AD7 and A8-A15. For addresses from 0 to 1FFFH, A13-A15 are low, so U7 is selected at its pin 20. After a short delay, the 8052 brings ALE low, which causes U7 to store the lower address byte. After another short delay, the 8052 replaces the address on AD0-AD7 with the data to be written. A low pulse at pin 27 (WE) causes the RAM to write the data into the address specified by A0-A12.
Read cycles are similar, except that a pulse at pin 22 (OE) causes the requested data to appear on AD0-AD7, where the 8052 reads it.
With a 32K RAM, the process is the same, except that A15 is the chip select and there are two more address lines on the chip.
Static RAM chips are rated by their read-access time, which is the maximum time the chip will require to place a byte on the data bus after a read is requested. With a crystal frequency of 12 Mhz or lower, an access time of 250 nanoseconds or less is fine for accessing external data or code memory. Access times and other timing characteristics are described in the timing diagrams in the data sheets for the 8052 and RAM.
When you use the 8052-BASIC, you don’t have to worry about any of these specifics about the read and write cycles. If the circuit is wired correctly, and if all of the components are functioning as they should, reading and writing occur automatically in the course of executing BASIC-52 statements and commands. A single program line in BASIC-52 can cause dozens or more read and write operations to occur.
Logic families. Logic chips U3, U4, and U6 are HCT-family components, which have TTL-compatible inputs and CMOS-compatible outputs. This means that they can interface directly to either TTL or CMOS logic.
If HCT-family parts aren’t available, there are alternatives. You may use an LSTTL chip (74LS08, 74LS138, 74LS373) for U3, U4, or U6. Or, if you use a CMOS 80C52-BASIC for U2, you may use an HCMOS 74HC08 or 74HC138 for U3 or U6. If U3 is a 74HC08 or 74HCT08, you may use a 75HC373 for U4. For U1, you may use a 74HC14 or 74LS14.
The Microcontroller Idea Book |
29 |
Chapter 3
Table 3-2. Voltage specifications for different types of logic, powered at 5V.
Logic Type |
Output |
Input |
||
0 (maximum) |
1 (minimum) |
0 (maximum) |
1 (minimum) |
|
TTL, including LSTTL |
0.4V |
2.4V |
0.8V |
2.0V |
most NMOS |
||||
HCTMOS |
0.1V |
4.9V |
0.8V |
2.0V |
HCMOS |
0.1V |
4.9V |
1.0V |
3.5V |
4000-series CMOS |
0.1V |
4.9V |
1.5V |
3.5V |
Table 3-2 summarizes the input and output voltage specifications for different logic-device families. The main point to remember is that a TTL logic-high output voltage (and most NMOS high outputs) may be as low as 2.4V, which does not meet the minimum input-voltage requirement for HCMOS or 4000-series CMOS devices. To interface a TTL output to CMOS, use an HCTMOS device, which accepts TTL-logic inputs. Or, you may add a pull-up resistor to a TTL output to pull it near +5V.
Serial Interface
The final chip in the schematic is U5, a MAX232 driver/receiver, which is the popular single-chip solution for RS-232 interfaces. One side connects to the 8052’s serial input and output on pins 10 and 11 of U1, and the other side sends and receives signals at standard RS-232 levels to a personal computer. Larger capacitor values for C4-C7 are fine, and the MAX232A version can use values as small as 0.1 microfarad. If you splurge on a MAX233, which has internal capacitors, you don’t need C4-C7 at all.
Power Supply
A final essential component is the power supply. For the basic system, all you need is a regulated +5-volt supply. These are widely available from mail-order suppliers. An output capability of at least 500 milliamperes is recommended.
Capacitors C8-C13 provide power-supply decoupling. Digital devices draw current as they switch. Capacitors C9-C13 store energy that the components can draw quickly, without causing spikes in the supply or ground lines. C8 stores energy for quick recharging of C9-C13. The exact values aren’t critical, but C9-C13 should be a type with good high-fre- quency response, such as ceramic, mica, or polystyrene.
LED1 and current-limiting resistor R10 are an optional power-on indicator.
30 |
The Microcontroller Idea Book |
Powering Up
Figure 3-3. This is the circuit board on which I wire-wrapped and tested many of the circuits in this book.
Circuit Construction
This circuit is intended for use as a flexible system for testing and experimenting, rather than a fixed, unchanging design for a single application. For this reason, I recommend building it with wire-wrapping or another construction method that allows easy changes and additions. Figure 3-3 shows an 8052-BASIC circuit wire-wrapped onto perfboard.
Reading the Schematic
In the schematic, I used a couple of different techniques to represent connections between pins and components. In the reset circuit, connections are drawn as direct point-to-point lines. For the address and data lines, I used buses for a neater, more compact schematic. When you wire these connections, use the signal labels as a guide. For example, the label D0 tells you to interconnect these points: pin 39 of U2, pin 3 of U4, pin 11 of U7, and one end of R2. Other connections are indicated by labels. For example, the WRITE label tells you to connect pin 16 of U2 and pin 27 of U7.
Another point to be aware of is the conventions used in the schematics and text of this book for indicating an active-low signal, or a signal that is valid, or enabled, when low. In this book, the schematics use a leading hyphen (-WRITE) , while the text uses an overscore (WRITE). Their meanings are the same.
The Microcontroller Idea Book |
31 |
Chapter 3
Figure 3-4. How to determine the correct orientation for ICs, diodes, LEDs, and electrolytic capacitors.
32 |
The Microcontroller Idea Book |
Powering Up
Construction Tips
These are some things to be aware of as you build the circuit:
•Choose a circuit board that has room for additions, at least 4 by 6 inches.
•A board with interleaved buses, such as Vector’s 3677 series, allows easy, low-impedance connections to +5V and ground. Designate one bus as ground, and the other as +5V. For power and ground connections, wrap one end of the wire to the appropriate pin on the chip, and trim and solder the other end directly to the bus.
•To connect the power and ground buses to the +5V supply, use thick (AWG #22 or lower) wires, not #30 wire-wrap wires. You can solder the other ends of the wires to banana plugs or screw terminals, or clip your power-supply leads directly to the wires.
•The schematic doesn’t show an ON/OFF switch for the circuit, but you can add a SPST toggle or slide switch in series with the connection to the +5V supply if you wish.
•Place C8 near where the +5V supply connects to the board. Mount decoupling capacitors C9-C13 so that each chip’s +5V and GND pins are near a capacitor. In other words, space the capacitors evenly around the board; don’t group them all in one area. Keep the wires or traces between the capacitor’s leads and the IC’s +5V and ground pins as short as possible.
•To minimize noise in the oscillator circuits, place XTAL1, C2, and C3 close to pins 18 and 19 of U2 and connect them with short wires. Wire the ground terminals of C2 and C3 directly to pin 20 of U2.
•When you wire the following components, correct orientation is required: C1, C4-C8, D1, LED1, and U1-U7. Figure 3-4 shows common polarity indicators for these components. Notice that C7’s positive terminal connects to ground, and C6’s negative terminal connects to +5V, since these capacitors connect to the MAX232’s -10V and +10V outputs.
•As you wire the circuits, remember that everything on the wire-wrap or solder side of the board is a mirror image of the way it looks on the component side of the board. If pin 1 is in the upper left corner on the component side, it’s in the upper right corner on the wire-wrap side (assuming that you flip the board over from side to side, not top to bottom).
•Labels on the wire-wrap side are helpful. You can place a dot of indelible ink near pin 1, or adhesive labels between the pins, or use prelabeled and punched plastic labels that slide onto the wire-wrap pins.
The Microcontroller Idea Book |
33 |
Chapter 3
Figure 3-5. Pin connections for 25-pin and 9-pin RS-232 connectors.
• Don’t plug the ICs into their sockets until you’ve completed wiring all of the circuits.
Unused Gates
Two gates on U3 and five gates on U1 are unused. To prevent the unused CMOS inputs from floating and possibly drawing excessive currents, wire pins 9, 10, 12, and 13 of U3 to ground or +5V. Do the same for pins 3, 5, 9, 11, and 13 of U1. Don’t forget to remove these connections if you later use the pins. If you are using LSTTL chips (74LS08, 74LS14), leave the unused inputs open.
34 |
The Microcontroller Idea Book |
Powering Up
Serial Connectors
Connections to RS-232 OUT and RS-232 IN depend on the type of serial connector you have on your personal computer or its serial cable.
Connectors vary, but two common ones are a male 25-pin or 9-pin D-connector. (The outer shell of a D-connector is roughly in the shape of a D.) For the 8052-BASIC system, you’ll need a mating female 25-pin or 9-pin D-connector. The connection has just three wires. A solder-cup-type connector allows easy soldering of the wires.
Figure 3-5 shows the wiring for 9- and 25-pin connectors. A few computers require additional handshaking signals. BASIC-52 doesn’t support these, but you can simulate them by connecting together pins 5, 6, 8, and 20 at the personal-computer end of the link. (Pin numbers are for a 25-pin connector.)
Powering Up
The first time you power up an untested circuit, it pays to be cautious. I recommend the following steps:
First Steps
Visually inspect the circuit. You don’t have to spend a lot of time on this, but sometimes a missing or miswired wire or component or another problem will become obvious.
Install U1-U7 on the board, making sure that pin 1 on each is oriented correctly. Set J1 to BASIC, and set J2 and J3 to match the size of your RAM at U7.
With an ohmmeter, measure the resistance from +5V to ground, to be sure these aren’t shorted together by mistake. The exact value you measure isn’t critical, but if you read less than 100 ohms, something is miswired and you need to find and fix the problem before you continue.
If you suspect a problem, check the wiring of the power and ground connections, comparing the connections to those on the schematic. Be sure all components are oriented correctly. When all checks out, you’re ready to boot up BASIC-52.
Booting BASIC-52
For the initial check, begin with everything powered down. I’ll use the term host computer, or host system, to refer to the personal computer, and target computer, or target system, to refer to the 8052-BASIC circuits. Included are some specific tips for users of Datastorm’s
The Microcontroller Idea Book |
35 |
Chapter 3
Figure 3-6. BASIC-52’s sign-on message and a simple program, using the Windows Terminal accessory for communications.
Procomm Plus for DOS and Microsoft Windows 3.1’s Terminal Accessory, but other communications software should have similar features and abilities.
Turn on the host computer and run your communications software. Configure the software for 8 data bits, no parity, and 1 stop bit. The baud rate you select isn’t critical, since BASIC-52 automatically adjusts to what you are using. To start, use a rate of 9600 or less. Don’t enable any handshaking or flow-control options such as XON/XOFF or RTS/CTS.
Select the appropriate serial, or COM, port, if necessary. If you’re using an MS-DOS (IBM-compatible) computer, you must find a COM port and interrupt-request (IRQ) level that aren’t being used by your modem, mouse, or another device. Because COM1 and COM3 often share an IRQ level, as do COM2 and COM4, you generally can’t use COM1 and COM3 at the same time, or COM2 and COM4. If you have an external modem, you can unplug it and use its serial port.
In Procomm Plus, use the line/port setup menu (ALT+P) to configure. In the Windows Terminal, use the Settings menu. Cable together the serial ports of the host and target systems.
36 |
The Microcontroller Idea Book |