0% found this document useful (0 votes)
27 views

Lab Manual Microcontroller and Interfacing 3151707 GECGn

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Lab Manual Microcontroller and Interfacing 3151707 GECGn

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

A Laboratory Manual for

Microcontroller and Interfacing


(3151707)

B.E. Semester5
(INSTRUMENATION & CONTROL)

GOVERNMENT ENGINEERING COLLEGE,


SECTOR-28, GANDHINAGAR

Directorate of Technical Education,


Gandhinagar, Gujarat
GOVERNMENT ENGINEERING COLLEGE,
SECTOR-28, GANDHINAGAR

Certificate

This is to certify that Mr./Ms. ___________________________________


________ Enrollment No. _______________ of B.E. Semester 5th
Instrumentation & Control Engineering of this Institute (GTU Code: 013)
has satisfactorily completed the Practical work for the subject
Microcontroller and Interfacing (3151707) for the academic year 2023-24.

Place: __________
Date: __________

Name and Sign of Faculty member

Head of the Department


Microcontroller and Interfacing(3151707)

Preface

The main objective of laboratory, practical, and field work is to enhance the required skills and
create the ability among students to solve real-time problems by developing relevant
competencies in the psychomotor domain. With this in mind, Gujarat Technological University
(GTU) has designed a competency-focused, outcome-based curriculum for engineering degree
programs, with sufficient weightage given to practical work. This emphasizes the importance of
skill enhancement among students, utilizing every second of allotted practical time to achieve
relevant outcomes through performing experiments, rather than just studying theoretical
concepts.

Effective implementation of a competency-focused, outcome-based curriculum requires that


every practical is keenly designed to serve as a tool to develop and enhance the relevant
competencies required by various industries for every student. These psychomotor skills are
difficult to develop through traditional chalk-and-board content delivery methods in the
classroom. Therefore, this lab manual is designed to focus on industry-defined, relevant
outcomes, rather than the old practice of conducting practicals to prove concepts and theories.
By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which createsaninterest and students can have basic idea prior to
performance.This in turn enhances pre-determined outcomes amongst students.Each experiment
in this manual begins with competency, industry relevant skills, course outcomes as well as
practical outcomes (objectives). The students will also achieve safety and necessary precautions
to be taken while performing practical.

This manual also provides guidelines to faculty members to facilitate studentcentric lab
activities through each experiment by arranging and managing necessary resources in order that
the students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.

The course “Microcontroller and Interfacing” is an indispensable and fundamental


component of the instrumentation and embedded systems. Microcontrollers are vital in
instrumentation and control systems, as they offer a flexible and efficient way to monitor and
control processes. Interfacing is also crucial, as it involves connecting devices to the
microcontroller, enabling data transfer and control signal exchange. Understanding
microcontrollers and interfacing is critical for engineers to design, develop and maintain
effective control systems, optimizing performance, reducing costs, and improving reliability
and safety.

Although utmost care has been taken in preparing this lab manual, there is always room for
improvement. We welcome constructive suggestions to enhance the manual and correct any
errors that may be present.
Microcontroller and Interfacing(3151707)

Practical – Course Outcome matrix

Course Outcomes (COs):


After learning the course the students should be able to:
CO1 Able to understand and explain microcomputer architectures, microcontroller family,
addressing modes, data types in Embedded C, basics of serial communication, timer-counter
configuration and interrupt handling.

CO2 Able to write, debug and analyze the code in assembly as well as Embedded C language.
CO3 Able to apply digital logic design and programming principles to interface and access external
memories and Input-Output devices like keyboard, Seven segment LED and LCD displays,
ADC, DAC etc. with micro controller.
CO4 Able to calculate instruction execution time, delay, baud rate, and write assembly and C Code,
identify the timer mode, serial communication mode and interrupt priorities
CO5 Able to work as an individual and as a team-member to design, formulate and implement
timer, counter and interrupt programming based applications using microcontroller.
Sr. CO CO CO CO CO
Objective(s) of Experiment
No. 1 2 3 4 5

1. To study and perform data transfer programming. √ √

To study and perform arithmetic instruction


2. √ √
programming.
To study and perform boolean& logical instructions
3. √ √
programming.

4. To study and perform code conversion programming. √

5. To study and perform timer programming. √ √

To study and perform serial communication


6. √ √
programming.
To study and perform temperature sensor interfacing
7. √ √
using ADC.

8. To study and perform LCD interfacing. √ √

To study and perform interfacing matrix keypad and 7-


9. √ √
segment display.

10. To study and perform Interfacing of stepper motor. √ √

Suggested Project / Case study


Microcontroller and Interfacing(3151707)

Industry Relevant Skills

The following industry relevant competency are expected to be developed in the student by
undertaking the practical work of this laboratory.
1. Ability to design and implement microcontroller-based control systems.
2. Proficiency in interfacing microcontrollers with various sensors and actuators.
3. Knowledge of programming languages and software tools used in microcontroller-based
systems.
4. Skill in troubleshooting and maintaining microcontroller-based systems.
5. Understanding of various communication protocols used in microcontroller-based
systems.

Guidelines forFaculty members


