Department of Electronics and Communication Engineering
MICROCONTROLLER LAB ( BECL456A )
B.E - IV Semester
2022 scheme - Lab Manual
2024-25
Prepared by Approved by
Dr Shreesha Kalkoor M Dr. Ravishankar C V
Associate Professor Professor & HOD
Dept. Of ECE., SAIT. Dept. Of ECE., SAIT.
Name :
USN :
Batch : Section :
Department of Electronics and Communication Engineering
VISION AND MISSION OF THE INSTITUTE
VISION
The future is embodied in the present generation. Professional education combined
with practical exposure to create values in the students who are the future of our
nation.
MISSION
Work oriented education combined with ethical values, character building in context
of today`s millennium.
QUALITY POLICY
The Sambhram Institute of Technology is committed to create quality professionals
to meet the emerging industrial and social needs through innovative teaching applied
research, Industrial Interaction, placing faith in human values and aiming at continual
improvement in all activities. We strive to provide the quality education that meets
the need and aspirations of the students, employers and society. The institute aims to
respond to all of these groups by providing curriculum and support which is necessary
to enable the progression and to allow individuals to grow, develop and become
universally accepted technocrat.
Department of Electronics and Communication Engineering
DEPARTMENT VISION
“To harness emerging technology by rendering innovative and excellent technical
knowledge for the benefit of mankind.”
DEPARTMENT MISSION
“To imbibe a blend of practical and theoretical ideas in the students to make them
knowledgeable, industrious, entrepreneurial and professional, so that they contribute
not only to the country but also to the world and to humanity in general.”
Department of Electronics and Communication Engineering
Program Educational Objectives (PEOs)
After successful completion of the program, the graduates will be
ECPEO 1: Able to apply concepts of mathematics, science and computing to Electronics and
Communication Engineering.
ECPEO 2: Able to design and develop interdisciplinary and innovative systems.
ECPEO 3: Able to inculcate effective communication skills, team work, ethics, leadership in
preparation for a successful career in industry and R&D organizations.
Program Specific Outcomes (PSOs)
At the end of the program, the student
PSO1. Should be able to clearly understand the concepts and applications in the field of
Communication / networking, signal processing, embedded systems and semiconductor
technology.
PSO2. Should be able to associate the learning from the courses related to Microelectronics, Signal
processing, Microcomputers, Embedded and Communication Systems to arrive at solutions
to real world problems.
PSO3. Should have the capability to comprehend the technological advancements in the usage of
modern design tools to analyze and design subsystems/processes for a variety of
applications.
PSO4. Should possess the skills to communicate in both oral and written forms, the work already
done and the future plans with necessary road maps, demonstrating the practice of
professional ethics and the concerns for societal and environmental wellbeing.
Department of Electronics and Communication Engineering
Course objectives:
This laboratory course enables students to,
Course objectives: This course will enable students to:
• Understand the basic programming of Microcontrollers.
• Develop the 8051 Microcontroller-based programs for various applications using Assembly
Language & C Programming.
• Program 8051 Microcontroller to control an external hardware using suitable I/O ports.
Course outcomes:
At the end of the course the student will be able to:
Course Outcome:
1. Develop programs to manipulate data using different instructions.
2. Develop Testing and experimental procedures on 8051 Microcontroller, Analyze their
operation under different cases.
3. Develop programs for 8051 Microcontroller to implement real world problems.
4. Develop Microcontroller applications using external hardware [Link] your text
Department of Electronics and Communication Engineering
Program outcomes (POs):
Engineering Graduates will be able to:
PO1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2. 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.
PO3. 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.
PO4. 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.
PO5. 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.
PO6. 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.
PO7. 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.
PO8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO10. 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.
PO11. 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.
PO12. 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.
Department of Electronics and Communication Engineering
CO-PO and PSO Mapping
PO PSO
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4
CO1 2 - - 3 - - - - - - - - 2 2 - -
CO2 1 - - 3 - - - - - - - - 2 2 - -
CO3 3 - - - - - - - - - - - 2 2 - -
CO4 - - - - 3 - - - - - - - 2 2 - -
SUM 6 - - 6 3 - - - - - - - 8 8 - -
AVG 2 - - 3 3 - - - - - - - 2 2 - -
3- Highly mapped 2- Moderately mapped 1- Slightly mapped
Department of Electronics and Communication Engineering
INSTRUCTIONS TO THE CANDIDATES
➢ Student should come with thorough preparation for the experiment to be conducted.
➢ Student should take prior permission from the concerned faculty before availing the leave.
➢ Student should come with proper dress code and to be present on time in the laboratory.
➢ Student will not be permitted to attend the laboratory unless they bring the practical record
fully completed in all respects pertaining to the experiment conducted in the previous class.
➢ Student will not be permitted to attend the laboratory unless they bring the observation book
fully completed in all respects pertaining to the experiment to be conducted in present class.
➢ Experiment should be started conducting only after the staff-in-charge has checked the
circuit diagram. All the calculations should be made in the observation book. Specimen
calculations for one set of readings have to be shown in the practical record.
➢ Wherever graphs to be drawn, A-4 size graphs only should be used and the same should be
firmly attached in the practical record.
➢ Practical record and observation book should be neatly maintained.
➢ Student should obtain the signature of the staff-in-charge in the observation book after
completing each experiment.
➢ Theory related to each experiment should be written in the practical record before procedure
in your own words with appropriate references.
BECL456A MICROCONTROLLER LAB
Course objectives: This course will enable students to:
• Understand the basic programming of Microcontrollers.
• Develop the 8051 Microcontroller-based programs for various applications using Assembly
Language & C Programming.
• Program 8051 Microcontroller to control an external hardware using suitable I/O ports.
Note: Execute the following experiments by using Keil Microvision Simulator (any 8051
Microcontroller can be chosen as the target) and Hardware Interfacing Programs using 8051
Trainer Kit.
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.
Department of ECE, Sambhram IT, Bangalore Page 1
BECL456A MICROCONTROLLER LAB
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.
Course Outcome:
Develop programs to manipulate data using different instructions
Develop Testing and experimental procedures on 8051 Microcontroller, Analyze their
operation under different cases.
Develop programs for 8051 Microcontroller to implement real world problems.
Develop Microcontroller applications using external hardware interface.
Suggested Learning Resources: “The 8051Microcontroller: Hardware, Software and
Applications”, V Udayashankara
Department of ECE, Sambhram IT, Bangalore Page 2
BECL456A MICROCONTROLLER LAB
TABLE OF CONTENTS
Sl. No. Contents Page No.
1. Introduction 4
2. Software Execution Procedure 6
3. Hardware Execution Procedure 19
Part-A: Assembly Language Programming
Data Transfer programs
1. Block Transfer 10
2. External memory block transfer 10
3. Exchange of data block 11
4. Exchange of data block with external memory 11
Arithmetic & Logical operation programs
5. Addition 12
6. Subtraction 12
7. Multiplication 12
8. Division 13
9. Separate +ve and –ve 13
10. Separate even and odd 13
11. Sort the array in ascending/descending order 14
12. Largest/Smallest 14
Counter Operation Programs
13. BCD Up counter 15
14. BCD Down counter 15
15. Hexadecimal Up counter 16
16. Hexadecimal Down counter 16
C programming
1. Add first 10 integer numbers 17
2. Factorial 17
3. Square 17
4. Count 1’s & 0’s 18
Part-B: Hardware Interfacing
1. Stepper Motor 20
2. DAC 22
Department of ECE, Sambhram IT, Bangalore Page 3
BECL456A MICROCONTROLLER LAB
ARCHITECTURE OF 8051
PIN DIAGRAM OF 8051
Department of ECE, Sambhram IT, Bangalore Page 4
BECL456A MICROCONTROLLER LAB
Department of ECE, Sambhram IT, Bangalore Page 5
BECL456A MICROCONTROLLER LAB
8051 INSTRUCTION SET:
STEPS TO BE FOLLOWED FOR MICROCONTROLLER SOFTWARE
PROGRAMS:
1. Double click keil μVision4
2. Go to PROJECT in tool bar and select new project
ProjectNew
uVision Project
3. Enter project name (*.UV2). and save it ( Create a folder in D drive and always save
your file inside the folder)
Department of ECE, Sambhram IT, Bangalore Page 6
BECL456A MICROCONTROLLER LAB
Type file name
Click Save
4. A window will appear where you have to choose the PIC Target as “Target1”
5. In database select ATMEL. Again select AT89C51ED2. Click ok.
Select
AtmelAT89C51ED2
Click OK
Click NO
6. Go to FILE in tool bar and select new file.
FileNew
7. Type the program and save it.(With an extension of *.asm for assembly or *.c for ‘C’
programme) (Make sure that your file should be saved in your created folder at D drive)
Department of ECE, Sambhram IT, Bangalore Page 7
BECL456A MICROCONTROLLER LAB
Type the program
Type Filename as *.asm/*.c
Click Save
8. Right click on source group1 then click on Add files to group “source group 1”.
9. Select the programme name and click Add
Right click on Source Group1
Click Add Files to Group ‘Source
Group 1’
Click Add
Click Close
10. Right click on Target1 then select “Build Target”
11. Check for errors
Right Click on File
Click Build target
Get 0 Errors
12. Go to Debug in tool bar, click on start/stop Debug session
Department of ECE, Sambhram IT, Bangalore Page 8
BECL456A MICROCONTROLLER LAB
DebugStart/Stop Debug Session
DebugRun(or Step Over)
Department of ECE, Sambhram IT, Bangalore Page 9
BECL456A MICROCONTROLLER LAB
I. Assembly Language Programming
DATA TRANSFER PROGRAMS
1. Write an ALP to move a block of 5 data bytes from RAM locations 20H to 40H
Program Comments Result
ORG 00H
MOV R2,#5
MOV R0,#20H
MOV R1,#40H
UP: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,UP
HERE: SJMP HERE
END
2. Write an ALP to transfer 5 bytes of data from source 2000h to destination 2050h
using external memory location
Program Comments Result
ORG 0000H
MOV DPTR, #2000H
MOV R0, #50H
MOV R2, #5
REPEAT: MOVX A, @DPTR
MOV @R0, A
INC DPTR
INC R0
DJNZ R2,REPEAT
MOV DPTR, #2050H
MOV R0, #50H
MOV R2, #5
REPEAT1: MOV A,@R0
MOVX @DPTR,A
INC DPTR
INC R0
DJNZ R2,REPEAT1
HERE: SJMP HERE
END
Department of ECE, Sambhram IT, Bangalore Page 10
BECL456A MICROCONTROLLER LAB
3. Write assembly language program to exchange 5 bytes of data at internal memory
20H location to 40H location
Program Comments Result
ORG 0000H
MOV R0, #20H
MOV R1, #40H
MOV R2, #5
UP: MOV A, @R0
XCH A, @R1
MOV @R0, A
INC R0
INC R1
DJNZ R2,UP
HERE: SJMP HERE
END
4. Write an ALP to exchange 5 bytes of data from external memory location 0000H
with internal memory 10H location.
Program Comments Result
ORG 0000H
MOV DPTR, #0000H
MOV R0, #10H
MOV R2, #5
REPEAT: MOVX A, @DPTR
XCH A,@R0
MOVX @DPTR,A
INC DPTR
INC R0
DJNZ R2,REPEAT
HERE: SJMP HERE
END
Department of ECE, Sambhram IT, Bangalore Page 11
BECL456A MICROCONTROLLER LAB
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 Comments Result
ORG 0000H
MOV R0,#34H
MOV A,@R0
INC R0
ADD A,@R0
MOV R5,A
JNC DOWN
MOV R6,#1
DOWN: NOP
HERE:SJMP HERE
END
6. Write an ALP to subtract the bytes in Internal RAM 34h & 35h store the result in
register R5 (LSB) & R6 (MSB).
Program Comments Result
ORG 0000H
MOV A,34H
SUBB A,35H
MOV R5,A
JNC DOWN
MOV R6,#1
DOWN: NOP
HERE:SJMP HERE
END
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 Comments Result
ORG 0000H
MOV A,30H
MOV B,31H
MUL AB
MOV 32H,A
MOV 33H,B
HERE:SJMP HERE
END
Department of ECE, Sambhram IT, Bangalore Page 12
BECL456A MICROCONTROLLER LAB
8. Write an ALP to perform division operation on 8-bit number by 8-bit number.
Program Comments Result
ORG 0000H
MOV A,30H
MOV B,31H
DIV AB
MOV 32H,A
MOV 33H,B
HERE:SJMP HERE
END
9. Write an ALP to separate positive and negative in a given array
Program Comments Result
ORG 0000H
MOV DPTR, #1000H
MOV R0,#30H
MOV R1,#3AH
MOV R2,#05
UP: MOVX A,@DPTR
INC DPTR
RLC A
JB PSW.7,NEXT
RRC A
MOV @R0,A
INC R0
SJMP DOWN
NEXT:RRC A
MOV @R1,A
INC R1
DOWN: DJNZ R2,UP
HERE: SJMP HERE
END
10. Write an ALP to separate even or odd elements in a given array.
Program Comments Result
ORG 0000H
MOV DPTR, #1000H
MOV R0,#30H
MOV R1,#3AH
MOV R2,#05
UP: MOVX A,@DPTR
INC DPTR
RRC A
JB PSW.7,NEXT
RLC A
MOV @R0,A
INC R0
SJMP DOWN
Department of ECE, Sambhram IT, Bangalore Page 13
BECL456A MICROCONTROLLER LAB
NEXT:RLC A
MOV @R1,A
INC R1
DOWN: DJNZ R2,UP
HERE: SJMP HERE
END
11. Write an ALP to arrange the numbers in Ascending & Descending order.
Program Comments Result
ORG 0000H
MOV R2,#04H
OUTER:MOV R0,#40H
MOV A,R2
MOV R1,A
INNER:MOV A,@R0
INC R0
MOV B,@R0
CJNE A,B,NEXT
NEXT:JC DOWN
MOV @R0,A
DEC R0
MOV @R0,B
INC R0
DOWN:DJNZ R1,INNER
DJNZ R2, OUTER
END
12. Write an ALP to find Largest & Smallest number from a given array starting from
20h & store it in Internal Memory location 40h.
Program Comments Result
ORG 00H
MOV R3,#04H
MOV R0,#20H
MOV R1,#40H
MOV A,@R0
INC R0
UP: MOV B,@R0
CJNE A,B,NEXT
NEXT: JNC NOCARRY
MOV A,@R0
NOCARRY: INC R0
DJNZ R3,UP
MOV @R1,A
END
Department of ECE, Sambhram IT, Bangalore Page 14
BECL456A MICROCONTROLLER LAB
Counter Operation Programs:
13. Write an ALP for Decimal UP-Counter.
Program Comments Result
ORG 0000H ViewWatch and call Stack
MOV A,#00H window.
UP: ACALL DELAY Press F2 to edit and type A
ADD A,#01H
DA A
JNZ UP
HERE: SJMP HERE
DELAY: MOV R1, #0FFH
DECR1:MOV R2,#0FFH
DECR: MOV R3,#0FFH
HERE1: DJNZ R3,HERE1
DJNZ R2,DECR
DJNZ R1,DECR1
RET
END
14. Write an ALP for Decimal DOWN-Counter.
Program Comments Result
ORG 0000H ViewWatch and call Stack
MOV A,#99H window.
UP: ACALL DELAY Press F2 to edit and type A
ADD A,#99H
DA A
JNZ UP
HERE: SJMP HERE
DELAY: MOV R1, #0FFH
DECR1:MOV R2,#0FFH
DECR: MOV R3,#0FFH
HERE1: DJNZ R3,HERE1
DJNZ R2,DECR
DJNZ R1,DECR1
RET
END
Department of ECE, Sambhram IT, Bangalore Page 15
BECL456A MICROCONTROLLER LAB
15. Write an ALP for Hexadecimal UP-Counter.
Program Comments Result
ORG 0000H ViewWatch and call Stack
MOV A, #00h window.
BACK: ACALL DELAY Press F2 to edit and type A
INC A
JNZ BACK
HERE: SJMP HERE
DELAY: MOV R1, #0FFH
DECR1:MOV R2,#0FFH
DECR: MOV R3,#0FFH
HERE1: DJNZ R3,HERE1
DJNZ R2,DECR
DJNZ R1,DECR1
RET
END
16. Write an ALP for Hexadecimal DOWN-Counter.
Program Comments Result
ORG 0000H ViewWatch and call Stack
MOV A, #0FFh window.
BACK: ACALL DELAY Press F2 to edit and type A
DEC A
JNZ BACK
HERE: SJMP HERE
DELAY: MOV R1, #0FFH
DECR1:MOV R2,#0FFH
DECR: MOV R3,#0FFH
HERE1: DJNZ R3,HERE1
DJNZ R2,DECR
DJNZ R1,DECR1
RET
END
Department of ECE, Sambhram IT, Bangalore Page 16
BECL456A MICROCONTROLLER LAB
II. C Programming
1. Write an 8051 C program to find the sum of first 10 Integer Numbers.
Program Comments Result
#include <reg51.h> RESULT:
void main ( ) Note: Check the result in
{ D:0XE0 location
unsigned char sum,a;
unsigned char i;
for (i=0; i<=10; i++)
{
sum+=a;
a++;
}
while(1);
}
2. Write an 8051 C program to find Factorial of a given number.
Program Comments Result
#include <reg51.h> NOTE: CHECK THE
void main ( ) RESULTS IN R6 & R7
{ REGISTERS
unsigned int a=1,i; *. MAXIMUM “ i” VALUE
for(i=7;i>0; i--) CAN BE 8
a*=i;
while(1);
}
3. Write an 8051 C program to find the Square of a number (1 to 10) using Look-Up
Table.
Program Comments Result
#include <reg51.h>
void main ( )
{
unsigned int result, num=4;
unsigned int
tab[]={0x0,0x1,0x4,0x9,
0x16,0x25,
0x36,0x49,
0x64,0x81,0x100};
if(num<10)
result =tab[num];
else
result=0;
while(1);
}
Department of ECE, Sambhram IT, Bangalore Page 17
BECL456A MICROCONTROLLER LAB
4. Write an 8051 C program to count the number of Ones and Zeros in two consecutive
memory locations.
Program Comments Result
#include <reg51.h>
void main ( )
{
unsigned char
a[]={0xfa,0xfa},i;
unsigned char ones, zeros;
CY=0;
for(i=0;i<8;i++)
{
a[0]>>=1;
if(CY==1) ones++;
else zeros++;
a[1]>>=1;
if(CY==1) ones++;
else zeros++;
Department of ECE, Sambhram IT, Bangalore Page 18
BECL456A MICROCONTROLLER LAB
STEPS TO BE FOLLOWED FOR INTERFACING PROGRAMS:
1. Follow the initial steps as in software program execution, in addition follow the given
below
2. Again right click on Target1 select OPTION FOR TARGET1
Right click on Target1
Select Option for Target1
3. Select Device then select AT89C51ED2
4. Select Target Xtal(MHz): 11.0592 and Tick on Use On-chip XRAM
5. Select Output and Tick on Create HEX file
6. Right click on Target1 and select Rebuild Target
7. Do the power supply connection for Development kit and press Reset 3 to 4 times.
8. Make connection from CPU to Development Board
Department of ECE, Sambhram IT, Bangalore Page 19
BECL456A MICROCONTROLLER LAB
9. In the μC Development board kit keep the programme switch in PROG[red] mode.
10. Close/Minimize the keil window and double click on
11. Select Device menu find 89C51ED2, click ok
12. Select File menu Load Hex file then browse your created Hex file
13. Select Setting menu Communication, RS232 then set Baud rate as 9600
14. Click on Run
15. Click on Start Application
III. Hardware Interfacing Programs
1. Write an 8051 C Program to rotate stepper motor in Clock & Anti-Clockwise
direction.
FULL STEP -TWO PHASE ON SCHEME
STEP A B C D
1 1 0 0 1
2 1 1 0 0
3 0 1 1 0
4 0 0 1 1
Department of ECE, Sambhram IT, Bangalore Page 20
BECL456A MICROCONTROLLER LAB
CLOCKWISE ROTATION CLOCKWISE ROTATION ANTICOLCKWISE
#include<reg51.h> (ANOTHER TYPE) ROTATION
void delay(unsigned int x) #include<reg51.h>
{ #include<reg51.h> void delay(unsigned int x)
for(;x>0;x--); void delay(unsigned int x) {
} { for(;x>0;x--);
main() for(;x>0;x--); }
{ } main()
unsigned char val,i; main() {
while(1) { unsigned char val,i,j,k;
{ unsigned char val; while(1)
val=0x88; while(1) {
for(i=0;i<4;i++) { for(i=0;i<0x19;i++)
{ val=0x03; {
P2=val; P2=val; val=0x88;
val=val>>1; delay(5750); for(j=0;j<4;j++)
delay(575); val=0x09; {
}}} P2=val; P2=val;
delay(5750); val=val>>1;
val=0x0c; delay(1000);
P2=val; }}
delay(5750); for(k=0;k<0x32;k++)
val=0x06; {
P2=val; val=0x11;
delay(5750); for(j=0;j<4;j++)
}} {
P2=val;
val=val<<1;
delay(1000);
}}}}
Department of ECE, Sambhram IT, Bangalore Page 21
BECL456A MICROCONTROLLER LAB
2. Write an 8051 C program to Generate Sine & Square waveforms using DAC
interface.
SINE wave:
#include<reg51.h>
main()
{
unsigned char
a[]={128,192,238,255,238,192,128,64,17,0,
17, 64};
int i;
while(1)
{
for(i=0;i<12;i++)
P0=a[i];
}}
SQUARE wave:
#include<reg51.h>
void delay(unsigned int x)
{
for(;x>0;x--);
}
main()
{
unsigned char on=0xff,off=0x00;while(1)
{
P0=on;
delay(500);
P0=off;
delay(500);
}}
Department of ECE, Sambhram IT, Bangalore Page 22
Viva Questions
General Questions
1. What is a microcontroller? How does it differ from a microprocessor?
2. What are the main components of a microcontroller?
3. What is the purpose of the program counter, accumulator, and flags in a microcontroller?
4. How do you differentiate between 8-bit, 16-bit, and 32-bit microcontrollers?
5. What are the advantages and disadvantages of using microcontrollers?
6. What is the role of a microcontroller in embedded systems?
7. How do microcontrollers interact with external devices?
8. What is the difference between a microcontroller and a system-on-chip (SoC)?
9. Can you name some popular microcontroller families?
10. What are the typical applications of microcontrollers?
8051 Microcontroller Questions
1. What is the architecture of the 8051 microcontroller?
2. Explain the different operating modes of the 8051 microcontroller.
3. How do you program the 8051 microcontroller? What are the different programming modes?
4. What is the purpose of the PSEN, ALE, and EA pins in the 8051 microcontroller?
5. How do you interface external memory with the 8051 microcontroller?
6. Can you explain the 8051 microcontroller's interrupt structure?
7. How do you handle interrupts in the 8051 microcontroller?
8. What is the role of the 8051 microcontroller's timer/counter?
9. Can you explain the 8051 microcontroller's serial communication capabilities?
10. How do you implement serial communication using the 8051 microcontroller?
11. What is the purpose of the 8051 microcontroller's port pins?
12. Can you explain the 8051 microcontroller's power management features?
13. How do you reset the 8051 microcontroller?
14. Can you explain the 8051 microcontroller's oscillator circuit?
15. How do you troubleshoot common issues with the 8051 microcontroller?
Programming and Interfacing Questions
1. Write a simple program to blink an LED using the 8051 microcontroller.
2. How do you interface a keypad with the 8051 microcontroller?
3. Can you explain how to use the 8051 microcontroller's timer/counter for timing applications?
4. How do you interface an LCD display with the 8051 microcontroller?
5. Can you write a program to perform a simple arithmetic operation using the 8051
microcontroller?
6. How do you implement a delay function using the 8051 microcontroller?
7. Can you explain how to use the 8051 microcontroller's serial communication capabilities for
data transfer?
8. How do you interface a stepper motor with the 8051 microcontroller?
9. Can you explain how to use the 8051 microcontroller's interrupt structure for event handling?
10. How do you implement a simple alarm system using the 8051 microcontroller?
11. Can you explain how to use the 8051 microcontroller's power management features for low-
power applications?
12. How do you interface a temperature sensor with the 8051 microcontroller?
13. Can you write a program to perform a simple data logging application using the 8051
microcontroller?
14. How do you implement a simple security system using the 8051 microcontroller?
15. Can you explain how to use the 8051 microcontroller's oscillator circuit for clock generation?
Assembly Language Programming Questions
1. What is the purpose of the MOV instruction in 8051 Assembly Language?
2. How do you load a value into the accumulator (A) register?
3. What is the difference between the MOVC and MOVX instructions?
4. How do you perform arithmetic operations in 8051 Assembly Language?
5. What is the purpose of the JMP instruction?
6. How do you implement a loop in 8051 Assembly Language?
7. What is the difference between the DJNZ and JNZ instructions?
8. How do you handle interrupts in 8051 Assembly Language?
9. What is the purpose of the PUSH and POP instructions?
10. How do you implement a subroutine in 8051 Assembly Language?
11. What is the difference between the CALL and LCALL instructions?
12. How do you pass parameters to a subroutine in 8051 Assembly Language?
13. What is the purpose of the RET instruction?
14. How do you implement a delay loop in 8051 Assembly Language?
15. What is the difference between the NOP and SJMP instructions?
16. How do you use the SETB and CLR instructions?
17. What is the purpose of the CPL instruction?
18. How do you implement a bit manipulation operation in 8051 Assembly Language?
19. What is the difference between the ANL and ORL instructions?
20. How do you use the XRL instruction?
C Programming Questions
1. What is the difference between #include and #define directives?
2. How do you declare and initialize variables in C?
3. What is the purpose of the main() function?
4. How do you perform input/output operations in C?
5. What is the difference between printf() and scanf() functions?
6. How do you use arrays in C?
7. What is the purpose of the sizeof() operator?
8. How do you implement control structures (if-else, switch, loops) in C?
9. What is the difference between break and continue statements?
10. How do you use functions in C?
11. What is the purpose of the return statement?
12. How do you pass parameters to a function in C?
13. What is the difference between call-by-value and call-by-reference?
14. How do you use pointers in C?
15. What is the purpose of the & operator?
16. How do you implement structures in C?
17. What is the purpose of the typedef keyword?
18. How do you use unions in C?
19. What is the difference between auto and register storage classes?
20. How do you use extern variables in C?
Microcontroller-Specific Questions
1. What is the purpose of the 8051 microcontroller's port pins?
2. How do you configure the 8051 microcontroller's timer/counter?
3. What is the purpose of the 8051 microcontroller's serial communication capabilities?
4. How do you implement interrupt-driven I/O in the 8051 microcontroller?
5. What is the purpose of the 8051 microcontroller's power management features?
6. How do you use the 8051 microcontroller's analog-to-digital converter (ADC)?
7. What is the purpose of the 8051 microcontroller's pulse-width modulation (PWM)
capabilities?
8. How do you implement a simple LED blinker using the 8051 microcontroller?
9. What is the purpose of the 8051 microcontroller's watchdog timer?
10. How do you use the 8051 microcontroller's Brown-Out Detection (BOD) feature?
11. What is the purpose of the 8051 microcontroller's clock circuit?
12. How do you configure the 8051 microcontroller's memory organization?
13. What is the purpose of the 8051 microcontroller's stack?
14. How do you implement a simple calculator using the 8051 microcontroller?
15. What is the purpose of the 8051 microcontroller's UART?
16. How do you use the 8051 microcontroller's SPI interface?
17. What is the purpose of the 8051 microcontroller's I2C interface?
18. How do you implement a simple temperature monitoring system using the 8051
microcontroller?
19. What is the purpose of the 8051 microcontroller's ADC conversion process?
20. How do you use the 8051 microcontroller's DAC conversion process?
****************************************