当前位置:文档之家› 多功能数字电子钟_VHDL

多功能数字电子钟_VHDL

多功能数字电子钟_VHDL
多功能数字电子钟_VHDL

《VHDL课程设计》实验报告

多功能数字电子钟

姓名:

班级:

学号:

指导老师:

成绩:

完成时间:2008年1月4日星期五

完成地点:502机房

一、实验目的

1.学习数字系统设计的自顶向下设计法及控制器的设计。

2.加深利用EDA技术实现数字系统的体会。

二、实验仪器及器件

1.EDA 开发软件(1套)

2.微机(1台)

3.实验开发系统(1台)

4.其他器件和材料(若干)

三、实验要求及设计方案

1.设计一个具有24进制计时、显示、整点报时、时间设置和闹钟功能的数字钟,要求时钟的最小分辨率时间为1s。

2.数字钟的设计方案如下:

系统输入:mode为计时显示和闹钟定时显示转换输入;set为校时和定时设置的时、分、秒转换输入;k为校时和定时设置的时、分、秒手动加1输入;clk为时钟信号;reset为系统复位信号。输入信号均由按键产生。

系统输出:LED显示输出;蜂鸣器(bell)声音信号输出。

3.多功能数字钟系统功能的具体描述如下:

计时:正常工作状态下,每日按24小时计时制计时并显示,蜂鸣器逢整点报时。

校时:在计时显示状态下,按下“set键”,进入“小时”校时状态,再次按下“set键”,进入“分”校时状态,继续按下“set键”,进入“秒”校时状态,第四次按下“set键”又回复到正常计时显示状态。

1)“小时”校时状态:进入“小时”校时状态后,显示“小时”的数码管闪烁,每按动“k”键一次,“小时”+1,若不按动“k”键则小时数不变,一直按下“k”键则小时数一4Hz的频率递增计数。 2)“分”校时状态:进入“分”校时状态后,显示“分”的数码管闪烁,每按动“k”键一次,“分”+1,若不按动“k”键则分数不变,一直按下“k”键则分数一4Hz的频率递增计数。

3)“秒”校时状态:进入“秒”校时状态后,显示“秒”的数码管闪烁,每按动“k”键一次,“秒”+1,若不按动“k”键则秒数不变,一直按下“k”键则秒数一4Hz的频率递增计数。

整点报时:蜂鸣器在“59”分钟的第51、53、55、57秒发出频率为512Hz的低音,在“59”秒发出频率为1024Hz的高音,结束时为整点。

显示:采用8个LED数码管分别显示时、分、秒并且他们之间用“—”隔开。

闹钟:闹钟定时时间到,蜂鸣器发出周期为1s的滴、滴声,持续时间为10秒;闹钟定时显示。

闹钟定时设置:在闹钟显示状态下,按下“set键”,进入“小时”校时状态,再次按下“set键”,进入“分”校时状态,继续按下“set键”,进入“秒”校时状态,第四次按下“set键”又回复到闹钟显示状态。

闹钟的时、分、秒设置过程和计时设置相同。

计时显示和闹钟显示之间的转换:按动“mode”键,数字钟将在计时显示和闹钟定时显示之间转换。

4)多功能数字钟系统结构逻辑框图如下:

5)控制器的MDS 图如下:

四、各功能模块的源程序代码:

-- CONTOR 模块 library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity contor is

port(clk,k,set,reset,mode : in std_logic;

chs,cht,cms,cmt,css,cst,flashh,flashm,flashs,sel_show :out std_logic);

end contor;

architecture contor_arch of contor is

type states is(s0,s1,s2,s3,s4,s5,s6,s7);

s0

s1

s2

s3

s7

s6 s5

s4

mode =0 mode =0

set=0

set=0

set=0

set=0

set=0

set=0

set=0

S0: 显示计时时间 S1: 调计时的时 S2: 调计时的分 S3: 调计时的秒 S4: 显示闹钟时间 S5: 调闹钟的时

控 制 器

set k reset clk

计时 校时 电路

显示 选择 控制 电路

动态显示电路

分频器

clk3

f1024 f4 f

闹钟 定时 比较 电路

蜂鸣器

mode set=0

signal current_state,next_state :states;

begin

process (reset,clk,next_state)

begin

if (reset='1')then

current_state<=s0;

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

current_state<=next_state;

end if;

end process;

process(current_state,k,set)

begin

case current_state is

when s0=>