1. Teacher should provide the guideline with demonstration of practical to the students
with all features.
2. Teacher shall explain basic concepts/theory related to the experiment to the students
before starting of each practical
3. Involve all the students in performance of each experiment.
4. Teacher is expected to share the skills and competencies to be developed in the
students and ensure that the respective skills and competencies are developed in the
students after the completion of the experimentation.
5. Teachers should give opportunity to students for hands-on experience after the
demonstration.
6. Teacher may provide additional knowledge and skills to the students even though not
covered in the manual but are expected from the students by concerned industry.
7. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions or not.
8. Teacher is expected to refer complete curriculum of the course and follow the
guidelines for implementation.

Instructions for Students


1. Students are expected to carefully listen to all the theory classes delivered by the faculty
members and understand the COs, content of the course, teaching and examination
scheme, skill set to be developed etc.
2. Students shall organize the work in the group and make record of all observations.
3. Students shall develop maintenance skill as expected by industries.
4. Student shall attempt to develop related hand-on skills and build confidence.
5. Student shall develop the habits of evolving more ideas, innovations, skills etc. apart from
those included in scope of manual.
6. Student shall refer technical magazines and data books.
7. Student should develop a habit of submitting the experimentation work as per the schedule
and s/he should be well preparedfor the same.

Common Safety Instructions


1. Students are expected to handle computers and trainer kits with care and caution.
Microcontroller and Interfacing(3151707)

Index
(Progressive Assessment Sheet)

Sign. of
Sr. Page Date of Date of Assessment
Objective(s) of Experiment Teacher with Remarks
No. No. performance submission Marks
date

1 To study and perform data transfer programming.

2 To study and perform arithmetic instruction programming.

3 To study and perform boolean& logical instructions programming.

4 To study and perform code conversion programming.

5 To study and perform timer programming.

6 To study and perform serial communication programming.

7 To study and perform temperature sensor interfacing using ADC.

8 To study and perform LCD interfacing.

9 To study and perform interfacing matrix keypad and 7-segment display.

10 To study and perform Interfacing of stepper motor.

Suggested Project / Case study

Total
INTRODUCTION
Earlier to Microcontrollers, Microprocessors were greatly used for each and every
purpose. Microprocessors were containing ALU, general purpose register, stack pointer, program
counter, clock counter and so many other features which today‟s Microcontroller also possesses.
But the difference between them exists with respect to the number of instructions, access times,
size, reliability, PCB size, and so on. The microprocessor contains a large instruction set called as
CISC processor whereas Microcontroller contains less number of instructions and is called as
RISC processor. The access time is less in the case of microcontrollers compared to
microprocessors and the PCB size reduces in the case of microcontrollers.
There are many versions of microcontrollers 8051, 80528751, AT8951 from Atmel
Corporation, and many more. In this manual, we will study the 8051 architecture, its features,
programming, and interfacing.
MCS 8051 is an 8-bit single-chip microcontroller with many built-in functionsand is the core for
all MCS-51 devices.
The main features of the 8051 core are:
 Operates with single Power Supply +5V.
 8-bit CPU optimized for control applications.
 16-bit program counter (PC) and 16-bit data pointer (DPTR).
 8-bit program status word (PSW).
 8-bit stack pointer (SP).
 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).
 128 bytes of On-Chip Data Memory (Internal RAM):
 Four Register Banks, each containing 8 registers (R0 to R7) [Total 32 reg]
 16-bytes of bit addressable memory.
 80 bytes of general-purpose data memory (Scratch Pad Area).
 Special Function Registers (SFR) to configure/operate microcontroller.
 32 bit bi-directional I/O Lines (4 ports P0 to P3).
 Two 16-bit timers/counters (T0 and T1).
 Full duplex UART (Universal Asynchronous Receiver/Transmitter).
 On-Chip oscillator and clock circuitry
Executing assembly language programs in Keil Microvision Software:
Follow the following steps to execute assembly language programs in Keil Microvision software:

Step 1: Open Keil Microvision software then click on the project then click on the new
Microvision project.

Step 2: Save your file with .asm extension for example (addition of numbers.asm) and save it.

Step 3: Select microchip AT89C51 and click on ok.


Step 4: Now click on target 1 and then double click on source group 1, select the file that you
saved previously with extension .asm add it to the source group, and close it.

Step 5: Now click on the + sign shown before source group 1, then double click on the file that
comes after clicking on +sign. Then write assembly language code in the plane text area that
appears.

Step 6: Click on build and rebuild to check errors then click on debug and start debug session.
Step 7: Then click on run you can run directly or you can run step by step by clicking every time
on the step or pressing F11 and then check the output here the output is visible in blue color.

By following the above-mentioned steps, you can execute any type of assembly language
statements or instructions and assembler directives in Keil Microvision software.
Familiarization with the EdSim51 simulator :

EdSim51 is a free, web-based, educational software package that is used to simulate and analyze
8051-based microcontroller systems. It is designed to provide students with a hands-on learning
experience and is a useful tool for instructors teaching microcontroller-based courses.

Students can use EdSim51 to design, code, and simulate programs on a virtual 8051
microcontroller, allowing them to test and debug their programs in a safe and controlled
environment. Additionally, EdSim51 provides a variety of built-in peripherals, such as LCDs,
keypad input, and serial communication, allowing students to design and test complete systems.

