Code: Select all
function1(){
PORTD.F6=0; // lift goes to 1st floor
PORTD.F7=1;
if(PORTB.F4!=1){ // it should stop here that is at 1st floor if the reed switch(magnetic switch) at 1st floor sense it , but in real whenever it sense it doesnot stops.... i don't understand why!!!!
delay_ms(100);
if(PORTB.F4!=1){
PORTD.F6=0;
PORTD.F7=0;
}
}
}
function2(){
PORTD.F6=0; // lift goes to 2nd floor
PORTD.F7=1;
if(PORTB.F5==0){ // it should stop here that is at 2nd floor if the reed switch(magnetic switch) at 2nd floor sense it , but in real whenever it sense it doesnot stops.... i don't understand why!!!!
PORTD.F6=0;
PORTD.F7=0;
}
}
function3(){
PORTD.F6=1; // lift goes to 1st floor
PORTD.F7=0;
if(PORTB.F4==0){ // it should stop here that is at 1st floor if the reed switch(magnetic switch) at 1st floor sense it , but in real whenever it sense it doesnot stops.... i don't understand why!!!!
PORTD.F6=0;
PORTD.F7=0;
}
}
function4(){ // lift goes to ground floor
PORTD.F6=1;
PORTD.F7=0;
if(PORTB.F3==0){ // it should stop here that is at ground floor if the reed switch(magnetic switch) at ground floor sense it , but in real whenever it sense it doesnot stops.... i don't understand why!!!!
PORTD.F6=0;
PORTD.F7=0;
}
}
function5(){
PORTD.F6=0; // lift starts again
PORTD.F7=1;
if(PORTB.F5==0){ // it should stop here that is at 2nd floor if the reed switch(magnetic switch) at 2nd floor sense it , but in real whenever it sense it doesnot stops.... i don't understand why!!!!
PORTD.F6=0;
PORTD.F7=0;
}
}
function6(){ // lift starts
PORTD.F6=1;
PORTD.F7=0;
if(PORTB.F3==0){
PORTD.F6=0; //it should stop here that is at ground floor if the reed switch(magnetic switch) at ground floor sense it , but in real whenever it sense it doesnot stops.... i don't understand why!!!!
PORTD.F7=0;
}
}
int main() {
TRISB.F0=1;
TRISB.F1=1;
TRISB.F2=1;
TRISB.F3=1;
TRISB.F4=1;
TRISB.F5=1;
TRISD.F6=0;
TRISD.F7=0;
PORTD.F6=0;
PORTD.F7=0; //initially the lift is at ground
while(1){
if(PORTB.F3==0 && PORTB.F1==0){ // if the lift is at ground and button 2 is pressed then it should go to function 1
function1();
}
if(PORTB.F4==0 && PORTB.F2==0){ // if the lift is at 1st floor and button 3 is pressed then it should go to function 2
function2();
}
if(PORTB.F5==0 && PORTB.F1==0){ // if the lift is at 2nd floor and button 2 is pressed then it should go to function 3
function3();
}
if(PORTB.F4==0 && PORTB.F0==0){ // if the lift is at 1st floor and button 1 is pressed then it should go to function 4
function4();
}
if(PORTB.F3==0 && PORTB.F2==0){ // if the lift is at ground and button 3 is pressed then it should go to function 5
function5();
}
if(PORTB.F5==0 && PORTB.F0==0){ // if the lift is at 2nd floor and button 1 is pressed then it should go to function 6
function6();
}
}
}