fpga按键控制数码管显示

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

介绍晶硅太阳能光伏组件结构
电装携面向未来移动社会的创新技术亮相上海车展
使用ESP32-CAM构建人脸ID控制的数字门锁系统
聊聊布隆过滤器
微信7.0.12内测版发布 新增小程序和小游戏的启动耗时优化
fpga按键控制数码管显示
ITO薄膜湿法刻蚀研究
什么是边缘计算网关以及什么是边缘计算?
RC522读写程序代码分享
滴滴与北汽集团联合推出新一代L4级自动驾驶车
联想YOGA S740 16GB内存版推出,搭载全新10nm i5和i7处理器
快120倍!韩国研发出快速充电锂电池
半导体行业眼中的工业4.0
使用于BMS电池管理系统中的电源模块
AI+安防打造智能安防的发展新格局
金升阳推出第三代驱动电源QA-R3/QA_C-R3系列产品
Switch模拟器更新已大幅提升性能
镀锌板有哪些种类
数字资产交易所开发币币交易网站开发
开源合规标准实践-“心寄源”法律沙龙(2023第六期 | 总第十一期)成功召开