You are on page 1of 14

Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 7(a)


Objectives:
 To examine and use an 8051 assembler.
 To examine and use an 8051 simulator.
 To examine the flag bits of the PSW.
 To examine the stack.

Reference:
 Mazidi and McKinlay, “The 8051 Microcontroller and Embedded Systems,” Chapter 2.

Materials:
 8051 assembler and simulator from Franklin Software Inc., Keil Corporation, or the assembler
of your choice.

Web Sites:
www.keil.com for Keil Corporation

Activity 1
Write and assemble a program to move value 99H to register A. Then from register A move it to
all registers R0 - R7. Use the simulator to single-step the program and examine the registers.

Activity 2
Write and assemble a program to add all the single digits of your ID number and save the result in
R2. Pick 7 random numbers (all single digit) if you do not want to use your ID number. Then use
the simulator to single-step the program and examine the registers.

Activity 3
Write and assemble a program that sequentially and repeatedly turn on/off the 8 LEDs from the
leftmost LED to the rightmost LED.

Activity 4

Write and assemble a program to add the following data and then use the simulator to examine
the CY flag. 92H, 23H, 66H, 87H, F5H

Activity 5
Write and assemble a program to load values into each of registers R0 - R4 and then push each of
these registers onto the stack. Single-step the program, and examine the stack and the SP register
after the execution of each instruction.

Telecommunication Engineering Department 1


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Activity 6
Write and assemble a program to:
(a) Set SP = 0D,
(b) Put a different value in each of RAM locations 0D, 0C, 0B, 0A, 09, and 08,
(c) POP each stack location into registers R0 - R4.

Use the simulator to single-step and examine the registers, the stack, and the stack pointer.

Telecommunication Engineering Department 2


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 7(a)


Worksheet
1. Indicate the size (8- or 16-bit) of each of the following registers.

PC = A= B=

R0= R1= R2= R7=

2. For Question 1, indicate the largest value (in decimal) that each register can contain.

PC = A= B=

R0= R1= R2= R7=

3. For Question 1, indicate the largest value (in hex) that each register can contain.

PC = A= B=

R0= R1= R2= R7=

4. Who generates each of the following files and what is the use of each.

.asm

.lst

.obj

.abs

.hex

Telecommunication Engineering Department 3


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

5. Find the value of the CY flag after the execution of the following code.

(a) MOV A,#85H


ADD A,#92H

(b) MOV A,#15H


ADD A,#72H

(c) MOV A,#0F5H


ADD A,#52H

(d) MOV A,#0FF


INC A

6. Upon reset, what is the value in the SP register?

7. Upon pushing data onto the stack, the SP register is _____________ (decremented,
incremented).

8. Upon popping data from the stack, the SP register is ___________ (decremented, incremented).

9. Can you change the value of the SP register? If yes, explain why you would want to do that.

10. The stack uses the same area of RAM as bank ______.

Telecommunication Engineering Department 4


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 7 (b)


Objectives:
 Introduction to MTS-51 Microcontroller Trainer.
 This experiment demonstrates that I/O port 2 controls LED pack D5 on the MTS-51 Trainer.
When P2 bit is 1, the corresponding LED is turned ON. When P2 bit is 0, the corresponding LED
is turned OFF. Place the SW2-4 in ON position.

Materials:
 8051 assembler and simulator.
 MTS-51 Trainer

Activity 1

Sequentially and repeatedly turn on/off the 8 LEDs from the leftmost LED to the rightmost LED.
The on time of each LED is 0.1 seconds.

Activity 2

Sequentially and repeatedly turn on/off the 8 LEDs from the leftmost LED to the rightmost LED.
When the rightmost LED is reached, the sequence is inverted. The on time of each LED is 0.1
seconds.

Activity 3
Sequentially turn on/off two LEDs from the two ends towards the middle. When the middle
reached, the sequence is inverted. The ON time of each LED is 1 second.

Activity 4
Turn on LEDs according to the following cases and repeat each case 8 times.
Case 1: Turn on LEDs from left to right.
Case 2: Turn on LEDs from right to left.
Case 3: Blink two sets (left and right sides) of LEDs alternately.
Case 4: Blink all of 8 LEDs.

Telecommunication Engineering Department 5


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 8 (a)


Objectives:
 This experiment uses the two-digit 7-segment display (DS3-DS4) of MTS-51 Trainer to show
decimal numbers.

Materials:
 8051 assembler and simulator.
 MTS-51 Trainer

Activity 1 (Two-Digit Up Counter)


Sequentially and repeatedly show the numbers 00 through 99 on DS3 and DS4. Each number
stays on 0.5 seconds.