One of the key benefits of EdSim51 is that it is accessible and user-friendly. It can be accessed
from any computer with an internet connection, and it does not require any additional software or
hardware. This makes it an ideal tool for remote learning and for students who do not have access
to physical microcontroller systems.

The top left box is the microcontroller panel which gives the student access to all of the 8051's
registers, data memory, and code memory. The upper middle part is the integrated development
environment (IDE) or the assembly code panel where the user either loads anassembly program or
writes the code directly. The top right box displays the list of the 32 port pins, the current value of
the port pin, and what each is connected to.

Overall, EdSim51 is a valuable resource for students learning about microcontrollers and
embedded systems, providing them with a powerful tool for experimentation, learning, and
project development.
Experiment No: 1
To study and perform data transfer programming.
Date:
Competency and Practical Skills: Ability to perform arithmetic operations on 8-bit and 16-bit
numbers using microcontrollers and proficiency in using programming languages and software
tools required for microcontroller-based systems.
Relevant CO: CO1, CO2
Objectives:Gain proficiency in programming and performing arithmetic operations on
microcontrollers.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Programs:
1. Write an assembly language program to transfer N = ___ bytes of datafrom location A:
_______h to location B: _______h.
Let N = 05h, A: 30h and B: 40h

Label Operands Remarks


MOV R0,#30H ; source address
MOV R1,#40H ; destination address
MOV R7,#05H ; Number of bytes to be moved
BACK: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R7,BACK ; repeat till all data transferred
END
2. Write an assembly language program to exchange N = ___h bytes of dataat location A:
______h and at location B: _______h.
Let N = 05h, A: 30h and B: 40h

Label Operands Remarks


MOV R0,#30H ; source address
MOV R1,#40H ; destination address
BACK: MOV R7,#05H ; count, the number of data to be exchanged
MOV A,@R0
MOV R4,A
MOV A,@R1
MOV @R0,A
MOV A,R4
MOV @R1,A
INC R0
INC R1
DJNZ R7,BACK
END
Exercises:
1. Write an assembly language program to find the largest element in a given array of N =___h
bytes at location 4000h. Store the largest elementat location 4062h.
2. Write an assembly language program to sort an array of N =____ h bytes of data in
ascending/descending order stored from location 9000h. (Using bubble sort algorithm)
3. Write an ALP in 8051 to Find maximum of the numbers stored in internal memory block from
40h to 5fh, send result to port 2 pins.
4. Write an ALP to Find minimum of the numbers stored in external RAM locations 2000h to
201fh, send result to external memory location 3000h.
5. Write a program in 8051 to sort data of memory location block in internal RAM locations 20h
to 2fh in ascending order.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:

Quiz:
1. Enumerate the objectives or goals of the microcontroller trainer kit.
2. List the available software for the microcontroller practical.
3. Describe the dissimilarities between internal memory and external memory in the 8051
microcontroller.
4. Specify the essential precautions when handling the microcontroller trainer kit and other
hardware in the practical.
5. Explain the function of Keil software in microcontroller programming.
Suggested Reference:Ch-2 & 6, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2nd editionby Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of arithmetic operations.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 2
To study and perform arithmetic instruction programming.
Date:
Competencyand Practical Skills: Analyzing data transfer and arithmetic operations on external
memory.
Relevant CO: CO1, CO2
Objectives: Gain a better understanding of data transfer and arithmetic operations on external
memory, and investigate methods for optimizing their performance.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Programs:
1. Write an assembly language program to perform the addition of two 16-bit numbers.

Label Operands Remarks


MOV R0,#34H ; lower nibble of No.1
MOV R1,#12H ; higher nibble of No.1
MOV R2,#0DCH ; lower nibble of No.2
MOV R3,#0FEH ; higher nibble of No.2
CLR C
MOV A,R0
ADD A,R2
MOV 22H,A
MOV A,R1
ADDC A,R3
MOV 21H,A
MOV 00H,C
END
2. Write an assembly language program to perform the subtraction oftwo 16-bit numbers.

Label Operands Remarks


MOV R0,#0DCH ; lower nibble of No.1
MOV R1,#0FEH ; higher nibble of No.1
MOV R2,#34H ; lower nibble of No.2
MOV R3,#12H ; higher nibble of No.2
CLR C
MOV A,R0
SUBB A,R2
MOV 22H,A
MOV A,R1
SUBB A,R3
MOV 21H,A
MOV 00H,C
END
Exercises:
1. Write a program in 8051 assembly language to add numbers stored in internal memory block
addressed from 30h to 3fh, store the result high byte to address of internal RAM 40h and low
byte to 41h.
2. Write an assembly language program to find the square of a number stored at memory
location 30h. Store the higher byte at 40h and lower byte at 41h.
3. Write a program in 8051 assembly language to add two numbers stored in external memory
location 2000h and 2001h, store result in external memory location 3000h, also if answer
contains carry, store the carry flag in LSB of external memory location 3001h.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:

