资源描述:
《verilog hdl电子时钟实验报告.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、电子时钟:电子时钟的功能:可以显示时间,还可以修改时间。结构图NO.7:此电路适合于设计时钟、定时器、秒表等。因为可利用键8和键5分别控制时钟的清零和设置时间的使能;利用键7、5和1进行时、分、秒的设置。实验代码:模块一:时间显示//clk:秒功能的时钟信号,为1Hz的脉冲信号//time_set_en:时间设置使能信号//time_clear(键8):时钟显示的清零//hourh_set,hourl_set,minh_set,minl_set,sech_set,secl_set:设置后的小时、分、秒//hourh,hourl:小时
2、的高低位//minh,minl:分的高低位//sech,secl:秒的高低位//cout:进位输出,即计满24小时,向天产生的进位输出信号moduletime_count(clk,time_set_en,time_clear,hourh_set,hourl_set,minh_set,minl_set,sech_set,secl_set,hourh,hourl,minh,minl,sech,secl);inputclk;inputtime_set_en,time_clear;input[3:0]hourh_set,hourl_set,
3、minh_set,minl_set,sech_set,secl_set;output[3:0]hourh,hourl,minh,minl,sech,secl;reg[3:0]hourh,hourl,minh,minl,sech,secl;regc1,c2;//c1和c2分别为秒向分,分向时的进位always@(posedgetime_set_enorposedgeclkorposedgetime_clear)beginif(time_set_en)//time_set_en:时间设置使能信号beginsech<=sech_set;s
4、ecl<=secl_set;minh<=minh_set;minl<=minl_set;hourh<=hourh_set;hourl<=hourl_set;endelseif(time_clear)//time_clear(键8):时钟显示的清零beginhourh<=0;hourl<=0;minh<=0;minl<=0;sech<=0;secl<=0;endelsebeginif(secl==9)//sech,secl:秒的高低位设置beginsecl<=0;if(sech==5)beginsech<=0;c1<=1;if(min
5、l==9)//minh,minl:分的高低位设置beginminl<=0;if(minh==5)beginminh<=0;c2<=1;if((hourh==2)&&(hourl==3))beginhourh<=0;hourl<=0;endif(hourl==9)//hourh,hourl:小时的高低位设置beginhourl<=0;if(hourh==2)hourh<=0;elsehourh<=hourh+1;endelsebeginhourl<=hourl+1;endendelsebeginminh<=minh+1;endende
6、lsebeginminl<=minl+1;c2<=0;endendelsebeginsech<=sech+1;endendelsebeginsecl<=secl+1;c1<=0;endendendendmodule模块二:时间设置//key7:设置数码管8和7//key4:设置数码管5和4//key1:设置数码管2和1//time_set_en(键5):设置时间的使能端//hourh_set,hourl_set,minh_set,minl_set,sech_set,secl_set:设置后的小时、分、秒//hourh,hourl,m
7、inh,minl,sech,secl:当前的小时,分,秒moduletime_set(key7,key4,key1,time_set_en,hourh,hourl,minh,minl,sech,secl,hourh_set,hourl_set,minh_set,minl_set,sech_set,secl_set);inputkey7,key4,key1;inputtime_set_en;input[3:0]hourh,hourl,minh,minl,sech,secl;output[3:0]hourh_set,hourl_set,
8、minh_set,minl_set,sech_set,secl_set;reg[3:0]hourh_set,hourl_set,minh_set,minl_set,sech_set,secl_set;always@(posedgeti