0% found this document useful (0 votes)
3 views24 pages

Embedded System Examples

The document contains three programs written in C for the 8051 microcontroller. The first program reads numbers from two input ports, adds them, and sends the result to a third port. The second program toggles an LED with a delay, and the third program transfers data from port P0 to port P1 continuously.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views24 pages

Embedded System Examples

The document contains three programs written in C for the 8051 microcontroller. The first program reads numbers from two input ports, adds them, and sends the result to a third port. The second program toggles an LED with a delay, and the third program transfers data from port P0 to port P1 continuously.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

1.

Write a Program to read the number 1 from port 1, number 2 from port 2 , then add
them ,store the result ,send it to Port 3.

#include<reg.51.h>
void main()
{
unsigned char a,b,c ;
P1 = 0XFF ; //make port 1 as input port
P2 = 0XFF ; //make port 2 as input port
a=P1;
b=P2;
c= a+b ;
P3= c;
}

2. Write a program to Turn on and off the LED with some delay.

#include<reg51.h>
sbit LED=P1.1;
void delay(void);
void main(void)
{
while(1)
{
LED=1;
delay();
LED=0;
delay();
}
}

void delay(void)
{
unsigned char i,k;
for(i=0;i<70;i++)
for(k=0;k<255;k++);
}

3. Write a program to transfer the data from port P0 to port P1.

#include<reg51.h>
void main (void )
{
unsigned char X;
P0=0XFF; // P0 as input port
P1=0X00; // P1 as output port
while(1)
{
X = P0; // read port0
P1 = X; // output data to port1
}

You might also like