智能家居控制系统C程序[日期:2010-03-03][来源:本站编辑作者:admin][字体:大中小](投递新闻)#includeAT89X55.Hbitr_flag;enumeepromtype{M2401,M2402,M2404,M2408,M2416,M2432,M2464,M24128,M24256};externbitRW24XX(unsignedchar*DataBuff,unsignedcharByteQuantity,unsignedintAddress,unsignedcharControlByte,enumeepromtypeEepromType);sbitkey=P2^0;bitkey_flag;sbitdog=P0^7;sbitLED=P0^0;sbitTELA=P3^6;sbitTEL=P3^7;sbitRING=P3^2;sbitswitching=P0^4;unsignedcharmode;bitpasswordflag;unsignedcharpassword[6];unsignedcharpasswordtest[6];voiddlms(unsignedintx);voidreset(void);voidopen(void);//****************************************************************////INT1中断服务程序////****************************************************************//unsignedcharring_fluctuation;unsignedcharring_count;bitring_flag;voidservice_int0()interrupt0using1{if(ring_fluctuation10){ring_fluctuation++;}}//****************************************************************////t1定时中断////****************************************************************//unsignedcharring_dlsm;unsignedcharring_time;unsignedintring_reset_time;unsignedchardlms_time;voidtimer1(void)interrupt3using0{TH1=0x3c;TL1=0xb0;dlms_time++;if(ring_fluctuation5){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_count2){ring_reset_time=800;}}}}if((ring_count==2)|(ring_count==1)){ring_time++;if(ring_time==200){ring_flag=1;}}if((ring_count0)&(ring_count6)){LED=INT0;}elseif(passwordflag){LED=~LED;}if(ring_count0){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;}}}//****************************************************************////INT1中断服务程序////****************************************************************//unsignedcharDTMF;voidservice_int1()interrupt2using1{EX1=0;DTMF=P1;DTMF=DTMF4;}voidmain(void){TMOD=0x11;TH1=0x3c;TL1=0xb0;TR1=1;ET1=1;IT0=1;EX0=1;IT1=0;EX1=1;reset();EA=0;r_flag=RW24XX(password,6,0x0000,0xa1,M2402);//Rif(P2_0==0)dlms(20);if(P2_0==0){ring_flag=1;mode=1;passwordflag=1;ring_count=7;ring_fluctuation=6;}EA=1;while(1){open();dog=~dog;switch(mode){case0:;break;case1:TEL=1;LED=0;//dlms_time=0;ring_reset_time=0;while(dlms_time40){dlms(1);TELA=~TELA;}ring_reset_time=0;LED=1;//TELA=0;mode++;DTMF=255;EX1=1;LED=switching;break;case2://passwordif(DTMF!=255){passwordtest[0]=DTMF;if(INT1==1){dlms_time=0;while(dlms_time2);if(INT1==1){DTMF=255;mode++;dlms_time=0;while(dlms_time10){dlms(2);TELA=~TELA;}EX1=1;TELA=0;}}}break;case3://passwordif(DTMF!=255){passwordtest[1]=DTMF;if(INT1==1){dlms_time=0;while(dlms_time2);if(INT1==1){DTMF=255;mode++;dlms_time=0;while(dlms_time10){dlms(2);TELA=~TELA;}EX1=1;TELA=0;}}}break;case4://passwordif(DTMF!=255){passwordtest[2]=DTMF;if(INT1==1){dlms_time=0;while(dlms_time2);if(INT1==1){DTMF=255;mode++;dlms_time=0;while(dlms_time10){dlms(2);TELA=~TELA;}EX1=1;TELA=0;}}}break;case5://passwordif(DTMF!=255){passwordtest[3]=DTMF;if(INT1==1){dlms_time=0;while(dlms_time2);if(INT1==1){DTMF=255;mode++;dlms_time=0;while(dlms_time10){dlms(2);TELA=~TELA;}EX1=1;TELA=0;}}}break;case6://passwordif(DTMF!=255){passwordtest[4]=DTMF;if(INT1==1){dlms_time=0;while(dlms_time2);if(INT1==1){DTMF=255;mode++;dlms_time=0;while(dlms_time10){dlms(2);TELA=~TELA;}EX1=1;TELA=0;}}}break;case7://passwordif(DTMF!=255){passwordtest[5]=DTMF;if(INT1==1){dlms_time=0;while(dlms_time2);if(INT1==1){DTMF=255;mode++;//EX1=1;}}}break;case8:if(passwordflag==0){if((passwordtest[0]==password[0])&(passwordtest[1]==password[1])&(passwordtest[2]==password[2])&(passwordtest[3]==password[3])&(passwordtest[4]==password[4])&(passwordtest[5]==password[5])){mode++;dlms_time=0;}else{reset();}}else{dlms_time=0;while(dlms_time10){dlms(2);TELA=~TELA;}TELA=0;password[0]=passwordtest[0];password[1]=passwordtest[1];password[2]=passwordtest[2];password[3]=passwordtest[3];password[4]=passwordtest[4];password[5]=passwordtest[5];EA=0;r_flag=RW24XX(password,6,0x0000,0xa0,M2402);//WEA=1;reset();}break;case9:while(dlms_time20){dlms(1);TELA=~TELA;}while(dlms_time25){}while(dlms_time45){dlms(1);TELA=~TELA;}TELA=0;EX1=1;mode++;break;case10:switch(DTMF){case1:if(ring_reset_time1050){dlms_time=0;switching=0;LED=0;while(dlms_time10){}while(dlms_time20){dlms(2);TELA=~TELA;}while(dlms_time30){}while(dlms_time40){dlms(2);TELA=~TELA;}TELA=0;DTMF=255;EX1=1;}break;case2:if(ring_reset_time1050){dlms_time=0;switching=1;LED=1;while(dlms_time10){}while(dlms_time20){dlms(4);TELA=~TELA;}while(dlms_time30){}while(dlms_time40){dlms(4);TELA=~TELA;}TELA=0;DTMF=255;EX1=1;}break;case12:reset();break;}break;//--------------------------------------------------------------------//default:;//--------------------------------------------------------------------//}}}voidreset(void){TEL=0;TELA=0;ring_fluctuation=0;ring_count=0;r