南北走向交通灯练习_第1页
南北走向交通灯练习_第2页
南北走向交通灯练习_第3页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、明德扬科技教育南北交通灯练习官网:淘宝:群目录counter_3 模块3明德扬科技公司主要是以 FPGA 为,专业从事 FPGA 配套开发板、FPGA 培训班或其他培训、研发 FPGA 技术开发、承接 FPGA 项目开发。欢迎加入明德扬 FPGA 和 ASIC97925396。明德扬以 PDF 格式提供源代码,是为了鼓励大家多思考,不要拿来就用,否则是学不好 FPGA 的。本代码对应的设计思路,请参考明德扬课程。counter_3 模块module counter_3( clk,rst_n, led_east, led_wast, led_south, led_nouth);/参数定义para

2、meterTIME_1S =50_000_000;/输入信号定义 inputinputclkrst_n;/输出信号定义output 2:0output 2:0led_east ;led_south;output 2:0output 2:0led_wast ;led_nouth;/输出信号 reg 定义regreg2:0led_east ;2:0led_south;/*regreg2:0led_wast ;2:0led_nouth;*/*另外一种写法*/wirewire2:0led_wast ;2:0led_nouth;/中间信号定义regreg29:04 :0cnt;cnt_o;/时序逻辑写法

3、/东面always(edge clk or negedge rst_n)beginif(rst_n=1b0)begin led_east = 3b110;endelse if(cnt_o=9)&(cnt=TIME_1S-1)begin led_east = 3b101;endelse if(cnt_o=14)&(cnt=TIME_1S-1)begin led_east = 3b011;endelse if(cnt_o=29)&(cnt=TIME_1S-1)begin led_east = 3b110;endelse beginled_east = led_east;endend/西面/*alw

4、ays(edge clk or negedge rst_n)beginif(rst_n=1b0)begin led_wast = 3b110;endelse if(cnt_o=9)&(cnt=TIME_1S-1)begin led_wast = 3b101;endelse if(cnt_o=14)&(cnt=TIME_1S-1)begin led_wast = 3b011;endelse if(cnt_o=29)&(cnt=TIME_1S-1)begin led_wast = 3b110;endelse beginled_wast = led_wast;endend*/*led_wast 使用

5、 wire 型*/ assign led_wast = led_east;/南面always(edge clk or negedge rst_n)beginif(rst_n=1b0)begin led_south = 3b011;endelse if(cnt_o=14)&(cnt=TIME_1S-1)begin led_south = 3b110;endelse if(cnt_o=24)&(cnt=TIME_1S-1)begin led_south = 3b101;endelse if(cnt_o=29)&(cnt=TIME_1S-1)begin led_south = 3b011;endel

6、se beginled_south = led_south;endend/北面/*always(edge clk or negedge rst_n)beginif(rst_n=1b0)begin led_nouth = 3b011;endelse if(cnt_o=14)&(cnt=TIME_1S-1)begin led_nouth = 3b110;endelse if(cnt_o=24)&(cnt=TIME_1S-1)beginled_nouth = 3b101;endelse if(cnt_o=29)&(cnt=TIME_1S-1)begin led_nouth = 3b011;endel

7、se beginled_nouth = led_nouth;endend*/*led_nouth 使用 wire 型*/ assign led_nouth = led_south;/计数器设计/基本计数器 always(edge clk or negedge rst_n)beginif(rst_n=1b0)begin cnt = 0;endelse if(cnt=TIME_1S-1)begin cnt = 0;endelse begincnt = cnt + 1;endend/计数器 oalways(edge clk or negedge rst_n)beginif(rst_n=1b0)begin cnt_o = 0;end/*else if(cnt_o=29)&(cnt=TIME_1S-1)begin cnt_o = 0;endelse if(cnt=TIME_1S-1)begin cnt_o = cnt_o + 1;endelse

温馨提示

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

评论

0/150

提交评论