[go: up one dir, main page]

100% found this document useful (1 vote)
819 views25 pages

Elevator Interfacing

The document describes a program to simulate a 4-floor elevator using an 8051 microcontroller and C programming. LEDs represent the floors and direction indicators. Floor requests are entered via switches. The program uses arrays to track current and requested floors and determine direction. It loads ports to control LEDs accordingly, incrementing/decrementing as the elevator moves up or down. The program runs in a continuous loop, waiting for input and moving the elevator in response.

Uploaded by

sharada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
819 views25 pages

Elevator Interfacing

The document describes a program to simulate a 4-floor elevator using an 8051 microcontroller and C programming. LEDs represent the floors and direction indicators. Floor requests are entered via switches. The program uses arrays to track current and requested floors and determine direction. It loads ports to control LEDs accordingly, incrementing/decrementing as the elevator moves up or down. The program runs in a continuous loop, waiting for input and moving the elevator in response.

Uploaded by

sharada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Program 3: Elevator

8051 Microcontroller Programming in C


Problem definition:

Write 8051 C program to interface Elevator.


Objective of Program:
An elevator or lift is a type of vertical transportation
that moves people or goods between floors (levels,
decks) of a building, vessel, or other structure.

In the laboratory, simulated environment is created.

Embedded systems can be used to control elevator.


Need and Application of concept:
• In offices, agriculture and manufacturing, an elevator is
used to lift people / materials, in a single / continuous
stream into cubicle, bins.

• Elevators was led by the need for movement of people,


raw materials including coal and any object.

• Demonstaration of 8051 microcontroller with C


programming, for real-time & real-life situation.
Theoretical background:
• 4 floors are assumed: 1st, 2nd, 3rd, 4th
• Floor request by pressing corresponding
switch
• LEDs represent lift floors.
• 10 LEDs used:
• green represent floor &
• yellow represent direction.
• But, all LEDs are, technically, connected
to 4 to 10 line decoder, using IC 7442.
How it works ?
1.1st floor (1st green)
LED is ON.
2.Select floor switch,
to opt for, say, 3rd from
bottom.
3.Green becomes OFF
& next yellow, blinks &
continue till 3rd green
reach.
4.Floor selection
moves green up or
down, as stated above.
ENCODERS AND DECODERS

DECODER

ONLY ONE INPUT ACTIVATED AT A TIME BINARY CODE INPUT

BINARY CODE OUTPUT ONLY ONE OUTPUT ACTIVATED AT A TIME

DECODER - a digital circuit that converts an input binary code into a


single numeric output.
Flow of process:
1. Arrays:
1. Flr with values ReqFlr & CurFlr calculates count i , get the no of
floors to travel.
2. Flr_Clr with values CurFlr gets blanking code to make Red LED off.
2. P0 is loaded with ReqFlr (requested floor), initially 0x01.
3. Upper nibble, simply, made 1111 (F), by ORing with 0x0F0.
4. P1 loaded with ABCD=0000, initially.
5. ABCD is connected to 4 to 10 line decoder using 7442
through P1, goes to the floor by count i, refer table.
6. Three cases are possible:
1. ReqFlr = CurFlr
2. ReqFlr > CurFlr
3. ReqFlr < CurFlr
7. Case 1: ReqFlr = CurFlr
1. Clear RED floor LED by loading P1 with code from Flr_Clr array.
2. Continue, to wait for floor request, inner while loop.
8. Case 2: ReqFlr > CurFlr
1. i = Flr[ReqFlr] - Flr[CurFlr]; gets up count
2. If .. then loop loads P1 with ABCD, increments count, j++
3. delay
9. Case 3: ReqFlr < CurFlr
1. i = Flr[ReqFlr] - Flr[CurFlr]; gets down count
2. If .. then loop loads P1 with ABCD, decrements count, J--
3. delay
10. Current floor becomes required floor
11. Clear floor indicator red LED using Flr_Clr array codes by loading in
P1
12. Outer while loop continues, infinitely.

