To develop skills to write embedded C program for arithmetic operations. Visit Website

To develop skills to write embedded C program for arithmetic operations.

Exp 05 Aim: To develop skills to write embedded C program for arithmetic operations.

For Addition

Algorithm: 

  1. Declare 3 unsigned char variables and 1 unsigned int variable
  2. Make P1 and P2 as Output
  3. Assign data to two variables
  4. Do the addition
  5. Display the result on port 1
  6. Multiply two numbers
  7. Display result on port 2
  8. 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: 

  1. Declare 3 unsigned char variables and 1 unsigned int variable
  2. Make P1 and P2 as Output
  3. Assign data to two variables
  4. Do the subtraction
  5. Display the result on port 1
  6. division two numbers
  7. Display result on port 2
  8. 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.









Post a Comment

Visit Website
Visit Website