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的更多相关文章
随机推荐
- Protel 99SE PCB 打印技巧
1. 打开 Protel99SE PCB 设计文档.从菜单File 下单击Print/Preview 打印预览菜单.出现PCB 打印预览介面. 2.从File 下单击 Setup Printer 设置 ...
- spring boot 下 500 404 错误页面处理
spring boot 作为微服务的便捷框架,在错误页面处理上也有一些新的处理,不同于之前的spring mvc 500的页面处理是比较简单的,用java config或者xml的形式,定义如下的be ...
- HDOJ 1003 Max Sum(线性dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 思路分析:该问题为最大连续子段和问题,使用动态规划求解: 1)最优子结构:假设数组为A[0, 1 ...
- Python生成随机数的方法
这篇文章主要介绍了Python生成随机数的方法,有需要的朋友可以参考一下 如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与 ...
- hdu 5007 水 弦
http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...
- SharePoint BCS
1. 开启相关的服务:管理中心-->应用程序管理-->管理服务器上的服务 2.
- Linux新手笔记 ibus
centos 6.4 32 笔记 一.安装gccyum install gcc ======================================================== ...
- Linux常用解压文件
tar.gz tar -zxvf filename.tar.gz tar.bz2 tar -vxjf filename.tar.bz2
- 深入浅出—JAVA(7)
7.继承与多态 遵守合约:覆盖的规则 方法的重载
- linux 进程通信
IPC: 管道,FIFO,信号,消息队列(system v/ posix),共享内存(system v/ posix),socket 同步机制: 互斥锁,条件变量,记录上锁, 信号量(system ...