EDA设计交通信号灯控制器.doc_第1页
EDA设计交通信号灯控制器.doc_第2页
EDA设计交通信号灯控制器.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/* 根据整体设计要求,编写各个功能部分Verilog HDL程序,设置各输入输出变量说明如下 clk: 为计数时钟; qclk:为扫描显示时钟; en: 使能信号,为1 的话,则控制器开始工作; rst: 复位信号,为1的话,控制及技术回到初始状态; hoid:特殊情况控制信号,为1的话,则两个方向无条件显示为红灯; light1: 控制主干道方向四盏灯的亮灭;其中,light10light2,分别控制主干道方向的 绿灯、黄灯和红灯; light2: 控制支干道方向四盏灯的亮灭;其中,light20 light22,分别控制支干道方向的 绿灯、黄灯和红灯; num1: 用于主干道方向灯的时间显示,8 位,可驱动两个数码管; num2: 用于支干道方向灯的时间显示,8 位,可驱动两个数码管; counter:用于数码管的译码输出; */module traffic(en,clk,qclk,rst,rst1,hold,num1,num2,light1,light2,counter,st1,st2); /输入输出及中间变量设置如下input en,clk,qclk,rst,hold,rst1; output st1,st2; output7:0 num1,num2; output6:0counter; output2:0 light1,light2; reg tim1,tim2,st1,st2; reg1:0state1,state2,ste; reg2:0light1,light2; reg3:0num; reg6:0counter; reg7:0 num1,num2; reg7:0 red1,red2,green1,green2,yellow1,yellow2;always(posedgeclk)/主干道交通灯点亮控制begin if(rst)/复位与特殊情况控制begin light1=3b001;num1=green1;endelseif(hold)begin light1=3b100;num1=green1;endelseif(en) begin/使能有效开始控制计数if(!tim1)/begin/tim1=1;case(state1) 2b00:beginnum1=green1;light1=3b001;state1=2b01;end2b01:beginnum1=yellow1;light1=3b010;state1=2b11;end2b11:beginnum1=red1;light1=3b100;state1=2b10;end2b10:beginnum1=yellow1;light1=3b010;state1=2b00;enddefault:light1=3b100;endcaseendalways (posedge clk ) /支道交通灯点亮控制begin if(rst) /复位与特殊情况控制 begin light2=3b100; num2=red2; end else if(hold) begin light2=3b100; num2=red2; end else if(en) begin if(!tim2)begin tim2=1; case(state1) 2b00:begin num2=red2;light2=3b100;state2=2b01;end 2b01:begin num2=yellow1;light2=3b010;state2=2b11;end 2b11:begin num2=green2;light2=3b001;state2=2b10;end 2b10:begin num2=yellow2;light2=3b010;state2=2b00;end default:light20) if(num13:0=0) begin num13:0=4b1001; num17:4=num17:4-1; end else num13:0=num13:0-1; if(num1=1) tim1=0; end end else begin light1=3b010; num1=2b00; tim1=0; end endalways (posedge qclk) begin /数码管扫描 if(rst1) begin st1=0; st2=0; end else begin case(st2,st1) 2b00:begin num=num13:0;st2,st1=2b01; end 2b01:begin num=num17:4;st2,st1=2b10; end 2b10:begin num=num23:0;st2,st1=2b11; end 2b11:begin num=num27:4;st2,st1=2b00; end endcase end endalways (posedge qclk) begin /数码管译码显示 case(num) 4b0000: counter=7b0111111; /0 4b0001: counter=7b0000110; /1 4b0010: counter=7b1011011; /2 4b0011: counter=7b1001111; /3 4b0100: counter=7b1100110; /4 4b0101: counter=7b1101101; /5 4b0110: counter=7b1111101; /6 4b0111: counter=7b00

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论