也许我们刚开始用到开发板的时候都会去做跑马灯的程序,后来给我们的要求是,如果硬件接口有限制,只有一个key 或者是button—— 我们的板子上是button,让你用一个button去控制这四个led,那么你应该怎么做呢? —— 之前的跑马灯都是一个key 对应一个led。 或许有其他的解决方案。

  这里的解决方案是计数法,按住其中一个button,led 会被循环点亮——每次只有一个是被点亮的。放开button,控制信号就定位在某一个led上。

the first one for the top

module   onekey_fourLED  (
clock ,
reset ,
i_key ,
o_led
); input clock ,reset ;
input i_key ;
output [:]o_led ; wire temp0,temp1 ;
key_edge u0 (
.clock(clock) ,
.reset (reset ),
.i_key (i_key),
.counter_en (temp0 )
); counter0 u1 (
.clock (clock ),
.reset (reset),
.i_key(i_key),
.counter_en(temp0),
.counter_full (temp1)
); led_sel u2(
.clock(clock),
.reset (reset ),
.en(temp0),
.cnt_full (temp1),
.o_led(o_led)
); endmodule

开关边沿检测模块

module  key_edge  (
clock ,
reset ,
i_key ,
counter_en
); input clock ,reset ;
input i_key ;
output reg counter_en ; reg r_key0 ,r_key1 ;
always @ (posedge clock )
begin
if(!reset )
begin
r_key0 <= 'b1 ;
r_key1 <= 'b1 ;
end
else
begin
r_key0 <= i_key ;
r_key1 <= r_key0 ; if((!r_key0) & (r_key1) ) //开关下降沿到来开始计数使能端打开
counter_en <= 'b1 ;
else if ((r_key0) & (!r_key1)) //开关上升沿到来,证明一次按下动作完毕
counter_en <= 'b0 ;
else ;
end
end endmodule

  

  对按下的button 时间进行计数

module  counter0  (
clock ,
reset ,
i_key,
counter_en,
counter_full
);
input clock ,reset ;
input i_key ;
input counter_en ; output reg counter_full; reg [:] cnt ;
always @ (posedge clock )
begin
if(!reset )
begin
cnt <= 'd0 ;
end
else
begin
if((!i_key) & (counter_en))
cnt <= cnt + 'd1;
else cnt <= 'd0 ;
end
end always @ (posedge clock )
begin
if(!reset )
counter_full <= 'd0 ;
else
begin
if(cnt == 'hff_ffff) counter_full <= 1'b1 ;
else counter_full <= 'b0 ;
end
end endmodule

  依据按键按下的时间选择led

module led_sel (
clock,
reset ,
en,
cnt_full ,
o_led
);
input clock ,reset ;
input en ,cnt_full;
output reg [:] o_led ; reg [:] o_led_cnt;
always @ (posedge clock )
begin
if(!reset )
o_led_cnt <= 'd0 ;
else if((en) & (cnt_full))
begin
if (o_led_cnt <= 'd3)o_led_cnt <= o_led_cnt + 2'd1 ;
else o_led_cnt <= 'd0 ;
end
end //reg [3:0] o_led_reg;
always @ (posedge clock )
begin
if(!reset )
o_led <= 'b1111 ;
else case (o_led_cnt)
'b00 : o_led <= 4'b1110;
'b01 : o_led <= 4'b1101;
'b10 : o_led <= 4'b1011;
'b11 : o_led <= 4'b0111;
default : o_led <= 'b1111 ;
endcase
end
// assign o_led = o_led_reg; endmodule

onekey_fourLED的更多相关文章

随机推荐

  1. [LeetCode]题解(python):003-Longest Substring Without Repeating Characters

    题目来源: https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题意分析: 题目是要求出最长的不 ...

  2. C#手机充值

    C#手机充值系统开发(基于聚合数据) 说是手机充值系统有点装了,其实就是调用了聚合数据的支付接口,其实挺简单的事 但是我发现博客园竟然没有类似文章,我就个出头鸟把我的代码贡献出来吧 首先说准备工作: ...

  3. python+opencv

    $cd numpy $ sudo python setup.py build $ sudo python setup.py installRunning from numpy source direc ...

  4. Oracle DBA常用的系统表

    1.2 DBA常用的表1.2.1  dba_开头    dba_users数据库用户信息    dba_segments  表段信息    dba_extents    数据区信息    dba_ob ...

  5. Python生成随机数的方法

    这篇文章主要介绍了Python生成随机数的方法,有需要的朋友可以参考一下 如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与 ...

  6. DRP过后,感受知识间的通性

    DRP视频看了不短的时间,真正开始DRP的时间是7月17号,至今两个月了.由于暑假期间英语的学习占得时间比较多,所以DRP视频进行的很慢.9月11号看完了DRP所有的视频,这个项目完成后最大的感受是: ...

  7. 3027 - Corporative Network(并差集)

    3027 - Corporative Network A very big corporation is developing its corporative network. In the begi ...

  8. find the most comfortable road(并差集,找差值最小的权值)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 【翻译】【中英对照】【企业库6】动手实验 Hands-On Lab 日志应用程序块索引页

    Logging Application Block Hands-On Lab for Enterprise Library 企业库的日志应用程序块动手实验 This walkthrough shoul ...

  10. [译]Stairway to Integration Services Level 15 – SSIS 参数回顾

    介绍 在本文中我们会研究SSIS变量姐妹: SSIS 变量. 我们会演示参数配置,通过包参数管理动态属性值,然后会演示SSIS包执行的时候参数怎么被配置的. SSIS Parameters 101 S ...