1、 input _50mhzin; input adjminkey, adjhrkey; input h12; input ncr; output 6:0led0, led1, led2, led3; wire 7:0 led_a, led_b; wire _1hz, _1khz, _5hz;0 hour, minute, second, set_hr, set_min; output hour12; wire h12; output 7:0led_sec; assign hour12 = h12; divided_frequency u0(_1hz,ncr,_50mhzin); top_clo
2、ck u1(hour, minute, second, _1hz, ncr, adjminkey, adjhrkey, _50mhzin); display u2(_50mhzin, _5hz, ncr, led_a, led_b, led_sec, hour, minute, second, h12); SEG7_LUT u3(led_a7:4, led3); SEG7_LUT u4(led_a3:0, led2); SEG7_LUT u5(led_b7:4, led1); SEG7_LUT u6(led_b3:0, led0); endmodule2.分频模块:module divided
3、_frequency(_1hzout,ncr,_50mhzin); input _50mhzin, ncr; output _1hzout; 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)
4、;/再调用三个10计数器,将1khz分为1hz assign en1=(q3:0 = 4h9); assign en2=(q7:4 = 4h9) & (q3: assign _1hzout = q11; assign _500hzout = q0;endmodule3.时钟运行模块module top_clock(hour, minute, second, _1hz, ncr, adjminkey, adjhrkey, _50mhzin); input _1hz, _50mhzin, ncr, adjminkey, adjhrkey;0 hour, minute, second;/时、分、秒每
5、个用八位二进制表示两位BCD码 /高电平,是使能一直打开 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=8h5
6、9); assign hrcp = adjhrkey? (minute,second=16h5959);/进位或校时使能控制4.显示模块:module display(_50mhz,_5hz,cr,led_a,led_b,led_sec,hour,minute,second,h12); input 7:0hour,minute,second;/时分秒 input _50mhz,cr,_5hz;0led_a,led_b,led_sec;/数码管显示缓存/12,24小时制切换 reg 7: reg 2:0mod;/模式变量 always(posedge _50mhz) begin led_b=mi
7、nute; led_sec=second;/模式0,显示时分秒 if(h12) begin led_a=hour; led_b=minute; led_sec=second; end else begin case(hour) 8h13,h14,h15,h16,h17,h18,h19,h22,h23,h24:led_a=hour-8h12;h20:led_a=8h08;h21:h09; default:led_a=hour; endcase end/12/24小时切换,24到12,相应BCD码减 end5.数码管操作模块module SEG7_LUT (iDIG,oSEG);input 3:0
8、 iDIG;output 6:0 oSEG;reg 6:always (iDIG)begin case(iDIG) 4h1: oSEG = 7b1111001; / -t-h2:b0100100; / | |h3:b0110000; / lt rth4:b0011001;h5:b0010010; / -m-h6:b0000010;h7:b1111000; / lb rbh8:b0000000;h9:b0010000; / -b-ha:b0001000;hb:b0000011;hc:b1000110;hd:b0100001;he:b0000110;hf:b0001110;h0:b1000000;
9、 endcaseend六、功能仿真1.六进制2.十进制3.六十进制(分了几张图截图)4.24进制5. 异步清零仿真6.正常计时仿真 秒计时 分计时 小时计时 23:59:59秒返07 手动校小时和分钟仿真ADJHrKey 与 AdjMinKey均为高电平有效,七、思考题1.什么是分层次的电路设计方法?叙述分层次设计电路的基本过程.答: 在电路设计中,可以将两个或者多个模块组合起来描述电路逻辑功能,通常称为分层次的电路设计.自顶而下和自底而上是两种常用的设计方法.在自顶而下的设计中,先定义顶层模块,然后再定义顶层模块中用到的子模块.而在自底而上的设计中,底层的各个子模块首先被确定下来,然后将这些
10、子模块组合起来构成顶层模块.2.在用MAX+PLUS II 软件设计数字钟电路时,简述对60进制计数器进行仿真分析的大致过程.若仿真时栅格的大小(GRID SIZE)为0.5ms,设置CP信号时倍率(Multiplied By)为软件默认值1,那么仿真文件的时间至少需要多长才能完整反映计数过程? 至少要0.5ms * 60 = 30ms八、 试验中遇到的问题与解决办法 这次实验主要是Verilog代码的编写和仿真,在波形的仿真过程中,有许多操作并不清楚,尤其是部分功能的波形仿真输出和如何手动调整时钟的波形仿真,虽然最后有同学帮忙,但是最后还是操作得很不熟练。九、 实验小结 本次实验让我们巩固了
11、Verilog代码编写与波形仿真,掌握了更多了相关波形的仿真操作,但是在部分功能的操作上,以及网格的重新建立等方面显得仍然不够熟练,还需要更多的锻炼。十、附录(附源代码)/clock.vmodule clock(led0,led1,led2,led3,led_sec,_50mhzin,adjminkey,adjhrkey,ncr,h12,hour12); wire 3:0hour_num1, hour_num0, min_num1, min_num0, second_num1, second_num0; Endmodule/topclock.v output 3:0 hour_num1, ho
12、ur_num0, min_num1, min_num0, second_num1, second_num0; /divfreq50M_5hz ut0(_5hz, ncr, _50mhzin); assign hour_num13:0 = hour7:4; assign hour_num0 = hour3:0; assign min_num1 = minute7: assign min_num1 = minute3: assign second_num1 = second7: assign second_num0 = second3:/display.v/SEG7_LUT.v / -t-/div
13、ided_frequency.vmodule divfreq50M_1Khz(_1khzout,ncr,_50mhzin); output _1khzout; reg _1khzout; reg15:0 cnt; always (posedge _50mhzin ) if(ncr) _1khzout=1b0; else if(cnt=16d24999) begin _1khzout=_1khzout; cnt=16 end/50000分频 else =cnt+1b1;module divfreq50M_5hz(_5hzout,ncr,_50mhzin); input _50mhzin,ncr;
14、 output _5hzout; reg _5hzout; reg24: if(ncr) _5hzout if(cnt=25d4999999) _5hzout=_5hzout;=25 end/一千万分频/counter10.vmodule counter10(q,ncr,en,cp);/模十 input cp,ncr,en; reg 3: always(posedge cp or negedge ncr) if(ncr) q=4b0000; else if (en) q=q; else if(q=4b1001) q else q=q+1module counter6(q,ncr,en,cp);/模6b0101) qmodule counter60(cnt,ncr,en,cp);/模60 wire enp; counter10 uc0(cnt3:0,ncr,en,cp); counter6 uc1(cnt7:4,ncr,enp,cp
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1