完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各位大神,帮帮忙,本人新手,在做51单片机的电梯控制系统,我想请问1、怎么去控制直流电机的转速,我想在规定时间内电机速度从零开始增加,然后逐渐减小,到达平层时变成零。
2、怎么样去获取到达平层的信息,我现在在protues仿真中用的是按键,手动去获取。
|
|
相关推荐
6个回答
|
|
这是仿真的电路图
|
|
|
|
#include
#define uchar unsigned char #define uint unsigned int #define MAX_FLOOR 5//楼层高度 uchar count,count1; uchar disnum,pwm1h,pwm2h,num,cycle,high,low; uchar gf,b;//gf 表示目的层,b 为等待计数累加位 uint nf;//当前所在楼层 uint up_call[MAX_FLOOR],down_call[MAX_FLOOR],in_call[MAX_FLOOR];//存放呼叫事件 uchar code dis[]= {0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};//0-16 数码显示代码 ***it F5=P0^0; // 电梯内5 楼 ***it F4=P0^1; // 电梯内4 楼 ***it F3=P0^2; // 电梯内3 楼 ***it F2=P0^3; // 电梯内2 楼 ***it F1=P0^4; // 电梯内1 楼 ***it F1U=P0^5; //1 楼向上按钮 ***it F2U=P0^6; //2 楼向上按钮 ***it F2D=P0^7; //2 楼向下按钮 ***it F3U=P2^0; //3 楼向上按钮 ***it F3D=P2^1; //3 楼向下按钮 ***it F4U=P2^2; //4 楼向上按钮 ***it F4D=P2^3; //4 楼向下按钮 ***it F5D=P2^4; //5 楼向下按钮 ***it pwm1=P3^5; //正转控制位 ***it pwm2=P3^6; //反转控制位 ***it EN=P3^7; //L298 使能端信号 ***it YI= P3^0; //一楼霍尔输出信号 ***it ER=P3^1; //二楼霍尔输出信号 ***it SAN=P3^2; //三楼霍尔处输出信号 ***it SI=P3^3; //四楼霍尔处输出信号 ***it WU=P3^4; //五楼霍尔处输出信号 //***it wela=P2^7; //数码管位选1 ***it RING=P2^7; ***it U=P2^5; //上行指示灯 ***it D=P2^6; //下行指示灯 void init(); // 初始化程序 void check(); //霍尔查询楼层 void display(uchar); //显示函数 void floor(); //楼层控制函数 void downer(); //下降函数 void uper(); //上升函数 void stop(); //停车函数 void getinput(); //按键查询函数 //************************************ // 初始化函数 void init() { TMOD=0x11; EA=1; ET0=1; ET1=1; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TH1=(65536-50000)/256; TL1=(65536-50000)%256; TR1=1; nf=1; pwm1=0; pwm2=0; U=0; D=0; EN=0; YI=1; ER=1; SAN=1; SI=1; WU=1; RING=0; } //****************************************** //1ms 延时程序 void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=100;y>0;y--); } //************************** // 停车报警等待程序 void stop() { U=0; D=0; EN=0; pwm1=0; pwm2=0; while(b!=120) { b++; if(b>30) {RING=0;} else RING=1; display(nf); } TR0=0; RING=0; b=0; disnum=0; } //按键检测程序; // ********************************* void getinput() { if(F5D==0) { down_call[4]=1; } else if(F4D==0) { down_call[3]=1; } else if(F4U==0) { up_call[3]=1; } else if(F3D==0) { down_call[2]=1; } else if(F3U==0) { up_call[2]=1; } else if(F2D==0) { down_call[1]=1; } else if(F2U==0) { up_call[1]=1; } else if(F1U==0) { up_call[0]=1; } else if(F1==0) { in_call[0]=1; } else if(F2==0) { in_call[1]=1; } else if(F3==0) { in_call[2]=1; } else if(F4==0) { in_call[3]=1; } else if(F5==0) { in_call[4]=1; } } //************************** //上升程序; void uper() { TR0=1; U=1; if(nf==1&&gf==5) { getinput(); //电梯在一楼去往五楼查询是否有顺路乘坐 check(); if(up_call[1]||in_call[1]) { for(high=50;high<=100;high++) { pwm2=0; pwm1=1; delay(high); pwm1=0; low=cycle-high; delay(low); } if(high<=50) { for(high=50;high>=0;high--) { pwm2=0; pwm1=1; delay(high); pwm1=0; low=cycle-high; delay(low); } } up_call[1]=0; in_call[1]=0; nf=2; ER=0; display(nf); stop(); //停车 } if(up_call[2]||in_call[2]) { for(high=50;high<=100;high++) { pwm2=0; pwm1=1; delay(high); pwm1=0; low=cycle-high; delay(low); } if(high<=50) { for(high=50;high>=0;high--) { pwm2=0; pwm1=1; delay(high); pwm1=0; low=cycle-high; delay(low); } } up_call[2]=0; in_call[2]=0; nf=3; SAN=0; display(nf); stop(); //停车 } if(up_call[3]||in_call[3]) { for(high=50;high<=100;high++) { pwm2=0; pwm1=1; delay(high); pwm1=0; low=cycle-high; delay(low); } if(high<=50) { for(high=50;high>=0;high--) { pwm2=0; pwm1=1; delay(high); pwm1=0; low=cycle-high; delay(low); } } up_call[3]=0; in_call[3]=0; nf=4; SI=0; display(nf); stop(); //停车 } } while(nf!=gf) { TR0=1; U=1; getinput(); check(); pwm1=1; pwm2=0; display(nf); } stop(); } //************************** //下降程序 void downer() { TR0=1; D=1; if(nf==5&&gf==1) { getinput();//电梯在5 楼去往1 楼查询是否有顺路 check(); if(down_call[3]==1||(in_call[3]==1)) { for(high=50;high<=100;high++) { pwm1=0; pwm2=1; delay(high); pwm2=0; low=cycle-high; delay(low); } if(high<=50) { for(high=50;high>=0;high--) { pwm1=0; pwm2=1; delay(high); pwm2=0; low=cycle-high; delay(low); } } down_call[3]=0; in_call[3]=0; nf=4; SI=0; display(nf); stop(); } if(down_call[2]==1||(in_call[2]==1)) { for(high=50;high<=100;high++) { pwm1=0; pwm2=1; delay(high); pwm2=0; low=cycle-high; delay(low); } if(high<=50) { for(high=50;high>=0;high--) { pwm1=0; pwm2=1; delay(high); pwm2=0; low=cycle-high; delay(low); } } down_call[2]=0; in_call[2]=0; nf=3; SAN=0; display(nf); stop(); } if(down_call[1]==1||(in_call[1]==1)) { for(high=50;high<=100;high++) { pwm1=0; pwm2=1; delay(high); pwm2=0; low=cycle-high; delay(low); } if(high<=50) { for(high=50;high>=0;high--) { pwm1=0; pwm2=1; delay(high); pwm2=0; low=cycle-high; delay(low); } } down_call[1]=0; in_call[1]=0; nf=2; ER=0; display(nf); stop(); } } while(nf!=gf) { TR0=1; D=1; getinput(); check(); pwm2=1; pwm1=0; display(nf); } stop(); } //************************** //霍尔楼层查询 void check() { if(YI==0) { nf=1; display(nf); } if(ER==0) { nf=2; display(nf); } if(SAN==0) { nf=3; display(nf); } if(SI==0) { nf=4; display(nf); } if(WU==0) { nf=5; display(nf); } } //************************** //电梯运行方式控制程序 void floor() { if(nf==1) // 电梯在一楼 { if(down_call[4]||in_call[4]) //5 楼为目的层 { gf=5; uper(); down_call[4]=0; in_call[4]=0; } else if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层 { gf=4; uper(); down_call[3]=0; up_call[3]=0; in_call[3]=0; } else if(down_call[1]||up_call[1]||in_call[1]) //2 楼为目的层 { gf=2; uper(); down_call[1]=0; up_call[1]=0; in_call[1]=0; } else if(down_call[2]||up_call[2]||in_call[2]) //3 楼为目的层 { gf=3; uper(); down_call[2]=0; up_call[2]=0; in_call[2]=0; } } if(nf==2) //电梯在二楼 { if(down_call[4]||in_call[4]) //5 楼为目的层 { gf=5; uper(); down_call[4]=0; in_call[4]=0; } else if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层 { gf=3; uper(); down_call[3]=0; up_call[3]=0; in_call[3]=0; } else if(down_call[2]||up_call[2]||in_call[2]) //3 楼为目的层 { gf=3; uper(); down_call[2]=0; up_call[2]=0; in_call[2]=0; } if(up_call[0]||in_call[0]) //1 楼为目的层 { gf=1; downer(); up_call[0]=0; in_call[0]=0; } } if(nf==3)//电梯在三楼 { if(down_call[4]||in_call[4]) //5 楼为目的层 { gf=5; uper(); down_call[4]=0; in_call[4]=0; } else if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层 { gf=4; uper(); down_call[3]=0; up_call[3]=0; in_call[3]=0; } else if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层 { gf=2; downer(); down_call[1]=0; in_call[1]=0; up_call[1]=0; } else if(in_call[0]||up_call[0]) //1 楼为目的层 { gf=1; downer(); in_call[0]=0; up_call[0]=0; } } if(nf==4)//电梯在四楼 { if(in_call[4]||down_call[4]) //5 楼为目的层 { gf=5; uper(); in_call[4]=0; down_call[4]=0; } else if(in_call[2]||up_call[2]||down_call[2]) //3 楼为目的层 { gf=3; downer(); in_call[2]=0; up_call[2]=0; down_call[2]=0; } else if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层 { gf=2; downer(); down_call[1]=0; in_call[1]=0; up_call[1]=0; } else if(in_call[0]||up_call[0]) //1 楼为目的层 { gf=1; downer(); in_call[0]=0; up_call[0]=0; } } if(nf==5)//电梯在五楼 { if(in_call[3]||up_call[3]||down_call[3]) //4 楼为目的层 { gf=4; downer(); in_call[3]=0; up_call[3]=0; down_call[3]=0; } else if(in_call[2]||up_call[2]||down_call[2]) //3 楼为目的层 { gf=3; downer(); in_call[2]=0; up_call[2]=0; down_call[2]=0; } else if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层 { gf=2; downer(); down_call[1]=0; in_call[1]=0; up_call[1]=0; } else if(in_call[0]||up_call[0]) //1 楼为目的层 { gf=1; downer(); in_call[0]=0; up_call[0]=0; } } } //显示函数 //************************************* void display(uchar nf) { P1=dis[nf]; delay(5); } //主函数 //************************************** void main() { init(); getinput(); while(1) { getinput(); check(); floor(); display(nf); } } //中断定时计数程序 //*********************************** void t0(void) interrupt 1 using 0 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; count++; if(count==20) { count=0; disnum++; if(disnum==1000) { disnum=0; } } } //************************************ void t1(void) interrupt 3 using 1 { TH1=(65536-100)/256; TL1=(65536-100)%256; count1++; EN=1; } |
|
|
|
|
|
|
|
用PWM控制293模块啊
|
|
|
|
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
|
|
|
|
请问你到了几层是怎么判断的?单片机怎么知道它是到了4层而不是5层?
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
205 浏览 0 评论
求助一下关于51系列单片机的Timer0的计时问题,TH0、TL0+1的时间是怎么算的?
1253 浏览 1 评论
【RA-Eco-RA4E2-64PIN-V1.0开发板试用】开箱+Keil环境搭建+点灯+点亮OLED
848 浏览 0 评论
【敏矽微ME32G070开发板免费体验】使用coremark测试敏矽微ME32G070 跑分
853 浏览 0 评论
【敏矽微ME32G070开发板免费体验】开箱+点灯+点亮OLED
1073 浏览 2 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12010 浏览 31 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 18:45 , Processed in 0.570148 second(s), Total 53, Slave 44 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号