




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
基于VHDL语言数字钟设计学 院:信息工程学院专 业: 姓 名: 学 号: 2010年6月15日一、设计要求1、具有以二十四小时制计时、显示、整点报时、时间设置和闹钟的功能。2、设计精度要求为1秒。二、设计目的1.掌握各类计数器以及计数器的级联方式;2.掌握数码管动态显示的原理与方法;3.掌握用FPGA技术的层次化设计方法;4.理解数字逻辑硬件和软件的设计思想;三、设计环境:Quartus II CPLD-5型试验箱四、系统功能描述1、系统输入:系统状态及较时、定时转换的控制信号为enset、k、set;时钟信号clk采用50MHz;校时复位信号为reset,输入信号均由按键信号产生。2、系统输出:LED显示输出;蜂鸣器声音信号输出。3、多功能数字电子钟系统功能的具体描述如下:(一)计时:正常工作状态下,每日按24h计时制计时并显示,蜂鸣器无声,逢整点报时。(二)校时:在计时显示状态下,按下“enset”键,接着按下“k”键,进入“小时”待校准状态,若此时按下“set”键,小时开始校准;之后按上“k”键则进入“分”待校准状态;继续按下“k”键则进入“秒”待复零状态;再次按上“k”键数码管显示闹钟时间,并进入闹钟“小时”待校准状态;再次按下“k”键则进入闹钟“分”待校准状态;若再按上“k”键恢复到正常计时显示状态。若校时过程中按下“reset”键,则系统恢复到正常计数状态。(1)“小时”校准状态:在“小时”校准状态下,显示“小时”的数码管以2Hz闪烁,并以2Hz的频率递增计数。(2)“分”校准状态:在“分”校准状态下,显示“分”的数码管以2Hz闪烁,并以2Hz的频率递增计数。(3)“秒”校准状态:在“秒复零”状态下,显示“秒”的数码管以2Hz闪烁,并以1Hz的频率递增计数。(4)闹钟“小时”校准状态:在闹钟“小时”校准状态下,显示“小时”的数码管以2Hz闪烁,并以2Hz的频率递增计数。(5)闹钟“分”校准状态:在闹钟“分”校准状态下,显示“分”的数码管以2Hz闪烁,并以2Hz的频率递增计数。(三)整点报时:蜂鸣器在“59”分钟的第“51”、“53”、“55”、“57”秒发频率为500Hz的低音,在“59”分钟的第“59”秒发频率为1000Hz的高音,结束时为整点。(四)显示:要求采用扫描显示方式驱动6个LED数码管显示小时、分、秒。(五)闹钟:闹钟定时时间到,蜂鸣器发出频率为1000Hz的高音,持续时间为60秒。五、各个模块分析说明1、分频器模块(1)模块说明:输入一个频率为50MHz的CLK,利用计数器分出1KHz的q1KHz,500Hz的q500Hz,2Hz的q2Hz和1Hz的q1Hz。(2)源程序:LIBRARY ieee; USE ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;ENTITY fdiv IS PORT (CLK: IN STD_LOGIC ; -输入时钟信号 q1KHz: BUFFER STD_LOGIC; q500Hz: BUFFER STD_LOGIC; q2Hz: BUFFER STD_LOGIC; q1Hz: OUT STD_LOGIC);END fdiv ; ARCHITECTURE bhv OF fdiv IS BEGIN P1KHZ:PROCESS(CLK)VARIABLE cout:INTEGER:=0;BEGIN IF CLKEVENT AND CLK=1 THEN cout:=cout+1; -每来个时钟上升沿时cout开始计数IF cout=25000 THEN q1KHz=0; -当cout=25000时,q1KHz输出“0” ELSIF cout50000 THEN q1KHz=1; -当25000cout=50000时,q1KHz ELSE cout:=0; -输出“1”,完成1KHz频率输出END IF; END IF; END PROCESS; P500HZ:PROCESS(q1KHz) -q1KHz作为输入信号,分出q500HzVARIABLE cout:INTEGER:=0;BEGINIF q1KHzEVENT AND q1KHz=1 THENcout:=cout+1;IF cout=1 THEN q500Hz=0; -二分频 ELSIF cout=2 THEN cout:=0;q500Hz=1;END IF; END IF; END PROCESS;P2HZ:PROCESS(q500Hz)VARIABLE cout:INTEGER:=0;BEGINIF q500HzEVENT AND q500Hz=1 THENcout:=cout+1;IF cout=125 THEN q2Hz=0; ELSIF cout250 THEN q2Hz=1; ELSE cout:=0;END IF; END IF; END PROCESS;P1HZ:PROCESS(q2Hz)VARIABLE cout:INTEGER:=0;BEGINIF q2HzEVENT AND q2Hz=1 THENcout:=cout+1;IF cout=1 THEN q1Hz=0; ELSIF cout=2 THEN cout:=0;q1Hz=1;END IF; END IF; END PROCESS;END bhv;(3)模块图:2、控制器模块(1)模块说明:输入端口enset,k,set键来控制6个状态,这六个状态分别是显示计时时间状态,调计时的时、分、秒状态,调闹铃的时、分的状态,reset键是复位键,用来回到显示计时时间的状态。(2)源程序:library ieee;use ieee.std_logic_1164.all;entity contl is port(clk,enset,k,set,reset:in std_logic; cth,ctm,cts,cbh,cbm,flashh,flashm,flashs,sel_show:out std_logic);end contl;architecture rtl of contl is type stats is (s0,s1,s2,s3,s4,s5); -定义6个状态 signal current_state,next_state:stats:=s0;begin process(clk,reset) begin if reset=1 then current_state=s0; elsif clkevent and clk=1 then if reset=0 then current_statecth=0;ctm=0;cts=0;cbh=0;cbm=0; flashh=0;flashm=0;flashs=0;sel_show=0; if (enset=1 and k=1)then -若enset和k为“1”, next_state=s1; -由s0态转到s1态 else next_statectm=0;cts=0;cbh=0;cbm=0; flashh=1;flashm=0;flashs=0;sel_show=0; if set=1 then cth=1; -若set为“1”,cth输出“1” else cth=0; -进入调小时状态。 end if; if (enset=1 and k=0)then -若enest为“1”,k为“0”, next_state=s2; -由s1态转到s2态 else next_statecth=0;cts=0;cbh=0;cbm=0; flashh=0;flashm=1;flashs=0;sel_show=0; if set=1 then ctm=1; else ctm=0; end if; if(enset=1 and k=1)then next_state=s3; else next_statecth=0;ctm=0;cbh=0;cbm=0; flashh=0;flashm=0;flashs=1;sel_show=0; if set=1 then cts=1; else cts=0; end if; if (enset=1 and k=0)then next_state=s4; else next_statecth=0;ctm=0;cts=0;cbm=0; flashh=1;flashm=0;flashs=0;sel_show=1; if set=1 then cbh=1; else cbh=0; end if; if(enset=1 and k=1)then next_state=s5; else next_statecth=0;ctm=0;cts=0;cbh=0; flashh=0;flashm=1;flashs=0;sel_show=1; if set=1 then cbm=1; else cbm=0; end if; if(enset=1 and k=0)then next_state=s0; else next_state=s5; end if; end case; end process;end rtl;(3)仿真波形图:(4)模块图:3、二选一模块(1)源程序:ENTITY mux21a ISPORT(a,b,s:IN BIT; y:OUT BIT);END ENTITY mux21a;ARCHITECTURE one OF mux21a ISBEGIN PROCESS(a,b,s)BEGINIF s=0 THEN y=a;ELSE -若s=0,y输出a,反之输出b。y=b;END IF;END PROCESS;END ARCHITECTURE one;(2)仿真波形图:(3)模块图:4、计时模块a、秒计时(1)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith;entity cnts60 is port(sld0:buffer std_logic_vector(3 downto 0); -小时个位 sld1:buffer std_logic_vector(7 downto 4); -小时十位 co: out std_logic; rest:in std_logic; clk :in std_logic);end cnts60;architecture rtl of cnts60 is begin process(clk,rest) begin if rest=1 then sld1=0000; sld0=0000; elsif (clkevent and clk=1) then if (sld1=0101and sld0=1001)then -当sld1=5,sld0=9时 sld1=0000; sld0=0000;co=1;-全清零,co输出“1” elsif sld0=1001 then sld0=0000; sld1=sld1+1;co=0; - sld1自加“1” else sld0=sld0+1;co=0; end if; end if; end process;end rtl;(2)仿真波形图:(3)模块图:b、分计时(1)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith;entity cnt60 is port(sld0:buffer std_logic_vector(3 downto 0); sld1:buffer std_logic_vector(7 downto 4); co: out std_logic; clk :in std_logic);end cnt60;architecture rtl of cnt60 is begin process(clk) begin if (clkevent and clk=1) then if (sld1=0101and sld0=1001)then sld1=0000; sld0=0000;co=1; elsif sld0=1001 then sld0=0000; sld1=sld1+1;co=0; else sld0=sld0+1;co=0; end if; end if; end process;end rtl;(2)仿真波形图:(3)模块图:c、小时计时(1)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith;entity cnt24 is port(sld0:buffer std_logic_vector(3 downto 0); sld1:buffer std_logic_vector(7 downto 4); clk :in std_logic);end cnt24;architecture rtl of cnt24 is signal s:std_logic_vector(7 downto 0);begin process(clk) begin s=sld1&sld0; if (clkevent and clk=1) then if s=00100011then sld1=0000; sld0=0000; elsif sld0=1001 then sld0=0000; sld1=sld1+1; else sld0=sld0+1; end if; end if; end process;end rtl;(2)仿真波形图:(3)模块图:d、闹钟分计时(1)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith;entity cntm60b is port(sld0:buffer std_logic_vector(3 downto 0); sld1:buffer std_logic_vector(7 downto 4); en:in std_logic; clk :in std_logic);end cntm60b;architecture rtl of cntm60b is begin process(clk) begin if (clkevent and clk=1) then if en=1 then if (sld1=0101and sld0=1001)then sld1=0000; sld0=0000; elsif sld0=1001 then sld0=0000; sld1=sld1+1; else sld0=sld0+1; end if; end if; end if; end process;end rtl;(2)仿真波形图:(3)模块图:e、闹钟小时计时(1)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith;entity cnth24b is port(sld0:buffer std_logic_vector(3 downto 0); sld1:buffer std_logic_vector(7 downto 4); en:in std_logic; clk :in std_logic);end cnth24b;architecture rtl of cnth24b is signal s:std_logic_vector(7 downto 0);begin process(clk,en,sld1,sld0) begin s=sld1&sld0; if (clkevent and clk=1) then if en=1 then if s=00100011then sld1=0000; sld0=0000; elsif sld0=1001 then sld0=0000; sld1=sld1+1; else sld0=sld0+1; end if; end if; end if; end process;end rtl;(2)仿真波形图:(3)模块图:5、闹钟比较模块(1)模块说明:比较正常计数时间与闹钟定时时间是否相等,若相等,compout输出“1”,反之输出“0”。(2)源程序:library ieee;use ieee.std_logic_1164.all;entity comp is port(th1,tm1:in std_logic_vector(7 downto 4); th0,tm0:in std_logic_vector(3 downto 0); bh1,bm1:in std_logic_vector(7 downto 4); bh0,bm0:in std_logic_vector(3 downto 0); compout:out std_logic);end comp;architecture rtl of comp isbegin process(th1,tm1,bh1,bm1,th0,tm0,bh0,bm0) begin if( th1=bh1 and tm1=bm1 and th0=bh0 and tm0=bm0 ) then compout=1;-当正常计数时间与闹钟定时时间相等时compout输出1 else compout=0; end if; end process;end rtl;(3)仿真波形图:(4)模块图:6、报时模块(1)模块说明:该模块既实现了整点报时的功能,又实现了闹铃的功能,蜂鸣器通过所选频率的不同,而发出不同的声音。(2)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity bel is port(tm1,ts1:in std_logic_vector(7 downto 4); tm0,ts0:in std_logic_vector(3 downto 0); compout,q1KHz,q500Hz,openbel:in std_logic; bell:out std_logic);end bel;architecture rtl of bel is signal t:std_logic_vector(7 downto 0);begin process(compout,q500Hz,q1KHz,openbel,tm1,tm0,ts1,ts0) begin if (openbel =0 ) then bell=0; end if; if (openbel =1 ) then if (compout=1) then - compout=1,闹铃响 bellbellbellbellbellbellbell=0; end case; else bell=0; end if; end if; end process;end rtl;(3)仿真波形图:(4)模块图:7、控制显示模块(1)模块说明:该模块实现了数码管既可以显示正常时间,又可以显示闹钟时间的功能;调时,定时闪烁功能也在此模块中真正实现。(2)源程序:library ieee;use ieee.std_logic_1164.all;entity show_con is port(th1,tm1,ts1:in std_logic_vector(7 downto 4); th0,tm0,ts0:in std_logic_vector(3 downto 0); bh1,bm1:in std_logic_vector(7 downto 4); bh0,bm0:in std_logic_vector(3 downto 0); sec1,min1,h1: out std_logic_vector(7 downto 4); sec0,min0,h0: out std_logic_vector(3 downto 0); q2Hz,flashs,flashh,flashm,sel_show:in std_logic);end show_con;architecture rtl of show_con isbegin process(th1,tm1,ts1,th0,tm0,ts0,bh1,bm1,bh0,bm0,q2Hz,flashs,flashh,flashm,sel_show) begin if sel_show=0then if ( flashh=1and q2Hz=1)then h1=1111;h0=1111; -显示小时数码管以2Hz闪烁 min1=tm1;min0=tm0; sec1=ts1;sec0=ts0; elsif (flashm=1and q2Hz=1)then h1=th1;h0=th0; min1=1111;min0=1111; sec1=ts1;sec0=ts0; elsif (flashs=1and q2Hz=1)then h1=th1;h0=th0; min1=tm1;min0=tm0; sec1=1111;sec0=1111; else h1=th1;h0=th0; min1=tm1;min0=tm0; sec1=ts1;sec0=ts0; end if; elsif sel_show=1then-若sel_show为“1”,数码管显示闹钟时间 if(flashh=1 and q2Hz=1)then h1=1111;h0=1111; min1=bm1;min0=bm0; sec1=0000;sec0=0000; elsif ( flashm=1 and q2Hz=1)then h1=bh1;h0=bh0; min1=1111;min0=1111; sec1=0000;sec0=0000; else h1=bh1;h0=bh0; min1=bm1;min0=bm0; sec1=0000;sec0=0000; end if ; end if; end process;end rtl;(3)模块图:8、动态扫描显示模块(1)模块说明:由6组输入信号和7个数据输出信号和8个位选通信号来实现数码管的驱动和信号扫描,进而实现了时钟时,分,秒的动态显示。(2)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity SCAN_LED isport(clk1:in std_logic; h0:i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年人事考试局公务员面试技巧及模拟题集
- 2025年乡村法律服务员职业能力及素质测试题库
- 2025年中国传统宫灯制作技艺传承模拟题
- 玉石字画买卖合同范文6篇
- 2025年版医疗器械经营监督管理办法试卷测试题及答案
- 议中心各项管理办法
- 2025年上海市选调生招聘考试行政职业能力测验模拟题
- 2025年公共卫生领域考试必-备知识点详解与模拟题集
- 2025年药品信息管理试题及答案
- 手卫生、职业暴露、标准预防院感试题(附答案)
- 拆除沥青路面基层施工方案
- 公司网络安全培训课件
- 电机成品检验报告
- (115)-第一章毛泽东思想及其历史地位
- 病原微生物实验室生物安全管理体系的建立与运行
- 部编人教版四年级上册道德与法治全册教案
- 建筑给排水-外文文献翻译
- 肿瘤和肾脏病
- 新教科版小学1-6年级科学需做实验目录汇总表
- 纪念中国人民抗日战争暨世界反法西斯战争胜利70周年阅兵式观后感
- 高中物理答题卡模板
评论
0/150
提交评论