可以使用键盘实现加减数的数码管的verilog hdl程序(基于黑金开发板)
2011-11-14 19:56
495 查看
module test(RESET,CLOCK,SEL,DIG,KEY_UP,KEY_DOWN);
input RESET,CLOCK,KEY_UP,KEY_DOWN;
output reg[5:0] SEL;
output reg[7:0] DIG;
parameter cnt=32'd2_000_0;
reg[31:0] cnt1;
reg b;
wire t;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
begin
cnt1<=0;
b<=0;
end
else if(cnt1==cnt)
begin
b<=~b;
cnt1<=0;
end
else
begin
cnt1<=cnt1+1;
b<=b;
end
end
assign t=b;
parameter cnt2=32'd5_000_000;
reg[22:0] cnt3;
reg d;
wire din;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
d<=1;
else if((!KEY_UP)||(!KEY_DOWN))
d<=0;
else
d<=1;
end
assign din=d;
reg[31:0] size;
wire[31:0] count;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
size<=0;
else if(cnt3==cnt2)
begin
cnt3<=0;
if(din==0)
begin
if(!KEY_UP)
begin
size<=size+1;
if(size>=59)
size<=0;
end
else if(!KEY_DOWN)
begin
size<=size-1;
if(size<=0)
size<=59;
end
end
end
else
cnt3<=cnt3+1;
end
assign count=size;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
DIG<=display(3);
else if(t)
begin
DIG<=display(ge(count));
SEL<=6'hfe;
end
else
begin
DIG<=display(shi(count));
SEL<=6'hfd;
end
end
function [7:0] display;
input[3:0] key;
case(key)
0: display=8'hc0;
1: display=8'hf9;
2: display=8'ha4;
3: display=8'hb0;
4: display=8'h99;
5: display=8'h92;
6: display=8'h82;
7: display=8'hf8;
8: display=8'h80;
default: display=8'h90;
endcase
endfunction
function[31:0] shi;
input [31:0] cou;
shi=cou/10;
endfunction
function[31:0] ge;
input [31:0] cou;
ge=cou%10;
endfunction
endmodule
input RESET,CLOCK,KEY_UP,KEY_DOWN;
output reg[5:0] SEL;
output reg[7:0] DIG;
parameter cnt=32'd2_000_0;
reg[31:0] cnt1;
reg b;
wire t;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
begin
cnt1<=0;
b<=0;
end
else if(cnt1==cnt)
begin
b<=~b;
cnt1<=0;
end
else
begin
cnt1<=cnt1+1;
b<=b;
end
end
assign t=b;
parameter cnt2=32'd5_000_000;
reg[22:0] cnt3;
reg d;
wire din;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
d<=1;
else if((!KEY_UP)||(!KEY_DOWN))
d<=0;
else
d<=1;
end
assign din=d;
reg[31:0] size;
wire[31:0] count;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
size<=0;
else if(cnt3==cnt2)
begin
cnt3<=0;
if(din==0)
begin
if(!KEY_UP)
begin
size<=size+1;
if(size>=59)
size<=0;
end
else if(!KEY_DOWN)
begin
size<=size-1;
if(size<=0)
size<=59;
end
end
end
else
cnt3<=cnt3+1;
end
assign count=size;
always @ (posedge CLOCK or negedge RESET)
begin
if(!RESET)
DIG<=display(3);
else if(t)
begin
DIG<=display(ge(count));
SEL<=6'hfe;
end
else
begin
DIG<=display(shi(count));
SEL<=6'hfd;
end
end
function [7:0] display;
input[3:0] key;
case(key)
0: display=8'hc0;
1: display=8'hf9;
2: display=8'ha4;
3: display=8'hb0;
4: display=8'h99;
5: display=8'h92;
6: display=8'h82;
7: display=8'hf8;
8: display=8'h80;
default: display=8'h90;
endcase
endfunction
function[31:0] shi;
input [31:0] cou;
shi=cou/10;
endfunction
function[31:0] ge;
input [31:0] cou;
ge=cou%10;
endfunction
endmodule
相关文章推荐
- 基于黑金开发板的秒表verilog hdl程序
- 使用黑金开发板做出的键盘边沿检测的用数码管显示的verilog hdl 程序
- 基于黑金开发板的键盘边沿检测程序
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--数码管封装(十六)
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--数码管电路驱动(八)
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--数码管电路驱动(八)
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--数码管封装(十六)
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--数码管封装(十六)
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--倾向并行操作(三)
- 使用Arduino开发板实现基于指纹识别的生物特征考勤系统
- Mouse without Borders是微软的一个软件实验项目,这款软件可让鼠标自由在局域网中的多台电脑间移动,键盘输入实现无缝切换,还可以直接用鼠标相互拖拽文件。 如果经常需要同时使用两台以
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--LCD(12864)封装(二十一)
- 使用go实现基于命令行的计算器程序
- 【FPGA黑金开发板】Verilog HDL那些事儿--串口模块(十一)
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--我眼中的FPGA 和Verilog HDL(一)
- 【C语言】【面试题】使用main函数的参数,实现一个整数计算机,程序可以接受三个参数
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--系统建模(二十三)
- 基于8051的扫描式键盘驱动和串并转换式显示编程实现人机I/O(键盘输入,数码管输出)
- 【连载】【FPGA黑金开发板】Verilog HDL那些事儿--RTC接口封装(二十二)