SlideShare a Scribd company logo
GURU NANAK DEV ENGINEERING COLLEGE, BIDAR
(ISO Certified Institute ISO 9001/2015)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Microcontrollers Lab
(BECL456A)
B.E –IV Semester
Name:
USN :
Batch: Section :
VISION OF THE INSTITUTE
To be a premier technological institution that fosters humanity, ethics and excellence in
education and research towards inspiring and developing future torch bearers.
MISSION OF THE INSTITUTE
M1 To impart quality educational experience and technical skills to students that enables them
to become leaders in their chosen professions.
M2 To nurture scientific temperament and promote research and development activities.
M3 To inculcate students with an ethical and human values so as to have big picture of societal
development in their future career.
M4 To provide service to industries and communities through educational, technical, and
professional activities.
VISION OF THE DEPARTMENT
To be a premier department known for quality education and research in the field of Electronics and
Communication Engineering for the benefit of mankind.
MISSION OF THE DEPARTMENT
M1 To provide State-of-art education and skills in the field of Electronics and Communication
Engineering
M2 To promote research culture and life-long learning to meet the challenges of rapid
technological change in their chosen professional field.
M3 To provide service to the society through engineering solutions.
Electronics & Communication Engineering Department
Program Outcomes as defined by NBA (PO) Engineering Graduates will be able to:
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of
the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change
PROGRAM EDUCATIONAL OBJECTIVES
PEO Statements
PEO1
Apply fundamentals and skills needed for a successful professional Electronics
& Communication Engineer and to pursue higher studies
PEO2
Adapt latest technologies needed for addressing real world problems.
PEO3
Embed self-learning abilities, humanitarian and ethical values for a successful
professional career.
PROGRAM SPECIFIC OUTCOMES
PSOs Statements
PSO 1 To analyze, design and develop various types of integrated electronics systems.
PSO 2 To apply their knowledge and skills to develop an application in communication
systems
INDEX
Laboratory Experiments:
S.No Name of the Experiment
I. Assembly Language Programming
Data Transfer Programs:
1
Write an ALP to move a block of n bytes of data from source (20h) to destination (40h)
using Internal-RAM.
2
Write an ALP to move a block of n bytes of data from source (2000h) to destination
(2050h) using External RAM.
3
Write an ALP To exchange the source block starting with address 20h, (Internal RAM)
containing N (05) bytes of data with destination block starting with address 40h (Internal
RAM).
4
Write an ALP to exchange the source block starting with address 10h (Internal memory),
containing n (06) bytes of data with destination block starting at location 00h (External
memory).
Arithmetic & Logical Operation Programs:
5
Write an ALP to add the byte in the RAM at 34h and 35h, store the result in the register
R5 (LSB) and R6 (MSB), using Indirect Addressing Mode.
6
Write an ALP to subtract the bytes in Internal RAM 34h &35h store the result in register
R5 (LSB) & R6 (MSB).
7
Write an ALP to multiply two 8-bit numbers stored at 30h and 31h and store16- bit result
in 32h and 33h of Internal RAM.
8 Write an ALP to perform division operation on 8-bit number by 8-bit number.
9 Write an ALP to separate positive and negative in a given array.
10 Write an ALP to separate even or odd elements in a given array.
11 Write an ALP to arrange the numbers in Ascending & Descending order.
12
Write an ALP to find Largest & Smallest number from a given array starting from 20h &
store it in Internal Memory location 40h.
Counter Operation Programs:
13 Write an ALP for Decimal UP-Counter.
14 Write an ALP for Decimal DOWN-Counter.
15 Write an ALP for Hexadecimal UP-Counter.
16 Write an ALP for Hexadecimal DOWN-Counter.
II. C Programming
1 Write an 8051 C program to find the sum of first 10 Integer Numbers.
2 Write an 8051 C program to find Factorial of a given number.
3 Write an 8051 C program to find the Square of a number (1 to 10) using Look-Up Table.
4
Write an 8051 C program to count the number of Ones and Zeros in two consecutive
memory locations.
III. Hardware Interfacing Programs
1 Write an 8051 C Program to rotate stepper motor in Clock & Anti-Clockwise direction.
2 Write an 8051 C program to Generate Sine & Square waveforms using DAC interface.
Keil µVision 3 software
 The Keil 8051 development tools are designed to solve the
complex problems facing embedded software developers. When
starting a new project, select the microcontroller you use from the
device database. The µVision IDE automatically sets all compiler,
assembler, linker, and memory options.
 An integrated development environment (IDE) is a software
application that provides comprehensive facilities for software
development. An IDE normally consists of at least a source-code
editor, build automation tools, and a debugger.
 µVision is a window-based software development platform that