Activity 2 (Two-Digit Down Counter)


Sequentially and repeatedly show the numbers 99 through 00 on DS3 and DS4. Each number
stays on 0.5 seconds.

Activity 3
Sequentially show the numbers from 00 to 99 and then from 99 to 00 on DS3 and DS4, and repeat
the sequence. Each number stays on 0.7 seconds.

Activity 4
Sequentially show the numbers from 00 to 99 on DS3 (ten digit) and DS4 (Units digit) using table
look up. Each number stays on 0.3 seconds.

Telecommunication Engineering Department 6


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 8 (b)


Objectives:

 To demonstrate the on-board Speaker control with the microcontroller on the MTS-51 Trainer.

Materials:
 8051 assembler and simulator.
 MTS-51 Trainer

Hardware Description:
 The signal to the speaker driver input comes from P3.7 pin. When a HIGH is fed to it the speaker
turns ON. When a LOW is fed the speaker is turned OFF.

Activity 1 (Speaker control)


Generate a 1-KHz tone for the Speaker interface on the MTS-51 trainer.

Activity 2
Speaker sounds a 1 KHz tone for 0.5 seconds and then keeps silence 0.5 seconds.

Telecommunication Engineering Department 7


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 9

OBJECTIVES:

 This experiment demonstrates the interfacing and control of 8x8 dot matrix LED (D3). And
uses it to display static and dynamic alphabets and decimal number.

HARDWARE DESCRIPTION:

 The D3 is a common cathode matrix LED. The row scan signal is emitted from P2 and the
column scan signal is emitted from P0. Both row and column scan signal are active-high signals,
that is, all LEDs are turned on when the row and column signals are all 1s. The 2803 Darlington
pairs are used to sink column currents.

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY 1 (Basic Matrix LED Control)


Sequentially turn on the column LEDs from column 1 to column 8 eight times, and then turn on
the row LEDs from row 1 to row 8 eight times.

ACTIVITY 2 (Static Character Display-1)


Show a 5x7 letter “A” on dot matrix LED.

ACTIVITY 3 (Static Character Display-1)


Sequentially show 5x7-dot characters A through Z and numbers 0 through 9.

ACTIVITY 4 (Dynamic Character Display)


Sequentially show 5x7-dot characters A through Z and numbers 0 through 9, and move it from the
left to right.

Telecommunication Engineering Department 8


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 10
OBJECTIVES:

 To learn Step Motor interfacing and to control the on-board 4-phase step motor M1 on
MTS-51 Trainer.

HARDWARE DESCRIPTION:
 The motor coils A, B, A’, B’ are energized by the signals on P2.3, P2.2, P2.1, P2.0,
respectively. Place switch SW2_8 in ON position. There are three switching schemes: 1-
phase-on, 2-phase-on and 1-2-phase-on switching.

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY 1 (Direction Control)


Drive the Step-motor to rotate in Clock-Wise (CW) direction using 2-phase-on switching.

ACTIVITY 2 (Revolution Control)


Drive the Step-motor to rotate one revolution CW and then rotate one revolution CCW,
continuously.

ACTIVITY 3 (Speed Control)


Drive the Step-motor to rotate one revolution CCW and then rotate two revolutions CW but with
double the CW revolution speed, continuously.

Telecommunication Engineering Department 9


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 11

OBJECTIVES:
 This experiment demonstrates the matrix keyboard control.
 Using the matrix keyboard control to the 4-phase step motor M1 on MTS-51 Trainer.

Hardware Description:
 The matrix keyboard KB1 and ecoder 74C922 builds the keyboard circuit. If a key is pressed ,
the corresponding binary value will present on the outputs DOD-DOA (P1.3 – P1.0) of the
encoder, as well as Data Available (DA) signal on the DA output. The DA signal is inverted by
an inverter and then connected to P3.2 (INT0) pin.

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY 1 (Keyboard Controls 7-Segment)


1. Show the key number on the 7-segment display DS4 when a key is pressed.
2. Place SW2-3 in ON position.

ACTIVITY 2 (Keyboard Controls LED)


Using the following keys on matrix keyboard, control the state of LEDs:
a) Key “0” pressed, all the 8 LEDs light up simultaneously.
b) Key “1” pressed, all the 8 LEDs blink.
c) Key “2” pressed, two sets (left and right sides) of LEDs blink alternately.

ACTIVITY 3 (Step Motor Direction Control)


1. Key “1” pressed, the step motor rotates one step CW.
2. Key “2” pressed, the step motor rotates two step CCW.

ACTIVITY 4 (Step Motor Revolution Control)


