Sei sulla pagina 1di 24

Tutorial 1

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.

 

MOV A,#0FF

;A=FFH

MOV

P1,A

;make P1 an input port

HERE:

MOV

A,P1

;get data from P1

MOV

P2,A

;send it to P2

SJMP HERE

;keep doing this

Name:

Date:

1. Upon reset, all ports of the 8051 are configured as

Class:

(output, input).

2. Which ports of the 8051 have internal pull-up resistors?

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.

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.

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 =

3. To send letter 'A' to be displayed on the LCD, 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?

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 V in (+) 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.

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.

3. Assume that V ref /2 is connected to 1.28 V. Find the following.

(a)

step size

(b)

maximum range for V in

(c)

D7 - D0 values if V in = 1.2 V

(d)

V in if D7 - D0 = 11111111

(e)

V in if D7 - D0 = 10011100

4. Assume that V ref /2 is connected to 1.9 V. Find the following.

(a) step size

(b)

(c)

(d)

(e)

maximum range for V in

D7 - D0 values if V in = 2.7 V

V in if D7 - D0 = 11111111

V in if D7 - D0 = 11011101

5. The ADC804 is a(n)

-bit converter.

6. To get step size of 2 mV, what is the value for Vref/2?

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.

Name:

1. What is a transducer?

Date:

Class:

2. What is the form of the transducer output?

3. What is preprocessing of transducer signals to be fed into an ADC called?

4. The LM35 and LM34 produce a

temperature.

5. The LM35/LM34 is a

mV output for every degree of change in

(linear, nonlinear) device. Discuss the

advantages of linear devices and of nonlinear devices.

6. Explain signal conditioning and its role in data acquisition.

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:

Oscilloscope

8051 trainer

8051 assembler

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.

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.

5. In mode 1, when is TFx set to high?

6. In mode 2, when is TFx set to high?

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.

Name:

1. The 8051 TxD and RxD signals

Date:

Class:

(are, are not) TTL-compatible.

2. In this lab, what is the role of the MAX233 (MAX232) chip?

3. With XTAL=11.0592 MHz, what is the maximum baud rate for the 8051?

4. Show how to achieve the maximum baud rate in Question 3.

5. What is the role of TI and RI?

6. True or false. The 8051 can transfer data in full-duplex.

7. For full duplex, what are the absolute minimum signals needed between the 8051 and

the PC? Give their names.

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.

Thank you to John Maddux for his input on this lab.

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 V ref is connected to 2.56 V. Find the following.

(a)

step size

(b)

maximum range for V in

(c)

D7 - D0 values if V in = 1.2 V

(d)

V in if D7 - D0 = 11111111

(e)

V in if D7 - D0 = 10011100

5. In the ADC809 assume that V ref is connected to 5V. Find the following.

(a)

step size

(b)

maximum range for V in

(c)

D7 - D0 values if Vin = 2.7 V

(d)

V in if D7 - D0 = 11111111

(e)

V in 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.

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.

Name:

Date:

Class:

1. Define the following terminology in DAC.

(a)

resolution

(b)

full-scale voltage output

(c)

settling time

2. For your circuit, find V out for the following inputs.

(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 V out for the following binary inputs.

(a)

11000010

(b)

01000001

(c)

00101100

(d)

11111111

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

Name:

Date:

Class:

1. Name all of the interrupts in the 8051 and their vector table addresses.

2. In timer mode 1, indicate when TF0 causes the interrupt.

3. In timer mode 2, indicate when TF0 causes the interrupt.

4. On reset, INT0 (and INT1) are

(edge, level) triggered.

5. On reset, which interrupt has the highest priority?

6. True or False. There is only a single interrupt for the serial data transfer.

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:

Last name, First name Date Course number

Each of the above must be printed on a separate line.

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:

MYDATA:

ORG 200

DB

"Smart Alex",OAH,0DH

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

Strobe

ACK

Normal State

Active State

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

the next byte of data to the printer.

(high, low) before issuing

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.

The following test program can be burned into the ROM.

ORG

0

 

MOV A,#55H

BACK:

MOV P1,A

ACALL DELAY

CPL

SJMP BACK

A

For the delay subroutine see Chapter 3.

Name:

Date:

Class:

1. Give the following information for the ROM used in this experiment.

Capacity:

Number of address pins:

Organization:

Number data pins:

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:

For data 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?

8. In Question 7, can we use P2.6 and P2.7 for I/O?

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.

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?