FPGA 数字系统设计(Verilog)
文章目录
设计一数字钟,具体要求如下:
- 以时、分、秒形式显示;
- 二十四小时循环;
- 具有复位功能;
- 具有时间校准和调时功能;
- 具有整点报时功能(声光同时显示);
- 完成全部流程:设计规范文杻、模块设计、代码输入、仿真或下载验证。
程序流程
所使用的芯片型号
Cyclone IV EP4CE15F17C8
部分代码展示
module time_clock (clk,rst,seg_l,seg_sel,rgb_led,key,sw2,sw3,beep);
input clk,rst;
input [3:0]key;
input sw2,sw3;
output reg beep;
output reg [7:0] seg_sel;
output reg [7:0] seg_l;
output reg [6:0] rgb_led;
//内部信号定义
//秒,时,分定义
reg [6:0] cnt_miao;
reg [6:0] cnt_fen;
reg [5:0] cnt_shi;
//脉冲
reg [30:0]count_1s;
reg [30:0]count_sw;
reg [30:0]count_05s;
reg [1:0] clk_led;
reg [2:0] cnt_sel;
//数码管定义
reg [8:0] seg [9:0];
parameter N1 = 40000000;
parameter M1 = 40000;
parameter N2 = 20000000;
always@(posedge clk) begin
if(!rst)
count_1s <= 0;
else if(count_1s == N1-1)
count_1s<=0;
else
count_1s<= count_1s + 1;
end
//数码管切换
always@(posedge clk) begin
if(!rst)
count_sw <= 0;
else if(count_sw == M1-1)
count_sw<=0;
else
count_sw<= count_sw + 1;
end
//调时模块脉冲
always@(posedge clk) begin
if(!rst)
count_05s <= 0;
else if(count_05s == N2-1)
count_05s<= 0;
else
count_05s<= count_05s + 1;
end
always @(posedge clk or negedge rst)
begin
if (!rst) //-------异步清零
begin
cnt_miao <= 0;
cnt_fen <=0;
cnt_shi <= 0;
end
//----------------------------------------开始计时