combines a robust and modern editor with a project manager and
make facility tool. It integrates all the tools needed to develop
embedded applications including a C/C++ compiler, macro
assembler, linker/locator, and a HEX file generator.
The µVision IDE and Debugger is the central part of the Keil
development toolchain and has numerous features that help the
programmer to develop embedded applications quickly and
successfully.
Steps for execution on Keil µvision3
Step 1: Create new folder on desktop
Step 2:Click on Keil µvision3 IDE
Step 3: Creating a 8051/8052 Project Using Keil µvision IDE
To create a new 8051 project using Keil IDE, Click on the ' Project ' item on the IDE
Menu bar and select ' New uVision Project... ' as shown in the above image.
Now give file name(e.g. P1) and your file should be in the Folder which you have
created in step1
Step 4:Selecting an 8051 Device in Keil
Select Atmel---AT89C51ED2
After selecting your 8051 derivative,You will get another dialog as shown
Above.Asking to copy STARTUP.A51
Click ' Yes '
Step 5: Click on file---select new file
Type program in text window and save it with same name with extension .asm as
given name to project in step 3
Step 6: Adding file to source group
Step 7: After adding file to source group, click on project → select build target
Step 8: After checking errors, click on debug → select start/stop debug, you will
get following window
Step 9: After that click on ok,then go on clicking step into { } to check step by step
execution.
I)Assembly Language Programming
1) Data Transfer Programs
1. Write an ALP to move a block of n bytes of data from source
(20h) to destination (40h) using Internal-RAM.
Program:
MOV R0, #20H
MOV R1, #40H
MOV R2, #05H
UP: MOV A,@R0
MOV @R1, A
INC R0
INC R1
DJNZ R2, UP
END
Result:
Before Execution After Execution
20H=01H 40H=01H
21H=03H 41H=03H
22H=04H 42H=04H
23H=06H 43H=06H
24H=0BH 44H=0BH
2. Write an ALP to move a block of n bytes of data from source
(2000h) to destination (2050h) using External RAM.
Program:
MOV DPTR,#2000H
MOV R0,#50H
MOV R1,#20H
MOV R2,#05H
UP:MOVX A,@DPTR
PUSH DPL
PUSH DPH
MOV A,R1
MOV DPH,A
MOV A,R0
MOV DPL,A
MOV A,R3
MOVX @DPTR,A
INC DPTR
MOV A,DPH
MOV R1,A
MOV A,DPL
MOV R0,A
POP DPL
POP DPH
INC DPTR
DJNZ R2,UP
END
Result:
Before Execution After Execution
2000H=01H 2050H=01H
2001H=02H 2051H=02H
2002H=03H 2052H=03H
2003H=04H 2053H=04H
2004H=05H 2054H=05H
3. Write an ALP To exchange the source block starting with
address 20h, (Internal RAM) containing N (05) bytes of data
with destination block starting with address 40h (Internal
RAM).
Program:
MOV R0, #20H
MOV R1, #40H
MOV R2, #05H
UP: MOV A,@R0
XCH @R1, A
MOV @R0, A
INC R0
INC R1
DJNZ R2, UP
END
Result:
Before Execution After Execution
20H=0FH 40H=01H 40H=0FH 20H=01H
21H=0EH 41H=02H 41H=0EH 21H=02H
22H=0DH 42H=03H 42H=0DH 22H=03H
23H=0CH 43H=04H 43H=0CH 23H=04H
24H=0BH 44H=05H 44H=0BH 24H=05H
4. Write an ALP to exchange the source block starting with
addresnn10h (Internal memory), containing n (06) bytes of
data with destination block starting at location 00h (External
memory).
Program:
MOV DPTR, #0000H
MOV R1, #10H
MOV R2, #05H
UP: MOVX A,@DPTR
XCH @R1, A
MOVX @DPTR, A
INC DPTR
INC R1
DJNZ R2, UP
END
Result:
Before Execution After Execution
10H<=0FH 0000H<=01H 10H<=01H 0000H<=0FH
11H<=0EH 0001H<=02H 11H<=02H 0001H<=0EH
12H<=0DH 0002H<=03H 12H<=03H 0002H<=0DH
13H<=0CH 0003H<=04H 13H<=04H 0003H<=0CH
14H<=0BH 0004H<=05H 14H<=05H 0004H<=0BH
2.Arithmetic & Logical Operation Programs
5. Write an ALP to add the byte in the RAM at 34h and 35h,
store the result in the register R5 (LSB) and R6 (MSB), using
Indirect Addressing Mode.
Program:
MOV R0,#34H
MOV R1,#35H
MOV R6,#00H
MOV A,@R0
ADD A,@R1
MOV R5,A
JNC DOWN
INC R6
DOWN:END
Result:
Before Execution After Execution
34H=05H R5=0AH
35H=05H R6=00H
6. Write an ALP to subtract the bytes in Internal RAM 34h &35h
store the result in register R5 (LSB) & R6 (MSB).
Program:
MOV R0,#34H
MOV R1,#35H
MOV R6,#00H
MOV A,@R0
SUBB A,@R1
MOV R5,A
END
Result:
Before Execution After Execution
34H=06H R5=01H
35H=05H
7. Write an ALP to multiply two 8-bit numbers stored at 30h and
31h and store16- bit result in 32h and 33h of Internal RAM.
Program:
MOV A,30H
MOV B,31H
MUL AB
MOV 32H,A
MOV 33H,B
END
Result:
Before Execution After Execution
30H=06H 32H=0CH
31H=02H 33H=00H
8. Write an ALP to perform division operation on 8-bit number
by 8- bit number.
Program:
MOV A,30H
MOV B,31H
DIV AB
MOV 32H,A
MOV 33H,B
END
Result:
Before Execution After Execution
30H=06H 32H=03H
31H=02H 33H=00H
9. Write an ALP to separate positive and negative in a given
array.
Program:
MOV 0D0H, #00H ; clear the PSW
MOV DPTR, #5000H
MOV R0, #30H
MOV R1, #20H
MOV R3, #05H
UP: MOVX A,@DPTR
RLC A
JNC NEXT
MOVX A,@DPTR
MOV @R1, A
INC R1
SJMP SKIP
NEXT: MOVX A,@DPTR
MOV @R0, A
INC R0
SKIP: INC DPTR
DJNZ R3, UP
END
Result:
Before Execution After Execution
5000H<= FFH 5000H<= FFH
5001H<= 08H 5001H<= 08H
5002H<= 80H 5002H<= 80H
5003H<= 05H 5003H<= 05H
5004H<= 16H 5004H<= 16H
Negative:
30H<= FFH
31H<= 80H
Positive:
20H<= 08H
21H<= 05H
Negative: FF & 80
22H<= 16H
Positive: 08, 05 & 16
Negative: Positive:
30H<= FFH 20H<=08H
31H<= 80H 21H<= 05H
22H<= 16H
FF <= 1 1 1 1 1 1 1 1
08 <= 0 0 0 0 1 0 0 0
80 <= 1 0 0 0 0 0 0 0
05 <= 0 0 0 0 0 1 0 1
16 <= 0 0 0 1 0 1 1 0
10.Write an ALP to separate even or odd elements in a given
array.
Program:
MOV 0D0H, #00H ; clear the PSW
MOV DPTR, #5000H
MOV R0, #30H
MOV R1, #20H
MOV R3, #05H
UP: MOVX A,@DPTR
RRC A
JNC NEXT
MOVX A,@DPTR
MOV @R1, A
INC R1
SJMP SKIP
NEXT: MOVX A,@DPTR
MOV @R0, A
INC R0
SKIP: INC DPTR
DJNZ R3, UP
END
Result:
Before Execution After Execution
5000H<= 05H 5000H<= 05H
5001H<= 06H 5001H<= 06H
5002H<= 07H 5002H<= 07H
5003H<= 08H 5003H<= 08H
5004H<= 09H 5004H<= 09H
Even:
30H<= 06H
31H<= 08H
Odd:
20H<= 05H
21H<= 07H Even: 06 & 08
22H<= 09H Odd: 05, 07 & 09
Even: Odd:
30H<= 06H 20H<=05H
31H<= 08H 21H<= 07H
22H<= 09H
05 <= 0 0 0 0 0 1 0 1
06 <= 0 0 0 0 0 1 1 0
07 <= 0 0 0 0 0 1 1 1
08 <= 0 0 0 0 1 0 0 0
09 <= 0 0 0 0 1 0 0 1
11.Write an ALP to arrange the numbers in Ascending &
Descending order.
I) Ascending order
Program:
MOV R3, #05H
UP: MOV DPTR, #5000H
MOV R2, #04H
AGAIN: MOV R1, 82H
MOVX A,@DPTR
MOV 30H, A
INC DPTR
MOVX A,@DPTR
CJNE A, 30H, DOWN
SJMP SKIP
DOWN: JNC SKIP
MOV 82H, R1
MOVX @DPTR, A
INC DPTR
MOV A, 30H
MOVX @DPTR, A
SKIP: DJNZ R2, AGAIN
DJNZ R3, UP
END
Result:
Before Execution After Execution
5000H<=08H 5000H<=01H
5001H<=01H 5001H<=02H
5002H<=02H 5002H<=05H
5003H<=09H 5003H<=08H
5004H<=05H 5004H<=09H
II) Descending order.
Program:
MOV R3, #05H
UP: MOV DPTR, #5000H
MOV R2, #04H
AGAIN: MOV R1, 82H
MOVX A,@DPTR
MOV 30H, A
INC DPTR
MOVX A,@DPTR
CJNE A, 30H, DOWN
SJMP SKIP
DOWN: JC SKIP
MOV 82H, R1
MOVX @DPTR, A
INC DPTR
MOV A, 30H
MOVX @DPTR, A
SKIP: DJNZ R2, AGAIN
DJNZ R3, UP
END
Result:
Before Execution After Execution
5000H<=08H 5000H<=09H
5001H<=01H 5001H<=08H
5002H<=02H 5002H<=05H
5003H<=09H 5003H<=02H
5004H<=05H 5004H<=01H
12. Write an ALP to find Largest & Smallest number from a given
array starting from 20h & store it in Internal Memory location
40h.
I)SMALLEST
Program:
MOV R0,#20H
MOV R2,#05H
MOV B,@R0
BACK:MOV A,@R0
CJNE A,B,LOOP
LOOP:JNC LOOP1
MOV B,A
INC R0
DJNZ R2,BACK
SJMP NEXT
LOOP1:INC R0
DJNZ R2,BACK
NEXT:MOV 40H,B
END
Result:
Before Execution After Execution
20H<=09H 40H=01H
21H<=08H
22H<=05H
23H<=02H
24H<=01H
II) LARGEST
Program:
MOV R0,#20H
MOV R2,#05H
MOV B,@R0
BACK:MOV A,@R0
CJNE A,B,LOOP
LOOP:JC LOOP1
MOV B,A
INC R0
DJNZ R2,BACK
SJMP NEXT
LOOP1:INC R0
DJNZ R2,BACK
NEXT:MOV 40H,B
END
Result:
Before Execution After Execution
20H<=09H 40H=09H
21H<=08H
22H<=05H
23H<=02H
24H<=01H
3.Counter Operation Programs:
13. Write an ALP for Decimal UP-Counter.
Program:
MOV A,#00H
L1:MOV P1,A
ADD A,#01H
DAA
LCALL DELAY
SJMP L1
DELAY:MOV TMOD,#01H
MOV R0,#0EH
BACK:MOV TL0,#00H
MOV TH0,#00H
SETB TR0
REPEAT:JNB TF0,REPEAT
CLR TR0
CLR TF0
DJNZ R0,BACK
RET
END
Result:
After Execution
00
01
02
03
.
.
96
97
98
99
14. Write an ALP for Decimal DOWN-Counter.
Program:
MOV A, #99H
UP: LCALL 061DH
MOV R3, A
MOV R4, #00H
MOV R5, #02H
LCALL 059EH
ADD A, #99H
DA A
CJNE A, #99H, UP
END
Result:
After Execution
99
98
97
96
.
.
03
02
01
00
15. Write an ALP for Hexadecimal UP-Counter.
Program:
MOV A, #00H
UP: LCALL 061DH
MOV R3, A
MOV R4, #00H
MOV R5, #02H
LCALL 059EH
ADD A, #01H
CJNE A, #00H, UP
END
Result:
After Execution
00
01
02
03
.
.
FC
FD
FE
FF
16. Write an ALP for Hexadecimal DOWN-Counter.
Program:
MOV A, #0FFH
UP: LCALL 061DH
MOV R3, A
MOV R4, #00H
MOV R5, #02H
LCALL 059EH
SUBB A, #01H
CJNE A, #0FFH, UP
END
Result:
After Execution
FF
FE
FD
FC
.
.
03
02
01
00
II. C Programming
1. Write an 8051 C program to find the sum of first 10 Integer
Numbers.
Program:
#include<reg51.h> // to include the 8051 register set
void main()
{
unsigned char i ;
unsigned int sum=0; //initialize sum with zero
for (i=1; i<=10; i++) //loop to 10 iteration
{
sum +=i ; //increment and add
}
P0=sum; //display the sum
while (1); //loop indefinitely
}
2.Write an 8051 c program to find factorial of a given number.
Program:
#include<reg51.h>//include the 8051 microcontroller header file
void main()
{
//give the number to which you need the factorial of the given number & initialize
with 1
unsigned int num=5, fact=1;
while(num>0)
{
fact = fact*num;
num--;
}
P1=fact; // display the result on the output port
while(1);
}
3.Write an 8051 C program to find the Square of a number (1 to 10)
using Look-Up Table.
Program:
#include<reg51.h>
//look-up table of squares
const unsigned char squares[]={1,4,9,16,25,36,49,64,81,100};
void main()
{
unsigned char number=9; //Number for which we want to find the square
while(number<=10)
{
unsigned char square=squares [number-1];
P1=square; //Display the result on port 1
}
}
4.Write an 8051 C program to count the number of Ones and Zeros
in two consecutive memory locations.
Program:
#include<reg51.h>
void main()
{
unsigned char data1,data2;
unsigned char onescount1=0,onescount2=0;
unsigned char zeroscount1=0,zeroscount2=0;
unsigned char i;
//Read the data from two consecutive memory locations
data1=*(unsigned char*)0x40;
data2=*(unsigned char*)0x41;
//count the number of ones and zeros in the first memory location
for(i=0;i<8;i++)
{
if((data1 & (1 << i))!=0)
onescount1++;
else
zeroscount1++;
}
//count the number of ones and zeros in the second memory location
for(i=0;i<8;i++)
{
if((data2 & (1<<i)) !=0)
onescount2++;
else
zeroscount2++;
}
//output the results
P1=onescount1+onescount2; //output ones count for the first + second memory
location
P2=zeroscount1+zeroscount2; //output ones count for the first + second memory
location
While(1){//Endless loop
}
}
III. Hardware Interfacing Programs
1.Write an 8051 C Program to rotate stepper motor in Clock &
Anti-Clockwise direction
Program:
#include<at89c5led2.h>
#include<stdio.h>
#define PHASED 0x09
#define PHASEC 0x0c
#define PHASEB 0x06
#define PHASEA 0x03
void delay_ms(unsigned int n)
{
int i;
for(i=0; i<n; i++)
{
}
}
void main()
{
while (1)
{
P0=PHASEA;
delay_ms(10000);
P0=PHASEB;
delay_ms(10000);
P0=PHASEC;
delay_ms(10000);
P0=PHASED;
delay_ms(10000);
}
}
2.Write an 8051 C program to Generate Sine & Square waveforms
using DAC interface.
#include <8051.h
// Define DAC interface pins
#define DAC_DATA P0 // DAC data bus connected to Port 0
// Delay function
void delay(unsigned int time) {
unsigned int i, j;
for(i = 0; i < time; i++)
for(j = 0; j < 1275; j++); // Adjust the delay as needed
}
// Function to generate sine waveform
void generateSine() {
unsigned char sineWave[] = {127, 159, 190, 219, 245, 255, 245, 219, 190,
159}; // Sine values for one cycle
unsigned char i;
while(1) {
for(i = 0; i < 10; i++) {
DAC_DATA = sineWave[i]; // Output sine waveform to DAC
delay(100); // Adjust delay for desired frequency
}
}
}
// Function to generate square waveform
void generateSquare() {
unsigned char squareWave[] = {0, 255}; // Square wave values
unsigned char i;
while(1) {
for(i = 0; i < 2; i++) {
DAC_DATA = squareWave[i]; // Output square waveform to DAC
delay(100); // Adjust delay for desired frequency
}
}
}
void main() {
// Initialize DAC interface
DAC_DATA = 0; // Initialize DAC data bus
while(1) {
generateSine(); // Generate sine waveform
//generateSquare(); // Uncomment this line to generate square
waveform
}
}
Viva Questions
1. What do you mean by Embedded System? Give examples.
2. Why are embedded Systems useful?
3. What is Embedded Controller?
4. What is Microcontroller?
5. List out the differences between Microcontroller and Microprocessor.
6. How are Microcontrollers more suitable than Microprocessor for Real Time Applications?
7. What are the General Features of Microcontroller?
8. Explain briefly the classification of Microcontroller.
9. Explain the general features of 8051 Microcontroller.
10. How many pin the 8051 has?
11. Differentiate between Program Memory and Data Memory.
12. What is the size of the Program and Data memory?
13. Write a note on internal RAM. What is the necessity of register banks?
14. What is the function of accumulator?
15. What are SFR’s?
16. What is the program counter? What is its use?
17. What is the size of the PC?
18. What is a stack pointer (SP)?
19. What is the size of SP?
20. What is the PSW? And briefly describe the function of its fields.
21. What is the difference between PC and DPTR?
22. What is the difference between PC and SP?
23. What is ALE? Explain the functions of the ALE in 8051.
24. What are the disadvantages of the ceramic resonator?
25. Explain briefly the difference between the Von Neumann and the Harvard Architecture.
26. Describe in detail how the register banks are organized.
27. What are the bit addressable registers and what is the need?
28. What is the need for the general purpose RAM area?
29. What is Stack and the Stack Pointer.
30. Explain briefly how internal and external ROM gets accessed.
31. What are the different addressing modes supported by 8051 Microcontroller ?
32. Explain the Immediate Addressing Mode.
33. Explain the Register Addressing Mode.
34. Explain the Direct Addressing Mode.
35. Explain the Indirect Addressing Mode.
36. Explain the Code Addressing Mode.
37. Explain in detail the Functional Classification of 8051 Instruction set
38. What are the instructions used to operate stack?
39. What are Accumulator specific transfer instructions?
40. What is the difference between INC and ADD instructions?
41. What is the difference between DEC and SUBB instructions?
42. What is the use of OV flag in MUL and DIV instructions?
43. What are single and two operand instructions?
44. Explain Unconditional and Conditional JMP and CALL instructions.
45. Explain the different types of RETURN instructions.
46. What is a software delay?
47. What are the factors to be considered while deciding a software delay?
48. What is a Machine cycle?
49. Give a brief introduction on Timers/Counter.
50. What is the difference between Timer and Counter operation?
51. How do you differentiate between Timers and Counters?
52. What is the significance of DA instruction?
53. What is packed and unpacked BCD?
54. What is the difference between CY and OV flag?
55. When will the OV flag be set?
56. What is an ASCII code?