Quiz:
1. Describe the purpose of studying data transfer and arithmetic operations on external memory.
2. Define external memory.
3. Identifying some common challenges associated with data transfer on external memory, and
taking action to address them.
4. List real-world applications can benefit from applying the outcomes of this practical exercise.
Suggested Reference: Ch-2, 3 & 6, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2nd edition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of data transfer instructions and arithmetic operations.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 3
To study and perform boolean & logical instructions programming.
Date:
Competency and Practical Skills: Develop competencies and skills such as programming,
problem-solving, debugging, familiarity with 8051 architecture.
Relevant CO: CO1, CO3
Objectives: To understand how to manipulate binary data and perform logical operations on it
using the various instructions available in the 8051 microcontroller.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Programs:
1. Write an ALP to compare two eight bit numbers NUM1 and NUM2 stored in external
memory locations 8000h and 8001h respectively. Reflect your result as: If NUM1<NUM2,
SET LSB of data RAM location 2FH (bit address 78H). If NUM1>NUM2, SET MSB of
location 2FH (bit address 7FH). If NUM1 = NUM2, then Clear both LSB & MSB of bit
addressablememory location 2FH.

Label Operands Remarks


MOV DPTR,#8000H ; store external memory location
MOVX A,@DPTR ; pointer for external memory location
MOV R0,A
INC DPTR
MOVX A,@DPTR
CLR C
SUBBA,R0 ; subtract
JZ EQUAL ; check for equal value and jump if yes
JNC SMALL ; check for lower value and jump if yes
SETB 7FH ; if not lower and equal then higher value
SJMP END1
SMALL: SETB 78H
SJMP END1
EQUAL: CLR 78H
CLR 7FH
END1: END
2. Write an assembly language program to count number of ones and zeros in aeight bit number.

Label Operands Remarks


MOV R1,#00H // to count number of 0s
MOV R2,#00H // to count number of 1s
MOV R7,#08H // counter for 8-bits
MOV A,#97H // data to count number of 1s and 0s
AGAIN: RLC A
JC NEXT
INC R1
NEXT: SJMP HERE
HERE: INC R2
DJNZ R7,AGAIN
END
Exercises:
1. Write a program in 8051 to sort data of memory location block in internal RAM locations 20h
to 2fh in ascending order.
2. Write an assembly language program to find whether given eight bit number is odd or even. If
odd store 00h in accumulator. If even store FFh inaccumulator.
3. Write an assembly language program to perform logical operations AND, OR, XOR on two
eight bit numbers stored in internal RAM locations 21h,22h.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:
Quiz:
1. Explain the purpose of the ANL instruction in 8051 programming.
2. Demonstrate how to perform a bitwise OR operation in 8051 microcontroller
programming using a specific instruction.
3. Illustrate how to clear a bit in a byte using the 8051 microcontroller.
4. Analyze the purpose of incorporating the XRL instruction in 8051 programming.
5. Compare and contrast the ORL and ANL instructions in 8051 programming.
6. Evaluate the effectiveness of the instruction used in 8051 programming to invert all the
bits within a byte.

Suggested Reference: Ch-2, 3, 4& 6, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2nd edition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of logical instructions and algorithms.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 4
To study and perform code conversion programming.
Date:
Competency and Practical Skills: Gain a deeper understanding of the 8051 architecture, the
instruction set, and how to write efficient code for it.
Relevant CO: CO1
Objectives: To learn the skills and techniques required to convert code written in one
programming language into code written in another programming language.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Program:
1. Write an assembly language program to convert a packed BCD number into ASCII number.

Label Operands Remarks


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ; dptr=8500h
MOVX A,@DPTR ; store the contents of memory location pointed by
DPTR into register A
MOV R0,A ; move the content of A to r0.
ANL A,#0FH ; make logical AND function with register A and
immediate data 0FH
ORL A,#30H ; make logical OR function with register A and
immediate data 30H
INC DPTR ; increment DPTR
MOVX @DPTR,A ; save the result in memory location 8501H
MOV A,R0 ; get the once again BCD number in register A
; make logical AND function with reg A and
ANL A,#0F0H immediate data 0F0h
SWAP A ; swap the contents of register A
ORL A,#30H ; make logical OR function with reg A and
immediate data 30H
INC DPTR ; increment DPTR
MOVX @DPTR,A ; save the result in memory location 8502H
LCALL 0003H ; end of asm file
Exercises:
1. Write an assembly language program to convert an ASCII number into Decimal.
2. Write an assembly language program to convert a decimal number into ASCII.
3. Write an assembly language program to convert a binary (hex) number into decimal. Write an
assembly language program to convert a decimal number into binary(hex).
4. Write a program in 8051 to read data from port 1 pins and convert it from packed ASCII to
Hex code and store result to internal RAM location 30h and 31h for lower and higher digits
respectively.
Safety and necessary Precautions:
1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:

Quiz:
1. Define packed ASCII.
2. How many bits are used to represent a packed ASCII character?
3. How many packed ASCII characters can be stored in a byte?
4. How can a packed ASCII character be converted back to its ASCII representation?
5. What is the decimal value of the packed ASCII character 0x47?
6. Which of the following programming languages supports packed ASCII natively?
a) Python b) C c) Java d) All options
7. What is the disadvantage of using packed ASCII?
a) It is not compatible with non-ASCII characters
b) It is more complex to implement than regular ASCII
c) It can lead to loss of data if not implemented properly.
8. Which instruction is used to convert a binary number to a BCD number in 8051
microcontroller?

