資源描述:
《二進制轉(zhuǎn)十進制Verilog實現(xiàn)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、/*八位二進制輸入三位十進制BCD碼輸出*/modulebcd(input[7:0]bin_in,//輸入二進制//3位bcd碼輸出outputreg[3:0]dec_out0=4'h0,outputreg[3:0]dec_out1=4'h0,outputreg[3:0]dec_out2=4'h0,inputclk);wire[2:0]c_in;wire[2:0]c_out;reg[3:0]dec_sreg0=4'h0;reg[3:0]dec_sreg1=4'h0;reg[3:0]dec_sreg2=4'h0;wire[
2、3:0]next_sreg0,next_sreg1,next_sreg2;reg[3:0]bit_cnt=4'h0;reg[7:0]bin_sreg;wireload=~
3、bit_cnt;//讀入二進制數(shù)據(jù),準備轉(zhuǎn)換wireconvert_ready=(bit_cnt==4'h9);//轉(zhuǎn)換成功wireconvert_end=(bit_cnt==4'ha);//完畢,重新開始/*************************************************************************
4、***************************************/always@(posedgeclk)beginif(convert_end)bit_cnt<=4'h0;elsebit_cnt<=bit_cnt+4'h1;end/**************************************************************************************************************/always@(posedgeclk)beginif(lo
5、ad)bin_sreg<=bin_in;elsebin_sreg<={bin_sreg[6:0],1'b0};endassignc_in[0]=bin_sreg[7];assignc_in[1]=(dec_sreg0>=5);assignc_in[2]=(dec_sreg1>=5);assignc_out[0]=c_in[1];assignc_out[1]=c_in[2];assignc_out[2]=(dec_sreg2>=5);//確定移位輸出assignnext_sreg0=c_out[0]?({dec_sreg0
6、[2:0],c_in[0]}+4'h6):({dec_sreg0[2:0],c_in[0]});assignnext_sreg1=c_out[1]?({dec_sreg1[2:0],c_in[1]}+4'h6):({dec_sreg1[2:0],c_in[1]});assignnext_sreg2=c_out[2]?({dec_sreg2[2:0],c_in[2]}+4'h6):({dec_sreg2[2:0],c_in[2]});//裝入數(shù)據(jù)/**************************************
7、**************************************************************************************************/always@(posedgeclk)beginif(load)begindec_sreg0<=4'h0;dec_sreg1<=4'h0;dec_sreg2<=4'h0;endelsebegindec_sreg0<=next_sreg0;dec_sreg1<=next_sreg1;dec_sreg2<=next_sreg2;e
8、ndend//輸出/**************************************************************************************************************************************/always@(posedgeclk)beginif(convert_ready)begindec_out0<=dec_sreg0;dec_out1<=dec_sreg1;dec_out2<=dec_sreg2;endendendmod
9、ule/*16為二進制輸入,5位十進制BCD碼輸出*/modulebcd1(input[15:0]bin_in,//輸入二進制//3位bcd碼輸出outputreg[3:0]dec_out0=4'h0,outputreg[3:0]dec_out1=4'h0,outputreg[3:0]dec_out2=4'h0,ou