Laboratory - Manual For 8051
Laboratory - Manual For 8051
MANUAL
The 8051 microcontroller
Based
Embedded Systems
Manish K Patel
INDEX
SR.No Laboratory
Introduction to Keil vision 4.0 Integrated development environment
1
(IDE).
2 Data transfer instructions and addressing modes in 8051
11 Keyboard interfacing
Objectives:
It is complete tutorial based on vision 4.0 IDE. It explains how to use vision 4.0 to develop
and test 8051 programs in assembly as well as C language. To support and ease the
understanding, a step wise explanation along with screen shots of vision 4.0 IDE windows is
given for a sample programs.
Laboratory exercise:
Execute the sample program given in the tutorial as explained and answer the following
questions.
Objectives:
To understand the data transfer operations in the 8051
To be familiar with different addressing modes used in instructions
ORG 0000H
MOV R0, #20H
MOV R2, #30H
MOV A, #10H
MOV 50H, R2
MOV @ R0, A
MOV DPTR, #0100H
MOVX @DPTR, A
MOV 7FH, A
MOV A, #03H
MOVC A,@A+DPTR
PUSH A
ORG 100H
DB 25H, 30H
DB 50H, 55H
END
Laboratory exercise:
Objective
To understand arithmetic and logical operations of the 8051 and their limitations.
ORG 0000H
MOV R2, #50H
MOV R3, #0F0H
MOV 50H, # 30H
MOV A, @R2
ADD R3, A
ADDC A, 50H
MOV B, R3
MUL AB
ANL A, #0FH
XRL A, #0FFH
CPL A
CLR C
RL A
RLC A
RR A
END
Laboratory exercise:
Objectives:
Refer example 6.2 and 6.3, Write byte level and bit level instructions for specified operations.
Assemble the instructions and observe the list file and prove that use of bit processing
instructions reduces the memory requirements for the program and makes program execution
faster.
Laboratory exercise:
Objectives:
Execute one or more programs from examples 9.8 to 9.16 and answer the following questions.
Laboratory exercise:
1. Identify the instruction(s) which makes the decision and/or transfers the program
execution to a new address.
2. What do we require to implement the loops?
3. When do we need the infinite loops?
4. Show how loops can be implemented using CJNE and DJNZ instructions.
5. How to implement if-else, while, do-while and for structures of high level language using
assembly language instructions of 8051
Refer example 7.14, modify the program to generate the square wave of 1 KHz on P1.0 and
discuss the factors affecting delay generated by a program.
Refer example7.12, modify this example convert array of 10 binary numbers in to BCD
numbers. Execute the program and answer the following questions
1. What is the contents of SP register and stack before and after ACALL BIN2BCD and
RET instructions.
2. What would be the size of program without using subroutine?
3. Comment on speed of execution of program which uses subroutines.
LABORATORY 6:
Objectives
Implement the circuit shown in Figure 11.8 (89C51 based simplest system) on bread board or
PCB, switch on the power supply and observe the waveforms at pins XTAL 2 and ALE and find
the frequency of waveforms and justify that why you got those values.
1. Read the status of the key and send it to the LED (LED should glow when key is pressed,
otherwise off)
2. Blink the LED every 1second
3. Generate the square wave of 10KHz on P1.0 (use delay generation using software)
4. Generate the square wave of maximum possible frequency on P1.0
Laboratory exercise:
Load the programs (one by one) in to microcontroller on-chip code memory using the
programmer device and observe the output on board. Answer the following questions.
Objectives:
Refer Appendix B: Using Keil vision 4.0 IDE (Refer topic Developing and testing program
in C language in second half)
Laboratory exercise:
Execute the sample program given in the Appendix B as explained (and few other programs
from chapter 12) and answer the following questions.
Objective:
Timing applications
Execute programs of example 14.5, 14.7, 14.9 and 14.12 to understand operation of timer as
interval timer to generate square wave or rectangular wave.
Observe the corresponding output waveform of square wave on logic analyzer window in
simulator mode [See vision help for details of logic analyzer window and how to use it]
Load the above programs on the 8051 board you have and observe the output (on corresponding
pins) on CRO.
Execute programs of examples 14.21, 14.24 and 14.25 in vision IDE. Note that external pulse
can be applied in simulator by clicking twice on box of P3.4 for T0 (or P3.5 for T1) of port 3
peripheral window. See that contents of timer registers are incremented after pair of every click
on corresponding box.
Load the program 14.25 on the 8051 board, apply square wave of unknown frequency on T0 pin
and observe the result on port1 and port2.
Laboratory exercise:
Objectives
Refer example 15.8, 15.10 and 15.11, execute (single step) these programs and observe output
i.e. transmitted data bytes in serial window (View serial window UART#1) in Vision 4.0
IDE
Refer example 15.9 and 15.13 to simulate the reception of data byte use virtual registers i.e. to
simulate reception of data byte 45H, type command SIN= 0x0045 in command window when
program is waiting for reception of a byte.
Laboratory exercise:
Objectives
Timer interrupts
Simulation: Refer example16.2 and 16.4. Execute these programs in simulator and observe
the output in logic analyzer.
Testing on hardware: Load above programs in 8051 based board you have, and execute the
programs and observe the output (square waves) on CRO.
External interrupts
Simulation: Refer program 16.10 and execute it in simulator. External interrupts can be
) and P3.3 (INT1
simulated by clicking on box of P3.2 (for INT0 ) in peripheral window of
port 3.
Testing on hardware: Make connections on 8051 board you have (or on bread board,
include power on reset, crystal connections and EA ) as shown in figure 16.5. Load the
program in on-chip code memory and execute the program.
Serial interrupts
Simulation: Refer examples 16.12, 16.14, 16.15 and execute the them in simulator. Refer
laboratory 9 (Serial communications) to know how to simulate serial data reception and
transmission.
Testing on hardware:
Connect the serial port of 8051 based board with COM port of PC. Execute the programs and
observe the data transmitted by 8051 in Hyper terminal (or Xtalk or equivalent application or
C program) window in PC.
Implement the figure 16.11 (of Project: Full duplex system at the end of chapter 16) using
two 8051 based boards. Load the programs in both boards and observe the result on LEDs.
Laboratory exercise:
Keyboard interfacing
Objectives:
Design 4 x 4 matrix keyboard and interface it with 89C51 (or any other variant) as shown in
schematic diagram shown in figure 17.8 (or use the 8051 based board you have). Load the
program given in interfacing example 17.3 in on-chip code memory of 89C51. Press the key and
observe the key code generated for pressed key on port 3.
Laboratory exercise:
Modify the program to generate ASCII code for pressed key.[Refer ex 17.4]
Rewrite the program of interfacing example for 5 x 4 matrix keyboard.
Discuss the importance of human factors that should be considered for key identification
program.
Discuss the significance of debouncing when interfacing mechanical switches. [Observe
the output code of the pressed key without including debounce delay in above program]
LABORATORY 12:
Objective
Refer interfacing example 18.8 and interface the LCD module as shown in schematic diagram of
figure18.10. Load the program in the on-chip memory of microcontroller. Observe the output on
LCD module.
Laboratory exercise:
Refer Project: Simple burglar alarm system at the end of chapter 18 and interface 7 segment
module with 8051 as shown in schematic diagram of figure 18.12. Load the program (given for
the project) in the 8051 and observe the output after pressing input switches.
LABORATORY 13:
Objectives
Interfacing ADCs
Refer interfacing example 19.4 and interface the ADC 0804chip as shown in schematic diagram
of figure19.2. Load the program in the memory of microcontroller. Apply different analog
voltages using potentiometer and note down equivalent digital output.
Note: These days all new variants of 8051 have on-chip ADCs. Check the datasheet of the
microcontroller you have and modify the above program to perform analog to digital conversion
using on-chip ADC. [Refer user manual of the board you have in your laboratory]
Laboratory exercise:
1. Change the VREF/2 and observe the digital output and see how the input voltage range
(and resolution) of ADC can be varied by VREF/2.
2. Repeat above experiment for multichannel ADC like ADC 0808.[Refer example 19.7]
3. Repeat the experiment for serial ADC like MAX1112/13[Refer interfacing example 19.8]
4. Write a program to read analog value at the interval of 1 second and store it in internal
RAM location 10H onwards. Store total 20 values. Apply low frequency sinewave as
analog input
5. Discuss the factor affecting selection of ADC.
Interfacing DACs
Refer Interfacing example 19.14 and interface the DAC AD557 chip as shown in schematic
diagram of figure19.8. Load the program in the memory of microcontroller. Observe the output
of DAC on CRO.
OR
Refer Interfacing example 19.16 and interface the DAC 0808 chip as shown in schematic
diagram of figure19.11. Load the program in the memory of microcontroller. Observe the output
of DAC on CRO.
Laboratory exercise:
1. Modify the program of interfacing example 19.14 to generate more accurate sine
wave.[Hint: make lookup table for more samples of sine wave.
2. Modify above program to change the frequency of sine (or sawtooth) wave.
3. Modify above program to generate different waveforms [Refer Project: Function
generator at the end of the chapter 19]
LABORATORY 14:
Objectives:
Interfacing DC motors
Refer interfacing example 20.9 and interfacing example 20.11. Interface the DC motors as shown
in schematic diagram of figure 20.11 and figure 20.14 Load the programs in the memory of
microcontroller. Run the programs.
Note: H-bridge is available in single IC form such as L293 (Quadruple half H drives, output
current 1A per channel). IC A3952 (Full bridge PWM motor driver) can also be used for
direction control of DC motor. Refer datasheets of these chips for their connections with DC
motors. Choose suitable driver circuit as per ratings of the motor.
Refer interfacing example 20.1 and interface stepper motor with 8051 as shown in figure 20.8.
Load the program in to code memory of microcontroller and run the program. Choose suitable
driver circuit as per ratings of the motor.
Laboratory exercise: