VHDL数字时钟实验报告

上传人:小** 文档编号:158187229 上传时间:2022-10-03 格式:DOC 页数:19 大小:110.50KB
收藏 版权申诉 举报 下载
VHDL数字时钟实验报告_第1页
第1页 / 共19页
VHDL数字时钟实验报告_第2页
第2页 / 共19页
VHDL数字时钟实验报告_第3页
第3页 / 共19页
资源描述:

《VHDL数字时钟实验报告》由会员分享,可在线阅读,更多相关《VHDL数字时钟实验报告(19页珍藏版)》请在装配图网上搜索。

1、VHDL数字时钟设计一、实验目的:进一步练习VHDL语言设计工程的建立与仿真的步骤和方法、熟悉VHDL语言基本设计实体的编写方法。同时,在已有知识的基础上,简单综合编写程序,仿制简单器械。二、实验环境:PC个人计算机、WindowsXP操作系统、QuartusII集成开发环境软件。三、设计要求:运用VHDL语言编写一个数字钟,具体要求:1. 具有时、分、秒计数的十进制数字显示功能,以24小时循环计时。2. 具有手动调节小时,分钟的功能。3. 具有闹钟的功能,能够在设定的闹钟时间发出闹铃声。四、实验步骤:1. 定义输入输出信号量port(clk:instd_logic;-时钟speak:outs

2、td_logic;-铃dout:outstd_logic_vector(7downto0);-晶体管显示setclk:instd_logic_vector(2downto0);-操作按钮d1,d2,d3,d4,d5,d6:outstd_logic);-六个晶体管2. 定义结构体中的信号量-时分秒的个位和十位signalsel:std_logic_vector(2downto0);signalhou1:std_logic_vector(3downto0);signalhou2:std_logic_vector(3downto0);signalmin1:std_logic_vector(3down

3、to0);signalmin2:std_logic_vector(3downto0);signalseth1:std_logic_vector(3downto0);signalseth2:std_logic_vector(3downto0);signalsetm1:std_logic_vector(3downto0);signalsetm2:std_logic_vector(3downto0);signalsec1:std_logic_vector(3downto0);signalsec2:std_logic_vector(3downto0);signalh1:std_logic_vector

4、(3downto0);signalh2:std_logic_vector(3downto0);signalm1:std_logic_vector(3downto0);signalm2:std_logic_vector(3downto0);signals1:std_logic_vector(3downto0);signals2:std_logic_vector(3downto0);signalsph1,sph2,spm1,spm2,sps1,sps2:std_logic_vector(3downto0);signalcount_sec:std_logic_vector(9downto0);sig

5、nalsec_co:std_logic;signalco1,co2,co3,co4:std_logic;-进位signalswitch:std_logic_vector(1downto0);-表示状态3.分频模块用来定义秒count_sec用来计时钟个数,当count_sec=1111111111时,及得到1Hz信号。代码如下:process(clk)is-defineasecondbeginif(clkeventandclk=1)thenif(count_sec=1111111111)thencount_sec=0000000000;sec_co=1;elsecount_sec=count_

6、sec+1;sec_co=0;endif;endif;endprocess;4时钟正常走时模块该模块使用6个进程实现,分别为秒个位计时、秒十位计时、分个位计时、分十位计时、时个位计时、时十位计时。process(sec_co)is秒个位beginifswitch=00then-正常状态ifsec_co=1thenifsec2=1001thensec2=0000;co1=1;elsesec2=sec2+1;co1=0;endif;endif;elsifswitch=01then-调时状态sec2=0000;endif;endprocess;process(co1)isbegin秒十位ifswit

7、ch=00thenifco1eventandco1=1thenif(sec1=0101)thensec1=0000;co2=1;elsesec1=sec1+1;co2=0;endif;endif;elsifswitch=01thensec1=0000;endif;endprocess;process(co1,co2)is分钟个位beginifswitch=00thenifco2eventandco2=1thenifmin2=1001thenmin2=0000;co3=1;elsemin2=min2+1;co3=0;endif;endif;elsifswitch=01thenmin2=setm2

8、;endif;endprocess;process(co3)is分钟十位beginifswitch=00thenifco3=1thenifmin1=0101thenmin1=0000;co4=1;elsemin1=min1+1;co4=0;endif;endif;elsifswitch=01thenmin1=setm1;endif;endprocess;process(co4)小时beginifswitch=00thenifco4=1thenif(hou1=0010)then-小时十位为2时,个位满3进一if(hou2=0011)thenhou2=0000;hou1=0000;elsehou2

9、=hou2+1;endif;else-小时十位为0或1,个位满9进一if(hou2=1001)thenhou2=0000;hou1=hou1+1;elsehou2=hou2+1;endif;endif;endif;elsifswitch=01thenhou1=seth1;hou2=seth2;endif;endprocess;5调时模块该进程用来控制时钟状态,switch为“00”时正常显示时间,为“01”时是进行调时,为“10”时是设置闹钟时间。代码如下:process(setclk(0)isbeginif(setclk(0)eventandsetclk(0)=1)thenif(switch

10、=10)thenswitch=00;elseswitch=switch+1;endif;endif;endprocess;process(setclk(2),switch,setclk(1)isbegin-setclk(l)为1调分if(switch=01andsetclk(1)=1)thenif(setclk(2)eventandsetclk(2)=1)thenif(setm2=1001)thensetm2=0000;if(setm1=0101)thensetm1=0000;elsesetm1=setm1+1;endif;elsesetm2=setm2+1;endif;endif;endif

11、;endprocess;process(setclk(2),switch,setclk(1)isbegin-setclk(l)为0调时if(switch=01andsetclk(1)=0)thenif(setclk(2)eventandsetclk(2)=l)thenif(sethl=00l0)thenif(seth2=00ll)thensethl=0000;seth2=0000;elseseth2=seth2+l;endif;elseif(seth2=l00l)thensethl=sethl+l;seth2=0000;elseseth2=seth2+l;endif;endif;endif;e

12、ndif;endprocess;6闹钟模块该模块由3个小模块组成,分别为设置闹钟时间、判断闹钟时间是否到达以及闹铃声音模块。(1)设置闹钟时间模块该进程用于设置闹钟时间。信号量switch为10时,表示设置闹钟时间;if(switch=10)then-调闹钟时,显示闹钟设置时间ifsel=000thend1doutdoutdoutdout=XXXXXXXX;endcase;elsifsel=001thend2doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=010thend3doutdoutdoutdo

13、utdoutdoutdout=XXXXXXXX;endcase;elsifsel=011thend4doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=100thend5doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=101thend6doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;endif;(2)闹铃声音模块通过分频产生蜂鸣,即发出闹铃声音。process(swit

14、ch)is闹铃begin-设置闹铃时秒归零ifswitch=10thensps1=0000;sps2=0000;endif;endprocess;process(switch,setclk(2),setclk(1)isbeginif(switch=10andsetclk(1)=1)thenif(setclk(2)eventandsetclk(2)=1)thenif(spm2=1001)thenspm2=0000;if(spm1=0101)thenspm1=0000;elsespm1=spm1+1;endif;elsespm2=spm2+1;endif;endif;endif;endproces

15、s;process(switch,setclk(2),setclk(1)isbeginif(switch=10andsetclk(1)=0)thenif(setclk(2)eventandsetclk(2)=1)thenif(sph1=0010)thenif(sph2=0011)thensph1=0000;sph2=0000;elsesph2=sph2+1;endif;elseif(sph2=1001)thensph2=0000;sph1=sph1+1;elsesph2=sph2+1;endif;endif;endif;endif;endprocess;process(clk,sph1,sph

16、2,spm1,spm2,hou1,hou2,min1,min2)isbeginif(sph1=hou1andsph2=hou2andspm1=min1andspm2=min2)thenspeak=clk;elsespeak=0;endif;endprocess;7数码管显示模块(1)选择时间显示process(key1,key2,change)beginif(key1=0)and(key2=0)thensec_0=sec_00;sec_1=sec_11;min_0=min_00;min_1=min_11;hour_1=hour_11;hour_0=hour_00;elsif(key1=1)an

17、d(key2=0)thensec_0=sec_000;sec_1=sec_111;min_0=min_000;min_1=min_111;hour_0=hour_000;hour_1=hour_111;elsif(key1=0)and(key2=1)thensec_0=sec_0000;sec_1=sec_1111;min_0=min_0000;min_1=min_1111;hour_0=hour_0000;hour_1=hour_1111;endif;endprocess;2)数码管时间显示ifsel=000thend1doutdoutdoutdout=XXXXXXXX;endcase;el

18、sifsel=001thend2doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=010thend3doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=011thend4doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=100thend5doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=101th

19、end6doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;endif;五、实验结果分析总结:该程序基本实现了数字时钟的基本功能,能够正常走时,并且可以校正时间,还可以进行闹钟设置。通过这次VHDL课程设计,我学到了很多,对于原本掌握的不好的数字逻辑相关知识,在课程设计具体实践中有了很深刻的认识,在对于QuartusII的操作上也有很大的提高,增加了操作的熟练程度,现在我已经有信心做任何的设计课题。在编程中还遇到其他一些小问题,有好多都是由于不够细心,不够严谨造成的,通过编程,我会一步步养成一个好的编程习惯,尽量避免一些不

20、必要的错误,一步步提高自己。在今后的学习中,我还需要不断学习,不断锻炼自己。六、附:源代码libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityclockisport(clk:instd_logic;-时钟speak:outstd_logic;-铃dout:outstd_logic_vector(7downto0);-晶体管显示setclk:instd_logic_vector(2downto0);-操作按钮d1,d2,d3,d4,d5,d6:outstd_logic);-六个晶体管endenti

21、tyclock;architectureoneofclockissignalsel:std_logic_vector(2downto0);signalhou1:std_logic_vector(3downto0);-时分秒的个位和十位signalhou2:std_logic_vector(3downto0);signalmin1:std_logic_vector(3downto0);signalmin2:std_logic_vector(3downto0);signalseth1:std_logic_vector(3downto0);signalseth2:std_logic_vector(3

22、downto0);signalsetm1:std_logic_vector(3downto0);signalsetm2:std_logic_vector(3downto0);signalsec1:std_logic_vector(3downto0);signalsec2:std_logic_vector(3downto0);signalh1:std_logic_vector(3downto0);signalh2:std_logic_vector(3downto0);signalm1:std_logic_vector(3downto0);signalm2:std_logic_vector(3do

23、wnto0);signals1:std_logic_vector(3downto0);signals2:std_logic_vector(3downto0);signalsph1,sph2,spm1,spm2,sps1,sps2:std_logic_vector(3downto0);signalcount_sec:std_logic_vector(9downto0);signalsec_co:std_logic;signalco1,co2,co3,co4:std_logic;-进位signalswitch:std_logic_vector(1downto0);-表示状态beginprocess

24、(clk)is-defineasecondbeginif(clkeventandclk=1)thenif(count_sec=1111111111)thencount_sec=0000000000;sec_co=1;elsecount_sec=count_sec+1;sec_co=0;endif;endif;endprocess;process(sec_co)is秒个位beginifswitch=00then-正常状态ifsec_co=1thenifsec2=1001thensec2=0000;co1=1;elsesec2=sec2+1;co1=0;endif;endif;elsifswitc

25、h=01then-调时状态sec2=0000;endif;endprocess;process(co1)is秒十位beginifswitch=00thenifco1eventandco1=1thenif(sec1=0101)thensec1=0000;co2=1;elsesec1=sec1+1;co2=0;endif;endif;elsifswitch=01thensec1=0000;endif;endprocess;process(co1,co2)is分钟个位beginifswitch=00thenifco2eventandco2=1thenifmin2=1001thenmin2=0000;

26、co3=1;elsemin2=min2+1;co3=0;endif;endif;elsifswitch=01thenmin2=setm2;endif;分钟十位endprocess;process(co3)isbeginifswitch=00thenifco3=1thenifmin1=0101thenmin1=0000;co4=1;elsemin1=min1+1;co4=0;endif;endif;elsifswitch=01thenmin1=setm1;endif;endprocess;process(co4)小时beginifswitch=00thenifco4=1thenif(hou1=0

27、010)then-小时十位为2时,个位满3进if(hou2=0011)thenhou2=0000;hou1=0000;elsehou2=hou2+1;endif;else-小时十位为0或1,个位满9进一if(hou2=1001)thenhou2=0000;hou1=hou1+1;elsehou2=hou2+1;endif;endif;endif;elsifswitch=01thenhou1=seth1;hou2=seth2;endif;endprocess;process(setclk(0)is-控制时钟状态,00正常,01调时,10闹钟beginif(setclk(0)eventandset

28、clk(0)=1)thenif(switch=10)thenswitch=00;elseswitch=switch+1;endif;endif;endprocess;process(setclk(2),switch,setclk(1)isbegin-setclk(l)为1调分if(switch=01andsetclk(1)=1)thenif(setclk(2)eventandsetclk(2)=1)thenif(setm2=1001)thensetm2=0000;if(setm1=0101)thensetm1=0000;elsesetm1=setm1+1;endif;elsesetm2=set

29、m2+1;endif;endif;endif;endprocess;process(setclk(2),switch,setclk(1)isbeginif(switch=01andsetclk(1)=0)thenif(setclk(2)eventandsetclk(2)=1)thenif(seth1=0010)thenif(seth2=0011)thenseth1=0000;seth2=0000;elseseth2=seth2+1;endif;elseif(seth2=1001)thenseth1=seth1+1;seth2=0000;elseseth2=seth2+1;endif;endif

30、;endif;endif;endprocess;process(switch)is闹铃begin-设置闹铃时秒归零ifswitch=10thensps1=0000;sps2=0000;endif;endprocess;process(switch,setclk(2),setclk(1)isbeginif(switch=10andsetclk(1)=1)thenif(setclk(2)eventandsetclk(2)=1)thenif(spm2=1001)thenspm2=0000;if(spm1=0101)thenspm1=0000;elsespm1=spm1+1;endif;elsespm

31、2=spm2+1;endif;endif;endif;endprocess;process(switch,setclk(2),setclk(1)isbeginif(switch=10andsetclk(1)=0)thenif(setclk(2)eventandsetclk(2)=1)thenif(sph1=0010)thenif(sph2=0011)thensph1=0000;sph2=0000;elsesph2=sph2+1;endif;elseif(sph2=1001)thensph2=0000;sph1=sph1+1;elsesph2=sph2+1;endif;endif;endif;e

32、ndif;endprocess;process(clk,sph1,sph2,spm1,spm2,hou1,hou2,min1,min2)isbeginif(sph1=hou1andsph2=hou2andspm1=min1andspm2=min2)thenspeak=clk;elsespeak=0;endif;endprocess;process(clk)模6计数begin-控制晶体管显示ifclkeventandclk=1thenifsel=101thensel=000;elsesel=sel+1;endif;endif;endprocess;process(sel)isbeginh1=ho

33、u1;h2=hou2;m1=min1;m2=min2;s1=sec1;s2=sec2;d1=1;d2=1;d3=1;d4=1;d5=1;d6=1;if(switch=10)then-调闹钟时,显示闹钟设置时间ifsel=000thend1doutdoutdoutdout=XXXXXXXX;endcase;elsifsel=001thend2doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=010thend3doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;els

34、ifsel=011thend4doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=100thend5doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=101thend6doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elseendif;ifsel=000thend1doutdoutdoutdout=XXXXXXXX;endcase;elsifsel=001thend2do

35、utdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=010thend3doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=011thend4doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=100thend5doutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;elsifsel=101thend6doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=XXXXXXXX;endcase;endif;endif;endprocess;endarchitecture;

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!