Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ground plus two storey elevator using function

Status
Not open for further replies.

syedzeyad

Newbie level 6
Joined
Nov 11, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Karachi, Pakistan, Pakistan
Activity points
1,373
can anyone figure out what is the problem in my code?

thanks

Code:
function1 (){
PORTD.F6=0;
PORTD.F7=1;
if(PORTB.F4!=1){
delay_ms(100);
if(PORTB.F4!=1){
PORTD.F6=0;
PORTD.F7=0;
}
}
}
 function2(){
PORTD.F6=0;
PORTD.F7=1;
if(PORTB.F5==0){
PORTD.F6=0;
PORTD.F7=0;
}
 }
 function3(){
PORTD.F6=1;
PORTD.F7=0;
if(PORTB.F4==0){
PORTD.F6=0;
PORTD.F7=0;
}
}
 function4(){
PORTD.F6=1;
PORTD.F7=0;
if(PORTB.F3==0){
PORTD.F6=0;
PORTD.F7=0;
}
}
 function5(){
PORTD.F6=0;
PORTD.F7=1;
if(PORTB.F5==0){
PORTD.F6=0;
PORTD.F7=0;
}
}
 function6(){
PORTD.F6=1;
PORTD.F7=0;
if(PORTB.F3==0){
PORTD.F6=0;
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;
while(1){
if(PORTB.F3==0 && PORTB.F1==0){
function1();

}
if(PORTB.F4==0 && PORTB.F2==0){
function2();
}

if(PORTB.F5==0 && PORTB.F1==0){
function3();
}
if(PORTB.F4==0 && PORTB.F0==0){
function4();
}
if(PORTB.F3==0 && PORTB.F2==0){
function5();
}
if(PORTB.F5==0 && PORTB.F0==0){
 function6();
}
}
}
 

ground plus two storey elevator using pic16f877a and reed (magnetic switches) for lev

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 it is not working correctly


lift.png


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();
}
}
}
 
Last edited by a moderator:

It would be much easier to understand if descriptive names were given to the pins and functions. Example:
Code:
if((GroundFloor==TRUE) && (CallFloor1==TRUE)) RaiseElevator();  // if the lift is at ground sensed by b3 and button 2 is pressed then it should go to function 1

I would think it also easier to say "if the wanted floor is higher, go up" and "if the wanted floor is lower, go down" instead of jumping from function to function.

Brian.
 

Re: ground plus two storey elevator using pic16f877a and reed (magnetic switches) for

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();
}
}
}
the problem is that the if condition inside the function is not executing...... Why??? Has i done any mistake?
 

if statement not working inside a function in micro c

Code:
# define FIRST_FLOOR PORTB.F3
# define SECOND_FLOOR PORTB.F4
# define BUTTON_1 PORTB.F0
# define THIRD_FLOOR PORTB.F5
# define BUTTON_2 PORTB.F1
# define BUTTON_3 PORTB.F2
#define POSITIVE PORTD.F6
#define  NEGATIVE PORTD.F7
# define TRUE 0
# define FALSE 1

SECONDFLOOR_UP();

THIRD(void);

SECONDFLOOR_DOWN(void);

FIRST(void);

DIRECT_THIRD_FLOOR(void);

DIRECT_FIRST_FLOOR(void);

void 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((FIRST_FLOOR==TRUE && BUTTON_2 ==TRUE) && SECOND_FLOOR==FALSE){
 delay_ms(100);
if((FIRST_FLOOR==TRUE && BUTTON_2 ==TRUE) && SECOND_FLOOR==FALSE){

SECONDFLOOR_UP();
}
}
}
}
SECONDFLOOR_UP(){

POSITIVE=TRUE;          // lift goes to 2ND floor
delay_ms(100);
NEGATIVE=FALSE;
if(SECOND_FLOOR==TRUE) {
POSITIVE=TRUE;
NEGATIVE=TRUE;
                   }
}
when i'm running the simulation on proteus while pressing the button corresponding to second floor the motor i.e the positive negative doesnot becomes true .. why? have i done wrong coding???
 

I do not have MikroC or your simulator so I can't run the program but I would suggest you change:
Code:
if((FIRST_FLOOR==TRUE && BUTTON_2 ==TRUE) && SECOND_FLOOR==FALSE){
to
Code:
if((FIRST_FLOOR==TRUE) && (BUTTON_2 ==TRUE) && (SECOND_FLOOR==FALSE)){
and see if that helps.

Brian.
 

There is no debounce code for buttons and hence button press will act erratically.
 

In this type of application it may not be necessary to use debounce routines. If written properly - and I'm trying to guide Syedzeyad rather than post a solution - debounce is not needed. Pressing a button should just set a target floor, releasing it again or contact bounces shouldn't make it go to a different floor or 'jitter' between them.

Similarly, the switches that detect when a floor has been reached do not need debounce. If you consider the debouncing period in terms of elevator travel, it would only be one or two mm anyway.

The program should work with three variable factors:
1. which floor is the target?
2. where is the elevator now?
3. is it already there?

from those three factors it can decide whether it has to move at all and if so, in which direction. It is also extensible to as many floors as its possible to wire switches for.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top