im working on pic 16f877a and mikroc
but the task i want is not achieved through this code.
Further problem is highlighted in the code comments
this is my code for ground plus two storey elevator
i'm checking it in proteus and the problem is that the if condition inside the function is not executing......
View attachment 126624
Code:
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 sensed by b3 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 sensed by b4 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 sensed by b5 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 sensed by b4 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 sensed by b3 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 sensed by b5 and button 1 is pressed then it should go to function 6
function6();
}
}
}