Suggested Reference: Ch-2, 3, 4 & 6, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2nd edition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks
Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of different number systems and its conversions.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 5
To study and perform timer programming.
Date:
Competency and Practical Skills: Develop skills in embedded systems programming, real-time
programming, and microcontroller-based design.
Relevant CO: CO4, CO5
Objectives: Tolearnuse of the built-in timers of the microcontroller for precise timing operations
and control functions
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Program:
1. Write an ALP to generate a square wave of frequency 72Hz on pin P1.0
Assume XTAL=11.0592MHz. With TH=00, the delay generated is256 x 1.085 µs =
277.76µs. therefore, to generate a delay of (1 / 72) = 138.88ms, the countto be loaded is 250 x
2=500.That is
T = 2 (250 × 256 × 1.085 µs) = 138.88ms, and frequency = 72 Hz

Label Operands Remarks


MOV TMOD, #2H ; ; Timer 0, mod 2;(8-bit, auto reload)
MOV TH0, #0
AGAIN: MOV R5, #250 ; multiple delay count
ACALL DELAY
CPL P1.0
SJMP AGAIN
DELAY: SETB TR0 ; start the timer 0
BACK: JNB TF0,BACK ; stay timer rolls over
CLR TR0 ; stop timer
CLR TF0 ; clear TF for next round
DJNZ R5,DELAY
RET
Exercises:
1. Generate 1 kHz square wave using 8051 timer.
2. Generate 10 kHz square wave using 8051 timer.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.
Conclusion:

Quiz:
1. Identify the microcontroller that is commonly used for timer programming.
2. Explain the benefits of using built-in timers in 8051 for timing operations.
3. List some functions that can be controlled using timer programming for 8051.
4. Discuss the significance of precise timing in microcontroller programming.
5. Provide examples of common applications of timer programming for 8051 microcontroller.

Suggested Reference: Ch-2, 3 &9, The 8051 Microcontroller and Embedded Systems Using
Assembly and C, 2nd edition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of timerin 8051.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 6
To study and perform serial communication programming.
Date:
Competency and Practical Skills: Gain understanding of serial communication protocols,
programming in assembly language, debugging, hardware interfacing, problem-solving, and
analytical skills.
Relevant CO: CO4, CO5
Objectives: To understand the basic principles of serial communication, configuring the 8051
microcontroller for serial communication, and writing programs to transmit and receive data using
the serial port.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Program:
1. Write a program for the 8051 to transfer the message „EARTH‟ serially at 9600 baud, 8 bit
data, 1 stop bit continuously.

Label Operands Remarks


ORG 0000H
LJMP START
ORG 0030H

START: MOV TMOD, #20H ; select timer 1 mode 2


MOV TH1, #0FDH ; load count to get reqd. baud rate of 9600
MOV SCON, #50H ;initialiseuart in mode 2 and 8-bit data and 1 stop bit
SETB TR1 ; start timer

LOOP: MOV A, #'E' ; load 1stletter „E‟ in a


ACALL LOAD ; call load subroutine
MOV A, #'A' ; load 2ndletter „A‟ in a
ACALL LOAD ; call load subroutine
MOV A, #'R' ; load 3rdletter „R‟ in a
ACALL LOAD ; call load subroutine
MOV A, #'T' ; load 4thletter „T‟ in a
ACALL LOAD ; call load subroutine
MOV A, #'H' ; load 5thletter „H‟ in a
ACALL LOAD ; call load subroutine
SJMP LOOP ; repeat steps

LOAD: MOV SBUF, A


HERE: JNB TI, HERE ; Check for transmit interrupt flag
CLR TI ; Clear transmit interrupt flag
RET
END
2. Write a program for the 8051 to transfer letter „A‟ serially at 4800- baud rate, 8-bit data,1 stop
bit continuously.

Label Operands Remarks


ORG 0000H
LJMP START
ORG 0030H

START: MOV TMOD, #20H ; select timer 1 mode 2


MOV TH1, #0FAH ; load count to get baud rate of 4800
MOV SCON, #50H ; initialize UART in mode 2 and 8-bit data and 1 stop
SETB TR1 bit
; start timer
AGAIN: MOV SBUF, #'A'
BACK: JNB TI, BACK ; load char „A‟ in SBUF
CLR TI ; check for transmit interrupt flag
SJMP AGAIN ; clear transmit interrupt flag
END

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:

Quiz:
1. State the full form of USART in Serial Communication Programming using 8051.
2. List the programming language used in Serial Communication Programming using 8051.
3. Define baud rate in Serial Communication Programming using 8051.
4. Justify the use of a crystal oscillator in Serial Communication Programming using 8051.
5. Compare UART and USART in Serial Communication Programming using 8051.
Suggested Reference: Ch-2, 3& 10,The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2nd edition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of serial communication protocol.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 7
To study and perform temperature sensor interfacing using ADC.
Date:
Competency and Practical Skills: Gain practical skills in microcontroller programming,
sensor and ADC interfacing, troubleshooting, data analysis, circuit design, and technical
communication.
Relevant CO: CO3, CO5
Objectives: To gain hands-on experience in interfacing a temperature sensor with an ADC and
8051 microcontroller, learn the principles of analog to digital conversion, and develop skills in
troubleshooting, data analysis, and technical communication.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Program:
1. Write a C program for Digital Voltmeter using 8051 Microcontroller, Voltage Sensor and
ADC0804.

