1. Keypad Codes TOP
// Door Driver Program developd by Xavier Capilitan
// Please see other Sentinal documentation
void opendoor(){ //output bit 00000001, for first bit
int value = 0x40; //of the data line!!!
outportb(0x37a, 0x02);
outportb(0x378, value);
printf("\nDoor is open.\n");
}
void closedoor(){ //output bit 00000010, reverses action of open
int value = 0x80;
outportb(0x37a, 0x02);
outportb(0x378, value);
printf("\nDoor is closed.\n");
}
void stopdriver(){ //this stops the voltage supply to motor
int value = 0x00;
outportb(0x37a, 0x02);
outportb(0x378, value);
}
int leftswitch() //left switch status checks if door is fully
{int stat; //closed or not!!!
stat=inportb(0x379);
do{ //loop until inport reads a 1e which means
stat=inportb(0x379); //door is fully closed and locked!!!
delay(500);
}while(stat!=0x2e);
if (stat==0x2e) //stops driver motor
{stopdriver();}
return 0;
}
int rswitch() //right switch status checks if door is fully
{int stat; //open.
do{ //unless there is a change in status of inport
stat=inportb(0x379); //lines to 6e which means that door has been opened
delay(500); //and closed
}while(stat!=0x5e);
if (stat==0x5e) //stops motor driver if right switch is on
and door is open
{stopdriver();}
return 0;
}
int doorstat() //checks door status if open or close
{int stat;
stat=inportb(0x379);
do{
stat=inportb(0x379);
delay(500);
}while(stat!=0x4e);
//2e indicates that right switch is on and door closed
if (stat==0x4e)
{closedoor();
printf("\nDoor is closed!!");}
return 0;
}
void door(){ //function calls for door to open, check status
opendoor(); //and door close
rswitch();
doorstat();
leftswitch();
outportb(0x378,0x00);
return;
}
int door_status() //separate function which indicates door status
{int check; //either close or open!!!
int stat=inportb(0x379); //for this particular program, door status check
if (stat==0x4e || stat==0x2e) //always returns a 1 meaning close!!!
{check = 1;}
else check=0;
return check;
}
/*
int main(){
clrscr() ;
outportb(0x378,0x00); //this secures that neither one of the input to motor is high
int grant=access();
if (grant!=0){door();}
int check=door_status(); //this takes on the return value of door_status
//printf("\n1 is close, O is open....%d", check)//either close '0' or open '1'
outportb(0x378,0x00); //same here, see previous comment on outportb()
getch();
return 0;
}*/
|