hex.v

来自「在FPGA上实现序列机 用的是Altera公司的DE1板子」· Verilog 代码 · 共 44 行

V
44
字号
//显示所接受正确序列的个数
module hex(clk,rst,Y_or_NO,hex0,hex1,ledg);
input clk;
input rst;
input Y_or_NO;
output [6:0] hex0,hex1;
output reg ledg;//灯的控制信号
reg [3:0] h0,h1;

always @(posedge clk or negedge rst) 
begin	   
	if (!rst)
	begin 
		h0<=4'b0;
		h1<=4'b0;
		ledg<=1'b0;
	end
/*	else if(load)//这是置位的一段程序
	begin 
		h3=(SW[9:6])>9 ? 9:SW[9:6];
		h2=(SW[9:6])>9 ? 9:SW[9:6];
    end
*/
	else if(Y_or_NO)//检测到一个正确的序列,计数器加1
	begin
	    ledg<=1'b1;
		if(h0==4'h9)
		begin 
			h0<=4'b0;
			if(h1==4'h9) h1<=4'b0;				
			else h1<=h1+4'b1;
		end
	    else h0<=h0+4'b1;
	end
	else 
	begin 
        ledg<=1'b0;
		h0<=h0;
		h1<=h1;
    end
end
decode4_7 decode0(hex0,h0);
decode4_7 decode1(hex1,h1);
endmodule 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?