📄 second.v
字号:
// **********************************************************************************
// FileName :second.v
//
// Discription :秒表模块
//
// Date :
//
// Author : dandan
// **********************************************************************************
module second(clk_100,reset,mode,mode_sec,sec_m_count,sec_s_count,sec_ms_count);
input clk_100,reset;
input [5:0] mode;
input [2:0] mode_sec;
output [7:0] sec_m_count,sec_s_count,sec_ms_count;
//主状态机
parameter Time_screen=6'b000_001, //时间正常显示
Time_set=6'b000_010, //设置时间
Date_set=6'b000_100, //设置日期
Clock_set=6'b001_000, //设置闹钟
Sec_clock=6'b010_000, //秒表
O_light_set=6'b100_000; //设置整点报时
//秒表状态机
parameter Sec_on=3'b010, //秒表计数开始
Sec_stop=3'b001, //秒表计数暂停
Sec_reset=3'b100; //秒表清零
reg [7:0] sec_m_count,sec_s_count,sec_ms_count; //秒表计数器
always@(posedge clk_100)
if(reset)
begin
sec_m_count<=0;
sec_s_count<=0;
sec_ms_count<=0;
end
else
begin
if(mode==Sec_clock) //当状态为秒表时
begin
if(mode_sec==Sec_reset) //秒表清零时
begin
sec_m_count<=0;
sec_s_count<=0;
sec_ms_count<=0;
end
else if(mode_sec==Sec_on) //当秒表开启时
begin
if(sec_m_count==59&&sec_s_count==59&&sec_ms_count==99)
begin
sec_m_count<=0;
sec_s_count<=0;
sec_ms_count<=0;
end
else if(sec_s_count==59&&sec_ms_count==99)
begin
sec_m_count<=sec_m_count+1;
sec_s_count<=0;
sec_ms_count<=0;
end
else if(sec_ms_count==99)
begin
sec_ms_count<=0;
sec_s_count<=sec_s_count+1;
end
else sec_ms_count<=sec_ms_count+1;
end
else if(mode_sec==Sec_stop) //当秒表暂停时
begin
sec_m_count<=sec_m_count;
sec_s_count<=sec_s_count;
sec_ms_count<=sec_ms_count;
end
end
else
begin //其他状态秒表置零
sec_m_count<=0;
sec_s_count<=0;
sec_ms_count<=0;
end
end
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -