版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、这个程序不需要你再添加任何的程序,你只需要添加楼层数就可以成功控制6层以上电梯,另外你必须得读懂每一块程序的作用,才能对这个程序有更好的应用module dtsj(clk,reset,up1,up2,up3,up4,up5,dn2,dn3,dn4,dn5,dn6,d1,d2,d3,d4,d5,d6,overw,pro,led,hex,Buzzer1,lig);input clk,reset; /reset键使用keyinput overw,pro,up1,up2,up3,up4,up5,dn2,dn3,dn4,dn5,dn6,d1,d2,d3,d4,d5,d6; /故障警报键output6:0
2、 hex,lig; /light和led用数码管output5:0 led;output Buzzer1;reg Buzzer1,door;reg6:0 hex,lig;reg2:0state,next_state,count;reg5:0 d,up,dn,now_f,curr,led; /d是内部按键,up外部上升按键,dn是外部下降按键, /now_f是当前楼层,curr是当前楼层的另外一个变量reg1:0 ud_f; /上升下降标志位reg light;/reg29:0 counter;/reg clkout;parameter idle_state=3'b001,open_st
3、ate=3'b010,close_state=3'b011, up_state=3'b100,down_state=3'b101,sleep_state=3'b110, alarm_state=3'b111,f1=6'b000001,f2=6'b000010,f3=6'b000100,f4=6'b001000 ,f5=6'b010000,f6=6'b100000,up_f=2'b01,dn_f=2'b10,idle=2'b00; /jiu zhong zhuang tai h
4、e shang sheng zhuang tai 'shang sheng zhuang tai he xia jia zhuang tai initial begin state<=idle_state; endalways (posedge clk or posedge reset) if(reset) state<=idle_state; else state<=next_state;always (state or up or dn or d or now_f or count or ud_f) case(state) open_state: begin if
5、(count<5) next_state=open_state; else next_state=close_state; end sleep_state: begin if(up|dn|d|ud_f)=0) begin next_state=close_state; end else next_state=idle_state; end idle_state: / 初始状态 begin if(up|dn|d|ud_f)=0) next_state=sleep_state; if(!overw|pro=1) next_state=alarm_state; else if(d>0)
6、begin if(d&now_f)>0) next_state=open_state; else if(d>now_f) next_state=up_state; else next_state=down_state; end else if(up&now_f)|(dn&now_f) next_state=open_state; else if(up>now_f)|(dn>now_f) next_state=up_state; else if(up|dn) next_state=down_state; else next_state=idle_s
7、tate; end up_state: begin if(up|dn|d|ud_f)=0) next_state=sleep_state; if(!overw|pro=1) next_state=alarm_state; else if(d&now_f)|(up&now_f) next_state=open_state; else if(d>now_f)|(up>now_f) next_state=up_state; else if(d<now_f)|(up<now_f) /else if(d|up) wait speak next_state=down
8、_state; else if(dn>0) begin if(dn>now_f) next_state=up_state; else if(dn&now_f)|(now_f<f6) next_state=open_state; else if(dn&now_f)&&(now_f=f6) next_state=open_state; else next_state=down_state; end else next_state=idle_state; end down_state: begin if(up|dn|d|ud_f)=0) next_s
9、tate=sleep_state; else if(!overw|pro=1) next_state=alarm_state; else if(d&now_f)|(dn&now_f) next_state=open_state; else if(d<now_f)&&(d!=6'b000001)|(dn<now_f)&&(dn!=6'b000001) next_state=down_state; else if(d>now_f)|(dn>now_f) next_state=up_state; else if(
10、up>0) begin if (up<now_f) next_state=down_state; else if(up&now_f)&&(now_f>f1) next_state=down_state; else if(up&now_f)&&(now_f=f1) next_state=open_state; else next_state=up_state; end else next_state=idle_state; end close_state: begin if(up|dn|d|ud_f)=0) next_state=
11、sleep_state; else if(!overw|pro=1) next_state=alarm_state; else if(ud_f=up_f) begin if(d&now_f)|(up&now_f) next_state=open_state; else if(d>now_f)|(up>now_f) next_state=up_state; else if(d|up) next_state=down_state; else if(dn>0) begin if(dn>now_f) next_state=up_state; else if(dn
12、&now_f)>0) next_state=open_state; else next_state=down_state; end else next_state=idle_state; end else if(ud_f=dn_f) begin if(d&now_f)|(dn&now_f) next_state=open_state; else if(d<now_f)&&(d!=6'b000000)|(dn<now_f)&&(dn!=6'b000000) next_state=down_state; el
13、se if(d|dn) next_state=up_state; else if(up>0) begin if(up<now_f) next_state=down_state; else if(up&now_f)>0) next_state=open_state; else next_state=up_state; end else next_state=idle_state; end else begin if(d>0) begin if(d&now_f)>0) next_state=open_state; else if(d>now_f)
14、 next_state=up_state; else next_state=down_state; end else if(up&now_f)&&(dn&now_f) next_state=open_state; else if(up>now_f)&&(dn>now_f) next_state=up_state; else if(up|dn) next_state=down_state; else next_state=idle_state; end end alarm_state: begin if(!overw|pro=1) be
15、gin /Buzzer1<=1'b1; next_state=open_state; end else begin /Buzzer1<=1'b0; if(d>0) begin if(d&now_f)>0) next_state=open_state; else if(d>now_f) next_state<=up_state; else next_state=down_state; end else if(up&now_f)|(dn&now_f) next_state=open_state; else if(up>
16、;now_f)|(dn>now_f) next_state=up_state; else if(up|dn) next_state=down_state; else next_state=idle_state; end end default: next_state<=idle_state; endcase always (up1 or up2 or up3 or up4 or up5) up =1'b0,up5,up4,up3,up2,up1; always (dn2 or dn3 or dn4 or dn5 or dn6) dn =dn6,dn5,dn4,dn3,dn2
17、,1'b0; always (d1 or d2 or d3 or d4 or d5 or d6) d =d6,d5,d4,d3,d2,d1; always (posedge clk or posedge reset) begin if(reset) count<=0; else if(next_state=open_state)&&(count<5) count<=count+1; else count<=0; endalways (posedge clk or posedge reset ) /always (reset or next_sta
18、te) if(reset) begin now_f<=f1; ud_f<=idle; led<=6'b000001; light<=1'b0; end else begin now_f<=now_f; curr=now_f; case(next_state) idle_state: begin now_f<=now_f; ud_f<=idle; led<=led; curr<=now_f; Buzzer1<=1'b0; end up_state: begin now_f<=now_f<<1;
19、ud_f<=up_f; led<=led+1; curr<=now_f; end down_state: begin now_f<=now_f>>1; ud_f<=dn_f; led<=led+1; curr<=now_f; end open_state: begin now_f<=now_f; ud_f<=ud_f; led<=led; door<=1'b1; light<=door; curr<=now_f; end close_state: begin now_f<=now_f; ud
20、_f<=ud_f; led<=led; curr<=now_f; door<=1'b0; light<=door; end alarm_state: begin now_f<=now_f; ud_f<=ud_f; led<=led; Buzzer1<=1'b1; curr<=now_f; door<=1'b1; light<=door; end sleep_state: begin now_f<=now_f; ud_f<=ud_f; led<=6'b000000; curr<=now_f; end default: begin now_f<=f1; ud_f<=idle; led<
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 44941-2024植物照明术语
- 2025版第四编合同法合同担保业务风险防范与法律解读3篇
- 2025年度紧急口译响应及协调服务合同3篇
- 噪音污染红线管理办法
- 采铜矿工程文明施工合同
- 石油天然气行业人员信息管理规章
- 实验室危险品使用与储存规定
- 连锁店管理锦囊员工培训
- 咖啡公司税务管理要点
- 配送责任协议
- 特色农产品超市方案
- 2024国有企业与民营企业之间的混合所有制改革合同
- 二次函数的几何性质(于特)(1)名师公开课获奖课件百校联赛一等奖课件
- GB/T 30595-2024建筑保温用挤塑聚苯板(XPS)系统材料
- 2024年人教版八年级地理上册期末考试卷(附答案)
- 医学免疫学-医学检验专业学习通超星期末考试答案章节答案2024年
- 《稻草人》阅读题及答案
- 独立基础土方开挖施工方案
- (建筑工程管理)常熟市建设工程施工图审查工作
- 国家职业技术技能标准 X2-10-07-17 陶瓷产品设计师(试行)劳社厅发200633号
- 瑜伽基础知识题库单选题100道及答案解析
评论
0/150
提交评论