资源描述:
《verilog数字时钟源程序 ,分频模块,计时模块,子函数调用,及测试模块》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、分频moduleclkgen(clock,reset,clkdiv,clk500);inputclock,reset;outputclkdiv;outputclk500;reg[31:0]counter1;regclkdiv;regclk500;reg[31:0]counter0;/********??1HZ?????*********/always@(posedgeclock)if(reset)beginclkdiv<=0;counter0<=0;endelseif(counter0==24'd4)beginc
2、ounter0<=0;clkdiv=~clkdiv;endelsebegincounter0<=counter0+1;clkdiv<=clkdiv;end/********??500HZ?????*********/always@(posedgeclock)if(reset)beginclk500<=0;counter1<=0;endelseif(counter1==24'd2)begincounter1<=0;clk500=~clk500;endelsebegincounter1<=counter1+1;clk
3、500<=clk500;endendmodule计数modulejishu24(clkdiv,clear,second,s_carry,minute,m_carry,hour,sL,sH,mL,mH,hL,hH);inputclkdiv,clear;output[5:0]second,minute;output[4:0]hour;outputs_carry,m_carry;outputsL,sH,mL,mH,hL,hH;regs_carry,m_carry;reg[5:0]second,minute;reg[4:
4、0]hour;regsL,sH,mL,mH,hL,hH;always@(posedgeclkdivorclear)if(clear)second<=0;elseif(second!=6'b111011)beginsecond<=second+1;s_carry<=0;endelsebeginsecond<=0;s_carry<=1;endalways@(posedges_carryorclear)if(clear)minute<=0;elseif(minute!=6'b111011)beginminute<=mi
5、nute+1;m_carry<=0;endelsebeginminute<=0;m_carry<=1;endalways@(posedgem_carryorclear)if(clear)hour<=0;elseif(hour!=5'b10111)beginhour<=hour+1;endelsebeginhour<=0;endalways@(posedgesecond)beginsL<=second%10;sH<=second/10;endalways@(posedgeminute)beginmL<=minute
6、%10;mH<=minute/10;endalways@(posedgehour)beginhL<=hour%10;hH<=hour/10;endendmodule显示moduledecode(clk500,reset,hH,hL,mH,mL,sH,sL,HIGH,LOW,COM);inputclk500;inputreset;inputhH,hL;//?????????inputmH,mL;//?????????inputsH,sL;//????????output[6:0]HIGH,LOW;//???????
7、???????output[7:0]COM;//??????????reg[7:0]show_temp_H,show_temp_L;//???????????????????reg[7:0]COM;reg[7:0]Uweixuan;//????COM????????????????reg[2:0]sm;//????reg[6:0]HIGH;//?????????????reg[6:0]LOW;//?????????????always@(posedgeclk500)beginif(sm==3'b111)sm<=3
8、'b000;elsesm<=sm+3'b001;Uweixuan<=Uweixuan<<1;//????????????????????????if(Uweixuan==8'b0000_0000)Uweixuan<=8'b0000_0001;//?Uweixuan???????COM=~Uweixuan;//?????????????????????Uweixuan???