flashh<='0';flashm<='0';flashs<='0';cht<='0';cmt<='0';cst<='0';

chs<='0';cms<='0';css<='0';sel_show<='1';

if(mode='0')then next_state<=s4;

elsif(k='1'and set='0' ) then

next_state<=s1;

else

next_state<=s0;

end if;

when s1=>

flashh<='1';flashm<='0';flashs<='0';cht<='1';cmt<='0';cst<='0';

chs<='0';cms<='0';css<='0';sel_show<='1';

if (set='0' ) then

next_state<=s2;

else

next_state<=s1;

end if;

when s2=>

flashh<='0';flashm<='1';flashs<='0';cht<='0';cmt<='1';cst<='0';

chs<='0';cms<='0';css<='0';sel_show<='1';

if (set='0') then

next_state<=s3;

else

next_state<=s2;

end if;

when s3=>

flashh<='0';flashm<='0';flashs<='1';cht<='0';cmt<='0';

cst<='1';chs<='0';cms<='0';css<='0';sel_show<='1';

if ( set='0' ) then

next_state<=s0;

else

next_state<=s3;

end if;

when s4=>

flashh<='0';flashm<='0';flashs<='0';cht<='0';cmt<='0';cst<='0';

chs<='0';cms<='0';css<='0';sel_show<='0';

if ( mode='0' ) then

next_state<=s0;

elsif ( k='1'and set='0' ) then

next_state<=s5;

else

next_state<=s4;

end if;

when s5=>

flashh<='1';flashm<='0';flashs<='0';cht<='0';cmt<='0';cst<='0';

chs<='1';cms<='0';css<='0';sel_show<='0';

if (set='0') then

next_state<=s6;

else

next_state<=s5;

end if;

when s6=>

flashh<='0';flashm<='1';flashs<='0';cht<='0';cmt<='0';

cst<='0';chs<='0';cms<='1';css<='0';sel_show<='0';

if (set='0' ) then

next_state<=s7;

else

next_state<=s6;

end if;

when s7=>

flashh<='0';flashm<='0';flashs<='1';cht<='0';cmt<='0';

cst<='0';chs<='0';cms<='0';css<='1';sel_show<='0';

If (set='0') then

next_state<=s4;

else

next_state<=s7;

end if;

end case;

end process;

end contor_arch;

--*********************TIMER模块********************

--********MUX2-1 模块******** library ieee;

use ieee.std_logic_1164.all; --*************cnt60模块*****

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity cnt60 is

port(clkin :in std_logic;

mh,ml :buffer std_logic_vector(3 downto 0);

co :buffer std_logic);

entity mux2_1 is

port(d0,d1,en :in std_logic;

sel :in std_logic;

y :out std_logic);

end mux2_1;

architecture mux2_1_arch of mux2_1 is

begin

process(d0,d1,sel)

begin

if(sel='0')then

y<=d0;

elsif(sel='1'and en='0')then

y<=d1 ;

end if;

end process;

end mux2_1_arch;

――*****************Time_com 模块*********

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

entity time_com is

port(hh,mh,sh,hl,ml,k :in std_logic_vector(3 downto 0);

chs,cms,css,f4 :in std_logic;

bsg,bmg,bhg,bsd,bmd,bhd :buffer std_logic_vector(3 downto 0);

comout :out std_logic);

end time_com;

architecture time_comx of time_com is

begin

com:process(hh,mh,sh,hl,ml)

begin

if(bhg=hh and bhd=hl and bmg=mh and bmd=ml and bsg=sh)then comout<='1';

else

comout<='0';

end if;

end process;

set:process(f4)

begin

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

if(chs='1'and k='0')then

if(bhg="0010" and bhd="0011")then

bhd<="0000";bhg<="0000";

elsif(bhd="1001")then

bhd<="0000";bhg<=bhg+1;

elsif(bhd="0000"or bhd="0001" or bhd="0010"or

bhd="0011"or bhd="0100"or bhd="0101"or bhd="0110"or

bhd="0111"or bhd="1000")then

bhd<=bhd+1;

end if;

end if;

end if;

end process;

process(f4)

begin

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

if(cms='1'and k='0')then

if(bmg="0101" and bmd="1001")then

bmd<="0000";bmg<="0000";

elsif(bmd="1001")then

bmd<="0000";bmg<=bmg+1;

elsif(bmd="0000"or bmd="0001" or bmd="0010"or

bmd="0011"or bmd="0100"or bmd="0101"or bmd="0110"or

bmd="0111"or bmd="1000")then

