Reset 為0 時七段顯示器顯示0
Reset 為1 時七段顯示器顯示 時七段顯示器顯示0到F的迴圈
把clk調小以方便觀察七段顯示器的變化
module Sequential_Counter (CLOCK_50,KEY,SW,LEDR,LEDG,HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7);
input CLOCK_50;
input [17:0] SW;
input [3:]KEY;
output [17:0] LEDR;
output [7:0] LEDG;
output [6:0] HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7;
assign HEX2=7'b111_1111; //off 7-segment Display
assign HEX3=7'b111_1111;
assign HEX4=7'b111_1111;
assign HEX5=7'b111_1111;
assign HEX6=7'b111_1111;
assign HEX7=7'b111_1111;
reg [3:0]Qout2;
//timer_counter1 (Clk50M, Clr,Qout);
timer_counter1 U0(CLOCK_50,KEY[0],Qout2);
hex_7seg c1(Qout2,HEX0);
endmodule
module timer_counter1 (Clk50M, Clr,Qout);
input Clk50M,Clr; // 一位元輸入
output reg [3:0] Qout; // 4位元輸出
reg [25:0] Q; // 宣告為暫存器資料
//50_000_000(10)=2FAF080(16) 26bit Data length
reg Clk1; // 宣告為暫存器資料
// 除頻得 1Hz
always@ (posedge Clk50M)
begin
if (!Clr || Q == 49_999_999) // 除 50M
Q = 0;
else
Q = Q + 1;
Clk1 = Q[25]; //Clk1=Q[25] 產生一個脈波
end
// 產生計時值
always@(posedge Clk1) // 時脈為 1 Hz
if (!Clr) // 全部歸零
Qout = 4'b0000;
else
Qout = Qout + 1;
end
//===============================
module hex_7seg (hex,seg_out);
input [3:0] hex;
output reg [6:0] seg_out;
always@ (hex)
begin
case (hex)
// gfe_dcba 7-segment
4'b0000 : seg_out = 7'b100_0000;
4'b0001 : seg_out = 7'b111_1001;
4'b0010 : seg_out = 7'b010_0100;
4'b0011 : seg_out = 7'b011_0000;
4'b0100 : seg_out = 7'b001_1001;
4'b0101 : seg_out = 7'b001_0010;
4'b0110 : seg_out = 7'b000_0010;
4'b0111 : seg_out = 7'b111_1000;
4'b1000 : seg_out = 7'b000_0000;
4'b1001 : seg_out = 7'b001_0000;
4'b1010 : seg_out = 7'b000_1000;
4'b1011 : seg_out = 7'b000_0011;
4'b1100 : seg_out = 7'b100_0110;
4'b1101 : seg_out = 7'b010_0001;
4'b1110 : seg_out = 7'b000_0110;
default : seg_out = 7'b000_1110;
endcase
end
endmodule
沒有留言:
張貼留言