数字逻辑之数字时钟显示与校时

来源:互联网 发布:网络赌钱游戏网站 编辑:程序博客网 时间:2024/05/22 02:11

数字逻辑课程设计报告

   

设计题目:多功能数字电子钟设计   

 

姓    名:        

                                                                        

所学专业:   软件工程          

                            

班    级:             

                                                                  

指导教师:             

 

日    期:2014.06.26             

 

 

 一.设计内容 4

1.设计要求 4

二.设计方案即总体功能 4

三.各部分具体设计 5

1.显示模块 5

1.秒部分 5

(2).分钟部分 7

(3)小时部分 9

(4)模八部分 11

(5)八选一部分 12

(6)时钟显示部分 14

2.校时模块 15

(1)按键校正按键的设置 15

(2)按键控制时分秒 17

四.总结 21




(1)具有以24小时制计时的功能。

(2)以24小时显示的功能。

(3)具有校时的功能

(4)设计精度为1S。

设计方案即总体功能

系统输入:系统状态及校时,时钟信号CLK,采用1024HZ,输入信号有按键K1,K2,K3产生,分别用来改变时分秒的大小。

系统输出:七段数码管显示时分秒输出。

 

时钟CLK需要1HZ,但输入的时钟信号为1024HZ,所以我们用到了分频器来改变频率的大小,达到我们所需要的频率1HZ时才输出。

VHDL程序代码如下:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity miao is

port (clk,en,clr:in std_logic;

   m1,m0:out std_logic_vector(3 downto 0);———m1,m0高低位

   co:out std_logic);————co进位

end miao;

architecture m of miao is

signal cnt1,cnt0:std_logic_vector(3 downto 0);

begin

process(clk)

begin

if(clr='0')then

cnt0<="0000";

cnt1<="0000";

