• CLK:時鐘信號。
  • CLR:異步復位信號。
  • PAUSE:暫停信號。
  • MSH、MSL:百分秒的高位和低位。
  • SH、SL:秒信號的高位和低位。
  • MH、ML:分鐘信號的高位和低位。

下面是數(shù)字跑表的Verilog 源代碼及說明。

module paobiao(CLK,CLR,PAUSE,MSH,MSL,SH,SL,MH,ML); //端口說明

input CLK,CLR;

input PAUSE;

output[3:0] MSH,MSL,SH,SL,MH,ML; //內部信號說明

reg[3:0] MSH,MSL,SH,SL,MH,ML;

reg cn1,cn2; //cn1為百分秒向秒的進位,cn2為秒向分的進位

//百分秒計數(shù)模塊,每計滿100,cn1 產生一個進位

always @(posedge CLK or posedge CLR) begin

if(CLR) begin //異步復位

{MSH,MSL}=8'h00;

cn1=0;

end

else if(!PAUSE) begin //PAUSE 為0時正常計數(shù),為1時暫停計數(shù)

if(MSL==9) begin

MSL=0; //低位計數(shù)至10時,低位歸零

if(MSH==9) begin

MSH=0; //低、高位計數(shù)至10時,高位歸零

cn1=1; //低、高位計數(shù)至10時,觸發(fā)進位位

end

else //低位計數(shù)至10,高位計數(shù)未至10時,高位計數(shù)

MSH=MSH+1;

end

else begin

MSL=MSL+1; //低位計數(shù)未至10時,低位計數(shù)

cn1=0; //低位計數(shù)未至10時,不觸發(fā)進位位

end

end

end

//秒計數(shù)模塊,每計滿60,cn2 產生一個進位

always @(posedge cn1 or posedge CLR) begin

if(CLR) begin //異步復位

{SH,SL}=8'h00;

cn2=0;

end

else if(SL==9) begin

SL=0; //低位計數(shù)至10時,低位歸零

if(SH==5) begin

SH=0; //低位計數(shù)至10,高位計數(shù)至6時,高位歸零

cn2=1; //低位計數(shù)至10,高位計數(shù)至6時,觸發(fā)進位位

end

else

SH=SH+1; //低位計數(shù)至10,高位計未數(shù)至6時,高位計數(shù)

end

else begin

SL=SL+1; //低位計數(shù)未至10時,低位計數(shù)

cn2=0; //低位計數(shù)未至10時,不觸發(fā)進位位

end

end

//分鐘計數(shù)模塊,每計滿60,系統(tǒng)自動清零

always @(posedge cn2 or posedge CLR) begin

if(CLR) begin //異步復位

{MH,ML}=8'h00;

end

else if(ML==9) begin

ML=0; //低位計數(shù)至10時,低位歸零

if(MH==5)

MH=0; //低位計數(shù)至10,高位計數(shù)至6時,高位歸零

else

MH=MH+1; //低位計數(shù)至10,高位計未數(shù)至6時,高位計數(shù)

end

else

ML=ML+1; //低位計數(shù)未至10時,低位計數(shù)

end

endmodule

通過上面的這3個模塊,即可實現(xiàn)數(shù)字跑表的功能。