onekey_fourLED
也许我们刚开始用到开发板的时候都会去做跑马灯的程序,后来给我们的要求是,如果硬件接口有限制,只有一个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的更多相关文章
随机推荐
- delphi 编译生成ipa文件
找IPA文件 开发模式ipa文件和发布模式ipa文件,路径不同. http://www.itnose.net/detail/6101808.html 一.开发模式Development 不需要真机,可 ...
- 转:CI配置SMARTY
1.到相应站点下载Smarty的源码包:2.将源码包里面的libs文件夹copy到CI的项目目录下面的libraries文件夹下,并重命名为Smarty:3.在目录 application/libra ...
- perl5 第十一章 文件系统
第十一章 文件系统 by flamephoenix 一.文件输入/输出函数 1.基本I/O函数 1)open函数 2)用open重定向输入 3)文件重定向 4)指定读写权限 ...
- 用Mediawiki做百科网站资源大参考
MediaWiki简易安装教程**关于mediawiki 一些好的资料: http://codex.wordpress.org.cn/Mediawiki%E5%BB%BA%E7%AB%99%E7%BB ...
- HDU 1157 Who's in the Middle
#include <cstdio> #include <algorithm> using namespace std; int main() { int n; while(sc ...
- IntelliJ IDEA 14 注册码生成器
IntelliJ IDEA 14 注册码生成器 文件为Java代码 自己编译运行里面的程序输入名称然后就生成注册码了工具:http://yun.baidu.com/s/1cZKsA部分工具生成的注册码 ...
- iOS开发之第三方分享QQ分享,史上最新最全第三方分享QQ方式实现
本文章源码地址: https://github.com/zhonggaorong/QQLoginDemo 项目搭建参考: (包含QQ登录源码下载 . QQ sdk集成) http://blog.cs ...
- Thread interrupt方法解析
初步理解 我们在看一些多线程代码的时候,有的时候会碰到使用interrupt()方法的时候.从字面的意思来理解,应该就是中断当前正在执行的线程.那么,对于一个我们设计的普通线程来说,如果我们在主线程里 ...
- win7如何快速设置开机启动项?
添加开机启动项方法: 找到windows开始菜单->所有程序->启动,右键打开, 进入C:\Users\Ocean\AppData\Roaming\Microsoft\Windows\St ...
- ACE6.2.0下载HTTP服务器文件
#include "ace/Log_Msg.h" // ACE_DEBUG的宏定义在这里.#include "ace/OS.h"#include "a ...