eda實驗(臨時)

loaf_發表於2020-12-27

第一段
//昨天的第一題
module led(Seg, S1, Clk, Reset);
output [7:0] Seg;
output [3:0] S1;
input Clk, Reset;
reg [3:0] S1_reg, Disp_dat;
reg[1:0] count;
wire LT_N, BI_N, LE;
assign LT_N = 1;
assign BI_N = 1;
assign LE = 0;

always @(posedge Clk or posedge Reset)
begin
if(Reset) count = 0;
else count = count + 1;
end
always @(count[1:0])
begin
case(count[1:0])
2’b00:Disp_dat = 4’b1000;
2’b01:Disp_dat = 4’b0010;
2’b10:Disp_dat = 4’b0001;
2’b11:Disp_dat = 4’b0111;
endcase

	case(count[1:0])
		2'b00:S1_reg = 4'b1110;
		2'b01:S1_reg = 4'b1101;
		2'b10:S1_reg = 4'b1011;
		2'b11:S1_reg = 4'b0111;
	endcase
end

HC4511 HC4511_0
(.A(Disp_dat), .Seg(Seg), .LT_N(LT_N), .BI_N(BI_N), .LE(LE));
assign S1 = S1_reg;
endmodule

第二段

//4511模組

module HC4511( A, Seg, LT, BI, LE );
input LT, BI, LE;
input [3:0] A;
output [7:0]Seg;
reg [7:0] SM_8S;
assign Seg= SM_8S;

always @(A or LT or BI or LE)
begin
if(!LT) SM_8S=8’b11111111;
else if(!BI) SM_8S=8’b00000000;
else if(LE) SM_8S=SM_8S;
else
case(A)
4’d0:SM_8S=8’b00111111;
4’d1:SM_8S=8’b00000110;
4’d2:SM_8S=8’b01011011;
4’d3:SM_8S=8’b01001111;
4’d4:SM_8S=8’b01100110;
4’d5:SM_8S=8’b01101101;
4’d6:SM_8S=8’b01111101;
4’d7:SM_8S=8’b00000111;
4’d8:SM_8S=8’b01111111;
4’d9:SM_8S=8’b01101111;
4’d10:SM_8S=8’b01110111;
4’d11:SM_8S=8’b01111100;
4’d12:SM_8S=8’b00111001;
4’d13:SM_8S=8’b01011110;
4’d14:SM_8S=8’b01111001;
4’d15:SM_8S=8’b01110001;
default:;
endcase
end
endmodule

第三段

//161模組
module HC161(Q, TC, MR, CP, CEP, CET, PE, D);
input MR, CP, CEP, CET, PE;
input [3:0] D;
output TC;
reg [3:0] Q;

always @(negedge MR, posedge CP)
if(!MR)
begin
Q = 0;
end
else if(CEP & CET & PE)
Q = Q + 1;
else if(!PE)
Q = D;
assign TC = &{CET, Q};
endmodule

第四段
//計數器數碼管顯示電路

module cnt_led(MRN, TC, PEN, CET, CEP, CP, Dn, Seg);
input MRN, PEN, CET, CEP, CP;
output TC;
wire LT_N, BI_N, LE;
input [3:0] Dn;
output[7:0] Seg;
wire [3:0] HC161_0_Qn;
assign LT_N = 1;
assign BI_N = 1;
assign LE = 0;

HC161 HC161_0(.CP(CP), .CEP(CEP), .CET(CET),.MRN(MRN), .PEN(PEN),.TC(TC),.Dn(Dn), .Qn(HC161_0_Qn));
HC4511 HC4511_0(.A(HC161_0_Qn), .Seg(Seg),LT_N(LT_N), .BI_N(BI_N), .LE(LE));
endmodule

相關文章