BCS402 Lab Manual
BCS402 Lab Manual
LAB MANUAL
(2023-24) EVEN SEM
BPOPS103
MICROCONTROLLERS
LABORATORY
IV Semester
Name:
USN:
Batch:
VISVESVARAYA TECHNOLOGICAL UNIVERSITY
JnanaSangama, Belagavi, Karnataka–590018
IV SEMESTER / B.E.
BCS402
MICROCONTROLLER LABORATORY
Prepared By:
DR.ANITHA T G PROF.KOKILA B P
PROFESSOR ASSISTANT PROFESSOR
VISION AND MISSION OF INSTITUTE
VISION
To be a best institution imparting quality engineering education to deal with community
needs through learning and performance.
MISSION
To implement path breaking student centric education methods.
To augment talent, nurture teamwork to transform to develop individual as
responsible citizen.
To educate the students and faculties about entrepreneurship to meet vibrant
requirements of the society.
Strengthen Industry-Institute Interaction for knowledge sharing
Vision
Mission
To enable learning in emerging technologies adopting innovative methods.
To enhance ability, cultivate collaboration to bring change in building
students approach towards society.
To make available platform for harnessing entrepreneurial and leadership qualities.
To partner continuously with industry to inculcate practical knowledge
PEO 1: Graduates will have the expertise in analyzing real time problems and providing
appropriate solutions related to Computer Science & Engineering.
PEO 2: Graduates will have the knowledge of fundamental principles and innovative
technologies to succeed in higher studies, and research.
PEO 3: Graduates will continue to learn and to adapt technology developments combined
with deep awareness of ethical responsibilities in profession
PROGRAM SPECIFIC OUTCOMES(PSO)
PSO 1: Apply the knowledge gained from Mathematics, Basic Computing, Basic Sciences
and Social Sciences in general and all computer science courses in particular to
identify, formulate and solve real life engineering problems.
PSO2: Identify the various analysis & design methodologies for facilitating development
of high quality system software products with focus on performance optimization.
PROGRAM OUTCOMES(POs)
PO2. Problem analysis: Identify, formulate, research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
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.
PO9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
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.
Do wear ID card and follow dress code. Do log off the computers when youfinish.
Be on time to LAB sessions.
Do ask for assistance if you need help.
Do keep your voice low when speaking to others in the LAB.
Do make suggestions as to how we can improve the LAB.
In case of any hardware related problem, ask LAB in charge for solution.
If you are the last one leaving the LAB, make sure that the staff in charge of theLAB
is informed to close the LAB
Do keep the LAB as clean as possible.
Do prepare for lab programs before entering the lab
Don’ts
Do not use mobile phone inside the lab.
Don’t do anything that can make the LAB dirty (like eating, throwing wastepapers
etc).
Do not carry any external devices without permission.
Don’t move the chairs of the LAB.
Don’t interchange any part of one computer with another.
Don’t leave the computers of the LAB turned on while leaving the LAB.
Do not install or download any software or modify or delete any system files onany
lab computers.
Do not damage, remove, or disconnect any labels, parts, cables, or equipment.
Don’t attempt to bypass the computer security system.
Do not read or modify other user’s file.
If you leave the lab, do not leave your personal belongings unattended.
We are not responsible for any theft.
INDEX
Sl. Program Title
No
1 Module – 1.1. Using Keil software, observe the various Registers, Dump, CPSR, with a simple
Assembly Language Programs (ALP).
3. Develop an ALP to multiply two 16-bit binary numbers.
4. Develop an ALP to find the sum of first 10 integer numbers.
5. Develop an ALP to find the largest/smallest number in an array of 32 numbers.
6. Develop an ALP to count the number of ones and zeros in two consecutive memory locations.
Module – 3 7. Simulate a program in C for ARM microcontroller using KEIL to sort the
numbers in ascending/descending order using bubble sort.
8. Simulate a program in C for ARM microcontroller to find factorial of a number.
9. Simulate a program in C for ARM microcontroller to demonstrate case conversion of
characters from upper to lowercase and lower to uppercase.
Module – 4 and 5
10. Demonstrate enabling and disabling of Interrupts in ARM.
11. Demonstrate the handling of divide by zero, Invalid Operation and Overflow exceptions in
ARM. Course outcomes
2 Module – 2 2. Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical
operations (Demonstrate with the help of a suitable program).
5
6
7
10
11
12
COMPUTER PROGRAMMING LABORATORY (BPOPS103)
1. Simulation of a Simple
Calculator. #include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,result;
char op;
clrscr();
printf("\nEnter arithmetic operation [operand(3) operator(+ * / -) operand(4)] \n"); scanf("%d%c
%d",&n1,&op,&n2);
switch(op)
{
case '+': result=n1+n2;
printf("\n Sum=%d",result);
break;
case '-': result=n1-n2;
printf("\nDifference=%d",result);
break;
case '*': result=n1*n2;
printf("\nProduct=%d",result);
break;
case '/': if(n2!=0)
{
float result1=(float)n1/n2; printf("\nQuotient=
%.3f",result1);
}
else
{
printf("\nDivide error!");
}
break;
case '%': result=n1%n2;
printf("\nReminder=%d",result);
break;
default : printf("\nInvalid operator!");
break;
}
getch();
}
SAMPLE OUTPUT:
Sum=7
Difference=-1
Quotient=0.750000
Product=12
Reminder=3
Divide error!
Invalid operator!
ALGORITHM:
Start
Step 1: [Enter first number] read num1
Step 2: [Enter Second number] read num2
Step 3:[Enter Choice] read choice
Step 4:[To perform addition] if the choice is equal to plus add num1 and num2 print result.
Step 5: [To perform subtraction] if the choice is equal to minus subtracts num2 from num1 print
result.
Step 6: [To perform multiplication] if the choice is equal to multiplication multiply num1 and
num2 print result.
Step 7: [To perform division] if the choice is equal to division divide num1 by num2 print
result. Step 8: [To perform Modulus] if the choice is equal to modulus divide num1 by num2
print result (remainder)
STOP
Flowchart
2. Compute the roots of a quadratic equation by accepting the coefficients. Print appropriate
messages.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,r1,r2,d;
clrscr();
printf("Enter the Co-Efficients\
n"); scanf("%f%f%f",&a,&b,&c);
if(a==0||b==0||c==0)
{
printf("Invalid Inputs\n");
}
else
{
d=b*b-4*a*c;
if(d>0)
{
printf("The roots are Real and Distinct\
n"); r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\nr1=%f",r1);
printf("\nr2=%f",r2);
}
else if(d<0)
{
printf("The roots are Real and Imaginary\
n"); r1=-b/(2*a);
r2=sqrt(fabs(d))/(2*a);
printf("\nr1=%f+i%f",r1,r2);
printf("\nr2=%f-i%f",r1,r2);
}
else
{
printf("The roots are Real and Equal\
n"); r1=r2=-b/(2*a);
printf("\nr1=r2=%f",r1);
}
}
getch();
SAMPLE OUTPUT:
1.000000
r1=-0.500000r2=-
1.000000
r1=-0.750000+i0.661438r2=-
0.750000-i0.661438
Algorithm
START
STEP 1: [Input the values of a, b, c]
read a, b, c
STEP 2: [Calculate the determinant]
determinant = b*b-4*a*c
STEP 3: [Check for validity]
If a is equal to 0 and b is equal to 0
print “Invalid Inputs”
STEP 4: [Check for different roots]
If a is equal to 0
print “Linear
equation” Root1=-c/b
Print “Root1”
STEP 5: [Check for real and equal roots]
If determinant is equal to 0
print “Roots are real and
equal” Root1= -b/(2*a)
Root2 = -b/(2*a)
Print “Root1 & Root2”
STEP 6: [Check for real and distinct roots]
If determinant is greater than 0
Then print “Roots are real and distinct”
Root1= (-b+ (sqrt (fabs (determinant))))/(2*a)
Root2= (-b-(sqrt (fabs (determinant))))/(2*a)
Flowchart
3. An electricity board charges the following rates for the use of electricity: for the first200
units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs 1
per unit. All users are charged a minimum of Rs. 100 as meter charge. If the total
amount is more than Rs 400, then an additional surcharge of 15% of total amount is
charged. Write a program to read the name of the user, number of units consumed and
print out the charges.
#include<stdio.h>
#include<conio.h>
void main()
{
int total,temp;
char name[20];
int units;
float charge;
clrscr();
printf("\nEnter the name of the consumer: ");
scanf("%s",name);
printf("\nEnter the units consumed: ");
scanf("%d",&units);
temp=units;
charge=100;
if(temp<200)
charge+=(0.8*temp);
else
{
charge+=(0.8*200);
temp-=200;
if(temp<100)
charge+=(0.9*temp);
else
{
charge+=(0.9*100);
temp-=100;
if(temp>0)
charge+=(temp);
if(charge>400)
charge+=(15*charge/100);
}
}
printf("\nNAME\t\tUNITS\t\tCHARGE");
printf("\n%s\t\t%d\t\t%f",name,units,charge);
getch();
}
SAMPLE OUTPUT:
ALGORITHM
Flowchart
4. Write a C Program to display the following by reading the number of rows as input,
1
1 2 1
1 2 3 2 1
12 3 4 3 2 1
---------------------------
nth row
#include <stdio.h>
void main()
{
int i,j,n;
printf("Input number of rows : ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
/* print blank spaces */
for(j=1;j<=n-i;j++)
printf(" ");
/* Display number in ascending order upto middle*/
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
}
SAMPLE OUTPUT:
1
121
12321
1234321
123454321
else
printf("\n Unsuccessful Search");
getch();
SAMPLE OUTPUT:
Unsuccessful Search
Algorithm
Step 1: Start
Step 2: read the value of n
STEP 3: initialize low=0, high=n-1
STEP 4: read the array elements
using loop and read key
STEP 5: repeat STEP 6 to STEP 9
until low <= high
STEP 6: calculate mid=(low+high)/2
STEP 7: if key=a[mid] set flag=1 goto STEP 9
Step 8: If key > a[mid]
low= mid+1
Step 9: if key < a[mid]
high=mid-1
Step 10: if(flag=1)
Print “ Element found”
else
print “Element not found”
Step 11: Stop
Flowchart
printf("\n");
}
printf("\n MATRIX B \n");
for(i = 0 ; i < p ; i++)
{
for(j = 0 ; j < q ; j++)
{
printf(" %d \t", b[i][j]);
}
printf("\n");
}
printf("\n MATRIX C \n");
for(i = 0 ; i < m ; i++)
{
for(j = 0 ; j < q ; j++)
{
printf(" %d \t", c[i][j]);
}
printf("\n");
}
}
else
printf("Matrix A & B is not multiplicable");
getch();
}
SAMPLE OUTPUT:
MATRIX
A1 2
3 4
MATRIX
B1 2
1 2
MATRIX
C3 6
7 14
Algorithm
Step1: Start
Step2: read matrix A order m and n Step3: read matrix B order p and q Step4: if n not equal to p
print “multiplication not possible” goto Step11. Otherwise goto Step5
Step5: read the elements of matrix A, using loops for i=0 to m-
1 for j= to n-1
Step6: read the elements of matrix B, using loops for i=0 to p-1
for j=0 to q-1
Step7: calculate resultant matrix C using nested loops for i 0 to m-1
for j 0 to q-1
c[i][j]=0 c[i][j]=c[i][j]+a[i][k]*b[k]
[j]
Step8: print elements of matrix A using nested
loops for i to m-1
for j 0 to n-1
Step9: print elements of matrix B using nested
loops for i for j to p-1 to q-1
Step 10: print elements of matrix C using nested
loops for i 0 to n-1
for j 0 to q-1
Step 11: Stop
Flowchart
7. Compute sin(x)/cos(x) using Taylor series approximation. Compare your result with the
built-in library function. Print both the results with appropriate inferences.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define pi 3.142
void main()
{
int degree,i;
float x,nume,denom,sum=0,term;
clrscr();
printf("enter the value of degree\n");
scanf ("%d", °ree);
x=(degree*pi)/180;
nume=x;
denom=1;
i=2;
do
{
term=nume/denom;
nume= -nume*x*x;
denom=denom*i*(i+1);
sum=sum+term;
i=i+2;
}
while(fabs(term)>0.00001);
SAMPLE OUTPUT:
30
sin(30)=0.500059 without using built in function
sin(30)=0.500059 using built in function
Algorithm
Step 1: Start
Step 2: initialize sum to 0
Step 3: read the value of degree
Step 4: calculate
x=(degree*PI)/180 Step 5: initialize
nume to x
denom to 1 i=2
Step 6: do term=nume/denom; nume=nume*x*x; denom=denom*i*(i+1) sum=sum+term
i=i+2 while(fabs(term)>0.00001)
Step 7: print (sin(x) without built-in function)
Step 8: print sin(x) using built-in function
Step 9: Stop.
Flowchart
#include <stdio.h>
# #include<conio.h>
void main()
{
int n,i,j,a[10],b[10],temp;
clrscr();
printf("\n Enter the no. of elements : ");
scanf("%d",&n);
printf("\n Enter %d elements\n",n);
for(i = 0 ; i < n ; i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
for(i = 0 ; i < n-1 ; i++)
{
for(j = 0 ; j < n-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("\nThe original elements are\n ");
for(i = 0 ; i < n ; i++)
printf("%d \n",b[i]);
printf("\nThe Sorted elements are\n ");
for(i = 0 ; i < n ; i++)
printf("%d \n",a[i]);
getch();
}
SAMPLE OUTPUT:
Enter 5 elements
12 45 76 3 0
Algorithm
Step1: Start
Step2: Read the value of n
Step3: Read the array elements using loop
for i to n-1
Step4: Repeat steps using nested loop
Step5: for i=0 to n-1 for j=0 to n-i
if(a[j] > a[j+1]) temp = a[j]; a[j] = a[j+1]; a[j+1] = temp;
Step6: print the sorted elements using loop for i=0 to n-1
Step7: Stop
9.Write functions to implement string operations such as compare, concatenate, string length.
Convince the parameter passing techniques.
#include<stdio.h>
int slength(char str[])
{
int len; //int len=0;
for(len=0;str[len]!='\0';len++); //while(str[len]!='\0')
return len; //len++;
//return len;
}
conc[i]=str1[i];
for(j=0; j<slength(str2);j++)
conc[i++]=str2[j]; conc[i]='\
0';
}
void main()
{
char str1[50],str2[50],conc[100];
int len,choice;
clrscr();
while(1)
{
printf("\n\n\nMAIN MENU\n");
printf("\n1.Compare strings\n2.Concatenate Strings\n3.String Length\n4.Exit\n\n");
} // End of Switch
}} //End of While
SAMPLE OUTPUT:
MAIN MENU
1.Compare strings
2.Concatenate Strings
3.String Length
4.Exit
MAIN MENU
1.Compare strings
2.Concatenate Strings
3.String Length
4.Exit
Algorithm:
Step 3. [perform two string compare using a function] Call the function Str2cmp(s1,s2)
Step 4. [perform two string concatenation] Call the function Str2cat(s1,s2)
Step 5. Find the length of two string using a function] Call the function length(s1), length(s2)
Step 6. [Finished] Stop
Flowchart
34
COMPUTER PROGRAMMING LABORATORY (21CPL27/17)
10.Implement structures to read, write, and compute average- marks and the students
scoring above and below the average marks for a class of N students. #include<stdio.h>
#include<string.h>
struct student
{
int rnumber;
char name[20];
int marks;
char grade;
}stud[60];
void main()
{
int i,n;
float sum=0,avg=0;
clrscr();
printf("Enter the number of students");
scanf("%d",&n);
printf("\nEnter the roll number, Name , Marks and Grade of the student \n");
for(i=1;i<=n;i++)
{
printf("\nStudent %d details\n",i);
scanf("%d",&stud[i].rnumber);
scanf("%s",stud[i].name);
scanf("%d",&stud[i].marks);
fflush(stdin);
stud[i].grade=getchar();
sum+=stud[i].marks;
}
avg=sum/n;
printf("\n Avg marks is %f",avg); printf("\
nStudent Details are:"); printf("\nRoll_number\
tName\tMarks\tGrade"); for(i=1;i<=n;i++)
printf("\n%d\t\t%s\t%d\t%c\t",stud[i].rnumber,stud[i].name,stud[i].marks,stud[i].grade);
printf("\n Details of Students who scored Above avarage Marks\n"); printf("\nRoll_number\
tName\tMarks\tGrade\n");
for(i=1;i<=n;i++)
{
if(stud[i].marks >= avg) printf("\n%d\t\t%s\
t%d\t%c\t",
stud[i].rnumber,stud[i].name,stud[i].marks,stud[i].grade);
}
SAPTHAGIRI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 41
COMPUTER PROGRAMMING LABORATORY (21CPL27/17)
for(i=1;i<=n;i++)
{
if(stud[i].marks < avg) printf("\n%d\t\t%s\t
%d\t%c\t",
stud[i].rnumber,stud[i].name,stud[i].marks,stud[i].grade);
}
getch();
}
SAMPLE OUTPUT:
Enter the roll number, Name , Marks and Grade of the student
Student 1 details
10
pradeep
50
A
Student 2 details
15
manju
60
B
Student 3 details
20
govind
70
A
15 manju 60 B
20 govind 70 A
Details of Students who scored Below avarage
10 pradeep 50 A
Algorithm
Step 1: Start
Step 2: Define the structure with required variables Step 3: Read the value of n
Step 4: Read the student details using loop for i= 1 to n read rnumber, name marks, grade
Step 5: Calculate sum Sum=sum+marks
Flowchart
11.Develop a program using pointers to compute the sum, mean and standard deviation of all
e elements stored in an array of n real numbers.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a[10],*ptr,mean,std,sum=0,sumstd=0;
intn,i;
clrscr();
printf("enter the no of elements\n");
scanf("%d",&n);
printf("enter the array elemnts\
n"); for(i=0;i<n;i++)
scanf("%f",&a[i]);
ptr=a;
for(i=0;i<n;i++)
{
sum=sum+*ptr;
ptr++;
}
mean=sum/n;
ptr=a;
for(i=0;i<n;i++)
{
sumstd=sumstd+pow((*ptr-mean),2);
ptr++;
}
std=sqrt(sumstd/n); printf("sum=%f\
t",sum); printf("mean=%f\t",mean);
printf("standard deviation=%f\t",std);
getch();
}
SAMPLE OUTPUT:
Enter the no of elements
5
Enter the array elements
2
3
4
5
6
Sum=20.000 Mean=4.000 Standard deviation=1.414
COMPUTER PROGRAMMING LABORATORY (21CPL27/17)
Algorithm
FLOWCHART
COMPUTER PROGRAMMING LABORATORY (21CPL27/17)
12. Write a C program to copy a text file to another, read both the input file name and target
file name.
#include <stdio.h>
#include <stdlib.h> // For exit()
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
fclose(fptr1);
fclose(fptr2);
return 0;
}
COMPUTER PROGRAMMING LABORATORY (21CPL27/17)