Verilog程序代码集Word格式.docx

上传人:b****7 文档编号:22632591 上传时间:2023-02-04 格式:DOCX 页数:10 大小:16.63KB
下载 相关 举报
Verilog程序代码集Word格式.docx_第1页
第1页 / 共10页
Verilog程序代码集Word格式.docx_第2页
第2页 / 共10页
Verilog程序代码集Word格式.docx_第3页
第3页 / 共10页
Verilog程序代码集Word格式.docx_第4页
第4页 / 共10页
Verilog程序代码集Word格式.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

Verilog程序代码集Word格式.docx

《Verilog程序代码集Word格式.docx》由会员分享,可在线阅读,更多相关《Verilog程序代码集Word格式.docx(10页珍藏版)》请在冰豆网上搜索。

Verilog程序代码集Word格式.docx

B;

T2=Cin&

A;

T3=Cin&

Count=T1|T2|T3;

end

endmodule

结构体

moduleadder(a,b,Cin,Sum,Count);

inputa,b,Cin;

outputSum,Count;

Xora1(s1,a1,b);

Xora2(Sum,s1,Cin);

anda3(T1,a,b);

ora4(T2,a,b);

anda5(T3,Cin,T2);

ora6(Count,T1,T3);

Endmodule

2.数值比较器

判断两值是否相等

modulecompare(a,b,equal);

input[7:

outputequal;

assignequal=(a==b)?

|0;

谁大谁输出

modulecompare(a,b,out);

outputreg[7:

0]out;

always@(aorb)

if(a>

b)out<

=a;

elseif(a==b)out<

else 

 

out<

=b;

end

输出参数

modulecompare(a.b.xgy,xsy,xey);

0]x,y;

outputregxgy,xsy,xey;

always@(xory)

if(x==y) 

xey=1;

xey=0;

if(x>

y) 

beginxgy=1;

xsy=0;

elseif(x<

y)beginxgy=0;

xsy=1;

3.编码器(4-28-316-4编码)

case语句8-3编码(优先)

modulecode(in,out);

0]in;

outputreg[2:

always@(in)

casex(in)

beginf=1;

8’b1xxxxxxx:

out=3’b111;

8’b01xxxxxx:

out=3’b110;

8’b001xxxxx:

out=3’b101;

8’b0001xxxx:

out=3’b100;

8’b00001xxx:

out=3’b011;

8’b000001xx:

out=3’b010;

8’b0000001x:

out=3’b001;

8’b00000001:

out=3’b000;

default:

beginf=0:

endcase

if-else语句(4-2优先编码)

modulecode(in,out);

input[3:

outputreg[1:

if(in[3]==1):

out=2’b11;

elseif(in[2]==1):

out=2’b10;

elseif(in[1]==1):

out=2’b01;

elseif(in[0]==1):

out=2’b00;

elsebeginf=0;

4.多路选择器

行为描述(4选1)

modulechoice(A,B,C,D,ncsaddrout);

0]A,B,C,D;

inputncs;

input[1:

0]addr;

always@(AorBorCorDorncsoraddr)

if(!

ncs)

case(addr)

2’b00:

out=A;

2’b01:

out=B;

2’b10:

out=C;

2’b11:

out=D;

out=0;

5.设计一个4位双向移位寄存器。

moduleshift(sout,out,clk,in,sin,d,load);

inputclk,sin,d,load;

0]in;

outputsout;

output[3:

0]out;

reg[3:

always@(posedgeclk)

if(load)out<

=in;

else

if(d==0)

beginout<

=out>

>

1;

out[3]<

=sin;

sout<

=out[0];

else

=out<

<

out[0]<

=out[3];

6.11111010000序列检测器

moduleshift(q,s,d,clk);

output[11:

0]q;

outputs;

inputd;

inputclk;

reg[11:

 

regs;

q<

=q<

q[0]<

=d;

always@(posedgeclk)

if(q==12'

b11111010000)

s<

=1;

=0;

7.计数器

计数分频器

8分频占空比1:

1

modulediv(clk8,clk,rst);

inputclk,rst;

outputregclk8;

reg[2:

0]count;

always@(posedgeclk)

if(rst)begin

clk8<

count<

elsebegin

if(count==7)count<

count<

=count+1;

if(count<

=3)clk_8<

clk_8<

预置数计数

modulesetcount(clk,rst,F,out);

inputclk,rst,F;

outputregout;

0]count;

always@(posedgeclkorposedgerst)

if(rst)beginout<

elseif(F==1) 

=10;

elseif(count>

=15)begin

Count<

=o;

8.触发器

T=1时翻转

T触发器

T=0时保持翻转

moduleD_FF(T,clk,rst,Q,Qn);

inputT,clk,rst;

outputregQ,Qn;

Q<

Qn<

elseif(T) 

begin

=~Q 

Qn<

=~Qn;

end

=Q;

=Qn;

D触发器Qn+1=D(保持D)

moduleD_FF(D,clk,rst,Q,Qn);

inputD,clk,rst;

outputregQ,Qn;

ef(rst)beginQ<

beginQ<

=D;

=~D;

J=1K=0时Q=1置1

J=0K=1时Q=0置0

J=K=0时Q=Q保持

J=K=1时Q=~Q取反转

JK触发器

moduleJK_FF(J,K,clk,rst,Q,Qn);

inputJ,K,clk,rst;

outputQ,Qn;

if(rst) 

=1end

elseif(J==1&

&

K==0)begin

elseif((J==0&

K==1)begin

=Q;

=~Q;

Qn=~Qn;

9.测试程序(异或门测试)

‘timescale 

1ns/1ps

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1