The step motor rotates CW the same number of revolutions as the key pressed (0-9)

Telecommunication Engineering Department 10


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 12
OBJECTIVES:

 This experiment demonstrates the application of LCD module (LCM). LCMs are widely
used to display alphanumeric characters. The LCM on MTS-51 Trainer is a 20 characters x
2 lines back-light LCM.

Hardware Description:
 SW2-5 should be placed in ON position. P0 lines are connected to the data bus DB0-DB7
of LCM. P1.5, P1.6, and P1.7 are connected to RS, R/W, and E pins, respectively.

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY 1 (LCM Character Display-1)


Show the character string “Hello ! Welcome” in the middle of the first line of LCM.

ACTIVITY 2 (LCM Character Display-2)


Show the character string “Sir Syed University” in the middle of the first line of LCM and blink it
every 0.5 second interval.

ACTIVITY 3 (LCM Character Display-3)


Show the character string “Hello ! Welcome” on the right side of the first line of LCM and slowly
move to the middle position, and blink it.

ACTIVITY 4 (LCM Character Display-4)


Show the key value on the LCM screen and blink the cursor.

ACTIVITY 5 (LCM Character Display-5)


Design a 4-digit counter which automatically increments its value every second, and shows the
result in the middle of the first line of LCM screen.

ACTIVITY 6 (6-Digit Electronic Stopwatch)


Design a stopwatch in the middle of LCM screen in 00:00:00 (minutes:seconds:1/60 seconds)
format. The stopwatch has a resolution of 0.01 seconds. When the key “1” is pressed, the watch
starts or resumes counting. When the key “2” is pressed, pause counting. When the key “2” is
pressed, the watch is reset.
Telecommunication Engineering Department 11
Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 13
OBJECTIVES:

 To learn on-chip Timer/ counter control and their operation in Modes 0 and 1.
 Demonstrate the operation of basic pulse counter

Hardware Description:
 Mode 0: 13-bit timer
 Mode 1: 16-bit timer/ counter
 SW2-4 should be placed in ON position.

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY 1 (Timer/counter Mode-0)


Program timer/counter 0 operating in mode 0 and blink LEDs (D5) alternately. The ON/OFF time
is 1 second.

ACTIVITY 2 (Timer/counter Mode-1)


Program timer/counter 0 operating in mode 1 and sequentially turn on/off LEDs from leftmost to
the rightmost. The ON/OFF time is 0.5 seconds each.

ACTIVITY 3

Count the number of pulses from the 555 oscillator output and show the result on 7-segment
displays.

Telecommunication Engineering Department 12


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 14
OBJECTIVES:
 This experiment demonstrates the control application of photo interrupter.

Hardware Description:
 The MTS-51 has two photo-interrupts PH1 and PH2. When light is blocked, the
phototransistor is cut off and low presents on the inverter output terminal. When light is
not blocked the phototransistor conducts in saturation and a high presents on the inverter
output terminal

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY
Use PH2 output to control the direction of rotation of the step motor. When PH2 is not blocked by
an object (for example, a piece of paper), the step motor rotates CW. If PH2 is blocked by an
object, the step motor rotated CCW.

Telecommunication Engineering Department 13


Sir Syed University of Engineering & Technology
Microprocessor and Interfacing Techniques SSUET/QR/114

Laboratory Exercise 15
OBJECTIVES:

 This experiment demonstrates the Serial Communication using on-chip serial port Mode 1.
 This experiment demonstrates the Output port expansion using serial port Mode 0.

Hardware Description:
 The serial port in mode 0 acts a shift register which sends 8 data bits through RXD and the
TXD on transmit. SIPO is followed.
 If two MTS-51 trainers are used, the JP2s on MTS-trainers should be interconnected such
that TXD of one is connected to the RXD of other, with a common Ground for both.

MATERIALS:
 8051 assembler and simulator.
 MTS-51 Trainer

ACTIVITY 1 (UART in Mode-1)


When a key is pressed on one MTS-51 trainer, the key is displayed on the 7-segment of the other
MTS-51 trainer

ACTIVITY 2
Program for the following sequence:
1. Sequentially turn on/off LEDs from left to right, 4 times
2. Sequentially turn on/off LEDs from right to left, 4 times
3. Sequentially turn on/off LEDs from left to right, and then invert the sequence 2 times.
4. Blink two sets of LEDs (right and left sides) alternately, 4 times
5. Turn on/off two LEDs ends to the middle and then from middle to ends, 4 times
[Place SW2_2 in ON position to enable LED pack 04]

Telecommunication Engineering Department 14


Sir Syed University of Engineering & Technology

You might also like