Team1

Members: Markus Lehtinen, Miika Viitala, Rohit Björkqvist and Timo Levänen

Name State 1 State 0
motor On Off
direction Up Down
sensor_C(Closed) On Off
sensor_O(Open) On Off
loading(Closing/Opening indicator) On Off
button Down(Pressed) Up(Not pressed)
GarageDoor.c
 
#include <REG51.H>
#include <Ports.H>
 
void main (void)
{
 unsigned int i;
 P3 = 0x00;
 P1 = 0x00;
 sensor_c = 1;
 sensor_o = 0;
 while(1)
  {
    if (button == 1 && sensor_c == 0 && sensor_o == 1)  //sensor = 1, on  --- sensor = 0, off
    {
    direction = 0; // 1 = up  0 = down
    motor = 1;     // 1 = on 0 = off
        for (i = 0; i < 40000;i++)
        {
              if ( i % 2 == 0)
              {
              loading = 1; //Blink
              }
              else
              {
              loading = 0;
              }
        }
        door = 0; //Door = 0, closed --- Door = 1, open
        motor = 0;
        sensor_c = 1;
        sensor_o = 0;
        button = 0; 
    }
 
    if (button == 1 && sensor_c == 1 && sensor_o == 0)
    {
    direction = 1;
    motor = 1;  
        for (i = 0; i < 40000;i++)
        {
            if ( i % 2 == 0)
            {
            loading = 1; //Blink
            }
            else
            {
            loading = 0;
            }
        }
        door = 1;
        motor = 0;
        sensor_c = 0;
        sensor_o = 1;
        button = 0; 
    }
  }                                                           
}
Ports.h
 
#ifndef Ports
#define Ports
 
sbit motor = P3^0;
sbit direction = P3^1;
sbit sensor_c = P3^2;
sbit sensor_o = P3^3;
sbit door = P3^4;
sbit loading = P3^7;
sbit button = P1^0;
 
#endif
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License