基于VHDL的数字时钟实验报告

数字时钟实验报告

  实验目的】:

     设计一个24小时制数字钟,要求能显示时,分,秒,并且可以手动调整时和分

试验中所用器材】:

     开发环境MAXPLUSIIZY11EDA13BE 试验系统, VHDL 语言.

设计原理

数字钟的主体是计数器,它记录并显示接收到的秒脉冲个数,其中秒和分为模60计数器,小时是模24计数器,分别产生3BCD码。BCD码经译码,驱动后接数码管显示电路。

秒模60计数器的进位作为分模60计数器的时钟,分模60计数器的进位作为模24计数器的时钟。

为了实现手动调整时间,在外部增加了setm(调整分),seth(调整时)按键,当这两个按键为低电平时,电路正常计时,当为高电平时,分别调整分,时。同时在外部还增加了一个清零按键clr.和消抖动电路。

单元模块设计部分

   消抖动电路关键部分

signal key_in1,key_in2:std_logic:='0';

begin

process(clk,key_in)

begin

if clk'event and clk='1' then

   key_in1<=key_in;key_in2<=key_in1;

   if  key_in='1' and key_in1='1' and key_in2='1' then  key_out<='1';

   else key_out<='0';

  时序仿真图

 

60计数器程序关键部分

signal md_temp,mg_temp:std_logic_vector(3 downto 0);

begin

process(clk,clr)

begin

if clr='1' then

   md_temp<="0000"; mg_temp<="0000";

elsif set='1' then

     md_temp<=setl; mg_temp<=seth;

elsif clk'event and clk='1' then

     if md_temp="1001" then

        md_temp<="0000";mg_temp<=mg_temp+'1';

     else md_temp<=md_temp+'1';

     end if;

if md_temp="1001" and mg_temp="0101" then

   md_temp<="0000";mg_temp<="0000";

秒时序仿真图

分时序仿真

分的清零和调整时间部分

24计数器程序关键部分

signal hd_temp,hg_temp:std_logic_vector(3 downto 0);

begin

process(clk,clr,set,setl,seth)is

       begin

            if set='1' then hd_temp<=setl; hg_temp<=seth;

            elsif clr='1' then  hd_temp<="0000";  hg_temp<="0000";

            elsif clk'event and clk='1' then

                if hg_temp="0010" and hd_temp="0011" then

                           hd_temp<="0000"; hg_temp<="0000";

                elsif hd_temp="1001" then

                   hg_temp<=hg_temp+'1'  hd_temp<="0000";

                else hd_temp<=hd_temp+'1';

                  end if;

              end if;

 end process ;

时时序仿真图

清零和调时

 

显示部分关键程序

 process (sd,sg,md,mg,hd,hg)

begin

              case sd is

 

                  when "0000" =>sl<="1111110";

                  when "0001" =>sl<="0110000";

                  when "0010" =>sl<="1101101";

                  when "0011" =>sl<="1111001";

                  when "0100" =>sl<="0110011";

                  when "0101" =>sl<="1011011";

                  when "0110" =>sl<="1011111";

                  when "0111" =>sl<="1110000";

                  when "1000" =>sl<="1111111";

                  when "1001" =>sl<="1111011";

                  when others =>sl<="0000000";

                 end case;  

  if clk_g'event and clk_g='1' then

   if sel="101" then

      sel<="000";

   else sel<=sel+'1';

   end if;

end if;

end process;

 

process(sel,sd,sl,sg,sh,md,ml,mg,mh,hd,hl,hg,hh)

begin 

  case sel is 

       when"000"=>led<=sl;

                  led_which<=sd;

       when"001"=>led<=sh;

                  led_which<=sg;

       when"010"=>led<=ml;

                  led_which<=md;

       when"011"=>led<=mh;

                  led_which<=mg;

       when"100"=>led<=hl;

                  led_which<=hd;

       when"101"=>led<=hh;

                 led_which<=hg;

       when others=>led<="0000000";

                    led_which<="0000";

   end case;

仿真图

顶层文件关键程序

port(

      clk,clk_g:in std_logic;-----clk_g是用在数码管显示里面的信号

      clr:      in std_logic;------clr=1 清零

      setm,seth:in std_logic;---------setm1时调分,seth1时调时

      setd,setg:in std_logic_vector(3 downto 0);----调整时间的时候,setd调整的是低位setg调整高位

      led:out std_logic_vector(6 downto 0);

      sel_out: out std_logic_vector(2 downto 0);

      led_which: out std_logic_vector(3 downto 0));---输出的是秒分时的哪一个

begin

    u1:de_shake port map (clk=>clk,key_in=>clr,key_out=>clro);

    u2:de_shake port map (clk=>clk,key_in=>setm,key_out=>setmo);

    u3:de_shake port map (clk=>clk,key_in=>seth,key_out=>setho);

    u4:s60      port map (clk=>clk,clr=>clro,sd=>sdl,sg=>sgh,fenmaichong=>fenmaichongo);

u5:m60 port map (clk=>fenmaichongo,clr=>clro,md=>mdl,mg=>mgh,xiaoshimaichong=>xiaoshimaichongo,setl=>setd,seth=>setg,set=>setmo);

u6:h24      port map (clk=>xiaoshimaichongo,clr=>clro,hd=>hdl,hg=>hgh,set=>setho,setl=>setd,seth=>setg);

    u7:led_xs   port map (clk_g=>clk_g,sd=>sdl,sg=>sgh,md=>mdl,mg=>mgh,hd=>hdl,hg=>hgh,led=>led,sel_out=>sel_out,led_which=>led_which);

 

时序仿真

 

结论

本设计,满足了本次试验设计的任务要求,能显示时分秒,并且可以手动调节分和时。

按动setm1时,将setd的四位二进制数输入到分的低位.

按动setm1时,将setg的四位二进制数输入到分的高位.

按动seth1时,将setd的四位二进制数输入到时的低位.

按动seth1时,将setg的四位二进制数输入到时的高位 .

 

 

 

转载于:https://www.cnblogs.com/liuxing1893/archive/2009/05/18/1459407.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值