时钟——倒计时实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验报告
实验已实验功能:
有时钟计时,秒钟清零端,时钟,分钟加一按键,用了一个拨码,当拨码电平为0时倒计时,从99开始到00再回到99,当拨码电平为1时,任意按下时钟或分钟加一的按键,即可回到时钟状态。

源程序代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity exp15 is
port( Clk : in std_logic; --时钟输入
Rst : in std_logic; --复位输入
S1,S2,S3 : in std_logic; --时间调节输入
SPK : out std_logic; --扬声器输出
Display : out std_logic_vector(7 downto 0); --七段码管显示输出 SEG_SEL,SEG_SEL1: buffer std_logic_vector(2 downto 0) --七段码管扫描驱动);
end exp15;
architecture behave of exp15 is
signal Disp_Temp,Disp_Temp1: integer range 0 to 15;
signal Disp_Decode,Disp_Decode1: std_logic_vector(7 downto 0);
signal SEC1,SEC10 : integer range 0 to 9;--秒钟个位、十位
signal MIN1,MIN10 : integer range 0 to 9;--分钟个位、十位
signal HOUR1,HOUR10 : integer range 0 to 9;--小时个位、十位
signal djs1,djs10 : integer range 0 to 9;
signal Clk_Count1 : std_logic_vector(13 downto 0);--产生1Hz时钟的分频计数器
signal Clk1Hz : std_logic;
signal Music_Count : std_logic_vector(2 downto 0);
signal flag : std_logic;--标识符
begin
process(Clk)
begin
if(Clk'event and Clk='1') then
if(Clk_Count1<10000) then
Clk_Count1<=Clk_Count1+1;
else
Clk_Count1<="00000000000001";
end if;
end if;
end process;
Clk1Hz<=Clk_Count1(13);--产生一秒时钟
process(Clk1Hz,Rst)
begin
if(Rst='0') then --系统复位
djs1<=9;
djs10<=9;
SEC1<=0;
SEC10<=0;
MIN1<=0;
MIN10<=0;
HOUR1<=0;
HOUR10<=0;
elsif(Clk1Hz'event and Clk1Hz='1') then --正常运行 if(S3='0') then—倒计时状态
flag<='0';
if(djs1=0 and djs10=0) then
djs1<=9;djs10<=9;
elsif(djs1=0) then
djs1<=9;
if(djs10=0) then
djs10<=9;
else djs10<=djs10-1;
end if;
else djs1<=djs1-1;
end if;
elsif(S1='0') then --调节小时
flag<='1';
if(HOUR1=9) then
HOUR1<=0;
HOUR10<=HOUR10+1;
elsif(HOUR10=2 and HOUR1=3) then
HOUR1<=0;
HOUR10<=0;
else
HOUR1<=HOUR1+1;
end if;
elsif(S2='0') then --调节分钟
flag<='1';
if(MIN1=9) then
MIN1<=0;
if(MIN10=5) then
MIN10<=0;
else
MIN10<=MIN10+1;
end if;
else
MIN1<=MIN1+1;
end if;
elsif(SEC1=9)then--时钟自动计时过程
SEC1<=0;
if(SEC10=5) then
SEC10<=0;
if(MIN1=9) then
MIN1<=0;
if(MIN10=5) then
MIN10<=0;
if(HOUR1=9) then
HOUR1<=0;
HOUR10<=HOUR10+1;
elsif(HOUR10=2 and HOUR1=3) then
HOUR1<=0;
HOUR10<=0;
else
HOUR1<=HOUR1+1;
end if;
else
MIN10<=MIN10+1;
end if;
else
MIN1<=MIN1+1;
end if;
else
SEC10<=SEC10+1;
end if;
else
SEC1<=SEC1+1;
end if;
end if;
end process;
process(Clk)
begin
if(Clk'event and Clk='1') then
Music_Count<=Music_Count+1;
if(MIN10=5 and MIN1=9 and SEC10=5) then --在59分50秒开始提示 if((SEC1 MOD 2)=0) then --在偶数秒开始发声
SPK<=Music_Count(2); --嘀
else
SPK<='0';
end if;
elsif(MIN10=0 and MIN1=0 and SEC10=0 and SEC1=0) then
SPK<=Music_Count(1); --嗒
else
SPK<='0';
end if;
end if;
end process;
process(SEG_SEL) –倒计时和时钟状态的气短数码管驱动过程,用flag标识符的不同来进行转换
begin
case (SEG_SEL+1) is
when "000"=>
if flag='1' then Disp_Temp<=HOUR10;end if;
if flag='0' then Disp_Temp1<=11;end if;
when "001"=>
if flag='1' then Disp_Temp<=HOUR1;end if;
if flag='0' then Disp_Temp1<=11;end if;
when "010"=>
if flag='1' then Disp_Temp<=10;end if;
if flag='0' then Disp_Temp1<=11;end if;
when "011"=>
if flag='1' then Disp_Temp<=MIN10;end if;
if flag='0' then Disp_Temp1<=11;end if;
when "100"=>
if flag='1' then Disp_Temp<=MIN1;end if;
if flag='0' then Disp_Temp1<=11;end if;
when "101"=>
if flag='1' then Disp_Temp<=10;end if;
if flag='0' then Disp_Temp1<=11;end if;
when "110"=>
if flag='1' then Disp_Temp<=SEC10;end if;
if flag='0' then Disp_Temp1<=djs10;end if;
when "111"=>
if flag='1' then Disp_Temp<=SEC1;end if;
if flag='0' then Disp_Temp1<=djs1;end if;
end case;
end process;
process(Clk)
begin
if(Clk'event and Clk='1') then --扫描累加
SEG_SEL<=SEG_SEL+1;
if flag='1' then Display<=Disp_Decode;end if; if flag='0' then Display<=Disp_Decode1;end if; end if;
end process;
process(Disp_Temp) --时钟显示转换
begin
case Disp_Temp is
when 0=>Disp_Decode<="00111111"; --0
when 1=>Disp_Decode<="00000110"; --1
when 2=>Disp_Decode<="01011011"; --2
when 3=>Disp_Decode<="01001111"; --3
when 4=>Disp_Decode<="01100110"; --4
when 5=>Disp_Decode<="01101101"; --5
when 6=>Disp_Decode<="01111101"; --6
when 7=>Disp_Decode<="00000111"; --7
when 8=>Disp_Decode<="01111111"; --8
when 9=>Disp_Decode<="01101111"; --9
when 10=>Disp_Decode<="01000000"; ---
when others=>Disp_Decode<="00000000"; --全灭 end case;
end process;
process(Disp_Temp1) --倒计时显示转换
begin
case Disp_Temp1 is
when 0=>Disp_Decode1<="00111111"; --0
when 1=>Disp_Decode1<="00000110"; --1
when 2=>Disp_Decode1<="01011011"; --2
when 3=>Disp_Decode1<="01001111"; --3
when 4=>Disp_Decode1<="01100110"; --4
when 5=>Disp_Decode1<="01101101"; --5
when 6=>Disp_Decode1<="01111101"; --6
when 7=>Disp_Decode1<="00000111"; --7
when 8=>Disp_Decode1<="01111111"; --8
when 9=>Disp_Decode1<="01101111"; --9
when 10=>Disp_Decode1<="01000000"; ---
when others=>Disp_Decode1<="00000000"; --全灭 end case;
end process;
end behave;
功能仿真截图:
程序下载成功,功能已实现,因为用电平触发,所以只有当倒计时的电平为高时,再按下时钟或分钟的加一按键,才能回到时钟状态。

相关文档
最新文档