Embedded System Examples
Embedded System Examples
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++);
}
#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
}