Exp 05 Aim: To develop skills to write embedded C program for arithmetic operations.
For
Addition
Algorithm:
- Declare 3 unsigned char variables and 1 unsigned int variable
- Make P1 and P2 as Output
- Assign data to two variables
- Do the addition
- Display the result on port 1
- Multiply two numbers
- Display result on port 2
- Stop
Flow chart:
Program:
#include<reg51.h> void main (void) { unsigned char p,q,r; unsigned int s;
P1=0x00;
P2=0x00; p=0x04; q=0x02; r=
p+q;
P1=r; s=p*q; P2=s;
while(1); } |
/*
Special function register declarations */ /* for the intended 8051 derivative */ //Declare three 8 bit characters //Declare one 16 bit integer // P1 as outpour port // P2 as outpour port //Assign values to character //Perform the addition //Display addition result on P1 //Perform the multiplication // Display multiplication result on P2 |
For
Subtraction
Algorithm:
- Declare 3 unsigned char variables and 1 unsigned int variable
- Make P1 and P2 as Output
- Assign data to two variables
- Do the subtraction
- Display the result on port 1
- division two numbers
- Display result on port 2
- Stop
Flow chart:
Program:
#include<reg51.h> void main (void) { unsigned char p,q,r; unsigned int s; P1=0x00; P2=0x00; p=0x04; q=0x02; r= p+q; P1=r; s=p/q; P2=s; while(1); } |
/*
Special function register declarations */ /* for the intended 8051 derivative */ //Declare three 8 bit characters //Declare one 16 bit integer // P1 as outpour port // P2 as outpour port //Assign values to character //Perform the addition //Display subtraction result on P1 //Perform the division // Display division result on P2 |
Conclusion: In this
experiment we performed different programs on Keil and observed the output.