elsif(clk'event and clk='1')then

if en='1' then

if cnt1="0101" and cnt0="1001" then 到59时产生进位

co<='1';

cnt0<="0000";

cnt1<="0000";

elsif cnt0<"1001" then

cnt0<=(cnt0+1);

else 

    cnt0<="0000";

cnt1<=cnt1+1;

co<='0';

end if;

end if;

end if;

m1<=cnt1;

m0<=cnt0;

end process;

end m;


当秒满59时产生一个进位信号,通过CO传给分钟,使得分钟加一。分钟为60进制,分钟到达59时产生进位一,传给时。

生成的器件图如下:

 

VHDL语言代码如下:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity fenzhong is

port (clk,en:in std_logic;

  f1,f0:out std_logic_vector(3 downto 0);————f1,f0高低位

co:out std_logic);——-CO进位

end fenzhong;

architecture f of fenzhong is

SIGNAL cnt1,cnt0:std_logic_vector(3 downto 0);

begin

process(clk)

begin

if(clk'event and clk='1')then

if en='1' then

if cnt1="0101" and cnt0="1001" then————分钟从00到59,到59时产生进位信号,传给CO

co<='1';

cnt0<="0000";

cnt1<="0000";

elsif cnt0<"1001" then

cnt0<=(cnt0+1);

else 

    cnt0<="0000";

cnt1<=cnt1+1;

co<='0';

end if;

end if;

end if;

f1<=cnt1;

f0<=cnt0;

end process;

end f;


小时接受分钟传来的进位信号,加一。小时为24进制,所以从00到23循环,23后变为00,以此循环计时。

器件图如下:

 

VHDL语言代码如下:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity xiaoshi is

port(clk,en:in std_logic;

     a1,a0:out std_logic_vector(3 downto 0));

end xiaoshi;

architecture beha of xiaoshi is

signal cnt1,cnt0:std_logic_vector(3 downto 0);

begin

process(clk)

begin

if(clk'event and clk='1') then

if en='1' then

if cnt1="0010" and cnt0="0011" then--设置从00到23循环

cnt1<="0000";

cnt0<="0000";

elsif cnt0<"1001" then

cnt0<=cnt0+1;

else

cnt0<="0000";

cnt1<=cnt1+1;

end if;

end if;

end if;

a1<=cnt1;

a0<=cnt0;

end process;

end beha;


数码管有八个,我们需要用到6个来显示时间,来达到00—00—00(23—59—59)的效果。所以用到了模八,用来循环时间。此时需要1024HZ的频率,所以直接连接输入的CLK即可。


VHDL语言代码如下:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity mo8 is

port(clr,clk,en:in std_logic;

     y:out std_logic_vector(2 downto 0));

end mo8;

architecture beha of mo8 is

signal p:std_logic_vector(2 downto 0);

begin

process(clk)

begin

if clk'event and clk='1' then

if en='1' then

if p="111" then--设置从0到7循环

p<="000";

elsif p<"111" then

p<=p+1;

end if;

end if;

end if;

y<=p;

end process;

end beha;

八个数码管选择显示

生成的器件图如下:

 

VHDL语言源代码如下:

library ieee;

use ieee.std_logic_1164.all;

entity mux8_1 is

port(m0,m1,m2,m3,m4,m5,m6,m7:in std_logic_vector(3 downto 0);

     sel:in std_logic_vector(2 downto 0);

     y:out std_logic_vector(3 downto 0));

end mux8_1;

architecture arc of mux8_1 is

begin

process(sel)

begin

case sel is

when"000"=>y<=m0;---0到7的八个数分别赋给MO到M7

when"001"=>y<=m1;

when"010"=>y<=m2;

when"011"=>y<=m3;

when"100"=>y<=m4;

when"101"=>y<=m5;

when"110"=>y<=m6;

when"111"=>y<=m7;

when others=>y<="XXXX";

end case;

end process;

end arc;

此模块是用来数码管显示数字,七段显示管(abcdefg),

来显示0到9的数字。


 

VHDL语言代码:

library ieee;

use ieee.std_logic_1164.all;

entity shizhong is

port(num:in std_logic_vector(3 downto 0);

     y: out std_logic_vector(6 downto 0));

end shizhong;

architecture beha of shizhong is

begin

process(num)

begin

case num is

when"0000"=>y<="1111110";--0到9对应的显示

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

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

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

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

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

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

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

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

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

when others=>y<="0000001";

end case;

end process;

end beha;

校时模块用来调整时分秒的大小,K1来控制时的调整,按一下,时间增加一,K2,用来调整分钟的大小,按一下加一,K3用来调整秒的大小,按一下秒归0.1)按键校正按键的设置

三个按键的设置,此时需要256HZ的频率,所以用到了分频器来改变频率使其累计达到要求输出。

代码:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

entity debounce is

port(clk,reset:in std_logic;  --256HZ

din:in std_logic;

dout:out std_logic);

end debounce;

architecture a of debounce is

type state is(s0,s1,s2);

signal current:state;

begin

process(clk,reset,din)

begin

if(reset='1')then

current<=s0;

dout<='1';

elsif (clk'event and clk='1')then

case current is

when s0=>dout<='1';

if(din='0')then

current<=s1;

else 

current<=s0;

end if;

when s1=>dout<='1';

if(din='0')then

current<=s2;

else 

current<=s0;

end if;

when s2=>dout<='0';

if(din='0')then

current<=s2;

else 

current<=s0;

end if;

when others=>dout<='1';

current<=s0;

end case;

end if;

end process;

end a;

代码:

library ieee;

use ieee.std_logic_1164.all;       

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

entity ctr1 is

port(clk:in std_logic;  --10HZ

key1,key2,key3,key4:in std_logic;

led1,led2,led3,led4:out std_logic);

end ctr1;

architecture a of ctr1 is

begin

process (clk)

begin

if(clk'event and clk='1')then

if(key1='0')then

led1<='1';led2<='0';led3<='0';led4<='0';--按下为高有效,使得led输出为1,所以用到了非门,使1变为0,让0传给miao的clr.

elsif(key2='0')then

led1<='0';led2<='1';led3<='0';led4<='0';

elsif(key3='0')then

led1<='0';led2<='0';led3<='1';led4<='0';

elsif(key4='0')then

led1<='0';led2<='0';led3<='0';led4<='1';

else

led1<='0';led2<='0';led3<='0';led4<='0';

end if;

end if;

end process;

end a;

四.总结

 通过这次课程设计,我们学到了很多东西,总结如下:

1.这次的课程设计加强了我们动手、思考和解决问题的能力,在整个设计过程中,我们通过设计数字时钟,熟练的掌握了24进制,60进制等VHDL程序语言,对硬件语言有了更深刻的理解。

2.搞清楚了一些器件的作用与特点,例如模八,八选一,分频器等,了解了或非门的应用。会按要求和所需的功能连接电路图,继而可以完成完整的顶层图。

3.这次的学习让我们更加明白了团结合作的重要性,在设计电路的时候,我们遇到了一些困难,但是和伙伴们一起讨论,积极思考,就会有思路,就可以找到解决的办法。如果只是自己一个人在那里想总是解决不了问题,而且还会耗费在这上面的很多时间,所以集体的力量是伟大的,要团结合作。

 每一次的学习都会让我们有收获,这次的课程设计对我们很有意义!

 

 

 

 

 

 

0 0