多功能数字电子钟 VHDL.docx
《多功能数字电子钟 VHDL.docx》由会员分享,可在线阅读,更多相关《多功能数字电子钟 VHDL.docx(16页珍藏版)》请在冰豆网上搜索。
多功能数字电子钟VHDL
《VHDL课程设计》实验报告
多功能数字电子钟
姓名:
班级:
学号:
指导老师:
成绩:
完成时间:
2008年1月4日星期五
完成地点:
502机房
一、实验目的
1.学习数字系统设计的自顶向下设计法及控制器的设计。
2.加深利用EDA技术实现数字系统的体会。
二、实验仪器及器件
台)微机(11套)2.1.EDA开发软件(其他器件与材料(若干)4.实验开发系统(1台)3.三、实验要求及设计方案
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)多功能数字钟系统结构逻辑框图如下:
mode动set态计时显示控校时显k制选择电路示器控制电reset电路路clk闹f1024定clk3
比f4电f
5)控制器的MDS图如下:
0mods4
s0
mod=set=0
set=0
显示计时时间S0:
s5
s1
set=0
调计时的时S1:
set=0
set=0
set=0
S2:
调计时的分调计时的秒S3:
s6s2
显示闹钟时间S4:
set=0
set=0
S5:
调闹钟的时s7
s3
S6:
调闹钟的分
:
四、各功能模块的源程序代码--CONTOR模块libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entitycontoris
port(clk,k,set,reset,mode:
instd_logic;
:
outstd_logic);
chs,cht,cms,cmt,css,cst,flashh,flashm,flashs,sel_show
endcontor;
architecturecontor_archofcontoris
typestatesis(s0,s1,s2,s3,s4,s5,s6,s7);
signalcurrent_state,next_state:
states;
begin
process(reset,clk,next_state)
begin
if(reset='1')then
current_state<=s0;
elsif(clk'eventandclk='1')then
current_state<=next_state;
endif;
endprocess;
process(current_state,k,set)
begin
casecurrent_stateis
whens0=>
flashh<='0';flashm<='0';flashs<='0';cht<='0';cmt<='0';cst<='0';
chs<='0';cms<='0';css<='0';sel_show<='1';
if(mode='0')thennext_state<=s4;
elsif(k='1'andset='0')then
next_state<=s1;
else
next_state<=s0;
endif;
whens1=>
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;
endif;
whens2=>
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;
endif;
whens3=>
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;
endif;
whens4=>
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'andset='0')then
next_state<=s5;
else
next_state<=s4;
endif;
whens5=>
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;
endif;
whens6=>
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;
endif;
whens7=>
flashh<='0';flashm<='0';flashs<='1';cht<='0';cmt<='0';
cst<='0';chs<='0';cms<='0';css<='1';sel_show<='0';
thenIf(set='0')
next_state<=s4;
else
next_state<=s7;
endif;
endcase;
endprocess;
endcontor_arch;
********************--*********************TIMER模块
********模块--********MUX2-1*****模块--*************cnt60libraryieee;libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;entitymux2_1is
entitycnt60isport(d0,d1,en:
instd_logic;
:
instd_logic;port(clkinsel:
instd_logic;
std_logic_vector(3
mh,ml:
buffer:
outstd_logic);
ydownto0);
endmux2_1;co:
bufferstd_logic);architecturemux2_1_archofmux2_1isendminute;
beginarchitecturecnt60xofminutecnt60is
beginprocess(d0,d1,sel)
process(clkin)begin
beginif(sel='0')then
if(rising_edge(clkin))then
y<=d0;
if(mh=1andml=@1)then
elsif(sel='1'anden='0')thenmh<=y<=d1;elsif(ml=@1)thenendif;ml<=
elseml<=ml+1;co<='0';
endprocess;
endif;endmux2_1_arch;
endif;
endprocess;
endcnt60x;
――*****************Time_com模块*********
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entitytime_comis
port(hh,mh,sh,hl,ml,k:
instd_logic_vector(3downto0);
chs,cms,css,f4:
instd_logic;
bsg,bmg,bhg,bsd,bmd,bhd:
bufferstd_logic_vector(3downto0);
comout:
outstd_logic);
endtime_com;
architecturetime_comxoftime_comis
begin
com:
process(hh,mh,sh,hl,ml)
begin
if(bhg=hhandbhd=hlandbmg=mhandbmd=mlandbsg=sh)then
comout<='1';
else
comout<='0';
endif;
endprocess;
set:
process(f4)
begin
if(f4'eventandf4='1')then
if(chs='1'andk='0')then
if(bhg=0andbhd=1)then
bhd<=
elsif(bhd=@1)then
bhd<=
elsif(bhd=
bhd=1orbhd=0orbhd=1orbhd=0or
bhd=1orbhd=@0)then
bhd<=bhd+1;
endif;
endif;
endif;
endprocess;
process(f4)
begin
if(f4'eventandf4='1')then
if(cms='1'andk='0')then
if(bmg=1andbmd=@1)then
bmd<=
elsif(bmd=@1)then
bmd<=
elsif(bmd=
bmd=1orbmd=0orbmd=1orbmd=0or
bmd=1orbmd=@0)then
bmd<=bmd+1;
endif;
endif;
endif;
endprocess;
process(f4)
begin
if(f4'eventandf4='1')then
if(css='1'andk='0')then
if(bsg=1andbsd=@1)then
bsd<=
elsif(bsd=@1)then
bsd<=
elsif(bsd=
bsd=1orbsd=0orbsd=1orbsd=0or
bsd=1orbsd=@0)then
bsd<=bsd+1;
endif;
endif;
endif;
endprocess;
endtime_comx;
--*****************Show_contor模块****************************
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entityshow_contoris
port(hh,mh,sh,bhh,bmh,bsh,hl,ml,sl,bhl,bml,bsl:
instd_logic_vector(3downto0);
flashh,flashm,flashs,clk1,sel_show:
instd_logic;
sld0,shd1,mld3,mhd4,hld6,hhd7,line:
outstd_logic_vector(3downto0));
endshow_contor;
architectureshow_contor_archofshow_contoris
begin
line<=A0;
process(clk1)
begin
ifsel_show='1'then
sld0<=sl;
shd1<=sh;
mld3<=ml;
mhd4<=mh;
hld6<=hl;
hhd7<=hh;
elsifsel_show='0'then
sld0<=bsl;
shd1<=bsh;
mld3<=bml;
mhd4<=bmh;
hld6<=bhl;
hhd7<=bhh;
endif;
if(clk1='1'andflashs='1')then
sld0<=I1;shd1<=I1;
endif;
if(clk1='1'andflashm='1')then
mld3<=I1;mhd4<=I1;
endif;
if(clk1='1'andflashh='1')then
hld6<=I1;hhd7<=I1;
endif;
endprocess;
endshow_contor_arch;
--****************Dynamic_show模块代码(略)*********************
--*************Bell模块********************************************
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitybelis
port(mh,sh,ml,sl:
instd_logic_vector(3downto0);
comout,f512hz,f1024hz,clk:
instd_logic;
bell:
outstd_logic);
endbel;
architecturebel_archofbelis
begin
process(clk,mh,ml,sh,sl,f1024hz,f512hz)
begin
if(comout='1')then
bell<=clk;
elsif(mh=1andml=@1)then
if(sh=1)then
if(sl=@1)then
bell<=f1024hz;
elsif(sl=
bell<=f512hz;
endif;
else
bell<='0';
endif;
elsif(ml<@1ormh<1or
sh<1)then
bell<='0';
endif;
endprocess;
endbel_arch;
五、连接总图(如右):
六、波形仿真:
七、引脚锁定、编译、连线并下载到实验箱进行验证121416111150151152153154155156787980
183182reset2
reset1ky3bellsel1sel0sel2y0y1y2y4y5y6modeset
八、心得体会
为期一周的课程设计在紧张与忙碌中飞逝而过,我所选择的多功能电子钟在老师孜孜不倦的指导下和同学的热心帮助下终于成功了。
不但实现了题目所要求的全部功能,还实现了更人性化的功能(按一下按键执行一次加1操作)。
这一功能的实现是在x老师的启发和指导以及在xxx同学的帮助与提问下才得以实现的。
刚开始按照老师的思路虽然实现了按一下按键执行一次加1的功能,当时我以为自己成功了,可她发现秒钟到59后没有产生进位信号,分位没有加1。
在她发现错误后,我仔细研究了产生这种错误的原因,原来我把控制校时的使能信号输入端放在了计数器里边,它屏蔽了进位信号。
最后,我把控制校时的使能信号放在了mux2_1终于解决了不进位的错误。
通过这件事使我认识到与同学的讨论是十分有必要和重要的。
在与同学的讨论中不但使我发现了自己的错误和不足,还使自己开阔了眼界,增长了见识,增进了同学之间的友谊。
课程设计全方位的培养和考察我们解决问题以及处理将理论应用到实际当中的能力。
在设计编程的过程中,我们既经过了独立思考,也经过了团体协作。
我们必须在短期内锻炼迅速掌握一门语言的能力,并学会利用其他的资料与书籍。
可见课程设计的意义是十分重大和深远的。
.