Created
February 6, 2020 17:52
-
-
Save purplecandy/6fc05d5c11854a6fd6fc57c917cd3a76 to your computer and use it in GitHub Desktop.
ES lift practical code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<reg51.h> | |
int floor[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02}; | |
unsigned int curr = 0; | |
sbit gd = P1^3; | |
sbit f = P1^2; | |
sbit s = P1^1; | |
sbit t = P1^0; | |
void delay() | |
{ | |
int count=0; | |
while(count!=500) | |
{ | |
TMOD=0x01; //16-bit timer0 selected | |
TH0=0xF8; // Loading high byte in TH | |
TL0=0xCC; // Loaded low byte in TL | |
TR0=1; // Running the timer | |
while(!TF0); //Checking the timer flag register if it is not equal to 1 | |
TR0 = 0; // If TF0=1 stop the timer | |
TF0 = 0; // Clear the Timer Flag bit for next calculation | |
count++; | |
} | |
} | |
void changeFloor(unsigned int dest){ | |
unsigned int i = curr; | |
if(P2<floor[dest]){ | |
while(i>dest){ | |
i--; | |
delay(); | |
P2 = floor[i]; | |
} | |
} | |
if(P2>floor[dest]){ | |
while(i<dest){ | |
i++; | |
delay(); | |
P2 = floor[i]; | |
} | |
} | |
curr = dest; | |
} | |
void main(){ | |
P2 = 0x80; | |
while(1){ | |
if(gd==0){ | |
changeFloor(0); | |
} | |
if(f==0){ | |
changeFloor(2); | |
} | |
if(s==0){ | |
changeFloor(4); | |
} | |
if(t==0){ | |
changeFloor(6); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment