8051 Hardware Tutorials
8051 Hardware Tutorials
8051 Hardware Tutorials
OBJECTIVE:
¾ To test the 8051 system and its ports.
REFERENCE:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 4,
Appendix B, and Appendix C.2.
MATERIALS:
¾ 8051 trainer
¾ Logic probe
¾ DIP switches with pull-up resistors
¾ 8051 Assembler
You can either buy a pre-built 8051 trainer or wire-wrap your own trainer. Details on
wire-wrapping an 8051 trainer are given in Appendix B of the textbook. We will use such
a trainer in all subsequent labs.
ACTIVITY 1
Test the operation of the ports of your 8051 trainer as follows. Assemble and run
the test program given in Appendix B. The test program toggles the ports of the 8051.
Use a logic probe or the LEDs of your digital trainer to watch the bits of the ports toggle
on and off. Make sure that the time delay in between the "on" and "off" states is long
enough that you can observe each state clearly.
ACTIVITY 2
Test the 8051's ports for input operation as follows. Connect each bit of P1 (P1.0 -
P1.7) of the 8051 to DIP switches of your digital trainer. Make sure that the switches
have either pull-up resistors or are buffered as shown in Appendix C.2. Read Appendix
C.2 very carefully to make sure that you do not damage the port. Then write and run a
program to get data from P1 and send it to P2. Any change of status of the switches
connected to P1 will be instantly reflected on LEDs connected to P2. The testing program
could look like this.
1
Name: Date: Class:
1. Upon reset, all ports of the 8051 are configured as _____________ (output, input).
3. Which ports of the 8051 require the connection of external pull-up resistors in order to
be used for I/O? Show the drawing for the connection.
4. In the 8051, explain why we must write "1" to a port in order for it to be used for input.
5. Explain why we need to buffer the switches used as input in order to avoid damaging
the 8051 port.
2
Tutorial 2
OBJECTIVES:
¾ To understand the operation modes of an LCD.
¾ To interface and program an LCD.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 12.
¾ Dot Matrix LCD Module: Character-type DMC Series User's Manual by Optrex
Corp.
MATERIALS:
¾ 8051 Assembler
¾ 8051 Trainer
¾ 20x2 LCD DMC20261 from Optrex DMC series, or a compatible one.
ACTIVITY 1
Connect the LCD to your 8051 trainer as shown in Section 12.1 of the textbook.
Then write and run a program to display your name on line 1 of the LCD (first name
followed by last name with a space in between).
Note: If you are not monitoring the busy flag of the LCD, put a few milliseconds delay in
your program. See the discussion in Chapter 12.
ACTIVITY 2
Repeat Activity 1 while also putting the year you graduated from high school on
the second line. When you run your program, the LCD should show (for example):
Alex Young
Graduated in 1978
ACTIVITY 3
Write an LCD program to display your last name on the first line and the current
year on the second line. Both should be in the middle of the line.
3
Name: Date: Class:
1. How does the LCD distinguish data from instruction codes when receiving information
at its data pin?
2. To send the instruction code 01 to clear the display, we must make RS = ___.
4. What is the purpose of the E line? Is it an input or an output as far as the LCD is
concerned?
5. When is the information (code or data) on the LCD pin latched into the LCD?
4
Tutorial 3
OBJECTIVE:
¾ To interface an ADC to the 8051.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 12.
¾ Look for the ADC804 data sheet in The National Semiconductor Corp. web site:
www.national.com/catalog/AnalogDataAcquisition.html
MATERIALS:
¾ 8051 trainer
¾ 8051 assembler
¾ ADC804
¾ R=10 K ohms, C=150 pF
You can test the ADC804 before you connect it to the 8051. On the breadboard, set up
the circuit shown in Figure 12-5 of the textbook. This setup is called free running test
mode and is recommended by the manufacturer. In that figure, we use a potentiometer to
apply a 0-to-5 V analog voltage to the input Vin (+) of the ADC804 and the binary
outputs are monitored on the LEDs of the digital trainer. It must be noted that in free
running test mode the CS input is grounded and the WR input is connected to the INTR
output. However, according to National Semiconductor's databook "the WR and INTR
node should be momentarily forced to low following a power-up cycle to guarantee
operation."
Set the potentiometer at different points and see the digital binary output of the ADC
indicated on the LEDs. In each case, use the voltmeter to measure the POT voltage and
verify the result.
ACTIVITY
Connect the ADC804 to the 8051 as shown in Figure 12-7 or 12-8 in the textbook.
Then assemble and run a program to display the data on the LCD or send it to a PC
screen through the serial port of the 8051. Notice that the ADC output is between 0 to
FFH, where FFH is for a full-scale input. However, this must be converted to decimal and
then to ASCII in order to be displayed on the LCD. As you change the potentiometers,
the output should change, indicating the value of the analog input.
For the clock source of the ADC804 you have two more options beside the RC
circuit:
(1) use an external clock source (square wave TTL), or (2) use the XTAL frequency from
the 8051 trainer as shown in Chapter 12 for the ADC804. If you use the XTAL
frequency from the 8051, make sure that you use at least three or four D flip-flops to
bring down the frequency.
The next lab will build upon the connections you have made in this lab.
5
1. Indicate the direction of pins WR, RD, and INTR from the point of view of the 8051.
2. Give the three steps for converting data and getting the data out of the ADC804. State
the status of the CS, RD, INTR, and WR pins in each step.
6
Tutorial 4
OBJECTIVE:
¾ To interface an LM35 (or LM34) temperature sensor to the 8051 trainer.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 12.
¾ For the sensor's data sheet, see National Semiconductor’s web site:
www.national.com
MATERIALS:
¾ 8051 trainer
¾ 8051 assembler
¾ LM35 (or LM34)
¾ ADC804
¾ LM336-2.5
¾ 10K POT
¾ 1K, 1.5K, and 10K resistors
You need to complete Lab 3 to experiment with the temperature sensors before
performing this lab.
ACTIVITY
In place of a potentiometer, use the LM34 sensor and set up the circuit shown in
Figure 12-10 of the textbook. Then write a program to display the temperature on the
LCD (or PC monitor) continuously. Heat up or cool down the sensor and observe the
temperature.
7
Name: Date: Class:
1. What is a transducer?
4. The LM35 and LM34 produce a _______ mV output for every degree of change in
temperature.
8
Tutorial 5
OBJECTIVES:
¾ To program the 8051 timer.
¾ To generate a square wave using the 8051 timer.
REFERENCE:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 9.
MATERIALS:
¾ 8051 trainer
¾ 8051 assembler
¾ Oscilloscope
ACTIVITY 1
Write a program using timer 0 to generate a 500 Hz square wave frequency on
one of the pins of P1. Then examine the frequency using the oscilloscope. Modify the
count value to make sure that the frequency is exactly 500 Hz.
ACTIVITY 2
Write a program using timer 1 to generate a 1 kHz square wave frequency on one
of the pins of P1. Then examine the frequency using the oscilloscope. Modify the count
value to make sure that the frequency is exactly 1 kHz.
9
Name: Date: Class:
1. What is the maximum frequency that can be generated using Mode 1 if the crystal
frequency is 11.0592 MHz? Show your calculation.
2. What is the maximum frequency that can be generated using Mode 2 if the crystal
frequency is 11.0592 MHz? Show your calculation.
3. What is the lowest frequency that can be generated using Mode 1 if the crystal
frequency is 11.0592 MHz? Show your calculation.
4. What is the lowest frequency that can be generated using Mode 1 if the crystal
frequency is 11.0592 MHz? Show your calculation.
10
Tutorial 6
OBJECTIVES:
¾ To interface the MAX233 (or MAX232) to the 8051.
¾ To write a program to transfer data to a PC serially.
¾ To write a program to receive data from a PC serially.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 10.
¾ www.maxim-ic.com
MATERIALS:
¾ 8051 trainer
¾ 8051 assembler
¾ MAX233 (or MAX232)
¾ DB-9 RS232 connector with serial cable
¾ IBM PC/compatible computer with COM2 port
ACTIVITY 1
After connecting (wire wrapping) the MAX233 to the 8051 as shown in Figure
10-8 in the textbook, connect your 8051 system to the PC's COM 2 port. Then write a
program to transfer your last name to the PC continuously. On the PC side you need to
use the Hyperterminal program (or Terminal in Windows 3.x) which comes with MS
Windows 95 and 98. Here are the steps to set up Hyperterminal:
1. In Windows Accessory, click on Hyperterminal (if you get a modem installation
option, choose "NO").
2. Type a dummy name, and click OK.
3. For "Connect Using" select COM2 and click OK. We use COM2 since COM1 is
normally used by the mouse.
4. Pick 9600 (or whatever baud rate you programmed the 8051), 8 bit data, no parity bit,
and 1 stop bit.
5. Change the "Flow Control" to NONE or Xon/Xoff and click OK (definitely do not
choose the hardware option).
After running your 8051 serial program, you should see your last name fill the PC screen.
ACTIVITY 2
After making sure that Activity 1 works properly, write a program to get data
from the PC and display it on an LCD. If you do not have an LCD connected to the
8051, connect P1 to LEDs of your digital trainer and observe the incoming characters (or
use a logic probe). As you press a key on the PC's keyboard, the character is sent to the
8051 serially and is displayed on LEDs. The characters displayed on LEDs are in ASCII
(binary).
ACTIVITY 3
Modify and run the program in Activity 1 to transfer the data at the rate of 56K.
11
Name: Date: Class:
1. The 8051 TxD and RxD signals ________ (are, are not) TTL-compatible.
3. With XTAL=11.0592 MHz, what is the maximum baud rate for the 8051?
7. For full duplex, what are the absolute minimum signals needed between the 8051 and
the PC? Give their names.
12
Tutorial 7
OBJECTIVE:
¾ To interface an ADC809 to the 8051.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 12.
¾ www.national.com/catalog/AnalogDataAquisition.html
MATERIALS:
¾ 8051 assembler and trainer
¾ ADC808/809
¾ TTL square wave and TTL square wave clock source
ACTIVITY 1
In many applications we need to have multiple analog-to-digital converters. The
ADC808/809 is a single chip that can accommodate up to 8 analog inputs. These 8 inputs
are called channels and each is selected by an address. Read about this chip in Chapter 12
and also download the data sheets from the www.national.com web site.
Connect the ADC808/809 to the 8051 and write a program to display data input
from at least two of the channels. Each channel can be connected to separate
potentiometers to examine the data displayed.
Notice that the ADC output is between 0 to FFH where FFH is for a full-scale
input. However, this must be converted to decimal and then to ASCII in order to be
displayed on the LCD. As you change the potentiometers, the output should change,
indicating the value of the analog input.
For the clock source of the ADC808/809, you can either use an external clock
source (square wave TTL), which is preferable, or use the XTAL frequency from the
8051 XTAL as shown in Chapter 12 for the ADC804. Make sure that you use at least
three or four D flip-flops to bring down the frequency.
Notice the following points when interfacing the 8051 to the ADC808/809.
1. The ADC808/809 clock frequency is between 10 kHz and 1250 kHz and must be a
minimum of 3V peak.
2. The minimum pulse width for ALE = 200 µsec and OE = 250 µsec.
3. Read data from the ADC808/809 and follow these steps.
(a) Select the channel.
(b) Activate START (200 µsec).
(c) Poll EOC for high.
(d) Send low to OE (for a minimum of 250 µsec).
(e) Read the data from the data pin.
13
Name: Date: Class:
1. Indicate the direction of pins ALE, SC, EOC, and OE from the point of view of the
ADC808/809.
2. Give the steps for converting data and getting the data out of the ADC809. State the
status
of the SC and EOC pins in each step.
3. Give the role of signals ALE, A, B, and C in selecting the ADC channel.
4. In the ADC809 assume that Vref is connected to 2.56 V. Find the following.
(a) step size
(b) maximum range for Vin
(c) D7 - D0 values if Vin = 1.2 V
(d) Vin if D7 - D0 = 11111111
(e) Vin if D7 - D0 = 10011100
5. In the ADC809 assume that Vref is connected to 5V. Find the following.
(a) step size
(b) maximum range for Vin
(c) D7 - D0 values if Vin = 2.7 V
(d) Vin if D7 - D0 = 11111111
(e) Vin if D7 – D0 = 11011101
6. In connecting ADC808/809 to an 8051, indicate the direction of pins ALE, SC, EOC,
and OE from the point of view of the 8051.
14
Tutorial 8
OBJECTIVES:
¾ To interface a DAC to the 8051.
¾ To generate a sine wave on the scope using the DAC.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 13.
¾ www.national.com/catalog/AnalogDataAcquisition.html
MATERIALS:
¾ 8051 assembler and trainer
¾ DAC0808 from National Semiconductor (or its equivalent MC1408 from Motorola)
¾ 100 pF capacitor
¾ Resistors: 2 of 1K, 2 of 1.5K
¾ 5 K potentiometer
ACTIVITY
First generate (calculate) a table similar to Table 13-5 of the textbook for sine values of
4-degree increments. Then set up a circuit like the one shown in Figure 13-7. Write and
run a program to create the sine wave on the oscilloscope. Put a delay in between each
outputting of values to DAC and observe the sine wave on the scope. Change the delay
values and state your conclusions. Also in your circuit, change the POT value and
monitor the output sine wave on the scope.
15
Name: Date: Class:
(a) resolution
(a) 11001100
(b) 10001111
3. To get a smaller step size, we need DAC with ________ (more, less) data bit inputs.
4. In Figure 13-7 of the textbook, assume that R = 2.5 K ohms. Calculate Vout for the
following binary inputs.
(a) 11000010
(b) 01000001
(c) 00101100
(d) 11111111
16
Tutorial 9
OBJECTIVES:
¾ To program the timer interrupt of the 8051.
¾ To program the serial interrupt of the 8051.
¾ To program the hardware interrupt of the 8051.
REFERENCE:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 11.
MATERIALS:
¾ 8051 trainer
¾ 8051 assembler
¾ Square wave generator
ACTIVITY 1
Write an 8051 program to get data from one port and send it to another port
continuously while an interrupt will do the following: One of the timers will toggle the
PX.Y bit every 100 microseconds.
ACTIVITY 2
Write an 8051 program to get data from a single bit of P1.2 and send it to P1.7
continuously while an interrupt will do the following: A serial interrupt service routine
will receive data from a PC and display it on one of the ports. (Either connect LEDs to
this port to examine the data coming in or display the received data on an LCD).
ACTIVITY 3
Write an 8051 program to get data from one port and send it to another port
continuously while an interrupt can do the following: Connect the INT0 (or INT1) pin to
a normally high debounce SW and any time the switch is pressed, a single LED is turned
on.
ACTIVITY 4
Write an 8051 program to get data from one port and send it to another port continuously
while an interrupt will do the following: A square wave is connected to the INT0 (pin
3.2) and any time a H-to-L pulse comes in a single LED is turned on. The rate of "On"
and "Off" is the rate of the square wave. In this activity you can also use INT1
17
Name: Date: Class:
1. Name all of the interrupts in the 8051 and their vector table addresses.
6. True or False. There is only a single interrupt for the serial data transfer.
18
Tutorial 10
OBJECTIVES:
¾ To interface a Centronics printer to the 8051.
¾ To gain an understanding of printer handshaking signals.
REFERENCE:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 15,
plus Figure C-20.
MATERIALS:
¾ 8051 assembler and trainer
¾ Centronics printer
¾ 74LS244
ACTIVITY 1
Examine the Centronics cable pins and their description in Chapter 15 of the
textbook. Connect the data bus and handshaking signals of the printer to your 8051 as
shown in Figure C-20. Make sure you have buffered the signals with 74LS244 chips.
Write and run a program to print the message, "OK IT WORKS !"
ACTIVITY 2
Make the following modifications in the program of Activity 1. In the code
section put the following data:
Use the ASCII code OA (hex) for line feed and OD (hex) for carriage return to make sure
that each line is printed on a separate line, as shown below:
ORG 200
MYDATA: DB "Smart Alex",OAH,0DH
19
Name: Date: Class:
1. Indicate the direction of the following signals from the printer's point of view.
Signal Direction
D0-D7
STROBE
ACK
2. Indicate the direction of the following signals from the 8051's point of view.
Signal Direction
D0-D7
STROBE
ACK
3. For each of the following signals, indicate its normal status (high or low) and the
activation level for each (active low or active high).
Printer's Handshake Signal Normal State Active State
Strobe
ACK
4. Explain the role of the strobe and busy signals in the handshaking between the 8051
and the printer.
5. To make the printer latch in data at its data pins, the strobe pins needs a
______________ (H-to-L, L-to-H) signal.
6. In monitoring the busy signal, the 8051 looks for _______ (high, low) before issuing
the next byte of data to the printer.
20
Tutorial 11
OBJECTIVE:
¾ To interface an 8031 to external ROM.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 14
and Appendix B.
MATERIALS:
¾ 8031 microcontroller
¾ 27XX UV_EPROM (or 28XX EEPROM)
¾ 74LS373
¾ Wire wrapping tools
Study Chapter 14 and examine the 8031 connection to external memory. In the following
activities you can also use any of the 8051 chips.
ACTIVITY 1
First, study the basics of wire wrapping in Appendix B.1 if you have never done
any wire wrapping. Then wire wrap the 8031 connection to a ROM chip according to
Figure 14-11. The size of the ROM chip (UV-EPROM or EEPROM) should be 8K or
higher. Since this ROM chip is for code, make sure that the crystal and reset circuits are
also included in your design. See Chapter 4 for the crystal and reset connection.
ACTIVITY 2
After the wire wrapping is done in Activity 1, test the system by running a test
program burned into the ROM. The test program simply toggles P1 continuously with a
delay in between the "on" and "off" states. Notice that in connecting the 8031(8051) to
external memory we cannot use P2 for I/O ports. That is important since some people try
to use the unused portion of P2 for I/O.
ORG 0
MOV A,#55H
BACK: MOV P1,A
ACALL DELAY
CPL A
SJMP BACK
21
Name: Date: Class:
1. Give the following information for the ROM used in this experiment.
Capacity: Organization:
2. In the 8031/51, how do we make sure that program code is fetched from external
ROM?
3. What is the role of the PSEN pin in the 8031/51 connection to external ROM?
4. In connecting the 8031/51 to external ROM, explain the difference between the RD
and PSEN signals and where each one is used.
5. In connecting the 8031/51 to external ROM, explain the role of the following:
P0
P2
74LS373
6. What is the maximum external memory that can be connected to the 8031?
For code space:
7. In connecting the 8031 to an external memory, only P2.0 - P2.5 are used. What is the
size of this external memory?
22
Tutorial 12
OBJECTIVE:
¾ To interface an 8031 to the 8255.
REFERENCES:
¾ Mazidi and Mazidi, “The 8051 Microcontroller and Embedded Systems,” Chapter 15,
Appendix B.1.
MATERIALS:
¾ 8031(or 8051) microcontroller
¾ 8255
¾ 74LS373
¾ Wire wrapping tools
Study Chapter 15 and examine the 8031/51 connection to the 8255 chip. In the following
activities you can also use any of the 8051 chips.
ACTIVITY 1
If you have not done any wire wrapping before, study Appendix B.1. Wire wrap
the 8031 connection to an 8255 chip according to Figure 15-4 of the textbook. If you do
not want to use an inverter, connect the CS (chip select) pin to ground.
ACTIVITY 2
After wire wrapping the circuit in Activity 1, test the 8255. The test program
simply toggles ports A, B, and C of the 8255 continuously with a delay in between the
"on" and "off" states. The toggle program is given in Chapter 15.
23
Name: Date: Class:
1. Give the addresses assigned to each of the following ports in this experiment.
PA PB PC CR Port
2. Why do we use the "MOVX" instruction to access the 8255 in this experiment?
3. Write a program to get data from PA and send it to both PB and PC.
4. In connecting the 8031/51 to the 8255, explain the role of the RD and WR signals.
5. In connecting the 8031/51 to the 8255, explain the role of the following and indicate if
its
use is optional.
P0
P2
74LS373
6. Explain the term "memory mapped I/O." Is the 8255 connection in this experiment a
memory mapped I/O?
24