数字钟.docx
- 文档编号:15439122
- 上传时间:2023-07-04
- 格式:DOCX
- 页数:20
- 大小:152.04KB
数字钟.docx
《数字钟.docx》由会员分享,可在线阅读,更多相关《数字钟.docx(20页珍藏版)》请在冰点文库上搜索。
数字钟
大连理工大学本科实验报告
题目:
数字钟功能实现
课程名称:
数字电路课程设计
学院(系):
电信学部
专业:
班级:
学生姓名:
学号:
完成日期:
2012.12.26
成绩:
2012年12月26日
目录
1.设计要求…………………………………………3
2.设计分析及系统方案设计………………………3
3.系统以及模块硬件电路设计……………………5
4.系统的VHDL设计………………………………7
5.结论以及结果说明………………………………15
6.参考文献…………………………………………16
题目:
数字钟功能实现
1设计要求
1)个具有‘时’、‘分’、‘秒’的十进制数字显示(小时从00~23)计时器。
具有手动校时、校分的功能。
2)能进行整点报时。
要求发出仿中央人民广播电台的整点报时信号,即从59分50秒起,每隔2秒钟发出一次低音“嘟”的信号,连续5次,最后一次要求高音“嘀”的信号,此信号结束即达到整点。
(以指示灯闪烁代替)
3)定时与闹钟功能,能在设定的时间发出闹铃声,闹铃声持续时间为15秒。
4).具有人工清零功能,时分秒全部置零
2设计分析及系统方案设计
.数字计时器的基本工作原理
数字计时器一般都由振荡器、分频器、计数器、译码器、显示器等几部分组成。
其中振荡器和分频器组成标准秒信号发生器,由不同进制的计数器、译码器和显示器组成计时系统。
秒信号送入计数器进行计数,把累计的结果以‘时’、‘分’、‘秒’的数字显示出来。
‘时’显示由二十四进制计数器、译码器、显示器构成,‘分’、‘秒’显示由六十进制计数器、译码器、显示器构成。
其原理框图如图1所示。
振荡器是计数器的核心,振荡器的稳定度和频率的精度决定了计时器的准确度,所以通常选用石英晶体来构成振荡器。
一般来说,振荡器的频率越高,计时的精度越高,但耗电量将增大。
故设计者在设计电路时,应根据需要,设计出最佳电路。
常用的振荡器有由石英晶体和与非门组成的反馈振荡器、由555定时器与RC组成的多谐振荡器。
采用那种振荡器应根据系统的精度要求来选择。
由于我们的开发系统中有各种频率(从1Hz~12MHz)的信号源,因此设计系统时可直接使用。
在此不再给出振荡器的具体设计电路。
分频器的功能主要有两个:
一是产生标准脉冲信号,二是可提供功能扩展电路所需要的信号,如仿电台报时用的
Hz的高音频率信号和500Hz的低音频率信号。
用硬件描述语言设计分频器有三种常用的方法:
(1)加法分频器,
(2)减法分频器,(3)积分分频器
计数器部分对输入的秒脉冲进行计数。
它由模六、模十和模三计数器构成。
为了校时,计数器应具有异步预置功能。
(1)标准时钟源:
分频模块可将50Mhz的时钟源分出1Hz的时钟源用于计时,秒信号送入计数器进行计数,把累计的结果以‘时’、‘分’、‘秒’的数字显示出来。
‘时’显示由二十四进制计数器、译码器、显示器构成,‘分’、‘秒’显示由六十进制计数器、译码器、显示器构成.。
(2)模式选择器(sel):
可通过sel端控制闹钟模式或正常计时模式。
(3)模式控制器(mode):
将其设置成四个不同的工作状态s0,s1,s2,s3,通过mode端选择校时,分,秒。
(4)校时(set):
通过set端进行时,分加1.
(5)清零(clr):
通过clr端清零重新计时。
(6)闪烁控制模块:
分频模块将50Mhz的时钟源分出10Hz的时钟用于闪烁模块,当处于设置模式时,该模块将对应的显示位的7段数码驱动使能信号设置为10Hz时钟,即哪一位被设置,哪一位就闪烁。
(7)译码:
将输入的BCD码译码成7段数码显示的驱动。
(8)闹钟:
当预置到达时间时,LED灯就发光。
在此基础上给出系统的结构框图:
如图2所示
图2:
系统结构框图
3系统以及模块硬件电路设计
根据上述给出的系统总体结构框图,给出系统硬件电路设计,如图3所示:
图3硬件设计电路
DE2管脚编号:
seth_in
引脚号——接口
4系统的VHDL设计
端口说明:
clk:
时钟输入
Clr:
清零
sw0,sw1,sw2,sw3,sw4,sw5,sw6,sw7,key0,key1,key2,key3:
功能控制按键
ke1,ke2,sec1,sec2,min1,min2,hou1,hou2:
显示输出
alarm1,alarm2:
响铃输出信号
下面给出系统设计具体程序:
1)分频模块源程序:
libraryieee;--此模块共33行
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityc50m21kis
port(clr,clk:
instd_logic;--clr为清零端,clk为50Mhz时钟输入
cp,bclk:
outstd_logic--cp为1Khz时钟,bclk为10hz时钟
);
end;
architecturebehofc50m21kis
signalp1:
integerrange0to49999;--脉冲计数
signalp2:
integerrange0to4999999;--脉冲计数
signalbclk1:
std_logic;
begin
process(clk,clr)—对50Mhz时钟源进行分频
begin
if(clr='0')thencp<='0';bclk1<='0';
elsifrising_edge(clk)then--
ifp1=49999then
p1<=0;cp<='1';
else
p1<=p1+1;cp<='0';
endif;--cp为1Khz时钟
ifp2=4999999then
p2<=0;bclk1<=notbclk1;
else
p2<=p2+1;
endif;
endif;
bclk<=bclk1;--bclk为10hz时钟
endprocess;
end;
2)译码模块源程序:
libraryieee;--此模块共49行
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityyimais
port(qh,ql:
inintegerrange0to9;--数码管高低位的数值
bk:
instd_logic_vector(1downto0);--控制数码管的闪烁
dout1,dout2:
outstd_logic_vector(6downto0)--高低位输出
);
end;
architecturebehofyimais
begin
process(bk)
begin
if(bk(0)='1')thendout1<="1111111";--bk(0)=‘1’数码管低位不发光
else
caseqlis--低位译码
when0=>dout1<="1000000";
when1=>dout1<="1111001";
when2=>dout1<="0100100";
when3=>dout1<="0110000";
when4=>dout1<="0011001";
when5=>dout1<="0010010";
when6=>dout1<="0000010";
when7=>dout1<="1111000";
when8=>dout1<="0000000";
when9=>dout1<="0010000";
whenothers=>dout1<="1111111";
endcase;
endif;
ifbk
(1)='1'thendout2<="1111111";--数码管高位不发光
else
caseqhis--高位译码
when0=>dout2<="1000000";
when1=>dout2<="1111001";
when2=>dout2<="0100100";
when3=>dout2<="0110000";
when4=>dout2<="0011001";
when5=>dout2<="0010010";
when6=>dout2<="0000010";
when7=>dout2<="1111000";
when8=>dout2<="0000000";
when9=>dout2<="0010000";
whenothers=>dout2<="1111111";
endcase;
endif;
endprocess;
end;
3)闹钟模块源程序:
libraryieee;--此模块共36行
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityalarmeris
port(alarm,clk:
instd_logic;--alarm为闹钟输入,clk为时钟源
clr:
instd_logic;--clr控制闹钟结束
sound:
outstd_logic--闹钟输出端,控制闹钟是否有效
);
end;
architecturebehofalarmeris
signalp:
integerrange0to14999:
=14999;--控制闹钟响铃时间
signalcp:
std_logic;--
begin
process(clk,clr,alarm)—闹钟响铃15秒
begin
if(clr='0')thencp<='0';p<=14999;
elsif(alarm='1')thencp<='0';p<=0;
elsifrising_edge(clk)then
ifp>=14999then
p<=p;cp<='0';
else
p<=p+1;cp<='1';
endif;
endif;
endprocess;
process(cp,clr)
begin
if(clr='0')thensound<='0';
elsif(cp='1')then
sound<='1';
elsesound<='0';
endif;
endprocess;
end;
4)顶层文件及整点报时:
libraryieee;--此模块共205行
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entitytimeis
port(sel,clr,set,mode,clk:
instd_logic;--sel模式选择,clr清零
sound,ledr0,ledr1:
outstd_logic;--set校时校分,mode模式控制
d1,d2,d3,d4,d5,d6:
bufferstd_logic_vector(6downto0)--数码管输出
);
end;
architecturebehaveoftimeis
typestais(s0,s1,s2,s3);--定义四种工作状态
signalstate:
sta;
signalsl:
std_logic;--模式选择
signalbclk,cp,set_reg:
std_logic;--时钟源
signalalarm:
std_logic:
='0';--闹钟输入
signalblink:
std_logic_vector(5downto0);--闪烁输入
signalb1,b2,b3,b4,b5,b6:
std_logic_vector(6downto0);--正常计时数码管七段输出
signalalarm0,alarm1,alarm2,alarm3:
std_logic_vector(6downto0);闹钟模式数码管七段输出
signalhour,min,ahour,amin,sec:
integerrange0to60;--时分
signalhourh,hourl,minh,minl,ahourh,ahourl,aminh,aminl,sech,secl:
integerrange0to9;--时分高低位
componentc50m21k--调用分频模块
port(clr,clk:
instd_logic;
cp,bclk:
outstd_logic
);
endcomponent;
componentyima--调用译码模块
port(qh,ql:
inintegerrange0to9;
bk:
instd_logic_vector(1downto0);
dout1,dout2:
outstd_logic_vector(6downto0)
);
endcomponent;
componentalarmer--调用闹钟模块
port(alarm,clk:
instd_logic;
clr:
instd_logic;
sound:
outstd_logic
);
endcomponent;
begin
x1:
c50m21kportmap(clr,clk,cp,bclk);
process(sel,clr)
begin
if(clr='0')then
sl<='0';
elsif(sel'eventandsel='1')then
sl<=notsl;
endif;
endprocess;
process(mode,sl,clr)
begin
if(clr='0')then
state<=s0;
elsif(mode'eventandmode='1')then
caseslis
when'0'=>--正常计时模式
casestateis
whens0=>state<=s1;
whens1=>state<=s2;
whens2=>state<=s3;
whens3=>state<=s0;
endcase;
when'1'=>--闹钟模式
casestateis
whens0=>state<=s1;
whens1=>state<=s2;
whens2=>state<=s0;
whenothers=>state<=s0;
endcase;
endcase;
endif;
endprocess;
process(state,bclk)
begin
casestateis
whens0=>blink<="000000";
whens1=>--------------高两位闪烁
blink<=(5=>bclk,4=>bclk,others=>'0');
whens2=>---------------中间两位闪烁
blink<=(3=>bclk,2=>bclk,others=>'0');
whens3=>--------------低两位闪烁
blink<=(1=>bclk,0=>bclk,others=>'0');
endcase;
endprocess;
process(clr,cp,state)
variablep:
integerrange0to999;
begin
if(clr='0')then
hour<=0;min<=0;
sec<=0;ahour<=23;amin<=59;alarm<='0';
set_reg<='1';
elsif(cp'eventandcp='1')then-------------时分秒计数
if(p=999)then
p:
=0;
if(sec=59)then
sec<=0;
if(min=59)then
min<=0;
if(hour=23)then
hour<=0;
else
hour<=hour+1;
endif;
else
min<=min+1;
endif;
else
sec<=sec+1;
endif;
elsep:
=p+1;
endif;
casestateis
whens3=>-----------------计秒
if(set='1')then
if(set_reg='0')thenset_reg<='1';
if(sl='0')then
sec<=0;
endif;
endif;
elseset_reg<='0';
endif;
whens2=>------------------计分
if(set='1')then
if(set_reg='0')thenset_reg<='1';
if(sl='0')then
if(min=59)thenmin<=0;
elsemin<=min+1;endif;
elsif(sl='1')then
if(amin=59)thenamin<=0;
elseamin<=amin+1;
endif;
endif;
endif;
elseset_reg<='0';
endif;
whens1=>----------------计时
if(set='1')then
if(set_reg='0')thenset_reg<='1';
if(sl='0')then
if(hour=23)thenhour<=0;
elsehour<=hour+1;
endif;
elsif(sl='1')then
if(ahour=23)thenahour<=0;
elseahour<=ahour+1;
endif;
endif;
endif;
elseset_reg<='0';
endif;
whens0=>
endcase;
if(hour=ahourandamin=min+1andsec=59)thenalarm<='1';
elsealarm<='0';--已到预置闹钟时间
endif;
endif;
endprocess;
alarme:
alarmerportmap(alarm,cp,sel,sound);--闹钟模块映射
hourh<=(hour/10);hourl<=hourmod10;
minh<=(min/10);minl<=minmod10;
sech<=(sec/10);secl<=secmod10;
ahourh<=(ahour/10);ahourl<=ahourmod10;
aminh<=(amin/10);aminl<=aminmod10;
mx2:
yimaportmap(sech,secl,blink(1downto0),b1,b2);--译码模块映射
x3:
yimaportmap(minh,minl,blink(3downto2),b3,b4);
x4:
yimaportmap(hourh,hourl,blink(5downto4),b5,b6);
x33:
yimaportmap(aminh,aminl,blink(3downto2),alarm0,alarm1);
x44:
yimaportmap(ahourh,ahourl,blink(5downto4),alarm2,alarm3);
process(sl)
begin
caseslis
when'0'=>--正常计时译码
d1<=b1;d2<=b2;d3<=b3;d4<=b4;
d5<=b5;d6<=b6;
when'1'=>--闹钟模式译码
d1<="1111111";d2<="1111111";d3<=alarm0;d4<=alarm1;
d5<=alarm2;d6<=alarm3;
endcase;
if(min=59)then--整点报时
if(sec=52orsec=54orsec=56orsec=58)then
ledr0<='1';
elseledr0<='0';
endif;
elseledr0<='0';
endif;
if(min=0andsec=0)then
ledr1<='1';
elseledr1<='0';
endif;
endprocess;
end;
5结论以及结果说明
此次试验使用到了QuertusII6.0软件,及赛特龙2芯片。
编译运行正确,下载到实验板上调试结果基本上达到要求。
程序编译及仿真过程中运行状况良好,可以题设要求的计时,校时,闹钟,整点报时功能顺利实现,但是闹钟功能没有接上扬声器进行试验,故没有实现。
在本次试验中,遗憾的是没有加上数字钟的一些其他功能,如秒表,日期显示等
试验的代码编辑过程以及中间过程中,参考书的自主学习,使我对VHDL语言有了更深的认识和体会,编程中出现的许多问题也纠正了我对知识疏忽的地方,强化了知识结构,但到最后,依然没有能熟练地掌握这门知识,尚有欠缺的地方,程序的管理以及知识构架方面还存在疏漏,有很大的提升空间。
Vhdl对于工科学生是一门实用的工具,有必要熟练的掌握程序的编辑方法以及QuertusII6.0软件的使用方法。
参考文献
1普通图书
[2]蒋有绪,郭泉水,马娟,等.中国森林群落分类及其群落学特征[M].北京:
科学出版社,1998.
2期刊中析出的文献
[1]李炳穆.理想的图书馆员和信息专家的素质与形象[J].图书情报工,2000
(2):
5-8.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字