X
首页
技术
模拟电子
单片机
半导体
电源管理
嵌入式
传感器
最能打国产芯
应用
汽车电子
工业控制
家用电子
手机便携
安防电子
医疗电子
网络通信
测试测量
物联网
最能打国产芯
大学堂
首页
直播
专题
TI 培训
论坛
汽车电子
国产芯片
电机驱动控制
电源技术
单片机
模拟电子
PCB设计
电子竞赛
DIY/开源
嵌入式系统
医疗电子
颁奖专区
【厂商专区】
【电子技术】
【创意与实践】
【行业应用】
【休息一下】
最能打国产芯
活动中心
直播
发现活动
颁奖区
电子头条
参考设计
下载中心
分类资源
文集
排行榜
电路图
Datasheet
最能打国产芯
创新实验室
[资源共享] (FPGA实验五):Verilog HDL语言数码管时钟(时分秒)
bqgup
2019-4-26 19:49
楼主
Verilog HDL语言写得数码管时钟
module smg(
input ext_clk_50M,
inout reg div_clk_1K,
output reg[7:0]wei_xuan,
output reg[7:0]duan_xuan
);
reg [31:0]cnt;
reg [31:0]cnt1;//time
reg div_clk_1Hz;
reg [7:0]sec;
reg [7:0]min;
reg [7:0]h;
reg [2:0]duan_num;
always [url=home.php?mod=space&uid=775551]@[/url] (posedge ext_clk_50M)//scan clk
if(cnt == 32'd10_000)
begin
cnt <= 32'd0;
div_clk_1K <= ~div_clk_1K;
end
else cnt <= cnt + 32'd1;
always @ (posedge ext_clk_50M)//time clk
if(cnt1 == 32'd25_000_000)
begin
cnt1 <= 32'd0;
div_clk_1Hz <= ~div_clk_1Hz;
end
else cnt1 <= cnt1 + 32'd1;
////////////////////////////////////////////////////////////////
always @(posedge div_clk_1Hz)
if(sec == 8'd59)
begin
sec <= 8'd0;
min <= min + 8'd1;
if(min == 8'd59)
begin
min <= 8'd0;
h <= h + 8'd1;
if(h == 8'd23)
h <= 8'd0;
end
end
else sec <= sec + 8'd1;
////////////////////////////////////////////////////////////////
always @ (posedge div_clk_1K)
if(duan_num == 3'b110) duan_num <= 3'b0;
else duan_num <= duan_num + 3'b1;
always @ (sec or min or h or duan_num)//encoder
if(duan_num == 3'b001)
begin
wei_xuan <= 8'b0111_1111;
case(sec % 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 3'b010)
begin
wei_xuan <= 8'b1011_1111;
case(sec / 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 3'b011)
begin
wei_xuan <= 8'b1110_1111;
case(min % 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 3'b100)
begin
wei_xuan <= 8'b1111_0111;
case(min / 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 3'b101)//h
begin
wei_xuan <= 8'b1111_1101;
case(h % 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 3'b110)//h
begin
wei_xuan <= 8'b1111_1110;
case(h / 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
endmodule
代码写完使用JTAG(联合测试行动组)下载观看效果
:
HDL语言数码管时钟.mp4
(1.15 MB)
(下载次数: 11, 2019-4-26 19:37 上传)
数码管的效果是这样:
效果是这样的,看起来有点不太符合我们日常的观看习惯,我们对代码做个修改,让效果看起来更舒适。
module smg(
input ext_clk_50M,
inout reg div_clk_1K,
output reg[7:0]wei_xuan,
output reg[7:0]duan_xuan
);
reg [31:0]cnt;
reg [31:0]cnt1;//time
reg div_clk_1Hz;
reg [7:0]sec;
reg [7:0]min;
reg [7:0]h;
reg [3:0]duan_num;
always @ (posedge ext_clk_50M)//scan clk
if(cnt == 32'd10_000)
begin
cnt <= 32'd0;
div_clk_1K <= ~div_clk_1K;
end
else cnt <= cnt + 32'd1;
always @ (posedge ext_clk_50M)//time clk
if(cnt1 == 32'd25_000_000)
begin
cnt1 <= 32'd0;
div_clk_1Hz <= ~div_clk_1Hz;
end
else cnt1 <= cnt1 + 32'd1;
////////////////////////////////////////////////////////////////
always @(posedge div_clk_1Hz)
if(sec == 8'd59)
begin
sec <= 8'd0;
min <= min + 8'd1;
if(min == 8'd59)
begin
min <= 8'd0;
h <= h + 8'd1;
if(h == 8'd23)
h <= 8'd0;
end
end
else sec <= sec + 8'd1;
////////////////////////////////////////////////////////////////
always @ (posedge div_clk_1K)
if(duan_num == 4'b1000) duan_num <= 4'b0;
else duan_num <= duan_num + 4'b1;
always @ (sec or min or h or duan_num)//encoder
if(duan_num == 4'b0001)
begin
wei_xuan <= 8'b0111_1111;
case(sec % 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 4'b0010)
begin
wei_xuan <= 8'b1011_1111;
case(sec / 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 4'b0011)
begin
wei_xuan <= 8'b1110_1111;
case(min % 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 4'b0100)
begin
wei_xuan <= 8'b1111_0111;
case(min / 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 4'b0101)//h
begin
wei_xuan <= 8'b1111_1101;
case(h % 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 4'b0110)//h
begin
wei_xuan <= 8'b1111_1110;
case(h / 10)
8'd0: duan_xuan <= 8'b1100_0000;//0
8'd1: duan_xuan <= 8'b1111_1001;//1
8'd2: duan_xuan <= 8'b1010_0100;//2
8'd3: duan_xuan <= 8'b1011_0000;//3
8'd4: duan_xuan <= 8'b1001_1001;//4
8'd5: duan_xuan <= 8'b1001_0010;//5
8'd6: duan_xuan <= 8'b1000_0011;//6
8'd7: duan_xuan <= 8'b1111_1000;//7
8'd8: duan_xuan <= 8'b1000_0000;//8
8'd9: duan_xuan <= 8'b1001_0000;//9
endcase
end
else if(duan_num == 4'b0111)//-
begin
wei_xuan <= 8'b1111_1011;
duan_xuan <= 8'b1011_1111;//-
end
else if(duan_num == 4'b1000)//-
begin
wei_xuan <= 8'b1101_1111;
duan_xuan <= 8'b1011_1111;//-
end
endmodule
修改完的效果如下所示,个人感觉看出来比较舒服:
8位数码管.mp4
(1.16 MB)
(下载次数: 9, 2019-4-26 19:46 上传)
最后分享一下工程,方便大家使用下载:
4.4、数码管动态显示(时分秒).rar
(1.15 MB)
(下载次数: 35, 2019-4-26 19:48 上传)
4.5、数码管动态显示(时分秒8段).rar
(1.17 MB)
(下载次数: 68, 2019-4-26 19:48 上传)
欢迎大家讨论交流。
本帖最后由 bqgup 于 2019-4-26 19:51 编辑
点赞
回复评论
暂无评论,赶紧抢沙发吧
最新活动
报名直播赢【双肩包、京东卡、水杯】| 高可靠性IGBT的新选择——安世半导体650V IGBT
30套RV1106 Linux开发板(带摄像头),邀您动手挑战边缘AI~
安世半导体理想二极管与负载开关,保障物联网应用的稳健高效运行
免费申请 | 上百份MPS MIE模块,免费试用还有礼!
PI 电源小课堂|无 DC-DC 变换实现多路高精度输出反激电源
2024 瑞萨电子MCU/MPU工业技术研讨会——深圳、上海站, 火热报名中
随便看看
恩智浦推出最高支持1.5A的突破性0.37mm超平封装肖特基整流器
关于三极管的选用
SHT21 温湿度传感器Datasheet(英文)
在ti官网申请到了样品 没想到寄过来两个废片
之前发的是LDC1000的,1314在这里
传芯币改革在酝酿中,辛昕在边上乱弹(checked)
21世纪微电子技术的发展趋势与展望
无线USB技术概述
应用技巧/80C51便携式产品中的低功耗设计
模拟电子基本电路集35/90
arm9能做嵌入式web服务器吗
TL494在boost电路PWM波输出异常,求各位大佬帮帮忙
Zigbee超高清原创视频教程,非常爽,分享一下
关于单片机AGND和DGND的问题
“消夏福利 欢庆端午"抢楼活动精选资源汇总
【MSP430共享】采用MSP430Δ-ΣADC外设实现高精度测量
EDK实验教程中文翻译
重塑工程师体验:6月8日(今天)下午2点泰克新2系MSO全球发布会邀您参加!
关于wince注册表的几个问题
msp430g2553怎么驱动LCD1286403?
电子工程世界版权所有
京B2-20211791
京ICP备10001474号-1
京公网安备 11010802033920号
回复
写回复
收藏
回复