Flowchart
Flowchart
Flowchart
for
Microcontroller and
Applications
(22426 )
Semester-IV
Maharashtra State
Board of Technical Education, Mumbai
(Autonomous) (ISO 9001:2015) (ISO/IEC 27001:2013)
(Printed on November 2018)
Maharashtra State
Board of Technical Education
Certificate
This is to certify that Mr. / Ms …………………………………….
Roll No……………………….of ………… Semester of Diploma
in ……………………………………………………. of Institute
…………………………………………. (Code………………..)
has attained pre-defined practical outcomes(PROs) satisfactorily
in course Microcontroller and Applications (22426) for the
academic year 20…….to 20…..... as prescribed in the curriculum.
Seal of the
Institute
Microcontroller & Application (22426)
Preface
The primary focus of any engineering laboratory/ field work in the technical education
system is to develop the much needed industry relevant competencies and skills. With this in
view, MSBTE embarked on this innovative ‘I’ Scheme curricula for engineering diploma
programmes with outcome-base education as the focus and accordingly, relatively large amount
of time is allotted for the practical work. This displays the great importance of laboratory work
making each teacher; instructor and student to realize that every minute of the laboratory time
need to be effectively utilized to develop these outcomes, rather than doing other mundane
activities. Therefore, for the successful implementation of this outcome-based curriculum, every
practical has been designed to serve as a ‘vehicle’ to develop this industry identified competency
in every student. The practical skills are difficult to develop through ‘chalk and duster’ activity in
the classroom situation. Accordingly, the ‘I’ scheme laboratory manual development team
designed the practicals to focus on the outcomes, rather than the traditional age old practice of
conducting practicals to ‘verify the theory’ (which may become a byproduct along the way).
This laboratory manual is designed to help all stakeholders, especially the students,
teachers and instructors to develop in the student the pre-determined outcomes. It is expected
from each student that at least a day in advance, they have to thoroughly read through the
concerned practical procedure that they will do the next day and understand the minimum
theoretical background associated with the practical. Every practical in this manual begins by
identifying the competency, industry relevant skills, course outcomes and practical outcomes
which serve as a key focal point for doing the practical. The students will then become aware
about the skills they will achieve through procedure shown there and necessary precautions to be
taken, which will help them to apply in solving real-world problems in their professional life.
This manual also provides guidelines to teachers and instructors to effectively facilitate
student-centered lab activities through each practical exercise by arranging and managing
necessary resources in order that the students follow the procedures and precautions
systematically ensuring the achievement of outcomes in the students.
Microcontroller is used in almost all the domestic, industrial, consumer goods and other
high end products. Automation is used in every field of engineering and microcontroller is
inbuilt element of these systems and devices. Diploma engineers have to deal with various
microcontroller based systems and maintain them. This course is intended to develop the skills to
maintain and solve the application problems related to microcontrollers.
Although all care has been taken to check for mistakes in this laboratory manual, yet it is
impossible to claim perfection especially as this is the first edition. Any such errors and
suggestions for improvement can be brought to our notice and are highly welcome.
PO1. Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering
to solve the broad-based Electronics and Telecommunication engineering problems.
PO3. Experiments and practice: Experiments and practice: Plan to perform experiments and
practices to use the results to solve broad-based Electronics and Telecommunication engineering
problems.
PO4. Engineering tools: Apply relevant Electronics and Telecommunications technologies and
tools with an understanding of the limitations
PO5. The engineer and society: Assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to practice in field of Electronics and Telecommunication
engineering.
PO7. Ethics: Apply ethical principles for commitment to professional ethics, responsibilities and
norms of the practice also in the field of Electronics and Telecommunication engineering.
PO8. Individual and team work: Function effectively as a leader and team member in diverse/
multidisciplinary teams.
PO10. Life-long learning: Engage in independent and life-long learning activities in the context
of technological changes also in the Electronics and Telecommunication engineering and allied
industry.
PSO2. EDA Tools Usage: Use EDA tools to develop simple Electronics and
Telecommunication engineering related circuits.
Pro. CO CO CO CO CO
Practical Outcomes (PrO)
No. a. b. c. d. e.
Guidelines to Teachers
1. Teacher is expected to refer complete curriculum document and follow guidelines for
implementation
2. Teacher should provide the guideline with demonstration of practical to the students
with all features.
3. Teacher shall explain prior concepts to the students before starting of each practical
4. Involve students in performance of each practical.
5. Teacher should ensure that the respective skills and competencies are developed in the
students after the completion of the practical exercise.
6. Teachers should give opportunity to students for hands on experience after the
demonstration.
7. Teacher is expected to share the skills and competencies to be developed in the
students.
8. Teacher may provide additional knowledge and skills to the students even though not
covered in the manual but are expected the students by the industry.
9. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions.
10. Assess the skill achievement of the students and COs of each unit.
11. At the beginning Teacher should make the students acquainted with any of the
simulation software environment as few experiments are based on simulation.
12. It is desirable to paste the photo of actual experimental setup or draw block diagram of
experimental setup.
13. Practical No.1 should not be consider for Practical (ESE-End Semester Exam).
Content Page
List of Practicals and Progressive Assessment Sheet
Sr Date of Date of Dated Remar
Page Assessment
No Title of the practical perfor submiss sign. of ks (if
No. marks(25)
mance ion teacher any)
Total Marks
V Practical Outcome
Identify various blocks of 8051 microcontroller development board.
Keil IDE:
Keil is 8051 development tool which includes a text Editor, Assembler Debugger, linker,
Simulator, C-complier, hex converter, locator and some in-built features like logic
analyzer to observe various waveforms. It also includes terminal emulator. Keil supports
all 8051 derivatives and valuable tool for embedded software development.
Sr. Instrument
Specification Quantity
No. /Components
Single board system with 8K RAM,ROM memory
with battery backup,16X4,16X2LCD display, PC
Microcontroller
1. keyboard interfacing facility, Hex keypad facility, 1 No.
kit
single user cross c-compiler,RS-232,USB, interfacing
facility with built in power supply.
2. Desktop PC Loaded with open source IDE, simulation and program
1 No.
downloading software.
IX Precautions to be Followed
Do not power up development board when identifying blocks.
X Procedure
Steps for creating a project using Keil software:
1. Start Keil by double clicking on Keil icon. (Keil automatically opens the last project
which was opened previously, when Keil was closed).
“Select device for Target Target-1” window will open. It displays a list of manufacturers of
microcontrollers.
Double click on ATMEL or INTEL, list of supported microcontrollers gets displayed.
Select 80C51AH from INTEL or AT89C51 (or as per the target board) for ATMEL then
click ok.
Click file pull down menu. Select new, a text editor window will open. Save this file in a
same folder where project was stored. Give extension as .ASM or. A51.
On left hand project work space window will display Target1 and Source group1.
Right click on source group; Add files to source group 1.
Select file type as asm source file. Now all .asm file Name will be displayed. Select appropriate
file, click ADD and close.
Project work space window will display ‘Target 1’ and ‘Source group 1’ with added file name.
Type assembly language program. End with END directive. Save the file periodically.
Right click on source group, click on Build target or press F7.
Output window will display the errors if any. If there are some errors, then remove the errors
and repeat from step number 12 until no errors.
This step is optional for the experiments which need only simulation method to observe
the results.
To start the simulation. Click on Debug pull down. Then select start/Stop debug session
On start of debug session, project window will display all internal registers of 8051 and their
contents. To execute the program step by step, go no clicking on “step over” button.
Observe the logic levels of port pins, timers, interrupt etc, by clicking on Peripherals and select
appropriate.
Execute the program step by step and observe the logic levels on port pins.
Observe the serial communication by clicking VIEW pull down and select serial window-1
Option.
Please note that the features of Sr. no.16 to 18 are available only in debug mode.
XI Resources used
2.
XII Actual procedure followed (use blank sheet provided if space is not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XVI Interpretation of Results (Hardware and software features of 8051 development board
and Keil)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
1. …………………………………..
2. …………………………………..
3. …………………………………..
4. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Related Product Total
(15) Related (10) (25)
I Practical Significance
The addressing modes specifies the way data can be moved or copied from source to
destination location thus providing various options and flexibility for data transfer. This
practical will help the students to develop skills to allow the programmer to write
structured program which is essential to code maintainability.
V Practical Outcome
Write sample assembly language program using various addressing modes and
assembler directives.
1. Immediate addressing mode: The data is provided in instruction itself. The data is
identified by #before the numerical value
Ex: MOV A, #05H (The immediate date 05h provided in instruction is moved into A
register).
2. Register addressing mode: The registers hold the data. The permitted registers are
A, R7-R0 of each register bank.
Ex: MOV A, R0 content of R0 register is copied into Accumulator.
3. Direct addressing mode: The data is in the RAM memory location and this address
is given as part of instruction.
Ex: MOV A, 30H Content of RAM address 30H is copied into Accumulator.
5. Register specific mode: The operand is specified by certain specific registers such as
accumulator or DPTR
Ex: RRA Rotate the contents of accumulator to the right
6. Indexed Addressing mode: This addressing mode is basically used for accessing
data from look up table. Here the address of memory is indexed.
Ex: MOVC A, @A+DPTR. The content of A register is added with content of DPTR
and the resultant is the address of memory location from where the data is copied to A
register.
Assembler Directives:
The assembler directives are instructions to the assembler to carry out certain activity
during the assembly process. The common assembler directives are:
ORG indicates the beginning of the address
DB used to define 8-bit data in decimal, binary, hexadecimal, ASCII formats
EQU used to define a constant without occupying a memory location
END indicates end of the source file
Sr. Instrument
Specification Quantity
No. /Components
IX Precautions to be Followed
1. Check rules / syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window. It will display all internal registers of 8051
and their contents.
11. Note the contents of the registers in observation table.
Step 1-Algorithm
1. Start
2. Move the immediate data 23H into accumulator
3. Initialize R1 with memory location 30H
4. Move the content of the accumulator to the memory location pointer by R1.
5. Stop
Fig 2.1 Flowchart to move data from accumulator to memory location 30h
Memory Hex
Label Mnemonics Comments
Address Code
ORG 0000H
C:0x0000 7423 MOV A, #23H ;Move the data 23h into accumulator
C:0x0002 7930 MOV R1, #30H ;Move the address 30 h into register R1
C:0x0004 ;Move the contents of accumulator in
F7 MOV @R1, A
30h memory location
END ;Stop
Step 1-Algorithm
Start.
Use ORG directive to set memory location at 0000H.
Use data directive to write data 27h at memory location 0000H.
Initialize data pointer to memory location 0000H.
Clear contents of Accumulator.
Move into accumulator a byte of data located at address pointed by DPTR.
Initialize Data pointer to new memory location 2000H.
Move the contents of Accumulator to address pointed by DPTR.
Stop
Step 2-Flowchart
Problem statement #1 for student: Write a program to transfer the data 25h into register R2 of
Bank 0 and register R2 of Bank 1 using immediate and register addressing mode.
Memory
Hex Code Label Mnemonics Comments
Address
XI Resources Used
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations
After execution of sample program 1 After execution of sample program 2
Accumulator Accumulator
R1 DPTR
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XIX References / Suggestions for further reading
1. The 8051 Microcontroller and Embedded system Using Assembly and C-
Muhammad Ali Mazidi, Janice Gillispie Mazidi, Rolin D. Mckinlay- Pearson
/Prentice Hall, , 2nd edition, Delhi,2008, ISBN 978-8177589030
2. https://nptel.ac.in/courses/Webcourse-contents/IISc-
BANG/Microprocessors%20and%20Microcontrollers/pdf/Teacher_Slides/mod2/M2L
2.pdf
3. https://nptel.ac.in/courses/Webcourse-contents/IIT-
KANPUR/microcontrollers/chap2.pdf
XX Assessment Scheme
Performance Indicators Weightage
Process related: 15 Marks 60%
1 Use of IDE tools for programming 20%
2 Coding and Debugging ability 30%
3 Follow ethical practices. 10%
Product related: 10 Marks 40%
4 Correctness of algorithm/ Flow chart 20%
5 Relevance of output of the problem definition 15%
6 Timely Submission of report, Answer to sample 05%
questions
Total (25 Marks) 100 %
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
V Practical Outcome
Write an assembly language program (ALP) to perform arithmetic operations:
addition, subtraction, multiplication and division.
8051 uses DPTR, a 16 bit register to access the 16-bit data from external memory. It is used in
MOVX, MOVC command
Arithmetic operations affect flags in PSW register of 8051
Sr.
Instrument /Components Specification Quantity
No.
1 Desktop PC Loaded with open source IDE, simulation 1 No.
and program downloading software
IX Precautions to be Followed
1. Check rules / syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL and select AT89C51.
5. Type the program in text editor and save as filename.asm extension.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window.
11. Note the values of the result of various operations in the observation table.
Step 1-Algorithm
1. Move value 02 H in accumulator.
2. Add 03 H to the number stored in accumulator (02 H).
3. Move contents of accumulator to R0 register.
4. Clear accumulator.
5. Move number 05 H in accumulator.
6. Subtract value stored in accumulator (05 H) with 02 H.
7. Move contents of accumulator to register R1.
8. Clear accumulator and carry flag.
9. Move 03H in accumulator, 02H in register B.
10. Multiply the two numbers.
11. Store product in R2 and R3.
12. Clear accumulator.
13. Move 95 H and 10 H in registers A and B.
14. Divide the two numbers.
15. Move result in R4 and R5
16. Stop
Memory Hex
Label Mnemonics Comments
Address Code
ORG 0000H
C:0x0000 7402 MOV A, #02H ;Move the data 02h in accumulator
;Add the contents of accumulator
C:0x0002 2403 ADD A, #03H
with 03h
C:0x0004 F8 MOV R0, A ;Store the result in R0 register
C:0x0005 E4 CLR A ;Clear the contents of accumulator
C:0x0006 C3 CLR C ;Clear the carry flag
C:0x0007 7405 MOV A, #05H ;Move the data 05h in accumulator
;Subtract the contents of
C:0x0009 9402 SUBB A, #02H
accumulator and 02h
C:0x000B F9 MOV R1, A ;Store the result in R1 register
C:0x000C E4 CLR A ;Clear the contents of accumulator
C:0x000D 7403 MOV A, #03H ;Move the data 03h in accumulator
C:0x000F 75F0 MOV B, #04H ;Move the data 04h in accumulator
C:0x0011 A4 MUL AB ;Multiply the contents of A and B
C:0x0012 FA MOV R2, A ;Store the result (LSB) in R0
C:0x0013 ABF0 MOV R3, B ;Store the result (MSB) in R1
C:0x0015 E4 CLR A ;Clear the contents of accumulator
C:0x0016 7495 MOV A, #95H ;Move the data 95h in accumulator
C:0x0018 75F010 MOV B, #10H ;Move the data 10h in accumulator
C:0x001B 84 DIV AB ;Divide the contents of A and B
C:0x001C FC MOV R4, A ;Store the quotient in R4 register
C:0x001D ADF0 MOV R5, B ;Store the Remainder in R5 register
END ;Stop
Problem statement 1 for student: Write a program to perform series addition of ten bytes and
store the lower byte of result in 30h and higher byte of result in 31h
XI Resources Used
1.
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations for sample program (use blank sheet provided if space not sufficient)
Sr. No. Register used in the Operation Result after
code execution
1 R0 Addition
2 R1 Subtraction
3 R2 Multiplication (LSB)
4 R3 Multiplication (MSB)
5 R4 Division (Quotient)
6 R5 Division (Remainder)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
Dated signature
Marks Obtained
of Teacher
Process Product Related Total
Related (10) (25)
(15)
V Practical Outcome
Write an ALP to transfer data from source to destination location of internal/external
data memory.
Sr. Instrument
Specification Quantity
No. /Components
Loaded with open source IDE,
Desktop PC
1. simulation and program downloading 1 No.
software
IX Precautions to be Followed
1. Check rules/syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window. It will display all internal registers of 8051
and their contents.
Step 1: Algorithm
1. Set program starting address.
2. Initialize memory pointer as source.
3. Initialize memory pointer as destination
Step 2: Flowchart
Memory
Hex Code Label Mnemonics Comments
Address
C:0x0000 ORG 0000H
C:0x0000 7820 MOV R0,#20H ;Initialize source pointer R0 to 20H
C:0x0002 7940 MOV R1, #40H ;Initialize destination pointer R1 to
40H
C:0x0004 7F05 MOV R7, #05H ;Initialize byte counter
C:0x0006 E6 UP: MOV A, @R0 ;Move the contents of first source
location to Accumulator
C:0x0007 F7 MOV @R1,A ;Move the contents of Accumulator
to first destination location
C:0x0008 08 INC R0 ;Increment the contents of R0
C:0x0009 09 INC R1 ;Increment the contents of R1
C:0x000A DFFA DJNZ R7, UP ; Decrement counter by one Is it
zero? No ,jump to UP
END
Problem statement 1 for student: Write a program to transfer a block of five bytes from
internal memory location 40H to external memory location 2000H
XI Resources Used
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations for problem statement 1 (use blank sheet provided if space not sufficient)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
Dated signature
Marks Obtained
of Teacher
Process Product Related Total
Related (15) (10) (25)
Practical No. 5: Write ALP to find smallest / largest number from the given
data bytes stored in internal/external data memory locations
I Practical Significance
CJNE and DJNZ instructions of 8051 microcontroller perform two tasks in a single
instruction. The application of these instructions can be demonstrated in finding the
smallest and largest numbers from a block of numbers. This practical will help the
students to develop skills to use the compare and loop instructions.
V Practical Outcome
Write ALP to find smallest/largest number from the given data bytes stored in
internal/external data memory locations
Sr. Instrument
Specification Quantity
No. /Components
Loaded with open source IDE,
Desktop PC
1. simulation and program downloading 1 No.
software
IX Precautions to be Followed
1. Check rules / syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window. It will display all internal registers of 8051
and their contents.
11. Note down the readings in observation table
SAMPLE PROGRAM 1: Write ALP to find smallest number from the given five bytes stored
in internal memory locations 40H onwards and store the result in location 50H.
Step 1: Algorithm
1. Initialize source pointer R0 to 40H.
2. Initialize byte counter.
3. Load Accumulator with largest one byte number.
4. Move the contents of source location to B register.
5. Compare the two numbers.
6. If number is less then next number then go to step 8.
7. Replace number with next number which is largest.
8. Increment memory pointer to read next number in the array.
9. Decrement byte counter by 1.
10. If byte counter is not zero go to step 4.
11. Store the result.
12. Stop
Step 2: Flowchart
Memory
Hex Code Label Mnemonics Comments
Address
ORG 0000H
C:0x0000 7840 MOV R0,#40H ;Initialize source pointer R0 to 40H
C:0x0002 7905 MOV R1, #05H ;Initialize byte counter
C:0x0004 74FF MOV A, #0FFH
C:0x0006 86F0 UP: MOV B,@R0 ;read first byte to B register
C:0x0008 B5F000 CJNE A,B, ;compare first byte to max value
DOWN
C:0x000B 4002 DOWN: JC A_SMALL ;check carry
C:0x000D E5F0 MOV A,B ;move small value to A
C:0x000F 08 A_SMALL: INC R0 ;Increment the contents of R0
C:0x0010 D9F4 DJNZ R1, UP ; Decrement counter by one Is it
zero? No ,jump to UP
C:0x0012 F550 MOV 50H, A ;store smallest number to 50H
C:0x0014 80FE SJMP $ ;Halt after the smallest value is
available
END
Problem statement for student: Write ALP to find largest number from the given five bytes
stored in memory locations 20H onwards and store the result in location 60H
Memory
Hex Code Label Mnemonics Comments
Address
XI Resources Used
Sr.
Name of Resource. Specification Quantity
No.
1
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations for sample program (use blank sheet provided if space not sufficient)
Before execution After execution
Memory location Data Memory location Data
40H
41H
42H 50H
43H
44H
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
V Practical Outcome
Write ALP for arranging numbers in ascending /descending order stored in external
memory locations
Branch instructions like JNC—jump if no carry and CJNE—compare and jump if not
equal to are used to sort the numbers.
External data memory is read/write. Since external data memory is indirectly accessed
through a data pointer register (which must be loaded with an address), it is slower than
access to internal data memory.
DPTR, as the name suggests, is used to point to data. It is used by a number of commands
which allow the 8051 to access external memory. When the 8051 accesses external
memory it will access external memory at the address indicated by DPTR.
MOVX instruction
MOVX is a widely used instruction allowing access to external data memory space. To
bring externally stored data into the CPU, we use the instruction “MOVX A, @DPTR”.
This instruction will read the byte of data pointed to by register DPTR and store it in the
accumulator
Sr. Instrument
Specification Quantity
No. /Components
Desktop PC Loaded with open source IDE, simulation and
1 1 No.
program downloading software
IX Precautions to be Followed
1. Check rules / syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
SAMPLE PROGRAM 1: Write ALP for arranging five numbers in ascending order stored in
external memory location 3000H.
Step 1-Algorithm
1. Initialize comparison or pass counter
2. Initialize memory pointer to read number from array
3. Initialize byte counter
4. Read numbers from the array
5. Compare two numbers.
6. If number <=next number, then go to step 9.
7. Interchange or swap numbers.
8. Increment memory pointer to read next number from array.
9. Decrement byte counter by one.
10. If word counter is not equal to zero, then go to step 2.
11. Stop
ORG 0000h
C:0x0000 7805 UP1: MOV R0, #05H ;Initialize pass counter
MOV DPTR, ;Initialize memory pointer
C:0x0002
903000 #3000H
C:0x0005 7904 UP: MOV R1, #04H ;Initialize byte counter
C:0x0007 AA82 MOV R2, DPL ;Save the lower byte address
C:0x0009 E0 MOVX A, @DPTR ;Read number from array
C:0x000A ;Transfer the number to B
F5F0 MOV 0F0H, A register
C:0x000C A3 INC DPTR ;Increment memory pointer
C:0x000D E0 MOVX A, @DPTR ;Read next number from array
C:0x000E ;Compare number with next
B5F002 CJNE A, 0F0H, DN number
C:0x0011 011C AJMP SKIP
C:0x0013 ;If number>next number then
5007 DN: JNC SKIP go to SKIP
C:0x0015 ;Else exchange the number with
8A82 MOV DPL, R2 next number
C:0x0017 F0 MOVX @DPTR, A
C:0x0018 A3 INC DPTR
C:0x0019 E5F0 MOV A, 0F0H
C:0x001B F0 MOVX @DPTR, A
C:0x001C ;Decrement byte and if count
D9E7 SKIP: DJNZ R1, UP byte is not zero go to Up
C:0x001E ;Decrement pass counter and if
D8E0 DJNZ R0, UP1 not zero go to UP1
END
1) Problem statement for student: Write ALP for arranging five numbers in descending order
stored in external memory location 2000H.
.
Step 1-Algorithm Step 2-Flowchart
XI Resources Used
1.
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations for sample program (use blank sheet provided if space not sufficient)
3000H 3000H
3001H 3001H
3002H 3002H
3003H 3003H
3004H 3004H
3005H 3005H
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XIV References / Suggestions for further reading
1. http://nptel.ac.in/courses/Webcourse-contents/IIT-
KANPUR/microcontrollers/micro/ui/Course_home2_6.htm
2. https://www.youtube.com/watch?v=FOx8X8U4AXE
3. https://thinkelectronics.org/8051-program-arrange-numbers-ascending-order/
4. https://www.pearson.com/us/higher-education/product/Mazidi-8051-Microcontroller-
and-Embedded-Systems-The/9780138610227.html
XX Assessment Scheme
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related (15) Related (10) (25)
V Practical Outcome
Write an ALP to generate delay using register.
Very often the 11.0592 MHz crystal oscillator is used to make the 8051 -based system
compatible with the serial port of the IBM PC. In the original 8051, one machine cycle
lasts 12 oscillator periods. Therefore, to calculate the machine cycle for the 8051, we take
1/12 of the crystal frequency, then take its inverse, as shown below:
For 11.0592MHz/12 = 921.6KHz; machine cycle is 1/921.6KHz=1.085microsecond
Various 8051 versions and its clocks per machine cycle are as shown below:
2. USING TIMER: Many times, we require precise internal time delays between two
actions this can be accomplished using software techniques like Loop Technique, but
these delays keep the processor occupied because of which other important functions
cannot be done. To relieve the processor of this burden we can use TIMERS provided by
the controller. 8051 has two internal timers T0 and T1 (8052 has 3 timers T0, T1 and T2)
these timers can be controlled individually.
The following example explains how to calculate time delay for Loop method:
Solution:
The time delay inside the HERE loop is [250(1 + 1 + 1 + 1 + 2)] x 1.085 µsec=1500 x
1.085 µsec = 1627.5 µsec. Adding the two instructions outside the loop we have 1627.5
µsec + 3 x l.085 µsec = 1630.755 µsec
Sr. Instrument
Specification Quantity
No. /Components
1 Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software
IX Precautions to be Followed
1. Check rules / syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window. It will display all internal registers of 8051
and their contents.
11. Observe the waveform on logic analyzer and sketch the same in observations
SAMPLE PROGRAM 1: Write a program to toggle all the bits of port 1 every 200 ms.
Crystal frequency is 11.0592 MHz
Step- Algorithm
1. Move the contents 55H into accumulator.
2. Send the contents of Accumulator to port P1.
3. Call delay routine
4. Complement the contents of accumulator.
5. Jump back to repeat the steps.
6. Write a delay routine for 200 msec.
Memory Hex
Label Mnemonics Comments
Address Code
ORG 0000H
C:0x0000 800D SJMP START
C:0x0002 7D02 DELAY: MOV R5, #2 ;DELAY routine for 200 msec
C:0x0004 7CB4 HERE1: MOV R4, #180
C:0X0006 7BFF HERE2: MOV R3, #255
C:0X0008 DBFE HERE3: DJNZ R3, HERE3
C:0X000A DCFA DJNZ R4, HERE2
C:0x000C DDF6 DJNZ R5, HERE1
C:0x000E 22 RET
;Load the data 55h into
C:0x000F 7455 START: MOV A, #55H accumulator
C:0X0011 F590 AGAIN: MOV P1, A ;Send the contents of A to P1
C:0x0013 1102 ACALL DELAY ;Call Delay routine
C:0x0015 F4 CPL A ;Complement the contents of A
C:0x0016 80F9 SJMP AGAIN ;Branch to Again
END ;Stop.
Memory Hex
Address Label Mnemonics Comments
Code
XI Resources Used
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations for sample program (use blank sheet provided if space not sufficient)
Draw the waveform and mention the delay
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XIX References / Suggestions for further reading
1. The 8051 Microcontroller and Embedded system Using Assembly and C- Muhammad
Ali Mazidi, Janice Gillispie Mazidi, Rolin D. Mckinlay- Pearson /Prentice Hall, , 2nd
edition, Delhi,2008, ISBN 978-8177589030
2. https://www.youtube.com/watch?v=TWMai3oirnM
XX Assessment Scheme
Performance Indicators Weightage
Process related: 15 Marks 60%
1 Use of IDE tools for programming 20%
2 Coding and Debugging ability 30%
3 Follow ethical practices. 10%
Product related: 10 Marks 40%
4 Correctness of algorithm/ Flow chart 20%
5 Relevance of output of the problem definition 15%
6 Timely Submission of report, Answer to sample questions 05%
Total (Marks) 100 %
Name of Team Members
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated signature of
Marks Obtained
Teacher
Process Related Product Related Total
(15) (10) (25)
Practical No. 8: Write an ALP to transfer 8-bit data serially on serial port.
I Practical Significance
Many applications require microcontrollers to either accept the data in serial form or
output the data in serial form. Serial communication is commonly used in applications
such as industrial automation systems, scientific analysis and certain consumer products.
This practical will help the students to develop skills to understand the concepts of serial
port and how they are interfaced with microcontroller.
V Practical Outcome(PROs)
Write an ALP to transfer 8 bit data serially on serial port
For serial communication SCON SFR is used. It controls the serial bits.
SCON REGISTER:
Baud Rate
In serial communication the rate at which data bits are transmitted generates a term baud rate, the
baud rate is defined as bits/seconds or the changes in voltage levels/second.
Table No: 8.1 Values of Timer 1 Register for various Baud Rates
Baud Rate TH1(Decimal) TH1(Hex)
9600 -3 FD
4800 -6 FA
2400 -12 F4
1200 -24 E8
Note: XTAL = 11.0592 MHz.
SBUF Register
Serial buffer SFR is used for selection of baud rate in serial communication.
SBUF is a 8 bit register used in serial communication of 8051.Serial data is send by writing to
the register SBUF while data i s received by reading the same register. The SBUF is as
shown below:
Bit 7 Bit 0
SBUF has physically two registers, one write only and other is read only. Both registers use
one address 99H
A line driver such as the MAX232 chip is required to convert RS232 voltage levels to TTL
levels, and vice versa. 8051 has two pins that are used specifically for transferring and receiving
data serially. These two pins are called TXD and RXD and are part of the port 3 group (P3.0 and
P3.1) these pins are TTL compatible; therefore, they require a line driver to make them RS232
compatible.
Sr. Instrument/
Specification Quantity
No. Components
IX Precaution
Check rules / syntax of assembly programming.
X Procedure
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window. It will display all internal registers of 8051
and their contents. The output can be observed in UART1 window.
11. Hyper Terminal, a Windows XP application, can be used to receive or transmit serial
data through RS232. To open Hyper Terminal, go to Start Menu, select all programs,
go to Accessories, click on Communications and select Hyper Terminal.
12. To start a new connection, go to File menu and click on new connection. The
connection window opens up. Give a name to your connection and select 1st icon and
click on OK. Connection property window opens here. Select Bit rate as 9600bps,
Data bits 8, Parity as none, stop bit 1, Flow control none and click OK. Now the serial
data can be read on hyper terminal.
13. In program, Timer1 is used with auto reload setting. The baud rate is fixed to 9600bps
by loading TH1 to 0xFD. The value 0x50 is loaded in the SCON register. This will
initialize the serial port in Mode1. The program continuously receives a character (say
‘a’) from the serial port of the computer and transmits it back
SAMPLE PROGRAM 1: Write an ALP to transfer 8 bit data serially on serial port.
Step 1: Algorithm
Step 2: Flowchart
Problem statement 1 for student: Write a program to transfer to send letter “YES” at baud rate
9600 continuously.
XI Resources Used
2.
XII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIII Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Observations for sample program (use blank sheet provided if space not sufficient)
(UART window)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated signature
Marks Obtained
of Teacher
Process Product Total
Related (15) Related (10) (25)
V Practical Outcome
Interface LED with microcontroller and turn it ON with microcontroller interrupt.
disabled using the IE register when the external interrupt flag is edge triggered, the CPU
clears interrupt flag in response to the interrupt call. When it is level triggered then the
interrupt flag is cleared at high level of the interrupt signal.
Light emitting diodes: LEDs are the most commonly used components in many
applications. It has two terminals positive and negative as shown in the figure:
Commonly used LEDs will have voltage drop of 1.9v to 2.1v and current of 15mA
(Typically) or 20mA(high brightness) to glow at full intensity. This is applied through the
output pin of the microcontroller
b) Practical setup
Fig 9.4
Practical Setup
c) Simulation diagram
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1. Microcontroller Single board system with 8K RAM,ROM 1 No.
kit memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
keypad facility, single user cross c-compiler,RS-
232,USB, interfacing facility with built in power
supply.
2. Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software.
X Precautions to be followed
1. Use always current limiting resistor before LED connected to microcontroller
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (Keil IDE) or
any other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the program.
7. Download hex code in EPROM/Flash memory of microcontroller.
8. Interface LED to microcontroller as per circuit diagram shown in fig.
9. Observe the LED to glow when external interrupt occurs on P3.2.
Step 1: Algorithm
Main Program
1. Initialize port P1 as output.
2. Initialize port P3 as input.
3. Clear pin P1.1
4. Enable interrupt INT0.
5. Wait for Interrupt.
INT0 ISR
1. Set pin P1.1
2. Return from ISR
Step 2: Flowchart
Problem statement for student Interface two LEDs with microcontroller and turn them ON
with microcontroller interrupts.
Step 1: Algorithm Step 2: Flowchart
2.
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated signature of
Marks Obtained
Teacher
Process Related Product Total
(15) Related (10) (25)
Practical No. 10: Develop an ALP to generate pulse and square wave by using
Timer delay.
I Practical Significance
In 8051 timers are used to generate delays or as counters to count events happening
outside the microcontroller. In time required applications two available 16 bit timers are
operated in different modes to generate specific delay. This practical will help the
students to develop skills to program timers and generate delays.
V Practical Outcome
Develop an ALP to generate pulse and square wave by using Timer delay.
Timer0: 16 bit
Timer1: 16 bit
Gate: If bit is set Timer/counter is enable only while the INTx pin is high and the TRx control
pin is set when cleared the timer is enabled whenever the TRx control bit is set
C/T’: Timer or counter selected. Cleared for timer operation( input from internal system clock)
Set for counter operation(input from Tx input pin)
M1 Mo:
0 0 – Mode 0 -13 bit timer mode
0 1 – Mode 1 -16 bit timer mode
1 0 – Mode 2 -8 bit auto reload
11 – Mode 3 –Split timer mode
Clock source for timer
Timer needs a clock pulse to tick. For the 8051 timers if C/T’ = 0, the crystal frequency is
attached to the 8051 is the source of the clock for timer. Timer’s use 1/12 of XTAL frequency,
regardless of machine cycle time
Find the timer’s clock frequency and its period for 8051; If XTAL frequency = 11.0592 MHz
1/12 x 11.0592 MHz = 921.6 kHz;
T = 1/921.6 KHz = 1.085μs
TCON (timer control) Register: The timers are started by using instructions to set timer
Start bits TR0 and TR1, which are called timer run control bits. When timer counts to its
maximum value, it sets a flag TF0 or TF1
Timer Mode 1:
b) Simulation diagram
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1. Microcontroller Single board system with 8K RAM,ROM 1 No.
kit memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
keypad facility, single user cross c-compiler,RS-
232,USB, interfacing facility with built in power
supply.
2. Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software.
3. CRO Bandwidth AC 10Hz ~ 20MHz (-3dB). DC ~ 1 No.
20MHz (-3dB), X10 Probe
X Precautions to be followed
1. Check rules/syntax of assembly programming.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (Keil IDE) or
any other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the program.
7. Download hex code in EPROM/Flash memory of microcontroller.
8. Connect CRO probe to port pin and observe waveform.
9. Measure ON time and OFF time on CRO and draw the same in observation Table.
SAMPLE PROGRAM 1: To generate square wave by using Timer delay for count value
FFF2H.
Step 1: Algorithm
1. Load the TMOD value register indicating which timer (Timer 0 or Timer 1) is to be
used and which timer mode(0 or 1) is selected.
2. Load registers TL and TH with initial count values.
3. Start the timer.
4. Keep monitoring the timer flag (TF) with the “JNB TFx, target” instruction to see if it
is raised. Get out of the loop when TF becomes high.
5. Stop the timer.
6. Clear the TF flag for the next round.
7. Go back to Step 2 to load TH and TL again.
Step 2: Flowchart
Memory
Hex Code Label Mnemonics Comments
Address
ORG 0000h
C:0x0000 758901 MOV TMOD ,#01H ;Timer 0, mode 1
C:0x0003 758AF2 HERE: MOV TL0,#0F2H ;TL0=F2H
C:0x0006 758CFF MOV TH0,#0FFH ;TH0=FFH
C:0x0009 B295 CPL P1.5 ;toggle P1.5
C:0x000B 110F ACALL DELAY
C:0x000D 80F4 SJMP HERE ;load TH, TL again
C:0x000F D28C DELAY: SETB TR0 ;start Timer 0
;monitor Timer 0 overflow
C:0x0011 308DFD AGAIN: JNB TF0,AGAIN
flag until it rolls over
C:0x0014 C28C CLR TR0 ;stop Timer 0
C:0x0016 C28D CLR TF0 ;clear Timer 0 flag
C:0x0018 22 RET
END
Problem statement for student: Develop assembly program to generate pulse width of 5ms on
P2.3 using timer 0 mode1. Assume XTAL = 11.0592MHz
Sr.
Instrument /Components Specification Quantity
No.
1.
2.
3.
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
Draw Square wave and show TON and TOFF time
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
Performance Indicators Weightage
Process related(15 Marks) 60%
1 Coding and Debugging ability 30%
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated signature
Marks Obtained
of Teacher
Process Related Product Total
(15) Related (10) (25)
I Practical Significance
LED matrix displays are used as stadium displays, decorative displays and as visual
signals to human eye, to convey a message or meaning .LED matrix displays are
interfaced with microcontroller I/O port to display characters and different patterns. This
practical will help the students to develop skills to interface 4 X 4 LED matrix display to
microcontroller and display various pattern.
V Practical Outcome
Interface 4 X 4 LED matrix with 8051 to display various pattern.
Specifications: LED
1. Current: 20 mA
2. Voltage drop: 1.9 to 2.1 V
3. Power dissipation: 40 mW
4. Color: RED
Accessing individual LEDs: You turn on an individual LED by setting its row and column pins
to the proper logic 1. For example, referring to figure 11.2 LED matrix the switch in column 2 is
closed which ties the anodes of all of the LEDs in that column to positive voltage and on the left
the switch in row 1 is closed causing a ground level to be applied to the cathode of all of the
LEDs in that row. The LED at the intersection of column 2 and row 1 is forward biased and turns
on.
Fig 11.2 Addressing individual LED: 2nd column and 1st row
b) Simulation diagram
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1 Microcontroller Single board system with 8K RAM,ROM 1 No.
kit memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
keypad facility, single user cross c-
compiler,RS-232,USB, interfacing facility with
built in power supply.
2 Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software.
3 4 X4 LED Suitable to interface with 8051 trainer kit 1 No
matrix
X Precautions to be Followed
1. Always use driver circuit to interface LED matrix to microcontroller.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (Keil IDE) or
any other relevant software tool.
4. Debug program on IDE.
5. Simulate program on IDE.
6. Create hex file for the program.
7. Download hex code in EPROM/Flash memory of the microcontroller.
8. Interface4 X 4 LED matrix to 8051.
9. Observe different patterns on 4x4 LED matrix
SAMPLE PROGRAM 1: Write program to display various patterns on 4x4 LED matrix.
Step 1: Algorithm
1. Make port P2 used to interface 4x4 LED matrix as an output port.
2. Send F1H value to the port to turn ON first column all LED.
3. Add delay.
4. Send 1FH value to the port to display first row all LED.
5. Add delay.
6. Send 11H value to the port to display first column first row LED.
7. Add delay.
8. Send 88H value to the port to display fourth column fourth row LED.
9. Add delay.
10. For repeat operation go to step 2.
Step 2: Flowchart
Problem statement for student: Develop assembly program to turn ON and OFF all LEDs
connected to port 1 with some delay.
Memory
Hex Code Label Mnemonics Comments
Address
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
Maharashtra State Board of Technical Education 115
116
Microcontroller & Application (22426)
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX References / Suggestions for further reading
1. https://www.youtube.com/watch?v=-1UPPHjR0vk
2. https://www.youtube.com/watch?v=MmCGDJ90Qt4
3. https://www.youtube.com/watch?v=lZyc6ulpkyM
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related (15) Related (25)
(10)
Practical No. 12: Interface 7-segment display to display the decimal number
from 0 to 9.
I Practical Significance
In electronic displays like pricing menu at petrol pump, in metros, digital clocks and in
many electronics appliances most commonly used display device is a 7-segment display
(SSD). Seven segment displays are used to display decimal numbers from 0 to 9 and in
some cases, basic characters also. This practical will help the students to develop skills to
interface 7-segment display to microcontroller and display number from 0 to 9.
V Practical Outcome
Interface 7-segment display to display the decimal number from 0 to 9.
Specifications: 7-
segment display
Part No:
LDS-A516RI
Digit/Alpha:
Size:0.56" RED
Voltage drop across
per LED:2.2V
Max current per
LED: 10mA~20mA
Fig 12.1 Seven segment display Fig 12.2 CA 7-segment Peak wavelength
and pin configuration display constructional :660nm
diagram
LED segment is ON for logic ‘0’ (Ground) and OFF for logic ‘1’ (+5V).
b) Practical Setup
c) Simulation diagram
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1. Microcontroller
Single board system with 8K RAM,ROM memory with 1 No.
kit battery backup,16X4,16X2LCD display, PC keyboard
interfacing facility, Hex keypad facility, single user
cross c-compiler,RS-232,USB, interfacing facility with
built in power supply.
2. Desktop PC Loaded with open source IDE, simulation and program 1 No.
downloading software.
3. 7-segment LED 0.56 in 1-digit Red, common anode/common cathode 1No.
Display display.
X Precautions to be followed
1. Use always current limiting resistor before interfacing 7-segment display to
microcontroller.
2. For safe operation use seven segment displays at 25° temperature.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart.
3. Develop assembly program using Integrated Development Environment (Keil IDE) or
any other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file.
7. Download hex code in EPROM/Flash memory of microcontroller.
8. Interface CA type 7 segment display to microcontroller as per circuit diagram shown
in fig 12.4.
9. Observe and draw the display of numbers on 7-seven segment display.
10. Record the hex value in observation table.
Step 2: Flowchart
2.
3.
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
Sr. NO. Memory Location Hex Value
1 C:0x0200
2 C:0x0201
3 C:0x0202
4 C:0x0203
5 C:0x0204
6 C:0x0205
7 C:0x0206
8 C:0x0207
9 C:0x0208
10 C:0x0209
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
.
Dated signature
Marks Obtained
of Teacher
Process Product Total
Related Related (25)
(15) (10)
Practical No. 13: Interface relay with microcontroller and turn it ON and OFF
I Practical Significance
In Industrial applications low power devices microcontrollers drive relays are use to
control electrical loads beyond their direct drive capability. Relays are used wherever it is
necessary to control a high power or high voltage circuit with a low power circuit,
especially when galvanic isolation is desirable. Electromechanical protective relays are
used to detect overload and other faults on electrical lines by opening and closing circuit
breakers. This practical will help the students to develop skills to interface relay to
microcontroller and turn it ON and OFF.
V Practical Outcome
Interface relay with microcontroller and turn it ON and OFF.
b) Practical setup
c) Simulation diagram
XI Resources Required
Sr. Instrument
Specification Quantity
No. /Components
Microcontroller kit Single board systems with 8K RAM,ROM 1 No.
memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
1.
keypad facility, single user cross c-
compiler,RS-232,USB, interfacing facility
with built in power supply.
Desktop PC Loaded with open source IDE, simulation & 1 No.
2. program downloading software
3. Relay trainer board Suitable to interface with 8051 trainer kit 1 No.
X Precautions to be Followed
1. Use always driver circuit before interfacing relay to the microcontroller.
2. Use fly back diode to avoid voltage spikes.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (IDE) or any
other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the above program.
7. Download hex code in EPROM/Flash memory of microcontroller.
8. Interface relay to the microcontroller as per circuit diagram shown in Fig 13.4.
9. Observe the relay operation by connecting electrical load and note it in observation
Table 13.3
Problem statement for student: Develop assembly program to turn ON and OFF relay for 10
times.
1.
2.
3.
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
Performance Indicators Weightage
Process related(15 Marks) 60%
1 Coding and Debugging ability 30%
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated signature
Marks Obtained
of Teacher
Process Product Total
Related Related (10) (25)
(15)
Practical No. 14: Interface LCD with 8051 microcontroller to display the
characters and decimal numbers
I Practical Significance
LCDs are used in a wide range of applications including Computers,
televisions, instrument panels, calculator’s displays. They are common in consumer
devices and have replaced cathode ray tube (CRT) displays in most applications. LCDs
are interfaced with microcontrollers to display the given integer and character.
V Practical Outcome
Interface LCD with 8051 microcontroller to display the characters and decimal
numbers.
Specifications:16
x2 LCD display
Part No:
JHD162A
Char Dots:5 x 8
Number of data
line: 8 bit parallel
Driving
Mode:1/16
duty,1/5 bias
Available Types:
Fig. 14.1 Block Diagram of LCD display TN, STN
(Yellow, Green,
Grey, B/W)
6 Sends data to data pins when a Enable(E) 14 8-bit data pins DB7
high to low pulse is given
Fig 14.3 shows that each LCD have its own pixel rows and columns like 1×16 has single row
and sixteen columns i.e. 16 pixel and each pixel size is of 5×8 as shown but we can see only
5×7 cause last raw is used by cursor. Each character is display according to these pixels size
Table 14.2 LCD control lines and function
Rs -> Register select RW -> Read/Write EN -> Enable
Rs=1 -data register RW=1 -reading from LCD. EN= high to low (Logic ‘1’ delay
Rs=0 -command RW=0 -writing to LCD. Logic ‘0’) for use LCD module.
a) Practical setup
b) Simulation diagram
XI Resources Required
Sr. Instrument
Specification Quantity
No. /Components
Microcontroller kit Single board systems with 8K RAM,ROM 1 No.
memory with battery
backup,16X4,16X2LCD display, PC
1. keyboard interfacing facility, Hex keypad
facility, single user cross c-compiler,RS-
232,USB, interfacing facility with built in
power supply.
Desktop PC Loaded with open source IDE, simulation & 1 No.
2.
program downloading software
3. LCD Trainer board Suitable to interface with 8051 trainer kit 1
X Precautions to be Followed
1. LCD panel is made up of glass avoid applying strong pressure on to the surface of
display area.
2. Ensure proper connection then only give electric supply to circuit.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (IDE) or any
other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the above program.
7. Interface LCD display to microcontroller as per circuit diagram shown in Fig 14.4
8. Download hex code in EPROM/Flash memory of microcontroller
9. Observe output on LCD display and note it in observation Table 14.3
Memory Hex
Label Mnemonics Comments
Address Code
;Replace a bit address by a
RS BIT P3.3
symbol
RW BIT P3.4
EN BIT P3.5
ORG 0000H
;Set P1 as o/p port where
C:0x0000 759000 MOV P1, #00H
LCD is connected
;Call LCD initialize
C:0x0003 120015 LCALL LCD_INIT
subroutine
; Load program memory
C:0x0006 900050 MOV DPTR, #MSG
address into DPTR
C:0x0009 7A0A MOV R2, #10 ;Set counter of 10
C:0x000B E4 DISP_MSG: CLR A
;Read data from memory
C:0x000C 93 MOVC A,@A+DPTR
into A register
C:0x000D 120037 LCALL LCDDATA
;Increment pointer to next
C:0x0010 A3 INC DPTR
location
C:0x0011 DFF8 DJNZ R7, DISP_MSG ;Repeat loop for 10 times
C:0x0013 80FE SJMP $
; 2 lines and 5×7 matrix (8-
C:0x0015 7438 LCD_INIT: MOV A, #38h
bit mode)
C:0x0017 112A ACALL LCDCMD
C:0x0019 740E MOV A, #0eh ; Display on, cursor on
C:0x001B 112A ACALL LCDCMD
; Increment cursor (shift
C:0x001D 7406 MOV A, #06h
cursor to right)
C:0x001F 112A ACALL LCDCMD
C:0x0021 7401 MOV A, #01h ; Clear display screen
C:0x0023 112A ACALL LCDCMD
; Force cursor to beginning
C:0x0025 7480 MOV A, #80H
to 1st line
C:0x0027 112A ACALL LCDCMD
C:0x0029 22 RET
C:0x002A F590 LCDCMD: MOV P1,A ;Send command to lcd
C:0x002C C2B3 CLR RS ;Select command register
C:0x002E C2 B4 CLR RW ;Select write operation
C:0x0030 D2B5 SETB EN
C:0x0032 C2B5 CLR EN ;Latch command to lcd
Problem statement for student: Develop assembly program to display data “Wel” on 1st line
and “Come” on 2nd line of LCD
Memory
Hex Code Label Mnemonics Comments
Address
1.
2.
3.
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
1
2
3
4
5
6
7
8
9
10
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
1 ………………………......
2 ……………………….......
3 …………………………..
4 …………………………..
Dated
Marks Obtained signature of
Teacher
Process Related Product Total
(15) Related (25)
(10)
Practical No. 15: Interface the given keyboard with 8051 and display
the key pressed.
I Practical Significance
The predominant interface between humans and hardware is the keyboard in almost in all
electronic applications. The matrix keypad allows a designer to implement a large
number of inputs with a small number of microcontroller port pins. These keypads were
evolved originally for telephonic applications involving touch tone signaling. This
practical will help the students to develop skills to interface given keyboard to the
microcontroller and display key pressed.
V Practical Outcome
Interface the given keyboard with 8051 and display the key pressed.
4 x 4 matrix keypad connected to a single port of microcontroller. The keypad columns and rows are
connected to the port pins. The keypad can be decoded to find out which key was pressed. When a
key is pressed on the keypad, a row and column make a contact; otherwise, there is no
connection
Specifications: Keypad
Maximum voltage across each key: 24V
Maximum Current through each key: 30mA
Maximum operating temperature: 0°C to + 50°C
Easy interface
Long life
Table 15.1 4x4 Keypad: - Rows (R1, R2, R3, R4) Columns (C1, C2, C3, C4)
(Refer Fig.15.2)
Step1:- Make R1- 0 Checks C1, C2, C3,C4 Step3:- Make R3- 0 Checks C1, C2, C3,C4
If C1=0 – ‘0’ is pressed If C1=0 – ‘8’ is pressed
If C2=0 – ‘1’ is pressed If C2=0 – ‘9’ is pressed
If C3=0 – ‘2’ is pressed If C3=0 – ‘A’ is pressed
If C3=0 – ‘3’ is pressed If C3=0 – ‘B’ is pressed
Step2:- Make R2- 0 Checks C1, C2, C3,C4 Step4:- Make R4- 0 Checks C1, C2, C3,C4
If C1=0 – ‘4’ is pressed If C1=0 – ‘C’ is pressed
If C2=0 – ‘5’ is pressed If C2=0 – ‘D’ is pressed
If C3=0 – ‘6’ is pressed If C3=0 – ‘E’ is pressed
If C3=0 – ‘7’ is pressed If C3=0 – ‘F’ is pressed
.
.
b) Practical setup
c) Simulation diagram
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1. Microcontroller Single board systems with 8K RAM,ROM memory 1 No.
kit with battery backup,16X4,16X2LCD display, PC
keyboard interfacing facility, Hex keypad facility,
single user cross c-compiler,RS-232,USB,
interfacing facility with built in power supply.
2. Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software
X Precautions to be Followed
1. LCD panel is made up of glass avoid applying strong pressure on to the surface of
display area.
2. Ensure proper connection then only give electric supply to circuit.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart.
3. Develop assembly program using Integrated Development Environment (IDE).
4. Debug and simulate program on IDE.
5. Create hex file.
6. Download hex code in EPROM/Flash memory of microcontroller.
7. Interface 4x4 keypad and 16x2 LCD to microcontroller.
8. Observe output status of key and note it in observation Table
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
1 2
2 5
3 9
4 B
5 E
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
Practical No. 16: Interface ADC with 8051 microcontroller and verify
input / output.
I Practical Significance
In the real world most of the signals sensed and processed by humans are analog signals.
Analog-to-digital conversion is the primary means by which analog signals are converted
into digital data that can be processed by computers for various purposes. This practical
will help the students to develop skills to interface LCD to the microcontroller and verify
input/output.
V Practical Outcome
Interface ADC with 8051 microcontroller and verify input/output.
Types of ADC:
Serial ADC: Serial ADC’s consisting of just one output pin that delivers the output code one bit at a
time.
Parallel ADC: Parallel ADC’s consisting of several output pins that deliver all the bits of the output
code at the same time.
b) Practical Setup
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1. Microcontroller Single board systems with 8K RAM,ROM 1 No.
kit memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
keypad facility, single user cross c-compiler,RS-
232,USB, interfacing facility with built in power
supply.
2. Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software
X Precautions to be Followed
1. Refer datasheet for to provide clock frequency to ADC 0808 chip.
2. Care must be taken while taking observations during power up.
3. Use current limiting resistors for LED’s.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (IDE) or any
other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the above program.
7. Download hex code in EPROM/Flash memory of the microcontroller.
8. Interface ADC 0808 IC to the microcontroller as per circuit diagram shown in fig
16.2
9. To make changes in input refer observation Table and note hex output observed on
LEDs.
SAMPLE PROGRAM 1: Write a program to read the data from ADC and display on 8
LEDs connected to port 2.
STEP1- Algorithm
1. Select an analog channel by providing bits to A, B, and C addresses according to the
analog signal selection table.
2. Activate the ALE (address latch enable) pin.
3. Activate SC (start conversion) to initiate conversion.
4. Monitor EOC (end of conversion) to see whether conversion is finished. H-to L
output indicates that the data is converted and is ready to be picked up. If we do not
use EOC, we can read the converted digital data after a brief time delay. The delay
size depends on the speed of the external clock we connect to the CLK pin.
5. Activate OE (output enable) to read data out of the ADC chip.
Note: In ADC0808 that there is no self-clocking and the clock must be provided from an
external source to the CLK pin. Although the speed of conversion depends on the
frequency of the clock connected to the CLK pin, it cannot be faster than 100
microseconds.
Memory Hex
Label Mnemonics Comments
Address Code
ALE BIT P3.0
SC BIT P3.1
OE BIT P3.3
MY_DATA EQU P1
ORG 0000H
MOV
C:0x0000 7590FF ;make P1 as input
MY_DATA,#0FFH
C:0x003D 22 RET
END
1.
2.
3.
XIII Actual Procedure Followed (use blank sheet if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
1V
2V
3V
4V
5V
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX Assessment Scheme
Dated
Marks Obtained signature of
Teacher
Process Related Product Total
(15) Related (10) (25)
Practical No. 17: Interface DAC with 8051 microcontroller and observe
following waveforms: square wave, triangular wave, sawtooth wave
I Practical Significance
The digital to analog converter (DAC) is a device widely used to convert digital pulses to
analog signals. This practical will help the students to develop skills to interface DAC
with 8051 and generate different analog waveforms.
V Practical Outcome
Interface DAC with 8051 microcontroller and observe following waveforms: square
wave, triangular wave, sawtooth wave.
Where D0 is the LSB, D7 is the MSB for the inputs, and Iref is the input current. The
Iref current is generally set to 2.0mA.
b) Practical setup
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1 Microcontroller Single board systems with 8K RAM,ROM 1 No.
kit memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
keypad facility, single user cross c-compiler,RS-
232,USB, interfacing facility with built in power
supply.
2 Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software
3 DAC (0808) Suitable to interface 8051 board. 1 No
trainer board
X Precautions to be Followed
1. Operate DAC chip as per specifications given in the datasheet otherwise damage may
occur to the device.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (IDE) or any
other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the above program.
7. Download hex code in EPROM/Flash memory of microcontroller.
8. Interface DAC 0808 IC to the microcontroller as per circuit diagram shown in fig
17.2
9. Observe Triangular waveform on CRO and draw the same pattern in observation
mentioning Ton and Toff time.
Memory
Hex Code Label Mnemonics Comments
Address
ORG 0000h
C:0x0000 7400 REPEAT: MOV A,#00h ;clear A
C:0x0002 F590 INCR: MOV P1,A ;send value to P1
C:0x0004 04 INC A ;increment value
;compare with highest
C:0x0005 B4FFFA CJNE A,#0FFh,INCR
value
C:0x0008 F590 DECR: MOV P1,A
C:0x000A 14 DEC A ;decrement value
;compare with lowest
C:0x000B B400FA CJNE A,#00h,DECR
value
C:0x000E 80F0 SJMP REPEAT ;repeat
END
Problem statement for student: Develop assembly program to generate sawtooth waveform
using DAC 0808
Step 1-Algorithm Step 2-Flowchart
Memory Hex
Label Mnemonics Comments
Address Code
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XX Observations for sample program (use blank sheet provided if space not sufficient)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XIX References / Suggestions for further reading
1 https://en.wikipedia.org/wiki/Digital-to-analog_converter.
2 https://pdf1.alldatasheet.com/datasheet-pdf/view/512341/TI1/DAC0808.html
3 The 8051 Microcontroller and Embedded system Using Assembly and C-
Muhammad Ali Mazidi, Janice Gillispie Mazidi, Rolin D. Mckinlay- Pearson /
Prentice Hall, , 2nd edition, Delhi,2008, ISBN 978-8177589030.
XX Assessment Scheme
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related Related (25)
(15) (10)
V Practical Outcome
Interface stepper motor to microcontroller and rotate in clockwise and anti-clockwise
direction at the given angles.
Stepper motors convert electrical energy into precise mechanical motion. These motors rotate a
specific incremental distance per each step. The number of steps executed controls the degree of
rotation of the motor’s shaft
Frame 1: The top electromagnet (1) is turned on, Frame 2: The top electromagnet (1) is turned
attracting the nearest teeth of the gear-shaped off, and the right electromagnet (2) is
iron rotor. With the teeth aligned to energized, pulling the teeth into alignment
electromagnet 1, they will be slightly offset from with it. This results in a rotation of 1.8° in this
right electromagnet (2). example.
Frame 3: The bottom electromagnet (3) is Frame 4: The left electromagnet (4) is
energized; another 1.8° rotation occurs. energized, rotating again by 1.8°. When the
top electromagnet (1) is again enabled, the
rotor will have rotated by one tooth position;
since there are 50 teeth, it will take 200 steps
to make a full rotation in this example.
b) Practical setup
IX Resources Required
Sr. Instrument
Specification Quantity
No. /Components
1. Microcontroller
Single board systems with 8K RAM,ROM 1 No.
kit memory with battery backup,16X4,16X2LCD
display, PC keyboard interfacing facility, Hex
keypad facility, single user cross c-compiler,RS-
232,USB, interfacing facility with built in power
supply.
2. Desktop PC Loaded with open source IDE, simulation and 1 No.
program downloading software
3. Stepper Motor 1.8° Step angle, 50/100 RPM Stepper motor with 1 No.
Trainer ULN 2003 Driver.
X Precautions to be Followed
1. Use always driver circuit while interfacing stepper motor to microcontroller.
XI Procedure
1. Write algorithm for given problem.
2. Draw flowchart for the same.
3. Develop assembly program using Integrated Development Environment (IDE) or any
other relevant software tool.
4. Debug program on IDE.
5. Execute program on IDE.
6. Create hex file for the above program.
7. Download hex code in EPROM/Flash memory of the microcontroller.
8. Interface stepper motor to microcontroller as per circuit diagram shown in fig 18.5
9. Observe rotation of stepper motor and record in observation Table.
Step 1- Algorithm
1. Make the Port used to Interface stepper motor as an output port.
2. Set register as counter R2 =25 for 100 steps i.e.180° rotation.
3. Set register as counter R3= 4 for full step code
4. Initialize pointer to table which is in code memory i.e. DPTR.
5. Clear accumulator.
6. Read data from code memory.
7. Send code to stepper motor.
8. Increment DPTR to access next memory location code.
9. Decrement R3 and check for zero. Is counter R3=0? NO- go to step 5 else go to next.
10. Decrement R2 and check for zero. Is counter R2=0? NO- go to step 3 else go to next.
11. Stop.
Fig 18.5 Flowchart for stepper motor to rotate in clockwise 100 steps
Memory Hex
Label Mnemonics Comments
Address Code
ORG 0000H
C:0x0000 759000 MOV P1,#00H ;Define port as output port
;Set register as counter of 25 for
C:0x0003 7A19 MOV R2,#25
180 rotation
;set counter of 4 for full step code
C:0x0005 7B04 UP1: MOV R3,#4
sequence
;load address of program memory
C:0x0007 900200 MOV DPTR,#TABLE
into Data pointer
C:0x000A E4 UP: CLR A ;clear accumulator
;read step code from memory into
C:0x000B 93 MOVC A,@A+DPTR
accumulator
C:0x000C F590 MOV P1,A ;send step code to port
C:0x000E 1117 ACALL DELAY ;add delay
;increment memory pointer to read
C:0x0010 A3 INC DPTR
next step code
; decrement counter & jump to
C:0x0011 DBF7 DJNZ R3,UP memory location labeled as UP if
not equal to zero.
; decrement counter & jump to
C:0x0013 DAF0 DJNZ R2,UP1 memory location labeled as UP1 if
not equal to zero.
C:0x0015 80FE SJMP $ ;wait
C:0x0017 7C19 DELAY: MOV R4,#25 ;delay Subroutine
C:0x0019 7D64 L3: MOV R5,#100
C:0x001B 7E64 L2: MOV R6,#100
C:0x001D DEFE L1: DJNZ R6,L1
C:0x001F DDFA DJNZ R5,L2
C:0x0021 DCF6 DJNZ R4,L3
C:0x0023 22 RET
ORG 0050H
DB 09H, 0CH, 06H, ; Step code stored at code memory
C:0x0050 TABLE:
03H starting at location 0050H onward.
END
Problem statement for student: Develop assembly program for stepper motor to rotate 90° in
anticlockwise direction using rotate instruction. Assume step angle 1.8°
Step 1-Algorithm Step 2-Flowchart
2.
3.
4.
5.
XIII Actual Procedure Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XIV Precautions Followed (use blank sheet provided if space not sufficient)
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
................................................................................................................................................
XV Observations for sample program (use blank sheet provided if space not sufficient)
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
XX References / Suggestions for further reading
1. https://en.wikipedia.org/wiki/Stepper_motor.
2. https://www.jameco.com/Jameco/Products/ProdDS/155433.pdf
3. The 8051 Microcontroller and Embedded system Using Assembly and C- Muhammad
Ali Mazidi, Janice Gillispie Mazidi, Rolin D. Mckinlay- Pearson /Prentice Hall, , 2nd
edition, Delhi,2008, ISBN 978-8177589030
4. https://www.youtube.com/watch?v=TWMai3oirnM
Dated signature of
Marks Obtained
Teacher
Process Product Related Total
Related (15) (10) (25)