More Related Content

PPT
EPROM, PROM & ROM
PPTX
MultiSim.pptx
PPTX
Schematic and PCB Design Using Eagle
PPTX
Introduction to EDA Tools
DOCX
Applications of 8051 microcontrollers
PPTX
Unit II- Hardware design &amp; testing methods1 - Electronic Product Design
PDF
Question paper with solution the 8051 microcontroller based embedded systems...
PPT
VLSI subsystem design processes and illustration
EPROM, PROM & ROM
MultiSim.pptx
Schematic and PCB Design Using Eagle
Introduction to EDA Tools
Applications of 8051 microcontrollers
Unit II- Hardware design &amp; testing methods1 - Electronic Product Design
Question paper with solution the 8051 microcontroller based embedded systems...
VLSI subsystem design processes and illustration

What's hot (20)

PDF
Configuration of mesh topology in cisco packet tracer by Tanjilur RAhman
PPTX
peripheral interfacing
PDF
Speed checker on highway using 8051
PPTX
Harvard vs Von Neumann Architecture
PDF
CS4109 Computer System Architecture
PPTX
8051 Microcontroller
DOC
Program for hamming code using c
PDF
Computer Organization And Architecture lab manual
PPTX
Memory organization in computer architecture
PPTX
Chapter 1 Introduction to Digital Logic
PPTX
SRAM DRAM
PPTX
SORTING techniques.pptx
PPTX
computer organisation architecture.pptx
PPTX
Seminar on MATLAB
PPT
8251 usart programmable communication interface by aniket bhute
PPTX
Von neumann Architecture | Computer Science
PPTX
Traffic signal
PDF
Module 4 advanced microprocessors
PDF
Unit 3 devices&amp;buses
PPTX
Keil software
Configuration of mesh topology in cisco packet tracer by Tanjilur RAhman
peripheral interfacing
Speed checker on highway using 8051
Harvard vs Von Neumann Architecture
CS4109 Computer System Architecture
8051 Microcontroller
Program for hamming code using c
Computer Organization And Architecture lab manual
Memory organization in computer architecture
Chapter 1 Introduction to Digital Logic
SRAM DRAM
SORTING techniques.pptx
computer organisation architecture.pptx
Seminar on MATLAB
8251 usart programmable communication interface by aniket bhute
Von neumann Architecture | Computer Science
Traffic signal
Module 4 advanced microprocessors
Unit 3 devices&amp;buses
Keil software
Ad

