Professional Documents
Culture Documents
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.
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.
PC = A= B=
2. For Question 1, indicate the largest value (in decimal) that each register can contain.
PC = A= B=
3. For Question 1, indicate the largest value (in hex) that each register can contain.
PC = A= B=
4. Who generates each of the following files and what is the use of each.
.asm
.lst
.obj
.abs
.hex
5. Find the value of the CY flag after the execution of the following code.
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 ______.
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.
Materials:
8051 assembler and simulator.
MTS-51 Trainer
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.
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 2
Speaker sounds a 1 KHz tone for 0.5 seconds and then keeps silence 0.5 seconds.
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
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
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
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
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 3
Count the number of pulses from the 555 oscillator output and show the result on 7-segment
displays.
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.
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 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]