Aim:
Develop an 8051-program using KeilC to interface an elevator using I/O ports for solving the
following conditions
a. Move the elevator to the user selected floor
b. Once the elevator reaches the desired floor, automatically come back to the ground
floor after some delay

Algorithm:
Start the program.
Initialize port A, port B and port C as output ports.
Move the sequence of input to port A.
Call the delay Routine
Execute the above steps in a while loop
Stop the program

Program:
#include<stdio.h>
#include <REG51.H>
unsigned char xdata control _at_ 0xe003;
unsigned char xdata porta _at_ 0xe000;
unsigned char xdata portb _at_ 0xe001;
unsigned char xdata portc _at_ 0xe002;
void delay(int g);
void main()
{
int i,j,k,m,n,o,p;
int port[9] = { 0,0x3,0x06,0x09,00,0xe0,0xd3,0xb6,0x79};
int tx=0x82;
int *txp=&tx;
control=*txp;
i=0;
o=0;
p=i;
st: p=p|0xf0;
porta = p;
do{
k=portb;
k=k|0xf0;
j=k;
k=k-0xff;
}
while(k==0);
if (j==0xf7)
o=3;
if (j==0xfb)
o=2;
if (j==0xfd)
o=1;
if (j==0xfe)
o=0;
dec: delay(10000);
delay(10000);
m=port[o];
m=m-i;
if(m<0)
goto down;
else
if(m==0)
goto reset;
else
{
i++;
p=i;
n=i|0xf0;
porta= n;
goto dec;
}
down : i--;
p=i;
n=i|0xf0;
porta = n;
goto dec;
reset : o=o+0x5;
porta = port[o];
goto st;
}
void delay(int g)
{
int h;
for(h=0;h<=g;g++)
{
;
}}