




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
基于DE0的数字钟设计方案1.方案内容 1.完成基本功能:以数字形式显示时、分、秒的时间;小时计数器为同步24进制 手动校时、校分 2.扩展功能:任意时刻闹钟; 小时显示(12/24)切换电路 3.扩展仿电台报时,秒表高级功能 4.添加年月日,显示日期,手动较准日期 5.整体调试和测试2设计原理图 闹钟原理图秒表原理图 显示切换模块 年月日处理流程图开关分配3.代码分析主程序(顶层模块)module clock(led0,led1,led2,led3,dot,led_sec,_50mhzin,alarm,sethrkey,setminkey, ctrbell,adjminkey,adjhrkey,adjy,adjm,adjd,button,ncr,start_stpw,pause,h12,hstop,hour12);/*定义各输入输出变量 led0,led1,led2,led3:四位七段数码管显示的数字; dot:隔开小时与分钟的点,没清零是总是亮 led_sec:八个发光二极管显示的两位BCD码数字 button:模式切换按钮 alarm:控制蜂鸣器发声的信号 setthrkey,setminkey,adjminkey,adjhrkey,dady,adjm,adjd:设定闹钟,校时,校日期 ctrlbell:闹钟响铃使能 ncr:清零,初始化 start_stpw:秒表启停 pause:秒表暂停 h12:12/24小时制切换 hstop:秒表状态显示,分配第九个led灯 hour12:12小时制显示,分配第十个led灯,灯亮时,表示小时为十二小时制*/ input _50mhzin; input sethrkey,setminkey,ctrbell; input adjminkey,adjhrkey; input adjy,adjm,adjd; input button,h12; input ncr,start_stpw,pause; output 6:0led0,led1,led2,led3;wire 7:0 led_a,led_b; wire _1hz,_500hz,_1khz,_5hz; wire 7:0 hour,minute,second,set_hr,set_min,stpw_sec,stpw_dsec,year,month,day; /分别为小时,分钟,秒,闹钟的小时、分钟,秒表的秒、分秒 ,年,月,日。 wire alarm_clock,alarm_r; /alarm_clock:闹钟信号,alarm:仿电台报时信号 output alarm; output dot,hstop,hour12; wire dot,h12,hstop; output 7:0led_sec; assign dot=ncr; assign hstop=start_stpw; assign hour12=h12; /以上三个状态控制显示变量 divided_frequency u0(_1hz,_500hz,ncr,_50mhzin);/调用分频模块,将50Mhz分为1hz,500hz top_clock u1(hour,minute,second,_1hz,ncr,adjminkey,adjhrkey,_50mhzin); /顶层时钟模块,控制时钟显示与校时bell u2(alarm_clock,set_hr,set_min,hour,minute,second,sethrkey,setminkey,_50mhzin, _500hz,_1hz,ctrbell);/闹钟模块:设定闹钟,控制闹铃 divfreq50M_1Khz u3(_1khz,ncr,_50mhzin);/分频模块,50Mhz分成1Khz,用在驱动蜂鸣器 ring u4(alarm_r,minute,second,_1khz,_500hz);/仿电台报时模块 assign alarm=alarm_clock|alarm_r;/蜂鸣器驱动信号 SEG7_LUT u8(led_a7:4,led3); SEG7_LUT u9(led_a3:0,led2); SEG7_LUT u10(led_b7:4,led1); SEG7_LUT u11(led_b3:0,led0);/以上四行是led数码管显示模块 display u12(_500hz,_5hz,ncr,led_a,led_b,led_sec,hour,minute,second,set_hr,set_min,stpw_sec,stpw_dsec,year,month,day ,button,h12);/显示切换模块,模式控制 stopwatch u13(stpw_sec,stpw_dsec,start_stpw,pause,_50mhzin);/秒表模块 date u14(year,month,day,ncr,hour,minute,second,_5hz,adjy,adjm,adjd);/年月日模块 divfreq50M_5hz u15(_5hz,ncr,_50mhzin);/50Mhz到5hz分频模块,用于校时脉冲endmodule顶层时钟模块module top_clock(hour,minute,second,_1hz,ncr,adjminkey,adjhrkey,_50mhzin); input _1hz,_50mhzin,ncr,adjminkey,adjhrkey; output 7:0 hour,minute,second; wire 7:0 hour,minute,second;/时、分、秒每个用八位二进制表示两位BCD码 supply1 vdd; /高电平,是使能一直打开 wire mincp,hrcp,_5hz;/_5hz用于快速校时 divfreq50M_5hz ut0(_5hz,ncr,_50mhzin); counter60 ut1(second,ncr,vdd,_1hz); counter60 ut2(minute,ncr,vdd,mincp);/秒和分使用60进制 counter24 ut3(hour7:4,hour3:0,ncr,vdd,hrcp);/时钟为24进制(默认) assign mincp=adjminkey?_5hz:(second=8h59); assign hrcp=adjhrkey?_5hz:(minute,second=16h5959);/进位或校时使能控制endmodule闹钟模块module bell(alarm_clock,set_hr,set_min,hour,minute,second, sethrkey,setminkey,_50mhzin,_500hz,_1hz,ctrlbell); output alarm_clock;/蜂鸣器驱动信号 output 7:0 set_hr,set_min; wire 7:0 set_hr,set_min;/闹钟的时和分 wire alarm_clock; input _50mhzin,_500hz,_1hz; input sethrkey,setminkey;/设定闹钟时分的按钮 input ctrlbell; input 7:0 hour,minute,second; supply1 vdd;/高电平是闹钟使能一直有效 wire hrh_equ,hrl_equ,minh_equ,minl_equ;/中间变量,判断闹钟时刻是否已到 wire time_equ,_5hz;/闹钟时刻到来的标志 divfreq50M_5hz su0(_5hz,1,_50mhzin); counter60 su1(set_min,vdd,setminkey,_5hz);/设定闹钟分 counter24 su2(set_hr7:4,set_hr3:0,vdd,sethrkey,_5hz);/设定闹钟时 compare su3(hrh_equ,set_hr7:4,hour7:4); compare su4(hrl_equ,set_hr3:0,hour3:0); compare su5(minh_equ,set_min7:4,minute7:4); compare su6(minl_equ,set_min3:0,minute3:0);/四位数值都等是,表示闹钟时刻到 assign time_equ=(hrh_equ&hrl_equ&minh_equ&minl_equ); assign alarm_clock=ctrlbell?/闹钟时刻到,控制蜂鸣器发声(间隔1秒,频率500hz),否则继续 (time_equ&(second0=1b1)&_500hz)|(second0=1b0)&_50mhzin):1b0; Endmodule秒表模块module stopwatch(stopwatch_sec,stopwatch_dsec,ncr,pause,_50mhz); output 7:0 stopwatch_sec,stopwatch_dsec;/秒表的秒和分秒,BCD码表示 wire 7:0 stopwacth_sec,stopwatch_dsec; input ncr,pause,_50mhz; wire _100hz,eny; assign eny=(stopwatch_dsec=8h99);/分秒想秒进位使能 divfreq50M_100hz stpw1(_100hz,ncr,_50mhz); counter100 stwp2(stopwatch_dsec,ncr,pause,_100hz); counter100 stwp3(stopwatch_sec,ncr,2b1,eny);/两个100进制计数器,最多可计100秒 endmodule日历模块/*由于只有四位数码管,将数码管分配给月日显示,而年采用两位表示,范围为(20002099年),取后两位,用BCD码表示,再八位LED二极管上显示*/module date(year,month,day,ncr,hour,minute,second,_5hz,adjy,adjm,adjd); input ncr,_5hz;/5hz用于快速校日历 input 7:0 hour,minute,second; input adjy,adjm,adjd;/校准按钮 output 7:0 year,month,day; wire 7:0 year,month,day; wire ena,cpy,en,enm;/进位使能控制 assign en=(adjd=1b1)?_5hz:(hour=8h00)&(minute=8h00)&(second=8h00); /当校日有效时,5hz的的脉冲使日快速调整.其它有零点零分零秒向日进位 assign ena=(month=8h01)|(month=8h03)|(month=8h05)|(month=8h07)| (month=8h08)|(month=8h10)|(month=8h12)&(day=8h31)| (month=8h04)|(month=8h06)|(month=8h09)|(month=8h11)&(day=8h30)| (year%4=0)&(month=8h02)&(day=8h29)| (year%4!=0)&(month=8h02)&(day=8h28);/判断最后一日 assign enm=(adjm=1b1)?_5hz:(month=8h01)|(month=8h03)|(month=8h05)|(month=8h07)| (month=8h08)|(month=8h10)|(month=8h12)&(day=8h31)| (month=8h04)|(month=8h06)|(month=8h09)|(month=8h11)&(day=8h30)| (year%4=0)&(month=8h02)&(day=8h29)| (year%4!=0)&(month=8h02)&(day=8h28) &(hour=8h00)&(minute=8h00)&(second=8h00); /月时钟脉冲 assign cpy=(adjy=1b1)?_5hz:(month0);/年时钟脉冲 day uc0(day,ncr,1,ena,en);/日计数模块 month uc1(month7:4,month3:0,ncr,1,enm);/月计数模块 year uc2(year7:4,year3:0,ncr,1,cpy);/年计数模块 endmodule module day(day,ncr,en,eny,cp); input cp,ncr,en,eny; output 7:0day; reg 7:0day; always(negedge cp or negedge ncr) begin if (ncr) day=8h00; else if(en) day2d3)|(day3:04d9)|(day7:4=2d3)&(day3:0=2d1) begin day=8h01; end/如果超越31,则清到1日 else if (eny)/eny/判断哪一天为一个月的最后一天 begin day=8h01; end/若为最后一天,则清到第一天 else if(day3:0=4d9) begin day7:4=day7:4+1b1; day3:0=1b0; end else begin day3:0=day3:0+1b1; day7:4=day7:4; end endendmodulemodule month(cntc,cntd,ncr,en,cp); input cp,ncr,en; output 3:0 cntc,cntd; reg 3:0 cntc,cntd; always(posedge cp or negedge ncr) begin if (ncr) cntc,cntd=8h00; else if(en) cntc,cntd1b1)|(cntd4h9)|(cntc=1b1)&(cntd=2d3) begin cntc,cntd=8h01; end/超越12月,则清到一月 else if (cntc,cntd=8h12) begin cntc,cntd=8h01; end/到12月,再清到一月,循环 else if(cntd=9) begin cntc=1b1;cntd=1b0; end else begin cntd=cntd+1b1; cntc=cntc; end/BCD码下的进位控制 endendmodule module year(cntc,cntd,ncr,en,cp); input cp,ncr,en; output 3:0 cntc,cntd; reg 3:0 cntc,cntd; always(negedge cp or negedge ncr) begin if (ncr) cntc,cntd=8h00; else if(en) cntc,cntd=cntc,cntd; else if( (cntc=9)&(cntd=9) begin cntc,cntd=8h00; end/最高计到2099年,到最后一年则清到2000年 else if(cntd=4d9) begin cntd=1b0; cntc=cntc+1b1; end else begin cntc=cntc; cntd=3b011)mod=3b0;else mod=mod+3b001;/四个显示模式循环,按一下botton,切换一次endendalways(posedge _50mhz)begincase(mod)3b000:begin led_b=minute;led_sec=second;/模式0,显示时分秒 if(h12)begin led_a=hour;led_b=minute;led_sec=second;end else case(hour)8h13,8h14,8h15,8h16,8h17,8h18,8h19,8h22,8h23,8h24:led_a=hour-8h12;8h20:led_a=8h08;8h21:led_a=8h09;default:led_a=hour;endcase end/12/24小时切换,24到12,相应BCD码减3b001:begin led_a=set_hr;led_b=set_min;led_sec=8b0;end/显示闹钟设定的时 /分,led灯全灭3b010:begin led_a=stpw_sec;led_b=stpw_dsec;led_sec=_5hz;end /显示秒表秒,分秒,第一位led灯以5hz的频率闪烁3b011:begin led_a=month;led_b=day;led_sec=year;end/显示年月日endcaseendendmodule数码管译码显示模块module SEG7_LUT(iDIG,oSEG);input3:0iDIG;output6:0oSEG;reg6:0oSEG;always (iDIG)begincase(iDIG)4h1: oSEG = 7b;/ -t-4h2: oSEG = 7b; / | |4h3: oSEG = 7b; / lt rt4h4: oSEG = 7b; / | |4h5: oSEG = 7b; / -m-4h6: oSEG = 7b; / | |4h7: oSEG = 7b; / lb rb4h8: oSEG = 7b; / | |4h9: oSEG = 7b; / -b-4ha: oSEG = 7b;4hb: oSEG = 7b;4hc: oSEG = 7b;4hd: oSEG = 7b;4he: oSEG = 7b;4hf: oSEG = 7b;4h0: oSEG = 7b;endcaseendendmodule仿电台报时模块module ring(alarm_r,minute,second,_1khz,_500hz);input _1khz,_500hz;wire _1khz,_500hz;input 7:0minute,second;output alarm_r;reg alarm_r;always (1)if(minute=8h59)case(second)8h50,8h52,8h54,8h56:alarm_r=_500hz;8h58:alarm_r=_1khz;default:alarm_r=1b0;/快到整点时,蜂鸣器先以500hz低音响四声,间隔为1s再以1kz响一声endcaseelse alarm_r=1b0;/当alarm=0时,蜂鸣器不响endmodule比较模块module compare(equ,a,b); input 3:0 a,b; output equ; assign equ=(a=b);endmodule分频模块50M_1Khzmodule divfreq50M_1Khz(_1khzout,ncr,_50mhzin); input _50mhzin,ncr; output _1khzout; reg _1khzout; reg15:0 cnt; always (posedge _50mhzin ) begin if(ncr) _1khzout=1b0; else begin if(cnt=16d24999) begin _1khzout=_1khzout;cnt=16b0;end/50000分频 else cnt=cnt+1b1; end endendmodule50M_100hzmodule divfreq50M_100hz(_100hzout,ncr,_50mhzin); input _50mhzin,ncr; output _100hzout; reg _100hzout; reg18:0 cnt; always (posedge _50mhzin ) begin if(ncr) _100hzout=1b0; else begin if(cnt=19d) begin _100hzout=_100hzout;cnt=19b0;end/50万分频 else cnt=cnt+1b1; end endendmodule50M_5hzmodule divfreq50M_5hz(_5hzout,ncr,_50mhzin); input _50mhzin,ncr; output _5hzout; reg _5hzout; reg24:0 cnt; always (posedge _50mhzin ) begin if(ncr) _5hzout=1b0; else begin if(cnt=25d) begin _5hzout=_5hzout;cnt=25b0;end/一千万分频 else cnt=cnt+1b1; end endendmodule50M_1hzmodule divided_frequency(_1hzout,_500hzout,ncr,_50mhzin); input _50mhzin,ncr; output _1hzout,_500hzout; supply1 vdd; wire11:0 q; wire _1khzin; wire en1,en2; divfreq50M_1Khz du00(_1khzin,ncr,_50mhzin);/先调用1khz分频 counter10 du0(q3:0,ncr,vdd,_1khzin); counter10 du1(q7:4,ncr,en1,_1khzin); counter10 du2(q11:8,ncr,en2,_1khzin);/再调用三个10计数器,将1khz分为1hz assign en1=(q3:0=4h9); assign en2=(q7:4=4h9)&(q3:0=4h9); assign _1hzout=q11; assign _500hzout=q0; endmodule计数器模块module counter10(q,ncr,en,cp);/模十 input cp,ncr,en; output 3:0 q; reg 3:0 q; always(posedge cp or negedge ncr) begin if(ncr) q=4b0000; else if (en) q=q; else if(q=4b1001) q=4b0000; else q=q+1b1; endendmodulemodule counter6(q,ncr,en,cp);/模6 input cp,ncr,en; output 3:0 q; reg 3:0 q; always(posedge cp or negedge ncr) begin if(ncr) q=4b0000; else if (en) q=q; else if(q=4b0101) q=4b0000; else q=q+1b1; endendmodulemodule counter60(cnt,ncr,en,cp);/模60 input cp,ncr,en; output 7:0 cnt; wire 7:0 cnt; wire enp; counter10 uc0(cnt3:0,ncr,en,cp); counter6 uc1(cnt7:4,ncr,enp,cp);/模60计数器有一个模10,一个模6计数器组成 assign enp=(cnt3:0=4h9);endmodulemodule counter100(cnt,ncr,en,cp);/模100 input cp,ncr,en; output 7:0 cnt; wire 7:0 cnt; wire enp; counter10 uc0(cnt3:0,ncr,en,cp); counter10 uc1(cnt7:4,ncr,enp,cp);/模100计数器由两个模10计数器组成 assign enp=(cnt3:0=4h9);endmodulemodule counter24(cnth,cntl,ncr,en,cp);/模24 input cp,ncr,en; output 3:0 cnth,cntl; reg 3:0 cnth,cntl; always(posedge cp or negedge ncr) begin if (ncr) cnth,cntl=8h00; else if(en) cnth,cntl2)|(cntl9)|(cnth=2)&(cntl=3) begin cnth,cntl=8h00; end/超越24,则清零 else if(cnth=2)&(cntl3) begin cnth=cnth; cntl=cntl+1b1; end else if(cntl=9) begin cnth=cnth+1b1; cntl=4b0000; end else begin cnth=cnth; cntl=cntl+1b1; end end endmodule4.设计过程在数字钟设计过程中,依照方案内容一步一步做下来.实验都再Quartus9.1平台上做,使用的硬件是DE0开发板(外扩一个蜂鸣器).(1) 打开Quartus9.1软件,创建工程,具体过程不赘述.(2) 创建verilog文件,编写代码.(3) 由于程序规模比较大,故采用分步分块编写,调试的步骤.首先实现基本的时钟模块,实现校时,校分.时钟模块需要分频,计数子模块,这些分别
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人卫中医诊断学
- 口腔冷疗对急性髓系白血病患者化疗相关味觉改变的影响
- 小班健康:流鼻血了怎么办
- 二零二五年度饭店安全总监劳动合同(含应急预案)
- 安监局办事窗口管理办法
- 应对媒体来访管理办法
- 奉贤区民宿管理暂行办法
- 巡视专员日常管理办法
- 帮困救急基金管理办法
- 工程检验管理暂行办法
- 上市专项工作组管理办法
- 四川省成都市武侯区2024-2025学年八年级下学期期末物理试卷(含答案)
- 《思想道德与法治》学习通课后章节答案期末考试题库2025年
- 清廉讲堂活动方案
- 家居落地活动方案
- 陕西省专业技术人员继续教育2025公需课《党的二十届三中全会精神解读与高质量发展》20学时题库及答案
- 2024华师一附中自招考试数学试题
- 提高手术室垃圾分类正确率PDCA
- GB 16806-1997消防联动控制设备通用技术条件
- 320T履带吊安装方案 9
- 清洁间歇导尿重点技术评分重点标准
评论
0/150
提交评论