This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/Quartus/v6/jyh_4490_6_counter.v

40 lines
430 B
Coq
Raw Permalink Normal View History

2022-05-10 10:11:28 +00:00
module jyh_4490_6_counter(Q,clk,load,in,en,upd,co);
2022-05-10 09:37:13 +00:00
input[3:0] in;
2022-05-10 10:11:28 +00:00
input en,clk,load,upd;
2022-05-10 09:37:13 +00:00
output reg [3:0] Q;
output reg co;
reg co_flag;
2022-05-10 10:11:28 +00:00
always@(posedge clk)
begin
if(en)
2022-05-10 09:37:13 +00:00
begin
//同步置数
if(load)
begin
Q<=in;
co<=0;
end
else
begin
//正反计数
2022-05-11 06:25:40 +00:00
if(Q>=4'd9)
2022-05-10 09:37:13 +00:00
begin
2022-05-11 06:25:40 +00:00
Q<=4'd0;
co<=1;
2022-05-10 09:37:13 +00:00
end
2022-05-11 06:25:40 +00:00
else
2022-05-10 09:37:13 +00:00
begin
2022-05-11 06:25:40 +00:00
Q <= Q+1;
co<=0;
2022-05-10 09:37:13 +00:00
end
2022-05-11 06:25:40 +00:00
end
2022-05-10 09:37:13 +00:00
end
else
Q<=0;
end
endmodule