您当前的位置:五五电子网电子知识单片机-工控设备51单片机智能家居控制系统C程序 正文
智能家居控制系统C程序

智能家居控制系统C程序

点击数:7387 次   录入时间:03-04 11:54:21   整理:http://www.55dianzi.com   51单片机
#include <AT89X55.H>

bit r_flag;

enum  eepromtype  {M2401,M2402,M2404,M2408,M2416,M2432,M2464,M24128,M24256};
extern bit   RW24XX(unsigned char *DataBuff,unsigned char ByteQuantity,unsigned int Address,
                     unsigned char ControlByte,enum eepromtype EepromType);


sbit key   = P2^0;
bit key_flag;

sbit dog   = P0^7;
sbit LED   = P0^0;
sbit TELA   = P3^6;
sbit TEL  = P3^7;
sbit RING  = P3^2;
sbit switching =P0^4;


unsigned char mode;
bit passwordflag;
unsigned char password[6];
unsigned char passwordtest[6];

void dlms(unsigned int x);
void reset(void);
void open(void);

//****************************************************************  //
//               INT1中断服务程序                                   //
//****************************************************************  //
unsigned char ring_fluctuation;
unsigned char ring_count;
bit ring_flag;
void servICe_int0() interrupt 0 using 1
{
 if(ring_fluctuation<10)
   {
    ring_fluctuation++;     
    }
 }
//****************************************************************  //
//                      t1 定时中断                                   //
//****************************************************************  //    
unsigned char ring_dlsm;
unsigned char ring_time;
unsigned int ring_reset_time;
unsigned char dlms_time;
void timer1 (void) interrupt 3 using 0
{
  TH1=0x3c;
  TL1=0xb0;
  dlms_time++;
  if(ring_fluctuation>5)
    {
     EX0=0;//INT1_OFF;
     ring_dlsm++;
     if(ring_dlsm==20)//等待一秒
       {
        ring_dlsm=0;
        EX0=1;//INT1_ON;
        ring_fluctuation=0;
        ring_count++;//震铃次数

         if(ring_flag)//有效振铃
           {
            if(ring_count==6)
              {
               ring_count=7;
               mode=1;
               }
            }
         else//无效振铃
           {
            if(ring_count>2)
              {
               ring_reset_time=800;
               }
            }
        }
     }
   

   if((ring_count==2)|(ring_count==1))
     {
      ring_time++;
      if(ring_time==200)
        {
         ring_flag=1;
         }
      }
   if((ring_count>0)&(ring_count<6))
     {
      LED=INT0;
      }
    else if(passwordflag)
      {
      LED=~LED;
       }
   
   if(ring_count>0)
     {
      ring_reset_time++;
      if(ring_reset_time==1100)//55s
        {
         reset();
         LED=0;
          dlms(100);
         LED=1;
          dlms(100);
         LED=0;
          dlms(100);
         LED=1;
          dlms(100);
         LED=0;
          dlms(100);
         LED=1;
          dlms(100);
         LED=0;
          dlms(100);
         LED=1;
          dlms(100);
         LED=0;
          dlms(100);
         LED=1;
          dlms(100);
         LED=0;
          dlms(100);
         LED=switching;
         }
      }

 }

[1] [2] [3] [4] [5] [6] [7] [8] [9]  下一页


本文关键字:智能  控制系统  程序  51单片机单片机-工控设备 - 51单片机