资源描述:
《大量的verilog源代码.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、VerilogHDL程序举例一,基本组合逻辑功能:双向管脚(clockedbidirectionalpin)VerilogHDL:BidirectionalPinThisexampleimplementsaclockedbidirectionalpininVerilogHDL.ThevalueofOEdetermineswhetherbidirisaninput,feedingininp,oratri-state,drivingoutthevalueb.bidir.vmodulebidirec(oe,clk,inp,outp,bidir);
2、//PortDeclarationinputoe;inputclk;input[7:0]inp;output[7:0]outp;inout[7:0]bidir;reg[7:0]a;reg[7:0]b;assignbidir=oe?a:8'bZ;assignoutp=b;//AlwaysConstructalways@(posedgeclk)beginb<=bidir;a<=inp;endendmodule多路选择器(MUX)////-------------------------------------------------------
3、----------------------------//DESCRIPTION:Multiplexer//Codestyle:usedcasestatement//Widthofoutputterminal:8//Numberofterminals:4//Outputenableactive:HIGH//Outputvalueofallbitswhenenablenotactive:0//---------------------------------------------------------------------------
4、--------modulemux(EN,IN0,IN1,IN2,IN3,SEL,OUT);inputEN;input[7:0]IN0,IN1,IN2,IN3;input[1:0]SEL;output[7:0]OUT;reg[7:0]OUT;always@(SELorENorIN0orIN1orIN2orIN3)beginif(EN==0)OUT={8{1'b0}};elsecase(SEL)0:OUT=IN0;1:OUT=IN1;2:OUT=IN2;3:OUT=IN3;default:OUT={8{1'b0}};endcaseendend
5、module二进制到BCD码转换//////-----------------------------------------------------------------------------------//DESCRIPTION:BintoBcdconverter//Input(data_in)width:4//Output(data_out)width:8//Enable(EN)active:high//----------------------------------------------------------------
6、-------------------modulebin2bcd(data_in,EN,data_out);input[3:0]data_in;inputEN;output[7:0]data_out;reg[7:0]data_out;always@(data_inorEN)begindata_out={8{1'b0}};if(EN==1)begincase(data_in[3:1])3'b000:data_out[7:1]=7'b;3'b001:data_out[7:1]=7'b;3'b010:data_out[7:1]=7'b;3'b01
7、1:data_out[7:1]=7'b;3'b100:data_out[7:1]=7'b;3'b101:data_out[7:1]=7'b;3'b110:data_out[7:1]=7'b;3'b111:data_out[7:1]=7'b;default:data_out[7:1]={7{1'b0}};endcasedata_out[0]=data_in[0];endendendmodule二进制到格雷码转换//-----------------------------------------------------------------
8、------------------//DESCRIPTION:Bintograyconverter//Input(DATA_IN)width:4//Enable(EN)acti