void intro (void);


#include<reg51.h>
char i=0;
#define lcd P3
void delay (int d)
#define dat P2
{
sbit rs=P1^6;
unsigned char i=0;
sbit e=P1^7;
for(;d>0;d--)
void delay (int);
{
void display (unsigned char);
for(i=250;i>0;i--);
void cmd (unsigned char);
for(i=248;i>0;i--);
void init (void);
}
void string (char *);
}
void cmd (unsigned char c) string("Digital");
{ cmd(0xc0);
lcd=c; string("Voltmeter");
rs=0; delay(2000);
e=1; cmd(0x01);
delay(10); cmd(0x80);
e=0; }
} void main()
void display (unsigned char c) {
{ unsigned int temp=0;
lcd=c; unsigned int temp1=0;
rs=1; float val=0.0;
e=1;
delay(10); init();
e=0; intro();
} dat=0xff;
void string (char *c) while(1)
{ {
while(*c) if(i==0)
{ {
display(*c++); string(" Volts - ");
} i++;
} }
void init (void) val=dat*0.02; // 0.02 is resolution of
adc
{
val=val/0.2; // 0.2 is nothing but
cmd(0x38);
(R2/(R1+R2)) resistor values in the
cmd(0x01); voltage sensor
cmd(0x0c); cmd(0x89);
cmd(0x80); if((val>=1.0) && (val<10.0))
} {
void intro (void) display(' ');
{ temp=val*1000;
string("I & C");
cmd(0xc0); temp1=((temp/1000)+48);

string("Engg."); display(temp1);

delay(2000); display('.');

cmd(0x01);
temp1=(((temp/100)%10)+48);
display(temp1);
}
else if((val>=10.0) &&
(val<100.0))
{
temp=val*100;

temp1=((temp/1000)+48);
display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);
display('.');

temp1=(((temp/10)%10)+48);
display(temp1);
}
else
{
display(' ');
string("0.0");
}
delay(1000);
}
while(1);
}
Exercises:
1. Write a C program to measure temperature using any given temperature sensor and display
temperature on serial port of computer.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.
Conclusion:

Quiz:
1. Analyze the purpose of an ADC in temperature sensor interfacing.
2. Evaluate the factors that can affect the accuracy of temperature sensing using an ADC.

Suggested Reference: Ch-2, 3,4 & 13, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2ndedition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of ADC interfacing with microcontroller.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 8
To study and perform LCD interfacing.
Date:
Competency and Practical Skills: Gain practical skills in digital electronics,
microcontrollers, circuit design, troubleshooting, and hardware-software interfacing.
Relevant CO: CO2, CO3
Objectives: To understand the process of connecting and controlling an LCD display with a
microcontroller, and to gain practical experience in implementing the interfacing protocols using
assembly language programming and circuit design techniques.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Note: Help for LCD interfacing program can be taken from sample program of experiment 7.
Exercises:
1. Display “IC Engineering” on LCD display interfaced with 8051.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:
Quiz:
1. Identify the basic components required for interfacing an LCD display with 8051 and explain
their connections.
2. Differentiate between the various modes of operation of an LCD display.
3. Classify the different types of LCD displays that can be interfaced with 8051.
4. Identify the common issues that can occur during LCD interfacing and list the diagnostic and
resolution steps.

Suggested Reference: Ch-2, 3,4 & 12, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2ndedition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of LCD interfacing with microcontroller.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 9
To study and perform interfacing matrix keypad and 7-segment display.
Date:
Competency and Practical Skills: Develop competencies in microcontrollers, programming,
circuit design, problem-solving, attention to detail, and time management.
Relevant CO: CO2, CO3
Objectives: To learn how to connect and control common input and output devices with a
microcontroller.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Program:
1. Program to display "0" on the seven-segment display in assembly language.

Label Operands Remarks


ORG 0000H ; Execution starts here
SETB P0.3 ; Turn off the g segment
CLR P0.1 ; Turn on the a segment
CLR P0.0 ; Turn on the b segment
CLR P0.6 ; Turn on the c segment
CLR P0.5 ; Turn on the d segment
CLR P0.4 ; Turn on the e segment
CLR P0.2 ; Turn on the f segment

HERE: AJMP HERE ; Loop here forever


END
2. WAP in C language for 8051 to display numbers from „0‟ to „9‟, one by one with a delay
of few seconds.
Hardware Connection:

#include <reg51.h>

void DELAY_ms(unsigned int ms_Count)


{
unsigned int i,j;
for(i=0;i<ms_Count;i++)
{
for(j=0;j<100;j++);
}
}

int main()
{
char
seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int i;
while (1)
{
for (i = 0; i<= 9; i++) // loop to display 0-9
{
P2 = seg_code[i];
DELAY_ms(1000);
}
}
}
3. Interfacing Seven segment display to 8051.
Consider common cathode type seven segment display is connected on P1 of 8051.

