数字钟实验报告_第1页
数字钟实验报告_第2页
数字钟实验报告_第3页
数字钟实验报告_第4页
数字钟实验报告_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本科实验报告 21.正常的时、分、秒计时功能,分别由六个数码管显示时分秒的计时。(K1=1正常工作,K1=0时可以快速校分)K2是系统的校时开关(K2=1正常工作,K2=0时可以快速校时)2.整点报时功能(使用蜂鸣器报时,当时钟计到59`53``时开始报时,在59`53``,59`55``,59`57``时刻报时频率为512Hz,1.开发板各基本模块功能介绍z·按键(R8-OK,E1-UP,T8-DOWN,M2-LEFT,T9-RIGHT)检测到对应设置的电平后,产生响应每个LED位选分别由一个I/O口线(D0-D7)控制2.数字钟总体模块设计时钟及分频器模块:将50M时钟精确分成时钟模块所需的秒,按键消抖模块所需的150hz,所以在连续按压时会连续变化。块负责向时产生进位。同时,分和时在检测到来自按键的低电平后会在原有基础上加1.34并在用户按下按键后进行切换译码。之后在扫频选通模块的作用下向数码管输送段显信号。3.数字钟各模块具体原理及设计en采用上述类似方法可以很方便地把时钟分成用户所需要钟频率并提供给所需要的模块。秒、分、时模块:如图所示秒接受来自分频器秒的分频,得到进位,当记到59时。分的使能端接受来自秒的高位和低位位。时钟部分完全采用同步时钟设置,时、分严格同步进位。5译码器bell_coding,译码器bell_second_L,bell_second_H接的是系统时间。采用时钟调制,扫描进行按键识别。原理如下:/start的delay量,以时钟为检测周期,每个时钟上升沿到来时delay加1,当delaykey_out_reg取高电平。这样delay量就成为时钟的一个分频,并同时检测用户按下的操作。Start越大,抗抖动能力越强,但是速度越慢。反之灵敏度提升,抗抖能力下降。6使用分频器,将对应的时钟分成需要的频率。控制闹钟的声音音调和警报的间隔。1.开发板关闭要先关闭开发板电源再拔掉数据线,下载数据时不可拔掉数据线或电源线。2.QurtusII的开发版型号要选择正确。3.使用的用电路图连接的方法构建顶层模块,比较直观方便。是时序逻辑电路部分的理解。set_location_assignmentPIN_R9-toCLK(50M时钟管脚)set_location_assignmentPIN_M1-toRSTn(复位)set_location_assignmentPIN_M8-tocod[0]set_location_assignmentPIN_N11-tocod[7]set_location_assignmentPIN_P11-tocod[6]set_location_assignmentPIN_M10-tocod[5]set_location_assignmentPIN_M9-tocod[4]set_location_assignmentPIN_N9-tocod[3]set_location_assignmentPIN_P9-tocod[2]set_location_assignmentPIN_L7-tocod[1](数码管段显控制)set_location_assignmentPIN_N6-towela[5]set_location_assignmentPIN_P6-towela[4]set_location_assignmentPIN_M6-towela[3]set_location_assignmentPIN_M7-towela[2]set_location_assignmentPIN_P8-towela[1]set_location_assignmentPIN_N8-towela[0](数码管位显控制)set_location_assignmentPIN_M2-tohour_key(校时按键)set_location_assignmentPIN_T9-tominiute_key(校分按键)set_location_assignmentPIN_D6-tobuzzer(蜂鸣器)set_location_assignmentPIN_R8-toselect_key(切换显示时钟时间和闹钟时间)set_location_assignmentPIN_E1-tohour_bell_key(调闹钟时)set_location_assignmentPIN_T8-tominiute_bell_key(调闹钟分)3.部分源程序modulekey(inputCLK,inputkey_in,outputkey_out);gkeyoutregparameterstart'd8000000;reg:0]delay;always@(posedgeCLK)ifdelay==start)delay0;outregkeyindelay<=delay+1;key_out_reg<=1'b1;assignkey_out=key_out_reg;endmodule秒分频器模块modulesecond_en(inputCLK,outputsecond_enregsecond_en_reg;T1S=27'd49999999;//50Mhz的晶振reg[26:0]Count1;always@(posedgeCLKornegedgeTnCount1<=27'd0;second_en_reg<=1'b0;elseif(Count1==T1S)Count1<=27'd0;second_en_reg<=1'b1;//使Count1<=Count1+1'b1;second_en_reg<=1'b0;assignsecond_en=second_en_reg;endmodule块modulesecond(inputCLK,inputCLK,//inputsecond_en,//output[3:0]inputsecond_en,//output[3:0]second_H//reg[3:0]second_L_reg;//reg[3:0]second_H_reg;//always@(posedgeCLKornegedgeRSTn)second_H_reg<=4'd0;second_L_reg<=4'd0;elseif(second_en==1)//if(second_L_reg==4'd9)//second_L_reg<=清零if(second_H_reg==4'd5)//second_H_reg<=4'd0;second_H_reg<=second_H_reg+1;//否则十位加上1second_L_reg<=second_L_reg+1;//个位上一次状态不是9,这时个位无须清零,十位自然保持原样assignsecond_L=second_L_reg;assignsecond_H=second_H_reg;endmodulemoduleminiute(inputCLK,//50MHz时钟inputminiute_en,//inputminiute_en2,output[3:0]miniute_L,//分的个位output[3:0]miniute_H//分的十位reg[3:0]miniute_L_reg;//reg[3:0]miniute_H_reg;//always@(posedgeCLKornegedgeRSTn)miniute_H_reg<=4'd0;miniute_L_reg<=4'd0;elseif(miniute_en==1||miniute_en2==0)//if(miniute_L_reg==4'd9)//if(miniute_H_reg==4'd5)//miniute_H_reg<=4'd0;//如果十位上次已经达到miniute_L_reg<=4'd0;miniute_H_reg<=miniute_H_reg+1;niuteLregdminiute_L_reg<=miniute_L_reg+1;//个位上一次状态不是9,这时个位无须清零,十位自然保持原样assignminiute_L=miniute_L_reg;assignminiute_H=miniute_H_reg;endmodulemodulehour(inputCLK,//50MHz时钟//inputhour_en,//inputhour_en2,output[3:0]hour_L,output[3:0]hour_H//时的个位//时的十位reg[3:0]hour_L_reg;//reg[3:0]hour_H_reg;//always@(posedgeCLKornegedgeRSTn)hour_H_reg<=4'd0;hour_L_reg<=4'd0;if(hour_H_reg==4'd2)if(hour_L_reg==4'd3)hour_L_reg<=4'd0;hour_H_reg<=4'd0;hour_L_reg<=hour_L_reg+1;if(hour_L_reg==4'd9)hour_L_reg<=4'd0;hour_H_reg<=hour_H_reg+1;hour_L_reg<=hour_L_reg+1;assignhour_L=hour_L_reg;assignhour_H=hour_H_reg;endmodulemoduleminiute_en(inputCLK,input[3:0]sl,input[3:0]sh,inputsecond_en,outputminiute_enregminiute_en_reg;always@(posedgeCLK)//上边沿触发clkif(sh==4'b0101)if(sl==4'b1001)if(second_en==1)miniute_en_reg<=1'b1;miniute_en_reg<=1'b0;miniute_en_reg<=1'b0;ddminiute_en_reg<=1'b0;assignminiute_en=miniute_en_reg;endmodulemodulehour_en([3:0]sl,input[3:0]sh,input[3:0]ml,input[3:0]mh,inputwireminiute_en,inputCLK,outputhour_enreghour_en_reg;always@(posedgeCLK)if(mh==4'b0101)if(ml==4'b1001)if(sh==4'b0101)if(sl==4'b1001)if(miniute_en==1)hour_en_reg<=1'b1;ginhour_en_reg<=1'b0;hour_en_reg<=1'b0;hour_en_reg<=1'b0;hour_en_reg<=1'b0;hour_en_reg<=1'b0;assignhour_en=hour_en_reg;endmodule译码选择模块modulebell_coding(inputCLK,input[3:0]bell_second_L,input[3:0]bell_second_H,output[7:0]bell_second_L_cod,output[7:0]bell_second_H_cod,input[3:0]bell_miniute_L,input[3:0]bell_miniute_H,output[7:0]bell_miniute_L_cod,output[7:0]bell_miniute_H_cod,input[3:0]bell_hour_L,input[3:0]bell_hour_H,output[7:0]bell_hour_L_cod,output[7:0]bell_hour_H_codreg[7:0]second_L_cod_reg;reg[7:0]second_H_cod_reg;reg[7:0]miniute_L_cod_reg;reg[7:0]miniute_H_cod_reg;reg[7:0]hour_L_cod_reg;reg[7:0]hour_H_cod_reg;always@(posedgeCLK)case(bell_second_L)4'b0000:second_L_cod_reg<=~8'b0011_1111;4'b0001:second_L_cod_reg<=~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111:~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcasecase(bell_second_H)4'b0000~8'b0011_1111;4'b0001~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcasecase(bell_miniute_L)4'b0000~8'b0011_1111;4'b0001:second_L_cod_reg<=:second_L_cod_reg<=:second_L_cod_reg<=:second_L_cod_reg<=:second_L_cod_reg<=second_L_cod_reg<=:second_L_cod_reg<=:second_L_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=~8'b0000_0110;4'b0010:miniute_L_cod_reg<=~8'b0101_1011;4'b0011:miniute_L_cod_reg<=~8'b0100_1111;4'b0100:miniute_L_cod_reg<=~8'b0110_0110;4'b0101:miniute_L_cod_reg<=~8'b0110_1101;4'b0110:miniute_L_cod_reg<=~8'b0111_1101;4'b0111:miniute_L_cod_reg<=~8'b0000_0111;4'b1000:miniute_L_cod_reg<=~8'b0111_1111;4'b1001:miniute_L_cod_reg<=~8'b0110_1111;endcasecase(bell_miniute_H)b0:miniute_H_cod_reg<=~8'b0011_1111;b1:miniute_H_cod_reg<=~8'b0000_0110;b0:miniute_H_cod_reg<=~8'b0101_1011;b1:miniute_H_cod_reg<=~8'b0100_1111;b0:miniute_H_cod_reg<=~8'b0110_0110;b1:miniute_H_cod_reg<=~8'b0110_1101;b0:miniute_H_cod_reg<=~8'b0111_1101;b1:miniute_H_cod_reg<=~8'b0000_0111;b0:miniute_H_cod_reg<=~8'b0111_1111;b1:miniute_H_cod_reg<=~8'b0110_1111;endcasecase(bell_hour_L)4'b0000:hour_L_cod_reg<=~8'b0011_1111;4'b0001:hour_L_cod_reg<=~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcase::::::::hour_L_cod_reg<=hour_L_cod_reg<=hour_L_cod_reg<=hour_L_cod_reg<=hour_L_cod_reg<=hour_L_cod_reg<=hour_L_cod_reg<=hour_L_cod_reg<=case(bell_hour_H)4'b0000~8'b0011_1111;4'b0001~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcase::::::::::hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=assignbell_second_L_cod=second_L_cod_reg;assignbell_second_H_cod=second_H_cod_reg;assignbell_miniute_L_cod=miniute_L_cod_reg;assignbell_miniute_H_cod=miniute_H_cod_reg;assignbell_hour_L_cod=hour_L_cod_reg;assignbell_hour_H_cod=hour_H_cod_reg;endmodulemodulecoding_second(input[3:0]second_L,input[3:0]second_H,inputCLK,inputRSTn,output[7:0]second_L_cod,output[7:0]second_H_cod,input[3:0]miniute_L,input[3:0]miniute_H,output[7:0]miniute_L_cod,output[7:0]miniute_H_cod,input[3:0]hour_L,input[3:0]hour_H,output[7:0]hour_L_cod,output[7:0]hour_H_codreg[7:0]second_L_cod_reg;reg[7:0]second_H_cod_reg;reg[7:0]miniute_L_cod_reg;reg[7:0]miniute_H_cod_reg;reg[7:0]hour_L_cod_reg;reg[7:0]hour_H_cod_reg;always@(posedgeCLK)case(second_L)4'b0000:second_L_cod_reg<=~8'b0011_1111;4'b0001:second_L_cod_reg<=~8'b0000_0110;4'b0010:second_L_cod_reg<=~8'b0101_1011;4'b0011:second_L_cod_reg<=~8'b0100_1111;4'b0100:second_L_cod_reg<=~8'b0110_0110;4'b0101:second_L_cod_reg<=~8'b0110_1101;4'b0110:second_L_cod_reg<=~8'b0111_1101;4'b0111:second_L_cod_reg<=~8'b0000_0111;4'b1000:second_L_cod_reg<=~8'b0111_1111;4'b1001:second_L_cod_reg<=~8'b0110_1111;endcasecase(second_H)4'b0000~8'b0011_1111;4'b0001~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcasecase(miniute_L)4'b0000~8'b1011_1111;4'b0001~8'b1000_0110;4'b0010~8'b1101_1011;4'b0011~8'b1100_1111;4'b0100~8'b1110_0110;4'b0101~8'b1110_1101;4'b0110~8'b1111_1101;4'b0111~8'b1000_0111;4'b1000~8'b1111_1111;4'b1001~8'b1110_1111;endcasecase(miniute_H):second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:second_H_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=:miniute_L_cod_reg<=4'b0000~8'b0011_1111;4'b0001~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcasecase(hour_L)4'b0000~8'b1011_1111;4'b0001~8'b1000_0110;4'b0010~8'b1101_1011;4'b0011~8'b1100_1111;4'b0100~8'b1110_0110;4'b0101~8'b1110_1101;4'b0110~8'b1111_1101;4'b0111~8'b1000_0111;4'b1000~8'b1111_1111;4'b1001~8'b1110_1111;endcasecase(hour_H)HcodregHcodregHcodregHcodregHcodreguteHcodregHcodregdregdregdreghourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=hourLcod_reg<=4'b0000~8'b0011_1111;4'b0001~8'b0000_0110;4'b0010~8'b0101_1011;4'b0011~8'b0100_1111;4'b0100~8'b0110_0110;4'b0101~8'b0110_1101;4'b0110~8'b0111_1101;4'b0111~8'b0000_0111;4'b1000~8'b0111_1111;4'b1001~8'b0110_1111;endcase::::::::::hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=hour_H_cod_reg<=assignsecond_L_cod=second_L_cod_reg;assignsecond_H_cod=second_H_cod_reg;assignminiute_L_cod=miniute_L_cod_reg;assignminiute_H_cod=miniute_H_cod_reg;assignhour_L_cod=hour_L_cod_reg;assignhour_H_cod=hour_H_cod_reg;endmodulemoduleclock_bell_select(yinputCLK,input[7:0]second_L_cod1,input[7:0]second_H_cod1,input[7:0]miniute_L_cod1,input[7:0]miniute_H_cod1,input[7:0]hour_L_cod1,input[7:0]hour_H_cod1,[7:0]second_H_cod2,[7:0]second_L_cod2,input[7:0]miniute_L_cod2,input[7:0]miniute_H_cod2,input[7:0]hour_L_cod2,input[7:0]hour_H_cod2,output[7:0]second_L,output[7:0]second_H,output[7:0]miniute_L,output[7:0]miniute_H,output[7:0]hour_L,output[7:0]hour_Hreg[7:0]second_L_reg;reg[7:0]second_H_reg;reg[7:0]miniute_L_reg;reg[7:0]miniute_H_reg;reg[7:0]hour_L_reg;reg[7:0]hour_H_reg;regsbalways@(posedgeCLK)if(select_key==0)s<=~s;always@(posedgeCLK)if(s==1'b1)second_L_regsecond_H_regminiute_L_regminiute_H_reghour_L_reghour_H_regsecond_L_regsecond_H_regminiute_L_regminiute_H_reg<=second_L_cod1;<=second_H_cod1;<=miniute_L_cod1;<=miniute_H_cod1;<=hour_L_cod1;<=hour_H_cod1;<=second_L_cod2;<=second_H_cod2;<=miniute_L_cod2;<=miniute_H_cod2;<=hour_L<=hour_L_cod2;<=hour_H_cod2;hour_H_regassignsecond_L=second_L_reg;assignsecond_H=second_H_reg;assignminiute_L=miniute_L_reg;assignminiute_H=miniute_H_reg;assignhour_L=hour_L_reg;assignhour_H=hour_H_reg;endmodule扫频选通模块modulesweep(inputCLK,

温馨提示

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

评论

0/150

提交评论