Similar to Microcontroller lab manual 2022 scheme vtu (20)

PDF
PDF
Final 22POP13 Lab Manual- By SBL & PK.pdf
PDF
vtu data structures lab manual bcs304 pdf
PPTX
Physics lab ppt for btech students in engineetin
PDF
CS8383 Object Oriented Programming Laboratory Manual
PDF
CS3691 ES&IOT RECORD with output and results
DOCX
Cs8383 oop lab manual-2019
PDF
System design and 8051
PDF
12109 microprocessor & programming
PDF
microprocessor & programming
DOCX
Assembly Language Paper.docx
DOC
Embedded training report(mcs 51)
PDF
Ade manual with co po-18scheme
PPT
Assemblylanguageprogrammingof8085 100523023329-phpapp02
PDF
MEmbeddedS-laboratory-manual_MITMysore.pdf
PDF
Screenshot 2022-10-30 at 10.48.22 AM.pdf
PDF
Marcus Taylor Resume buzz 12-2016
PDF
Philip s
PDF
Philip s
Final 22POP13 Lab Manual- By SBL & PK.pdf
vtu data structures lab manual bcs304 pdf
Physics lab ppt for btech students in engineetin
CS8383 Object Oriented Programming Laboratory Manual
CS3691 ES&IOT RECORD with output and results
Cs8383 oop lab manual-2019
System design and 8051
12109 microprocessor & programming
microprocessor & programming
Assembly Language Paper.docx
Embedded training report(mcs 51)
Ade manual with co po-18scheme
Assemblylanguageprogrammingof8085 100523023329-phpapp02
MEmbeddedS-laboratory-manual_MITMysore.pdf
Screenshot 2022-10-30 at 10.48.22 AM.pdf
Marcus Taylor Resume buzz 12-2016
Philip s
Philip s
Ad