Label Operands Remarks


ORG 000H ; initial starting address
START: MOV A, #00001001B ; initial value of accumulator
MOV B,A
MOV R0,#0AH ;Register R0 initialized as counter which
counts from 10 to 0
LABEL: MOV A,B
INC A
MOV B,A
MOVC A,@A+PC ; adds the byte in A to the program counters
address
MOV P1,A
; calls the delay of the timer
ACALL DELAY
; Counter R0 decremented by 1
DEC R0
; R0 moved to accumulator to check if it is
MOV A,R0
zero in next instruction.
; Checks accumulator for zero and jumps to
JZ START START. Done to check if counting has been
finished.
SJMP LABEL
DB 3FH ; digit drive pattern for 0
DB 06H ; digit drive pattern for 1
DB 5BH ; digit drive pattern for 2
DB 4FH ; digit drive pattern for 3
DB 66H ; digit drive pattern for 4
DB 6DH ; digit drive pattern for 5
DB 7DH ; digit drive pattern for 6
DB 07H ; digit drive pattern for 7
DB 7FH ; digit drive pattern for 8
DB 6FH ; digit drive pattern for 9
DELAY: MOV R4,#05H ; subroutine for delay
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END
4. Write an ALP to display the key pressed on a matrix keyboard on a seven-segment
display.The hex keypad is interfaced to port 1 and seven segment LED display is
interfaced to port0 of the microcontroller.
Label Operands Remarks
ORG 00H
MOV DPTR,#LUT ; moves start Address of LUT to DPTR
MOV A,#11111111B ; loads A with all 1's
MOV P0,#00000000B ; initializes p0 as output port
BACK: MOV P1,#11111111B ; loads p1 with all 1's
CLR P1.0 ; makes row 1 low
JB P1.4,NEXT1 ; checks whether column 1 is low and jumps to next1
if not LOW
MOV A,#0D ; loads a with 0d if col is low (that means key 1 is
pressed)
ACALL DISPLAY ; calls display subroutine
NEXT1: JB P1.5, NEXT2 ; checks whether column 2 is low and so on...
MOV A,#1D
ACALL DISPLAY
NEXT2: JB P1.6,NEXT3
MOV A,#2D
ACALL DISPLAY
NEXT3: JB P1.7,NEXT4
MOV A,#3D
ACALL DISPLAY
NEXT4: SETB P1.0
CLR P1.1
JB P1.4,NEXT5
MOV A,#4D
ACALL DISPLAY
NEXT5: JB P1.5,NEXT6
MOV A,#5D
ACALL DISPLAY
NEXT6: JB P1.6,NEXT7
MOV A,#6D
ACALL DISPLAY
NEXT7: JB P1.7,NEXT8
MOV A,#7D
ACALL DISPLAY
NEXT8: SETB P1.1
CLR P1.2
JB P1.4,NEXT9
MOV A,#8D
ACALL DISPLAY
NEXT9: JB P1.5,NEXT10
MOV A,#9D
ACALL DISPLAY
NEXT10: JB P1.6,NEXT11
MOV A,#10D
ACALL DISPLAY
NEXT11: JB P1.7,NEXT12
MOV A,#11D
ACALL DISPLAY
NEXT12: SETB P1.2
CLR P1.3
JB P1.4,NEXT13
MOV A,#12D
ACALL DISPLAY
NEXT13: JB P1.5,NEXT14
MOV A,#13D
ACALL DISPLAY
NEXT14: JB P1.6,NEXT15
MOV A,#14D
ACALL DISPLAY
NEXT15: JB P1.7,BACK
MOV A,#15D
ACALL DISPLAY
DISPLAY: LJMP BACK
MOVC A,@A+DPTR ; gets digit drive pattern for the current key from
MOV P0, A LUT
RET ; puts corresponding digit drive pattern into P0

LUT: DB 3FH, 06H, 5BH,


4FH, 66H, 6DH, 7DH,
07H,7FH, 6FH,0F7H,
0FCH, 0B9H, 0DEH,
0F9H, 0F1H, 0

END

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:
Quiz:
1. Describe the differences between a seven-segment display and other types of displays.
2. Discuss the importance of properly debouncing the input signals from a matrix keypad.
3. Analyze the challenges that might arise when interfacing a matrix keypad and a seven-
segment display with a microcontroller, and suggest ways to overcome them.
4. Examine the advantages of using a matrix keypad over other input devices.
5. Define the perception of vision time for human beings.
6. Analyze the role of multiplexing in driving a large number of seven-segment displays with a
single microcontroller.
7. Evaluate the advantages and disadvantages of using a seven-segment display compared to
other types of displays.
8. Propose potential use cases for seven-segment displays in different industries and applications.

