新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2020-2-11
- 在线时间
- 1 小时
|
为什么要分模块写,把0.5s的计时器模块跟其他模块写在一起时,功能仿真正确,但在FPGA开发板上不能实现想要的效果、代码如下:请高人指点module seg_led_static(clk,rst,led_wei,led_duan);
input clk;
input rst;
output reg [5:0]led_wei;
output reg [7:0]led_duan;
reg cnt_flag;
reg [24:0]cnt;
reg [3:0] en;
//0.5s计时器
always@(posedge clk or negedge rst)
begin
if(!rst)
begin
cnt<=25'b0;
cnt_flag<=0;
end
else
if(cnt<25'd5-1'b1)
begin
cnt<=cnt+1'b1;
cnt_flag<=0;
end
else
begin
cnt<=25'b0;
cnt_flag<=1;
end
end
//0-f计时器
always@(posedge clk or negedge rst)
begin
if(!rst)
en<=4'b0000;
else
if(cnt_flag)
if(en<4'd15)
en<=en+1'b1;
else
en<=4'b0000;
else
en<=en;
end
always@(posedge clk or negedge rst)
begin
if(!rst)
led_wei<=6'b000000;
else
led_wei<=6'b111111;
end
//数码管显示
always@(posedge clk or negedge rst)
begin
if(!rst)
begin
led_duan<=8'b0000_0000;
end
else
begin
case(en)
4'd0: led_duan<=8'b11000000;
4'd1: led_duan<=8'b11111001;
4'd2: led_duan<=8'b10100100;
4'd3: led_duan<=8'b10110000;
4'd4: led_duan<=8'b10011001;
4'd5: led_duan<=8'b10010010;
4'd6: led_duan<=8'b10000010;
4'd7: led_duan<=8'b11111000;
4'd8: led_duan<=8'b10000000;
4'd9: led_duan<=8'b10010000;
4'd10: led_duan<=8'b10001000;
4'd11: led_duan<=8'b10000011;
4'd12: led_duan<=8'b11000110;
4'd13: led_duan<=8'b10100001;
4'd14: led_duan<=8'b10000110;
4'd15: led_duan<=8'b10001110;
default: led_duan<=8'b1100_0000;
endcase
end
end
endmodule
|
|