FPGA 按键控制数码管

module Digital(clk,key,dig,out);
	input clk,key;
	output dig;
	output[7:0] out;
	
	wire dig;
	reg[7:0] out;
	reg[4:0] count;
	
	assign dig=0;
	
	div(clk,clk_10hz);
	
	always@(posedge clk_10hz)
		begin		
			case( count )
				4'h0 : out = 8'hc0; //显示"0"
				4'h1 : out = 8'hf9; //显示"1"
				4'h2 : out = 8'ha4; //显示"2"
				4'h3 : out = 8'hb0; //显示"3"
				4'h4 : out = 8'h99; //显示"4"
				4'h5 : out = 8'h92; //显示"5"
				4'h6 : out = 8'h82; //显示"6"
				4'h7 : out = 8'hf8; //显示"7"
				4'h8 : out = 8'h80; //显示"8"
				4'h9 : out = 8'h90; //显示"9"
				4'ha : out = 8'h88; //显示"a"
				4'hb : out = 8'h83; //显示"b"
				4'hc : out = 8'hc6; //显示"c"
				4'hd : out = 8'ha1; //显示"d"
				4'he : out = 8'h86; //显示"e"
				4'hf : out = 8'h8e; //显示"f"
			endcase
			
			if( key==0 )
				count<=count+1;
			if( count>14 )
				count<=0;
		end
		
endmodule 

module div(clk,clk_10hz);
	input clk;
	output clk_10hz;
	
	reg[25:0] cnt;
	reg clk_10hz;
	
	always@(posedge clk)
		begin
			cnt<=cnt+1;
			if( cnt>2500000 )
				clk_10hz<=0;
			else if( cnt<2500000 )
				clk_10hz<=1;
			
			if( cnt>5000000 )
					cnt<=0;
		end
endmodule

  • 1
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值