Suggested Reference: Ch-2, 3, 4 & 12, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2ndedition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of keyboard interfacing with microcontroller.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Experiment No: 10
To study and perform Interfacing of stepper motor.
Date:
Competency and Practical Skills: Develop skills in embedded systems, assembly
programming, electronics, motor control, problem-solving, attention to detail, and project
management.
Relevant CO: CO3, CO5
Objectives: Togain practical knowledge and skills in embedded systems, microcontrollers, motor
control, and electronics, and to learn how to program a microcontroller to control a stepper motor.
Equipment/Instruments/Software: Keil Microvision software or EdSim51. However, other
software or microcontroller development boards or educational boards may also be used.
Sample Program:
1. Stepper Motor Interfacing with 8051.
P1.0,P1.1, P1.2 and P1.3 pins are used for controlling the phases A1, A2, A3 and A4 ofthe
stepper motor respectively. ULN2003 is used for driving the individual phases of the stepper
motor. ULN2003 is a darlington transistor array used for driving high current loads such as relays
and motors. ULN2003 has 8 individual channels each with 1A capacity.

The program first clears P1.0 for activating phase 1 (A1) of the stepper motor. This
condition is maintained for 65mS and then P1.0 is set for deactivating phase 1 of the motor. Then
the same process is repeated for the port pins P1.1 to P1.3 and the entire cycle is repeated over
and over to make the motor rotate in the clockwise direction. Timer 0 of the microcontroller is
configured in Mode1 for producing the 65mS delay. 65mS is the width of each control pulse.

Label Operands Remarks

A1 EQU P1.0 ; define phase


A2 EQU P1.1
A3 EQU P1.2
A4 EQU P1.3
ORG 00H
MOV TMOD, #00000001B
MAIN: CLR A1
ACALL DELAY
SETB A1
CLR A2
ACALL DELAY
SETB A2
CLR A3
ACALL DELAY
SETB A3
CLR A4
ACALL DELAY
SETB A4
SJMP MAIN
DELAY: MOV R6, #1D
BACK: MOVTH0, #00000000B
MOV TL0, #00000000B
SETB TR0
HERE2: JNB TF0, HERE2
CLR TR0
CLR TF0
DJNZ R6, BACK
RET
END

Exercises:
1. Drawconnection between a unipolar stepper motor and a microcontroller 8051, and develop an
assembly language program to rotate the motor continuously.

Safety and necessary Precautions:


1. Do not start the computer without instructions

Procedure:
1. Open Keil uVision software and create a new project.
2. Select the target device and configure the project settings.
3. Write the program code in C or assembly language using the Keil IDE.
4. Build the program and check for errors or warnings.

Conclusion:
Quiz:
1. List the types of stepper motors that is commonly used for interfacing with a Microcontroller
8051.
2. State the purpose of the LOOP subroutine in the program.
3. Discuss the importance of properly debouncing the input signals from a matrix keypad.
4. Propose modifications that can be made to the program to make the motor rotate in the
opposite direction.
5. Discuss the consequences of having a delay that is too short between the steps of the motor.
6. Discuss any limitations or restrictions associated with using a unipolar stepper motor in
controlling rotational motion.

Suggested Reference: Ch-2, 3, 4 & 17, The 8051 Microcontroller and Embedded Systems Using
Assembly and C,2ndedition by Muhammad Ali Mazidi.

References used by the students:

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total

Marks

Rubrics:
1. Group work while performing experiment on computer.
2. Understand the concept while performing coding.
3. Understanding of stepper motor interfacing with microcontroller.
4. Debugging and testing skills.
5. Quiz answers and submission in time.
Suggested Project / Case study
Suggested Project:
 Traffic Light Controller: Design a traffic light controller system using an 8051
microcontroller that can manage the timing and sequencing of traffic signals.
 Home Automation System: Develop a home automation system that can control home
appliances and devices using an 8051 microcontroller, such as lights, fans, air
conditioners, and security systems.
 Digital Clock with Alarm: Build a digital clock with an alarm function that can be
controlled using an 8051 microcontroller.
 Temperature Monitoring System: Develop a temperature monitoring system that can
measure and display the temperature of a room or environment using an 8051
microcontroller.
 Security System: Design a security system that can detect and alert you of intruders or
unauthorized access using an 8051 microcontroller.
 Water Level Controller: Develop a water level controller system that can automatically
control the water level in a tank or reservoir using an 8051 microcontroller.
 Smart Energy Meter: Build a smart energy meter that can monitor and track the energy
consumption of a home or building using an 8051 microcontroller.
 RFID Based Access Control System: Develop an access control system that uses RFID
technology to grant access to authorized users using an 8051 microcontroller.
 Automatic Door Opener: Design an automatic door opener system that can automatically
open and close doors using an 8051 microcontroller.
 Automated Car Parking System: Develop an automated car parking system that can guide
and park cars in a parking lot using an 8051 microcontroller.

Suggested Case Study:


 Design of an Automatic Room Light Controller with Visitor Counter using 8051
Microcontroller
 Real Time Clock Based Digital Clock using 8051 Microcontroller
 Development of a Smart Home Automation System with 8051 Microcontroller
 Design and Implementation of a Temperature Control System using 8051 Microcontroller
 Automatic Water Level Controller with Alarm System using 8051 Microcontroller
 Design of a Traffic Light Controller using 8051 Microcontroller
 Design and Implementation of a Smart Vehicle Parking System using 8051
Microcontroller
 Development of a Digital Tachometer using 8051 Microcontroller
 Design and Implementation of a Wireless Notice Board using 8051 Microcontroller
 Design of a Smart Energy Meter using 8051 Microcontroller

You might also like