fpga按键控制数码管显示

FPGA/ASIC技术

190人已加入

描述

按键与数码管显示

  LED数码管(LEDSegmentDisplays)是由多个发光二极管封装在一起组成“8”字型的器件,引线已在内部连接完成,只需引出它们的各个笔划,公共电极。LED数码管常用段数一般为7段有的另加一个小数点,还有一种是类似于3位“+1”型。位数有半位,1,2,3,4,5,6,8,10位等等。LED数码管根据LED的接法不同分为共阴和共阳两类,了解LED的这些特性,对编程是很重要的,因为不同类型的数码管,除了它们的硬件电路有差异外,编程方法也是不同的。图2是共阴和共阳极数码管的内部电路,它们的发光原理是一样的,只是它们的电源极性不同而已。颜色有红,绿,蓝,黄等几种。

FPGA

  图1这是一个7段两位带小数点10引脚的LED数码管

FPGA

  图2引脚定义

下面来介绍fpga按键控制数码管显示程序实现:

modulekey_led(clk_50M,key,duan_ma,wei_ma);

inputclk_50M;

input[3:0]key;//key为输入的键码的值

output[3:0]wei_ma;

output[7:0]duan_ma;

wire[3:0]key;

reg[7:0]duan_ma;

reg[3:0]wei_ma;

reg[3:0]key_temp;//设置了一个寄存器

always@(posedgeclk_50M)

begin

key_temp《=key;//把键码的值赋给寄存器

case(key_temp)

4‘b0111:duan_ma《=8’b1100_0000;//段码,按键后,数码管显示0

4‘b1011:duan_ma《=8’b1001_0000;//段码,数码管显示9

4‘b1101:duan_ma《=8’b1000_0010;//段码,数码管显示6

4‘b1110:duan_ma《=8’b1011_0000;//段码,数码管显示3

endcase

end

always@(posedgeclk_50M)

begin

case(key_temp)

4‘b0111:wei_ma《=4’b0111;//位选信号

4‘b1011:wei_ma《=4’b1011;

4‘b1101:wei_ma《=4’b1101;

4‘b1110:wei_ma《=4’b1110;

endcase

end

endmodule

数码管静态显示0-7

moduleled_0_7(clk,rst,dataout,en);

inputclk,rst;

output[7:0]dataout;//数码管的段码输出

output[7:0]en;//数码管的位选使能输出

reg[7:0]dataout;//各段数据输出

reg[7:0]en;

reg[15:0]cnt_scan;//扫描频率计数器

reg[4:0]dataout_buf;

always@(posedgeclkornegedgerst)

begin

if(!rst)begin

cnt_scan《=0;

end

elsebegin

cnt_scan《=cnt_scan+1;

end

end

always@(cnt_scan)

begin

case(cnt_scan[15:13])

3‘b000:

en=8’b1111_1110;

3‘b001:

en=8’b1111_1101;

3‘b010:

en=8’b1111_1011;

3‘b011:

en=8’b1111_0111;

3‘b100:

en=8’b1110_1111;

3‘b101:

en=8’b1101_1111;

3‘b110:

en=8’b1011_1111;

3‘b111:

en=8’b0111_1111;

default:

en=8‘b1111_1110;

endcase

end

always@(en)//对应COM信号给出各段数据

begin

case(en)

8’b1111_1110:

dataout_buf=0;

8‘b1111_1101:

dataout_buf=1;

8’b1111_1011:

dataout_buf=2;

8‘b1111_0111:

dataout_buf=3;

8’b1110_1111:

dataout_buf=4;

8‘b1101_1111:

dataout_buf=5;

8’b1011_1111:

dataout_buf=6;

8‘b0111_1111:

dataout_buf=7;

default:

dataout_buf=8;

endcase

end

always@(dataout_buf)

begin

case(dataout_buf)

4’b0000:

dataout=8‘b1100_0000;

4’b0001:

dataout=8‘b1111_1001;

4’b0010:

dataout=8‘b1010_0100;

4’b0011:

dataout=8‘b1011_0000;

4’b0100:

dataout=8‘b1001_1001;

4’b0101:

dataout=8‘b1001_0010;

4’b0110:

dataout=8‘b1000_0010;

4’b0111:

dataout=8‘b1111_1000;

4’b1000:

dataout=8‘b1000_0000;

4’b1001:

dataout=8‘b1001_1000;

4’b1010:

dataout=8‘b1000_1000;

4’b1011:

dataout=8‘b1000_0011;

4’b1100:

dataout=8‘b1100_0110;

4’b1101:

dataout=8‘b1010_0001;

4’b1110:

dataout=8‘b1000_0110;

4’b1111:

dataout=8‘b1000_1110;

endcase

end

endmodule

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分