bmd<=bmd+1;

end if;

end if;

end if;

end process;

process(f4)

begin

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

if(css='1' and k='0')then

if(bsg="0101" and bsd="1001")then

bsd<="0000";bsg<="0000";

elsif(bsd="1001")then

bsd<="0000";bsg<=bsg+1;

elsif(bsd="0000"or bsd="0001" or bsd="0010"or

bsd="0011"or bsd="0100"or bsd="0101"or bsd="0110"or

bsd="0111"or bsd="1000")then

bsd<=bsd+1;

end if;

end if;

end if;

end process;

end time_comx;

--*****************Show_contor模块**************************** library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

entity show_contor is

port(hh,mh,sh,bhh,bmh,bsh,hl,ml,sl,bhl,bml,bsl :in std_logic_vector(3 downto 0);

flashh,flashm,flashs,clk1,sel_show :in std_logic;

sld0,shd1,mld3,mhd4,hld6,hhd7,line :out std_logic_vector(3 downto 0)); end show_contor;

architecture show_contor_arch of show_contor is

begin

line<="1010";

process(clk1)

begin

if sel_show='1'then

sld0<=sl;

shd1<=sh;

mld3<=ml;

mhd4<=mh;

hld6<=hl;

hhd7<=hh;

elsif sel_show='0'then

sld0<=bsl;

shd1<=bsh;

mld3<=bml;

mhd4<=bmh;

hld6<=bhl;

hhd7<=bhh;

end if;

if(clk1='1' and flashs='1')then

sld0<="1111";shd1<="1111";

end if;

if(clk1='1' and flashm='1')then

mld3<="1111";mhd4<="1111";

end if;

if(clk1='1' and flashh='1')then

hld6<="1111";hhd7<="1111";

end if;

end process;

end show_contor_arch;

--****************Dynamic_show模块代码(略)********************* --*************Bell模块******************************************** library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity bel is

port(mh,sh,ml,sl :in std_logic_vector(3 downto 0);

comout,f512hz,f1024hz,clk :in std_logic;

bell :out std_logic);

end bel;

architecture bel_arch of bel is

begin

process(clk,mh,ml,sh,sl,f1024hz,f512hz)

begin

if(comout='1')then

bell<=clk;

elsif(mh="0101"and ml="1001" )then

if(sh="0101") then

if(sl="1001") then

bell<=f1024hz;

elsif(sl="0001" or sl="0011" or sl="0101" or sl="0111")then

end if;

else

bell<='0';

end if;

elsif(ml<"1001"or mh<"0101"or sh<"0101" )then

bell<='0';

end if;

end process;

end bel_arch;

五、连接总图(如右):

六、波形仿真:

七、引脚锁定、编译、连线并下载到实验箱进行验证

12 14 16 111 150 151 152 153 154 155 156 78 79 80 183 182

sel0 sel1 sel2 bell y0 y1 y2 y3 y4 y5 y6 mode set k reset1 reset2

八、心得体会

为期一周的课程设计在紧张和忙碌中飞逝而过,我所选择的多功能电子钟在老师孜孜不倦的指导下和同学的热心帮助下终于成功了。

不但实现了题目所要求的全部功能,还实现了更人性化的功能(按一下按键执行一次加1操作)。

这一功能的实现是在x老师的启发和指导以及在xxx同学的帮助和提问下才得以实现的。刚开始按照老师的思路虽然实现了按一下按键执行一次加1的功能,当时我以为自己成功了,可她发现秒钟到59后没有产生进位信号,分位没有加1。在她发现错误后,我仔细研究了产生这种错误的原因,原来我把控制校时的使能信号输入端放在了计数器里边,它屏蔽了进位信号。最后,我把控制校时的使能信号放在了mux2_1终于解决了不进位的错误。通过这件事使我认识到和同学的讨论是十分有必要和重要的。在和同学的讨论中不但使我发现了自己的错误和不足,还使自己开阔了眼界,增长了见识,增进了同学之间的友谊。

课程设计全方位的培养和考察我们解决问题以及处理将理论使用到实际当中的能力。在设计编程的过程中,我们既经过了独立思考,也经过了团体协作。我们必须在短期内锻炼迅速掌握一门语言的能力,并学会利用其他的资料和书籍。可见课程设计的意义是十分重大和深远的。

相关主题
文本预览
相关文档 最新文档