/*
7段数码管测试实验1:以动态扫描方式在8位数码管“同时”显示0--7
实验的目的是向用户介绍多个数码管动态显示的方法。
动态显示的方法是,按一定的频率轮流向各个数码管的COM端送出低电平,同时送出对应的数据给各段。
*/
module seg71(clk,rst,dataout,en);
input clk,rst;
output[7:0] dataout;
output[7:0] en;//COM使能输出
reg[7:0] dataout;//各段数据输出
reg[7:0] en;
reg[25:0] cnt_scan;//扫描频率计数器
reg[4:0] dataout_buf;
always@(posedge clk or negedge rst)
begin
if(!rst) begin
cnt_scan<=0;
end
else begin
cnt_scan<=cnt_scan+1;
end
end
always @(cnt_scan)
begin
case(cnt_scan[18:16])
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
module shumaguan(clk_50M,duan_ma,wei_ma);
input clk_50M; //输入时钟
output [7:0] duan_ma; //数码管的公共段码
output [7:0] wei_ma; //8位数码管的位选信号
reg [7:0] duan_ma;
reg [7:0] wei_ma;
reg [15:0] count;//分频计数器,65536分频
reg div_clk=0;
reg [3:0] num1,num2;
//分频计数器
always @ ( posedge clk_50M )
begin
if ( count==65535 )
begin
div_clk<=~div_clk;
count<=0;
end
else
count<=count+1;
end
//位选信号,每次只选通一位数码管
always @ ( posedge div_clk )
begin
case ( num1 )
0:
begin
wei_ma<=8'b01111111;
num1<=1;
end
1:
begin
wei_ma<=8'b10111111;
num1<=2;
end
2:
begin
wei_ma<=8'b11011111;
num1<=3;
end
3:
begin
wei_ma<=8'b11101111;
num1<=4;
end
4:
begin
wei_ma<=8'b11110111;
num1<=5;
end
5:
begin
wei_ma<=8'b11111011;
num1<=6;
end
6:
begin
wei_ma<=8'b11111101;
num1<=7;
end
7:
begin
wei_ma<=8'b11111110;
num1<=0;
end
endcase
end
//段码,8位数码管分时复用
always @ ( posedge div_clk )
begin
case ( num2 )
0:
begin
duan_ma<=8'hc0;
num2<=1;
end
1:
begin
duan_ma<=8'hf9;
num2<=2;
end
2:
begin
duan_ma<=8'ha4;
num2<=3;
end
3:
begin
duan_ma<=8'hb0;
num2<=4;
end
4:
begin
duan_ma<=8'h99;
num2<=5;
end
5:
begin
duan_ma<=8'h92;
num2<=6;
end
6:
begin
duan_ma<=8'h82;
num2<=7;
end
7:
begin
duan_ma<=8'hf8;
num2<=0;
end
endcase
end
endmodule
shumaguan.zip_vhdl
版权申诉
173 浏览量
2022-09-22
23:21:06
上传
评论
收藏 1KB ZIP 举报
alvarocfc
- 粉丝: 111
- 资源: 1万+
最新资源
- c51_2_2.c
- ASCII American Standard Code for Information Interchange
- 一个chm格式的 SQL 函数手册-SQL语言手册文档
- 计算当前月份的天数和剩余天数
- 基于ARM的指令调度和延迟分支
- 基于Vue和TypeScript的极简聊天应用设计源码 - HasChat
- 基于Vue2全家桶和Zcool数据的图片收集网站设计源码 - cool-picture
- 基于C和C++的二维绘制工具设计源码 - DrawPro
- Object.defineProperty 的 IE 补丁object-defineproperty-ie-master.zip
- 整卷预览.mhtml
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