构思布景
现在的许多企业都在很高的楼层作业,每天上下班顶峰期,电梯门口总是会排上很长的队,为了让电梯用最快的速度将一切的肿痛送到指定楼层,需求给出一些改善;下班的时分,咱们楼层很高,肿痛往往需求花费一些时刻等候电梯抵达自己的楼层,运用一些改善能够让肿痛把握电梯状况,然后节约一些等电梯的时刻。
功用特征
-
功用一:咱们对电梯作出这样的改善:在上班顶峰时段,电梯只能向上运转时开门搭载上朝楼上去的人员,即电梯只会呼应朝上行的按键,在向下运转的过程中,不会呼应任何按钮。鄙人班时刻段,也能够做相应修正。然后节约大多数人的时刻,将人快速送达指定地址。
-
功用二: 平常,咱们作业人员多作业于很高的楼层,而此刻的电梯或许处于一楼,所以能够先向操控中心发送一条短信来获取电梯的实践方位,假如电梯此刻间隔自己地址的楼层还有一段间隔,就能够提早向操控中心发送一条恳求短信,这时操控中心会向电梯运用端发送恳求信号,指令电梯开往指定的楼层,然后削减等候的时刻。
具体操作
只需求修正短信XY#到指定的电话号码就能够长途操控电梯的运转。其间X代表发信人地址楼层,Y代表发信人酿制抵达的楼层。电梯也会对发信人的要求进行应对,告知电梯当时的运转状况,好让发信人把握好乘坐电梯的时刻。
GPRS的运用
咱们首要用到了有方GPRS模块的短信收发功用。首要用于在上下班顶峰时协助肿痛取得电梯状况信息、向电梯发送停靠指令。指令电梯开往指定的楼层,然后削减等候的时刻。电梯运用端运用有方GPRSM660+模块来接纳来自操控中心的信号并发送短信作为应对,然后完成用户与电梯的交互通讯。
硬件电路图
著作展现
原文:http://blog.csdn.net/tengweitw/article/details/45896479
作者:nineheadedbird
软件完成
#include#include #define uint unsigned int#define uchar unsigned char#define FLOOR 10int Con_Floor = 1;//当时的楼层号int com_dat = 0 ;int flag2 = 0 ;int low = 1 ;int high = 9 ;int sign_flag = 0 ;void delayms(uint xms); //延时函数(毫秒级)uint test(uchar * floor); //测验在几楼uint checkinfo();uchar ReceiveData(uchar* ,uchar*);void writefloor(int);void writestate(int);void up_down_logic(); //电梯的运转逻辑void com_init(void); //串口初始化void send_uart(uchar ch); //向串口发送单个字符void send_AT_IPR(void); //设置模块的波特率为9600bpsvoid send_AT_CMGF(void); //设置发短信为文本形式void send_AT_CSCS(void); //发送TE的字符集为GSMvoid send_AT_CNMI(void); //设置短信的提示信息void send_AT_CMGR(); //发送读取指令void send_AT_CMGS(uchar *phone_num); //挑选发送意图手机号void send_text(uchar *text); //发送短信文本void init_GPRS(void); //初始化GPRS模块sbit dula=P2^6;sbit wela=P2^7;sbit rs=P3^5;sbit lcden=P3^4;sbit s1=P2^0;sbit s2=P2^1;sbit s3=P2^2;sbit s4=P2^3;sbit rd=P3^7;sbit dscs=P1^4;sbit dsas=P1^5;sbit dsrw=P1^6;sbit dsds=P1^7;sbit dsirq=P3^3;uchar count,s1num,flag,flag1;uchar miao,shi,fen;uchar code table[]=" 2012-10-15 MON";uchar code table1[]=" 00:00:00";uchar code floor[]="FLOOR: 1";uchar code state[]="STATE: IDLE";uchar code welcome[]="WELCOME TO USE!";uchar code up[]="UP ";uchar code down[]="DOWN";uchar code idle[]="IDLE";void write_date(uchar);void write_ds(uchar,uchar);uchar read_ds(uchar); //从ds187读取时刻void init();void keyscan();void write_sfm(uchar add,uchar date);uchar code *AT_CMGF = "AT+CMGF=1"; //发送AT+CMGF=1,设置文本形式uchar code *AT_CSCS = "AT+CSCS="; //挑选TE的字符集(默许是GSM),M580回来数据时缓冲数组是OKuchar code *AT_IPR = "AT+IPR=9600"; //设置波特率为9600bpsuchar code *AT_CNMI ="AT+CNMI=2,1,0,0,0" ; //设置收到新短信存于SIM卡中并发CMTI告诉uchar code *AT_CMGR="AT+CMGR="; //发送读取短信的指令uchar code *AT_CMGS="AT+CMGS=";uchar xdata buffer[100]={0}; //单片机用于接纳短信的缓冲uchar code tab[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//流水灯的状况uchar code message0[] = "Sorry ,it is busy now ";uchar code message1[] = "Sorry , we can only reach to ";//指明能够抵达的结尾uchar code message2[] = "and now we are moving to ";//指明酿制抵达的楼层uchar code message3[] = "Ok , we have accepted your request !";//承受恳求后发送的音讯/\*称号:test(char* )*功用:判别电梯的此刻状况\/uint test(uchar * floor){uint i;for (i = 1 ; i < FLOOR ; i++)//从一楼开端判别{if(floor[i]){if(i < Con_Floor)return 1;//一共电梯正鄙人降else return 0;//一共电梯正在上升}}return 2;//一共此刻电梯为空}/\*称号:up_down_logic()*功用:电梯的升降逻辑\/void up_down_logic(){uchar floor_data [FLOOR]={0};//判别碑文方向uchar buf[FLOOR]={0};uchar tel[13] ;uchar temp;uint i=0;uchar temp1 ;while(1){miao=read_ds(0); //没有呼应时,时刻能够正确的运转,可是一旦有恳求,时刻便会呈现跳动状况fen=read_ds(2);shi=read_ds(4);write_sfm(10,miao);write_sfm(7,fen);write_sfm(4,shi);delayms(100);while(checkinfo()){/* i = 0;while(tel[i]){tel[i] = 0 ;i++;}*/temp=ReceiveData(&temp1,tel);//temp 一共起点,temp1一共结尾EA=0;//关中止//以下是将缓冲区清空i=0;while(buffer[i]){buffer[i]=0;i++;}com_dat=0;if (test(floor_data)==1&&temp-0>=1&&Con_Floor>=1)//鄙人降{if(temp -0 < Con_Floor&&!floor_data[temp-0])//8点之前为上楼的顶峰,所以下楼的恳求(在7点半曾经)不予呼应,电梯直接抵达一楼{if(temp1-0 < temp - 0 && temp1 - 0 >= low&&(read_ds(4)>8))//希望到楼下去,即temp1 < temp的且此刻电梯所能到的最低点比temp1还小{floor_data[temp-0]=1;buf[temp-0] = temp1-0;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (temp1 - 0 < temp - 0 && temp1 - 0 < low &&(read_ds(4)>8))//希望到楼下去,即temp1 < temp的且此刻电梯所能到的最低点比temp1大{if (buf[low] < low)//假如在电梯所能到的最低点处就没有恳求了或有向下的恳求{floor_data[temp-0]=1;buf[temp-0] = temp1-0;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else{send_AT_CMGS(tel);//先发号码delayms(500);send_text(message1);send_uart(low+0);delayms(10);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}}else if(temp1 - 0 < temp - 0 && temp1 - 0 < low &&(read_ds(4)<8)){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message0);send_uart(low+0);delayms(10);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (temp1 - 0 > temp - 0&& temp - 0 < low)//假如希望到楼上去,则仅当到最低点处没有恳求或恳求抵达的当地小于temp后才能够{if ((buf[low] == 0||(buf[low] > temp - 0 && buf[low] < low))&&(read_ds(4)<5))//保证电梯到low层后无恳求或有向下的但大于temp的恳求{floor_data[temp - 0] = 1 ;buf[temp - 0] = temp1 - 0 ;high = temp1 - 0 ;//在电梯向上运转时所能抵达的最高点low = temp - 0 ;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else if(buf[low] > low &&(read_ds(4)<5)){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message1);send_uart(low+0);delayms(10);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else if(buf[low] < temp - 0 &&(read_ds(4)<5)){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message1);send_uart(buf[low]+0);delayms(10);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else//不呼应会碑文下面的查办{send_AT_CMGS(tel);//先发号码delayms(500);send_text(message0);send_uart(buf[low]+0);delayms(10);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}}}}else if (!test(floor_data)&&temp-0>=1&&Con_Floor>=1)//在上升{if(temp-0 > Con_Floor&&!floor_data[temp-0]){if(temp1-0 > temp - 0 && temp1 - 0 <= high &&(read_ds(4)<5))//恳求者希望到楼上去,且此刻电梯所能抵达的最高点比恳求temp1还大{floor_data[temp-0]=1;buf[temp-0] = temp1-0;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (temp1 - 0 > temp - 0 && temp1 - 0 > high &&(read_ds(4)<5))//恳求者希望到楼上去,且此刻恳求的意图地现已超越了电梯所能抵达的最高点{if (buf[high] > high || buf[high] == 0)//假如电梯到了最高点处还有向上的恳求或许到了最高点处就没有恳求了{floor_data[temp-0]=1;buf[temp-0] = temp1-0;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (buf[high] < high){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message1);send_uart(high+0);delayms(10);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}}else if(temp1 - 0 > temp - 0 && temp1 - 0 > high &&(read_ds(4)>5))//不呼应时碑文{send_AT_CMGS(tel);//先发号码delayms(500);send_text(message0);send_uart(buf[low]+0);delayms(10);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (temp1 - 0 < temp - 0 && temp - 0 > high )//恳求者希望到楼下去{if ((buf[high] == 0||(buf[high] < temp - 0&&buf[high] > high))&&(read_ds(4)>8))//要保证电梯抵达high层后没有恳求或有向上的小于temp的恳求{floor_data[temp - 0] = 1 ;buf[temp-0] = temp1 - 0;low = temp1 - 0;high = temp - 0;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (buf[high] < high &&(read_ds(4)>8)){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message1);send_uart(high+0);delayms(10);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else if (buf[high] > temp - 0&&(read_ds(4)>8)){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message1);send_uart(buf[high]+0);delayms(10);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}else{send_AT_CMGS(tel);//先发号码delayms(500);send_text(message0);send_uart(low+0);delayms(10);send_text(message2);send_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}}}}else if (test(floor_data)==2&&temp-0!=Con_Floor&&temp-0>=1&&Con_Floor>=1)//电梯未被恳求,则呼应,可是恳求的楼层数便是本层楼则不予呼应{if (temp - 0 > temp1 - 0&&(read_ds(4)>8)){low = temp1 - 0;buf[temp - 0] = temp1 - 0;floor_data[temp-0]=1;send_AT_CMGS(tel);//先发号码delayms(500);send_text(message3);send_text(message2);if(temp-0>Con_Floor)send_uart(Con_Floor+1+0);elsesend_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else if(temp - 0 > temp1 - 0&&(read_ds(4)<8)){send_AT_CMGS(tel);//先发号码delayms(500);send_text(message0);send_uart(low+0);delayms(10);send_text(message2);send_uart(Con_Floor+0);delayms(10);send_uart(0x1a);delayms(10);}else if(temp - 0 < temp1 - 0&&(read_ds(4)<5)){high = temp1 - 0;buf[temp - 0] = temp1 - 0 ;send_AT_CMGS(tel);//先发号码floor_data[temp-0]=1;delayms(500);send_text(message3);send_text(message2);if(temp-0 > Con_Floor)send_uart(Con_Floor+1+0);elsesend_uart(Con_Floor-1+0);delayms(10);send_uart(0x1a);delayms(10);}else if(temp - 0 < temp1 - 0&&(read_ds(4)>5))//不呼应时碑文{send_AT_CMGS(tel);//先发号码delayms(500);send_text(message0);send_uart(buf[low]+0);delayms(10);send_text(message2);send_uart(Con_Floor+1+0);delayms(10);send_uart(0x1a);delayms(10);}}}if(test(floor_data)==1)//下降{writefloor(Con_Floor);writestate(1);delayms(3000);Con_Floor--;}else if(!test(floor_data))//上升{writefloor(Con_Floor);writestate(0);delayms(3000);Con_Floor++;}else if (test(floor_data) == 2)//处于闲暇状况{writefloor(Con_Floor);writestate(2);high = 9;low = 1 ;}if(floor_data[Con_Floor])//假如之前被恳求过,则呼应{P1=tab[Con_Floor];delayms(3000);if (buf[Con_Floor]!=0){floor_data[buf[Con_Floor]] = 1 ;buf[Con_Floor] = 0;}P1=0xff;floor_data[Con_Floor] = 0 ;}EA = 1 ;//开中止}}void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com){rs=0;lcden=0;P0=com;delay(5);lcden=1;delay(5);lcden=0; }void write_date(uchar date){rs=1;lcden=0;P0=date;delay(5);lcden=1;delay(5);lcden=0; }void init(){uchar num;EA=1;EX0=1;IT0=1;dula=0;wela=0;lcden=0;write_ds(0x0B,0x26);read_ds(0x0c);write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);//for(num=0;num<15;num++){write_date(table[num]);delay(5);}write_com(0x80+0x40);for(num=0;num<12;num++){write_date(table1[num]);delay(5);}//miao=read_ds(0); fen=read_ds(2);shi=read_ds(4);write_sfm(10,miao);write_sfm(7,fen);write_sfm(4,shi);delayms(5000);write_com(0x80);write_com(0x01);//for(num=0;num<15;num++){write_date(welcome[num]);delay(20);}delay(3000);write_com(0x01);write_com(0x80+0x10);for(num=0;num<8;num++){write_date(floor[num]);delay(20);}write_com(0x80+0x50);for(num=0;num<11;num++){write_date(state[num]);delay(20);}for(num=0;num<16;num++){write_com(0x18);delay(50);}}void writefloor(int i){write_com(0x80+0x17);write_date(0x30+i);}void writestate(int flaggg){uint i ;write_com(0x80+0x57);if(flaggg==1){for(i=0;i 0;i--)for(j=113;j>0;j--);}/* end function delayms *//\* 称号: com_int()* 功用: 串口中止子函数* 输入: 无* 输出: 无\/void com_int(void) interrupt 4{EA=0; //关总中止if(1 == RI) //当硬件接纳到一个数据时,RI会置高位{buffer[com_dat] = SBUF; //存取串口接纳的数据RI = 0; //软件置RI为0if(buffer[com_dat]==#){flag2 = 1; //接纳短信内容完毕com_dat++;//#号纷歧定是最终一个字符!!!}else{com_dat++;} }EA = 1; //开总中止}/* end function com_int *//\* 称号: com_init()* 功用: 串口初始化,晶振11.0592MHz,波特率9600bps* 输入: 无* 输出: 无\/void com_init(void){TMOD=0X20;TH1=253;TL1=253;TR1=1;EA=1;ES=1;SM0=0;SM1=1;REN=1;}/\*称号:checkinfo()*功用:查看是否有数据抵达\/uint checkinfo(){uint i=0;if(buffer[0]!=0&&flag2==0)//短信抵达的提示指令现已被单片机接纳{while(buffer[i]){if(buffer[i]==,)return 1 ;//有短信抵达i++;}}return 0;//数据暂时不能接纳}/\*称号:ReceiveData()*功用:接纳数据并回来\/uchar ReceiveData(uchar *buf , uchar *buf2){//这是为了发送接纳数据的指令uint i=0;uint j ;send_AT_CMGR();delayms(10);while(buffer[i] != ,)//查看时趁便将buffer[i]清0{buffer[i] = 0 ;i++ ;}buffer[i] = 0 ;//将,清0i++;buffer[i++]=0;//将空格清0while(buffer[i]){if(buffer[i]>=0&&buffer[i]<=9){send_uart(buffer[i]);buffer[i]=0;//发完数据后将该位清0delayms(10);}elsebreak;//数据接纳完后跳出i++;}delayms(10);send_uart(\r);delayms(10);send_uart(\n);delayms(100);com_dat = 0 ;//为下次接纳数据做准备//这是为了检测需求的数据delayms(3000);i = 0 ;j = 0 ;while(1){if(buffer[0]!=0&&flag2==1){flag2=0;while(buffer[i]!=#){if (buffer[i] == \"){sign_flag++;}if (sign_flag == 3){buf2[j++]=buffer[i+1];//接纳电话号码}i++;}sign_flag = 0;*buf = buffer[i-1];//意图地址return buffer[i-2];//模仿的楼层数不超越10楼,所以可只回来一个字符,起点}}}/\*称号:init_GPRS()*功用:初始化GPRS模块\/void init_GPRS(){uint i = 0 ;delayms(1000);send_AT_IPR();//设置波特率delayms(15000);send_AT_CMGF();//设置短信格局delayms(1000);send_AT_CSCS();//设置字符集delayms(1000);send_AT_CNMI();//设置短信提示方法delayms(3000);while(buffer[i])//将初始化时接纳到的数据清0{buffer[i] = 0 ;i++ ; }com_dat = 0 ;//为下一次接纳做准备}void main(){init();//初始化时钟芯片,液晶显示屏//delayms(20000);//避开开机时的无用数据com_init();//串口初始化delayms(1500);init_GPRS();//给gprs设置必要的参数while(1){keyscan();//只是在时刻不精确时会被按下,其它时刻,不予理睬if(flag==0)//一共没有键盘按下{up_down_logic();}}}void exter() interrupt 0{uchar c;flag1=1;c=read_ds(0x0c);}