ground plus two storey lift using 16f877a and reed switch

General discussion on mikroBasic.
Post Reply
Author
Message
zeyad
Posts: 3
Joined: 01 Mar 2016 15:59

ground plus two storey lift using 16f877a and reed switch

#1 Post by zeyad » 01 Mar 2016 18:50

i am having problem in running the operation . the motor of lift doesnot respond on my code correctly please help me in correcting code
lift.png
lift.png (21.4 KiB) Viewed 6435 times

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();
}
}
}



mpc
Posts: 11
Joined: 05 May 2011 13:35

Re: ground plus two storey lift using 16f877a and reed switch

#2 Post by mpc » 13 May 2021 11:47

Hi

if(PORTB.F4!=1)

should be

if(PORTB.F4!==1)

like the functions for the other floors.

MC

Post Reply

Return to “mikroBasic General”