More from shilpa368375 (12)

DOCX
dsp module 4 pptpptrpppptxppppppppp.docx
PPTX
time module 2 ppt.pptxhhhhhhbbjbhhbhbbjh
PPTX
Digital Signal Processing module 1 ppt.pptx
PPTX
Digital Signal Processing Module 5 PPT.pptx
PPTX
management and entrepreneurship module 1
PPTX
module 4 ENTREPRENEURSHIP and social.pptx
PPTX
MOULE 3 lecture 1 embedded systems design
PPTX
leadership styles management and entrepreneurs
PPT
Management module 2 organization and staffing
PPTX
module 3 ENTREPRENEURSHIP and management
PPTX
Management and Entrepreneurship module one
PPT
Organization, staffing, directing and controlling
dsp module 4 pptpptrpppptxppppppppp.docx
time module 2 ppt.pptxhhhhhhbbjbhhbhbbjh
Digital Signal Processing module 1 ppt.pptx
Digital Signal Processing Module 5 PPT.pptx
management and entrepreneurship module 1
module 4 ENTREPRENEURSHIP and social.pptx
MOULE 3 lecture 1 embedded systems design
leadership styles management and entrepreneurs
Management module 2 organization and staffing
module 3 ENTREPRENEURSHIP and management
Management and Entrepreneurship module one
Organization, staffing, directing and controlling

Recently uploaded (20)

PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Welding lecture in detail for understanding
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
573137875-Attendance-Management-System-original
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Geodesy 1.pptx...............................................
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Sustainable Sites - Green Building Construction
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Mechanical Engineering MATERIALS Selection
Welding lecture in detail for understanding
Internet of Things (IOT) - A guide to understanding
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
573137875-Attendance-Management-System-original
OOP with Java - Java Introduction (Basics)
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Geodesy 1.pptx...............................................
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Lecture Notes Electrical Wiring System Components
Sustainable Sites - Green Building Construction
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
CYBER-CRIMES AND SECURITY A guide to understanding
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx

Microcontroller lab manual 2022 scheme vtu

  • 1. GURU NANAK DEV ENGINEERING COLLEGE, BIDAR (ISO Certified Institute ISO 9001/2015) DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING Microcontrollers Lab (BECL456A) B.E –IV Semester Name: USN : Batch: Section :
  • 2. VISION OF THE INSTITUTE To be a premier technological institution that fosters humanity, ethics and excellence in education and research towards inspiring and developing future torch bearers. MISSION OF THE INSTITUTE M1 To impart quality educational experience and technical skills to students that enables them to become leaders in their chosen professions. M2 To nurture scientific temperament and promote research and development activities. M3 To inculcate students with an ethical and human values so as to have big picture of societal development in their future career. M4 To provide service to industries and communities through educational, technical, and professional activities. VISION OF THE DEPARTMENT To be a premier department known for quality education and research in the field of Electronics and Communication Engineering for the benefit of mankind. MISSION OF THE DEPARTMENT M1 To provide State-of-art education and skills in the field of Electronics and Communication Engineering M2 To promote research culture and life-long learning to meet the challenges of rapid technological change in their chosen professional field. M3 To provide service to the society through engineering solutions.
  • 3. Electronics & Communication Engineering Department Program Outcomes as defined by NBA (PO) Engineering Graduates will be able to: 1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. 2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences. 3. Design/development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations. 4. Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. 5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering activities with an understanding of the limitations. 6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. 7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
  • 4. 8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. 9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. 10. Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions. 11. Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. 12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-long learning in the broadest context of technological change PROGRAM EDUCATIONAL OBJECTIVES PEO Statements PEO1 Apply fundamentals and skills needed for a successful professional Electronics & Communication Engineer and to pursue higher studies PEO2 Adapt latest technologies needed for addressing real world problems. PEO3 Embed self-learning abilities, humanitarian and ethical values for a successful professional career.
  • 5. PROGRAM SPECIFIC OUTCOMES PSOs Statements PSO 1 To analyze, design and develop various types of integrated electronics systems. PSO 2 To apply their knowledge and skills to develop an application in communication systems
  • 6. INDEX Laboratory Experiments: S.No Name of the Experiment I. Assembly Language Programming Data Transfer Programs: 1 Write an ALP to move a block of n bytes of data from source (20h) to destination (40h) using Internal-RAM. 2 Write an ALP to move a block of n bytes of data from source (2000h) to destination (2050h) using External RAM. 3 Write an ALP To exchange the source block starting with address 20h, (Internal RAM) containing N (05) bytes of data with destination block starting with address 40h (Internal RAM). 4 Write an ALP to exchange the source block starting with address 10h (Internal memory), containing n (06) bytes of data with destination block starting at location 00h (External memory). Arithmetic & Logical Operation Programs: 5 Write an ALP to add the byte in the RAM at 34h and 35h, store the result in the register R5 (LSB) and R6 (MSB), using Indirect Addressing Mode. 6 Write an ALP to subtract the bytes in Internal RAM 34h &35h store the result in register R5 (LSB) & R6 (MSB). 7 Write an ALP to multiply two 8-bit numbers stored at 30h and 31h and store16- bit result in 32h and 33h of Internal RAM. 8 Write an ALP to perform division operation on 8-bit number by 8-bit number. 9 Write an ALP to separate positive and negative in a given array. 10 Write an ALP to separate even or odd elements in a given array. 11 Write an ALP to arrange the numbers in Ascending & Descending order. 12 Write an ALP to find Largest & Smallest number from a given array starting from 20h & store it in Internal Memory location 40h. Counter Operation Programs: 13 Write an ALP for Decimal UP-Counter. 14 Write an ALP for Decimal DOWN-Counter. 15 Write an ALP for Hexadecimal UP-Counter. 16 Write an ALP for Hexadecimal DOWN-Counter. II. C Programming
  • 7. 1 Write an 8051 C program to find the sum of first 10 Integer Numbers. 2 Write an 8051 C program to find Factorial of a given number. 3 Write an 8051 C program to find the Square of a number (1 to 10) using Look-Up Table. 4 Write an 8051 C program to count the number of Ones and Zeros in two consecutive memory locations. III. Hardware Interfacing Programs 1 Write an 8051 C Program to rotate stepper motor in Clock & Anti-Clockwise direction. 2 Write an 8051 C program to Generate Sine & Square waveforms using DAC interface.
  • 8. Keil µVision 3 software  The Keil 8051 development tools are designed to solve the complex problems facing embedded software developers. When starting a new project, select the microcontroller you use from the device database. The µVision IDE automatically sets all compiler, assembler, linker, and memory options.  An integrated development environment (IDE) is a software application that provides comprehensive facilities for software development. An IDE normally consists of at least a source-code editor, build automation tools, and a debugger.  µVision is a window-based software development platform that combines a robust and modern editor with a project manager and make facility tool. It integrates all the tools needed to develop embedded applications including a C/C++ compiler, macro assembler, linker/locator, and a HEX file generator. The µVision IDE and Debugger is the central part of the Keil development toolchain and has numerous features that help the programmer to develop embedded applications quickly and successfully.
  • 9. Steps for execution on Keil µvision3 Step 1: Create new folder on desktop Step 2:Click on Keil µvision3 IDE Step 3: Creating a 8051/8052 Project Using Keil µvision IDE To create a new 8051 project using Keil IDE, Click on the ' Project ' item on the IDE Menu bar and select ' New uVision Project... ' as shown in the above image. Now give file name(e.g. P1) and your file should be in the Folder which you have created in step1
  • 10. Step 4:Selecting an 8051 Device in Keil Select Atmel---AT89C51ED2 After selecting your 8051 derivative,You will get another dialog as shown Above.Asking to copy STARTUP.A51 Click ' Yes '
  • 11. Step 5: Click on file---select new file Type program in text window and save it with same name with extension .asm as given name to project in step 3
  • 12. Step 6: Adding file to source group
  • 13. Step 7: After adding file to source group, click on project → select build target Step 8: After checking errors, click on debug → select start/stop debug, you will get following window
  • 14. Step 9: After that click on ok,then go on clicking step into { } to check step by step execution.
  • 15. I)Assembly Language Programming 1) Data Transfer Programs
  • 16. 1. Write an ALP to move a block of n bytes of data from source (20h) to destination (40h) using Internal-RAM. Program: MOV R0, #20H MOV R1, #40H MOV R2, #05H UP: MOV A,@R0 MOV @R1, A INC R0 INC R1 DJNZ R2, UP END Result: Before Execution After Execution 20H=01H 40H=01H 21H=03H 41H=03H 22H=04H 42H=04H 23H=06H 43H=06H 24H=0BH 44H=0BH
  • 17. 2. Write an ALP to move a block of n bytes of data from source (2000h) to destination (2050h) using External RAM. Program: MOV DPTR,#2000H MOV R0,#50H MOV R1,#20H MOV R2,#05H UP:MOVX A,@DPTR PUSH DPL PUSH DPH MOV A,R1 MOV DPH,A MOV A,R0 MOV DPL,A MOV A,R3 MOVX @DPTR,A INC DPTR MOV A,DPH MOV R1,A MOV A,DPL MOV R0,A POP DPL POP DPH INC DPTR DJNZ R2,UP END Result: Before Execution After Execution 2000H=01H 2050H=01H 2001H=02H 2051H=02H 2002H=03H 2052H=03H 2003H=04H 2053H=04H 2004H=05H 2054H=05H
  • 18. 3. Write an ALP To exchange the source block starting with address 20h, (Internal RAM) containing N (05) bytes of data with destination block starting with address 40h (Internal RAM). Program: MOV R0, #20H MOV R1, #40H MOV R2, #05H UP: MOV A,@R0 XCH @R1, A MOV @R0, A INC R0 INC R1 DJNZ R2, UP END Result: Before Execution After Execution 20H=0FH 40H=01H 40H=0FH 20H=01H 21H=0EH 41H=02H 41H=0EH 21H=02H 22H=0DH 42H=03H 42H=0DH 22H=03H 23H=0CH 43H=04H 43H=0CH 23H=04H 24H=0BH 44H=05H 44H=0BH 24H=05H
  • 19. 4. Write an ALP to exchange the source block starting with addresnn10h (Internal memory), containing n (06) bytes of data with destination block starting at location 00h (External memory). Program: MOV DPTR, #0000H MOV R1, #10H MOV R2, #05H UP: MOVX A,@DPTR XCH @R1, A MOVX @DPTR, A INC DPTR INC R1 DJNZ R2, UP END Result: Before Execution After Execution 10H<=0FH 0000H<=01H 10H<=01H 0000H<=0FH 11H<=0EH 0001H<=02H 11H<=02H 0001H<=0EH 12H<=0DH 0002H<=03H 12H<=03H 0002H<=0DH 13H<=0CH 0003H<=04H 13H<=04H 0003H<=0CH 14H<=0BH 0004H<=05H 14H<=05H 0004H<=0BH
  • 20. 2.Arithmetic & Logical Operation Programs
  • 21. 5. Write an ALP to add the byte in the RAM at 34h and 35h, store the result in the register R5 (LSB) and R6 (MSB), using Indirect Addressing Mode. Program: MOV R0,#34H MOV R1,#35H MOV R6,#00H MOV A,@R0 ADD A,@R1 MOV R5,A JNC DOWN INC R6 DOWN:END Result: Before Execution After Execution 34H=05H R5=0AH 35H=05H R6=00H
  • 22. 6. Write an ALP to subtract the bytes in Internal RAM 34h &35h store the result in register R5 (LSB) & R6 (MSB). Program: MOV R0,#34H MOV R1,#35H MOV R6,#00H MOV A,@R0 SUBB A,@R1 MOV R5,A END Result: Before Execution After Execution 34H=06H R5=01H 35H=05H
  • 23. 7. Write an ALP to multiply two 8-bit numbers stored at 30h and 31h and store16- bit result in 32h and 33h of Internal RAM. Program: MOV A,30H MOV B,31H MUL AB MOV 32H,A MOV 33H,B END Result: Before Execution After Execution 30H=06H 32H=0CH 31H=02H 33H=00H
  • 24. 8. Write an ALP to perform division operation on 8-bit number by 8- bit number. Program: MOV A,30H MOV B,31H DIV AB MOV 32H,A MOV 33H,B END Result: Before Execution After Execution 30H=06H 32H=03H 31H=02H 33H=00H
  • 25. 9. Write an ALP to separate positive and negative in a given array. Program: MOV 0D0H, #00H ; clear the PSW MOV DPTR, #5000H MOV R0, #30H MOV R1, #20H MOV R3, #05H UP: MOVX A,@DPTR RLC A JNC NEXT MOVX A,@DPTR MOV @R1, A INC R1 SJMP SKIP NEXT: MOVX A,@DPTR MOV @R0, A INC R0 SKIP: INC DPTR DJNZ R3, UP END Result: Before Execution After Execution 5000H<= FFH 5000H<= FFH 5001H<= 08H 5001H<= 08H 5002H<= 80H 5002H<= 80H 5003H<= 05H 5003H<= 05H 5004H<= 16H 5004H<= 16H
  • 26. Negative: 30H<= FFH 31H<= 80H Positive: 20H<= 08H 21H<= 05H Negative: FF & 80 22H<= 16H Positive: 08, 05 & 16 Negative: Positive: 30H<= FFH 20H<=08H 31H<= 80H 21H<= 05H 22H<= 16H FF <= 1 1 1 1 1 1 1 1 08 <= 0 0 0 0 1 0 0 0 80 <= 1 0 0 0 0 0 0 0 05 <= 0 0 0 0 0 1 0 1 16 <= 0 0 0 1 0 1 1 0
  • 27. 10.Write an ALP to separate even or odd elements in a given array. Program: MOV 0D0H, #00H ; clear the PSW MOV DPTR, #5000H MOV R0, #30H MOV R1, #20H MOV R3, #05H UP: MOVX A,@DPTR RRC A JNC NEXT MOVX A,@DPTR MOV @R1, A INC R1 SJMP SKIP NEXT: MOVX A,@DPTR MOV @R0, A INC R0 SKIP: INC DPTR DJNZ R3, UP END Result: Before Execution After Execution 5000H<= 05H 5000H<= 05H 5001H<= 06H 5001H<= 06H 5002H<= 07H 5002H<= 07H 5003H<= 08H 5003H<= 08H 5004H<= 09H 5004H<= 09H
  • 28. Even: 30H<= 06H 31H<= 08H Odd: 20H<= 05H 21H<= 07H Even: 06 & 08 22H<= 09H Odd: 05, 07 & 09 Even: Odd: 30H<= 06H 20H<=05H 31H<= 08H 21H<= 07H 22H<= 09H 05 <= 0 0 0 0 0 1 0 1 06 <= 0 0 0 0 0 1 1 0 07 <= 0 0 0 0 0 1 1 1 08 <= 0 0 0 0 1 0 0 0 09 <= 0 0 0 0 1 0 0 1
  • 29. 11.Write an ALP to arrange the numbers in Ascending & Descending order. I) Ascending order Program: MOV R3, #05H UP: MOV DPTR, #5000H MOV R2, #04H AGAIN: MOV R1, 82H MOVX A,@DPTR MOV 30H, A INC DPTR MOVX A,@DPTR CJNE A, 30H, DOWN SJMP SKIP DOWN: JNC SKIP MOV 82H, R1 MOVX @DPTR, A INC DPTR MOV A, 30H MOVX @DPTR, A SKIP: DJNZ R2, AGAIN DJNZ R3, UP END Result: Before Execution After Execution 5000H<=08H 5000H<=01H 5001H<=01H 5001H<=02H 5002H<=02H 5002H<=05H 5003H<=09H 5003H<=08H 5004H<=05H 5004H<=09H
  • 30. II) Descending order. Program: MOV R3, #05H UP: MOV DPTR, #5000H MOV R2, #04H AGAIN: MOV R1, 82H MOVX A,@DPTR MOV 30H, A INC DPTR MOVX A,@DPTR CJNE A, 30H, DOWN SJMP SKIP DOWN: JC SKIP MOV 82H, R1 MOVX @DPTR, A INC DPTR MOV A, 30H MOVX @DPTR, A SKIP: DJNZ R2, AGAIN DJNZ R3, UP END Result: Before Execution After Execution 5000H<=08H 5000H<=09H 5001H<=01H 5001H<=08H 5002H<=02H 5002H<=05H 5003H<=09H 5003H<=02H 5004H<=05H 5004H<=01H
  • 31. 12. Write an ALP to find Largest & Smallest number from a given array starting from 20h & store it in Internal Memory location 40h. I)SMALLEST Program: MOV R0,#20H MOV R2,#05H MOV B,@R0 BACK:MOV A,@R0 CJNE A,B,LOOP LOOP:JNC LOOP1 MOV B,A INC R0 DJNZ R2,BACK SJMP NEXT LOOP1:INC R0 DJNZ R2,BACK NEXT:MOV 40H,B END Result: Before Execution After Execution 20H<=09H 40H=01H 21H<=08H 22H<=05H 23H<=02H 24H<=01H
  • 32. II) LARGEST Program: MOV R0,#20H MOV R2,#05H MOV B,@R0 BACK:MOV A,@R0 CJNE A,B,LOOP LOOP:JC LOOP1 MOV B,A INC R0 DJNZ R2,BACK SJMP NEXT LOOP1:INC R0 DJNZ R2,BACK NEXT:MOV 40H,B END Result: Before Execution After Execution 20H<=09H 40H=09H 21H<=08H 22H<=05H 23H<=02H 24H<=01H
  • 34. 13. Write an ALP for Decimal UP-Counter. Program: MOV A,#00H L1:MOV P1,A ADD A,#01H DAA LCALL DELAY SJMP L1 DELAY:MOV TMOD,#01H MOV R0,#0EH BACK:MOV TL0,#00H MOV TH0,#00H SETB TR0 REPEAT:JNB TF0,REPEAT CLR TR0 CLR TF0 DJNZ R0,BACK RET END Result: After Execution 00 01 02 03 . . 96 97 98 99
  • 35. 14. Write an ALP for Decimal DOWN-Counter. Program: MOV A, #99H UP: LCALL 061DH MOV R3, A MOV R4, #00H MOV R5, #02H LCALL 059EH ADD A, #99H DA A CJNE A, #99H, UP END Result: After Execution 99 98 97 96 . . 03 02 01 00
  • 36. 15. Write an ALP for Hexadecimal UP-Counter. Program: MOV A, #00H UP: LCALL 061DH MOV R3, A MOV R4, #00H MOV R5, #02H LCALL 059EH ADD A, #01H CJNE A, #00H, UP END Result: After Execution 00 01 02 03 . . FC FD FE FF
  • 37. 16. Write an ALP for Hexadecimal DOWN-Counter. Program: MOV A, #0FFH UP: LCALL 061DH MOV R3, A MOV R4, #00H MOV R5, #02H LCALL 059EH SUBB A, #01H CJNE A, #0FFH, UP END Result: After Execution FF FE FD FC . . 03 02 01 00
  • 39. 1. Write an 8051 C program to find the sum of first 10 Integer Numbers. Program: #include<reg51.h> // to include the 8051 register set void main() { unsigned char i ; unsigned int sum=0; //initialize sum with zero for (i=1; i<=10; i++) //loop to 10 iteration { sum +=i ; //increment and add } P0=sum; //display the sum while (1); //loop indefinitely }
  • 40. 2.Write an 8051 c program to find factorial of a given number. Program: #include<reg51.h>//include the 8051 microcontroller header file void main() { //give the number to which you need the factorial of the given number & initialize with 1 unsigned int num=5, fact=1; while(num>0) { fact = fact*num; num--; } P1=fact; // display the result on the output port while(1); }
  • 41. 3.Write an 8051 C program to find the Square of a number (1 to 10) using Look-Up Table. Program: #include<reg51.h> //look-up table of squares const unsigned char squares[]={1,4,9,16,25,36,49,64,81,100}; void main() { unsigned char number=9; //Number for which we want to find the square while(number<=10) { unsigned char square=squares [number-1]; P1=square; //Display the result on port 1 } }
  • 42. 4.Write an 8051 C program to count the number of Ones and Zeros in two consecutive memory locations. Program: #include<reg51.h> void main() { unsigned char data1,data2; unsigned char onescount1=0,onescount2=0; unsigned char zeroscount1=0,zeroscount2=0; unsigned char i; //Read the data from two consecutive memory locations data1=*(unsigned char*)0x40; data2=*(unsigned char*)0x41; //count the number of ones and zeros in the first memory location for(i=0;i<8;i++) { if((data1 & (1 << i))!=0) onescount1++; else zeroscount1++; } //count the number of ones and zeros in the second memory location for(i=0;i<8;i++) { if((data2 & (1<<i)) !=0) onescount2++; else zeroscount2++; }
  • 43. //output the results P1=onescount1+onescount2; //output ones count for the first + second memory location P2=zeroscount1+zeroscount2; //output ones count for the first + second memory location While(1){//Endless loop } }
  • 45. 1.Write an 8051 C Program to rotate stepper motor in Clock & Anti-Clockwise direction Program: #include<at89c5led2.h> #include<stdio.h> #define PHASED 0x09 #define PHASEC 0x0c #define PHASEB 0x06 #define PHASEA 0x03 void delay_ms(unsigned int n) { int i; for(i=0; i<n; i++) { } } void main() { while (1) { P0=PHASEA; delay_ms(10000); P0=PHASEB; delay_ms(10000); P0=PHASEC; delay_ms(10000); P0=PHASED;
  • 46. delay_ms(10000); } } 2.Write an 8051 C program to Generate Sine & Square waveforms using DAC interface. #include <8051.h // Define DAC interface pins #define DAC_DATA P0 // DAC data bus connected to Port 0 // Delay function void delay(unsigned int time) { unsigned int i, j; for(i = 0; i < time; i++) for(j = 0; j < 1275; j++); // Adjust the delay as needed } // Function to generate sine waveform void generateSine() { unsigned char sineWave[] = {127, 159, 190, 219, 245, 255, 245, 219, 190, 159}; // Sine values for one cycle unsigned char i; while(1) { for(i = 0; i < 10; i++) { DAC_DATA = sineWave[i]; // Output sine waveform to DAC delay(100); // Adjust delay for desired frequency } } } // Function to generate square waveform void generateSquare() { unsigned char squareWave[] = {0, 255}; // Square wave values
  • 47. unsigned char i; while(1) { for(i = 0; i < 2; i++) { DAC_DATA = squareWave[i]; // Output square waveform to DAC delay(100); // Adjust delay for desired frequency } } } void main() { // Initialize DAC interface DAC_DATA = 0; // Initialize DAC data bus while(1) { generateSine(); // Generate sine waveform //generateSquare(); // Uncomment this line to generate square waveform } }
  • 48. Viva Questions 1. What do you mean by Embedded System? Give examples. 2. Why are embedded Systems useful? 3. What is Embedded Controller? 4. What is Microcontroller? 5. List out the differences between Microcontroller and Microprocessor. 6. How are Microcontrollers more suitable than Microprocessor for Real Time Applications? 7. What are the General Features of Microcontroller? 8. Explain briefly the classification of Microcontroller. 9. Explain the general features of 8051 Microcontroller. 10. How many pin the 8051 has? 11. Differentiate between Program Memory and Data Memory. 12. What is the size of the Program and Data memory? 13. Write a note on internal RAM. What is the necessity of register banks? 14. What is the function of accumulator? 15. What are SFR’s? 16. What is the program counter? What is its use? 17. What is the size of the PC? 18. What is a stack pointer (SP)? 19. What is the size of SP? 20. What is the PSW? And briefly describe the function of its fields. 21. What is the difference between PC and DPTR? 22. What is the difference between PC and SP? 23. What is ALE? Explain the functions of the ALE in 8051. 24. What are the disadvantages of the ceramic resonator? 25. Explain briefly the difference between the Von Neumann and the Harvard Architecture. 26. Describe in detail how the register banks are organized. 27. What are the bit addressable registers and what is the need? 28. What is the need for the general purpose RAM area? 29. What is Stack and the Stack Pointer. 30. Explain briefly how internal and external ROM gets accessed. 31. What are the different addressing modes supported by 8051 Microcontroller ? 32. Explain the Immediate Addressing Mode. 33. Explain the Register Addressing Mode.
  • 49. 34. Explain the Direct Addressing Mode. 35. Explain the Indirect Addressing Mode. 36. Explain the Code Addressing Mode. 37. Explain in detail the Functional Classification of 8051 Instruction set 38. What are the instructions used to operate stack? 39. What are Accumulator specific transfer instructions? 40. What is the difference between INC and ADD instructions? 41. What is the difference between DEC and SUBB instructions? 42. What is the use of OV flag in MUL and DIV instructions? 43. What are single and two operand instructions? 44. Explain Unconditional and Conditional JMP and CALL instructions. 45. Explain the different types of RETURN instructions. 46. What is a software delay? 47. What are the factors to be considered while deciding a software delay? 48. What is a Machine cycle? 49. Give a brief introduction on Timers/Counter. 50. What is the difference between Timer and Counter operation? 51. How do you differentiate between Timers and Counters? 52. What is the significance of DA instruction? 53. What is packed and unpacked BCD? 54. What is the difference between CY and OV flag? 55. When will the OV flag be set? 56. What is an ASCII code?