数字逻辑实验

 第二次实验
1.打开Modelism,然后点击new,选择library新建,再选择project,新建完项目。
2.填写代码并且运行
module crc( data_send,ready_s,data_out,resend, data_in,reset,data_receive,ready_r,clk,err ); parameter width=1,amount=12; output [width*amount+4:0]  data_send; output ready_s; output [width-1:0] data_out; output resend; input [width-1:0]data_in; input reset; input [width*amount+4:0] data_receive; input ready_r; input err; input clk; crc_send send1 (data_send,ready_s,data_in,reset,clk); crc_receive receive1 (data_out,resend, data_send,ready_r,clk,err); endmodule module crc_send(data_send,ready_s,data_in,reset,clk); parameter width=1,amount=12; output [width*amount+4:0] data_send; output ready_s; input [width-1:0] data_in; input reset,clk; reg [width*amount+4:0] data_send; reg ready_s; reg[width*amount:0] buf_in; reg [width*amount+4:0] buf_data_s; integer n,i; always @(posedge reset or posedge clk) begin if(reset) n=0; else if(n<amount-1) begin ready_s<=0; buf_in=buf_in<<width; buf_in[width-1:0]=data_in; n=n+1; end else begin buf_in=buf_in<<width; buf_in[width-1:0]=data_in; buf_data_s[width*amount+4:5]=buf_in; if(buf_in[11]) buf_in[11:6]=buf_in[11:6]^6'b110101; if(buf_in[10]) buf_in[10:5]=buf_in[10:5]^6'b110101; if (buf_in[9]) buf_in[9:4]=buf_in[9:4]^6'b110101; if(buf_in[8]) buf_in[8:3]=buf_in[8:3]^6'b110101; if(buf_in[7]) buf_in[7:2]=buf_in[7:2]^6'b110101; if(buf_in[6]) buf_in[6:1]=buf_in[6:1]^6'b110101; if (buf_in[5]) buf_in[5:0]=buf_in[5:0]^6'b110101; buf_data_s[4:0]=buf_in[4:0]; data_send[width*amount+4:0]=buf_data_s[width*amount+4:0]; n=0; ready_s<=1; end end endmodule module crc_receive (data_out,resend, data_receive,ready_r,clk,err); parameter width=1,amount=12; output[width-1:0] data_out; output resend; input[width*amount+4:1] data_receive; input ready_r,clk,err; reg [width-1:0] data_out; reg resend; reg [width*amount+4:0] buf_receive; reg [width*amount:0] buf_data_r; reg right; integer m; always @(posedge clk) begin if(ready_r) begin buf_receive=data_receive; if (err) buf_receive[16]=~buf_receive[16]; buf_data_r[width*amount:0]=buf__receive[width*amount+4:5]; if(buf_data_r[11]) buf_data_r[11:6]=buf_data_r[11:6]^6'b110101; if (buf_data_r[10]) buf_data_r[10:5]=buf_data_r[10:5]^6'b110101; if(buf_data_r[9]) buf_data_r[9:4]=buf_data_r[9:4]^6'b110101; if(buf_data_r[8]) buf_data_r[8:3]=buf_data_r[8:3]^6'b110101; if(buf_data_r[7]) buf_data_r[7:2]=buf_data_r[7:2]^6'b110101; if(buf_data_r[6]) buf_data_r[6:1]=buf_data_r[6:1]^6'b110101; if(buf_data_r(5]) buf_data_r[5:0]=buf_data_r[5:0]^6'b110101; if(! (buf_data_r[4:0]^buf_receive[4:0])) begin right=1; resend=0; data_out=buf_receive[16]; buf_receive=buf_receive<<width; m=1; end else begin right=0; resend=1; data_out='bz; end end else if(right) begin if(m<amount) begin data_out=buf_receive [width*amount+4:width*amount+5-width]; buf_receive=buf_receive<<width; m=m+1; end end end endmodule
3.修改并且整理仿真图

4上传视频

【第二次考试实验,十二章选题七-哔哩哔哩】https://b23.tv/vigNm5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值