P1
Lower nibble
=ABCD
Upper nibble
to control
hardware &
blanking RED
LED
Floor travel count, red LED clear
code –tables:
CurFlr To ReqFlr
Sample Case: CurFlr < ReqFlr 1st To 4th
1 8
0x00 0x09

i = Flr[ReqFlr] - Flr[CurFlr]=09-00=09, iterations in i loop


j = Flr[CurFlr]=Flr[00]=00
∴ i loops for 09 times
P1 = 0x0f0 | j=F0 OR 00=F0,
j++=j=j+1=00+01=01
In next iterations,
P1=F0 OR 01=F1,F2,F3,F4,F5,F6,F7,F8,F9
j=j+1=01+01=02,03,04,05,06,07,08,09  elevator travels to 4th floor
else /* If Current floor is < request floor */
{
i = Flr[ReqFlr] - Flr[CurFlr]; // Get the no of
//floors to travel j = Flr[CurFlr];
for(;i>0;i--) //Move the indicator Up
{
P1 = 0x0f0 | j;
j++;
delay(20000);
}
}
  Instructions used:
• Port loaded with hex code (LED glows = 1, LED off = 0)
P1 = 0x0f0 | j;
• infinite while … do loop
while(1)
{ …
}
• delay function
for(;x>0;x--);
Algorithm:
1. Append '1' at the Higher nibble position, ORing with 0FH.
2. Read Request floor from P0
3. Complement to get the proper input
4. If Request floor = Current Floor
1. Clear Floor Indicator
2. Go up to read again
5. If Current floor is > request floor
1. Get the no of floors to travel
2. Move the indicator down
3. Delay to visualize
5. If Current floor is < request floor
5. Get the no of floors to travel
6. Move the indicator Up
7. Delay to visualize
6. Update Current floor
7. Clear the indicator
8. Loop infinitely, from step 1
Code (8051 program in C):
/* 4 LEVEL ELEVATOR */

#include <at89c51xd2.h>

void delay(unsigned int);


unsigned char Flr[9] = {0xff,0x00,0x03,0xff,0x06,0xff,0xff,0xff,0x09};
unsigned char Flr_clr[9] =
{0xff,0x0E0,0x0D3,0xff,0x0B6,0xff,0xff,0xff,0x79};

unsigned char ReqFlr, CurFlr=0X01,i,j;

void main(void)
{ AUXR = 0x10; // Accessing Full XRAM
P1 = 0x00;
P1 = 0x0f0;
while(1)
{
P0 = 0x0f; // Configure Port as i/p
ReqFlr = P0 | 0xf0; // Append '1' at the Higher nibble
// position
while(ReqFlr == 0xff)
ReqFlr = P0 | 0xf0; /* Read Request Floor from P0 */

ReqFlr = ~ReqFlr; // Complement to get the proper input

if(CurFlr == ReqFlr) //If Request floor is equal to Current Floor


{ P1 = Flr_clr[CurFlr]; /* Clear Floor Indicator */
continue; /* Go up to read again */
}
else if(CurFlr > ReqFlr) // If Current floor is >
//request floor */
{
i = Flr[CurFlr] - Flr[ReqFlr]; //Get the no of floors to
//travel
j = Flr[CurFlr];

for(;i>0;i--) //Move the indicator down

{
P1 = 0x0f0 | j;
j--;
delay(20000); // Delay to visualize the effect
}
}
else /* If Current floor is < request floor */
{
i = Flr[ReqFlr] - Flr[CurFlr]; // Get the no of
//floors to travel
j = Flr[CurFlr];

for(;i>0;i--) //Move the indicator Up


{
P1 = 0x0f0 | j;
j++;
delay(20000);
}
}
CurFlr = ReqFlr; /* Update Current floor */
P1 = Flr_clr[CurFlr]; /* Clear the indicator */
}
}

void delay(unsigned int x)


{
for(;x>0;x--);
}
Learning outcome of experiment:
• Design and write the C programs for computing / IO /
logical tasks using 8051 Microcontroller. [L3]
Program Outcome of this course
(POs)
PO1:
Graduates will demonstrate the knowledge of
mathematics, basic sciences, logical reasoning and
engineering.
… ThanQ

You might also like