⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integrated.c

📁 门禁系统 interated with LCD
💻 C
字号:
//#include <htc.h>
#include<pic1687x.h>
#include<pic.h>
//#include "delay.h"
char step[] = {8, 4, 2, 1};
char r_step[] = {1, 2, 4, 8}; 
char Door_status,key_card;
void initialize_IO_ports(void)
{
//set the digital IO ports as per requirement
TRISA = 0x00;     //Port A as output
TRISB = 0xFF;     //PortB as input
TRISC = 0xFF;     //PortC as input
TRISD = 0x00;     //portD as output
}
void Open_door(void)
{
 int i=0,x;
 	RD3=0;
 	RD6=1;
    RD7=0;
 
   for ( x=0; x<25; x++)   
   {
       PORTA=step[i];
       //DelayMs(20);
       i++;
       
       if(i == 4)
            i = 0;
   }
}
void Close_door(void)
{
 int i=0,x;
  RD3=1;
  RD7=1;
  RD6=0;
 
  for ( x=0; x<25; x++)   
  {
      PORTA=r_step[i];
       //DelayMs(20);
       i++;
      
      if(i == 4)
            i = 0;
  }
}
void Fan(void)
{
      if (RB5 == 0 && RB7 == 0)              //Fan off
       {  
           RD4=0;
           RD5=0;
       }
       else if (RB5 == 1 && RB7 == 0)        //Fan low speed
       {
                 RD4=1;
                 RD5=0;
       }
       else if (RB5 == 0 && RB7 == 1)        //Fan medium speed
       {
            RD4=0;
            RD5=1;
       }
       else if (RB5 == 1 && RB7 == 1)        //Fan high speed
       {     
            RD4=1;
            RD5=1;
       }
}
void Door_operation(void)
{
      int x;
      
      if ( RB3 == 1 )
      {
       for(x=0;x<10;x++)
         //DelayMs(50);                        //Debouncing   
                    
         if( Door_status == 0 )
         {
             key_card = PORTB & 0x07;        //Checks for correct card
                     
             switch(key_card)
             {
              case 1:
                   Door_status=1;
                   Open_door();
                   key_card = 0;
                   break;
              case 2:
                   Door_status=1;
                   Open_door();
                   key_card = 0;
                   break;
              case 4:
                   Door_status=1;
                   Open_door();
                   key_card = 0;
                   break;
              default:;
             }  
         }
         else                                //toggle Door close
         {
             Door_status=0;
             Close_door();
         }
      }       
      
      if (RB4 == 1 )                         //Toggle door open/close
      {
       for(x=0;x<10;x++)
         //DelayMs(50);
                      
         if(Door_status == 0)
         {
          Door_status=1;
          Open_door();
          }     
         else 
         {
          Door_status=0;
          Close_door();
         }
             
       }
  
}
//main function
int main()
{
//Declare the variables for the main function here
    
    char Master_lock,Fire_escape,Fire_status;    
    
    initialize_IO_ports();
	  
      Fire_status=0;
	  Fire_escape=0;	
      Master_lock=0;                
      Door_status=0;     //Door initially closed           
      RD3=1;
      RD6=0;
      RD7=1;   
                      
//put the infinite loop here
      while(1)
      {
       Fan();                         //Fan operation
          
           
           if ( RC0 == 1 )                //Fire escape
           {
           		if (Door_status == 0)
           		{
           			Open_door();
           			Door_status=1;
           			while( RC0==1 )
           			{}
           		}
           
           }
           		
           if ( RC1 == 1)                 //Master lock
           		Master_lock=1;
           else
           		Master_lock=0;
           
           if (Master_lock== 0)
              Door_operation();
    
     };
return(1);
}


  



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -