这两个Verilog代码可以放在一个.v文件中吗:1.`timescale 1ns / 1ps module Top(clk,sw,led,flag, ADC_sdata, ADC_sclk,ADC_csn,slec_wei,slec_duan); input clk; input [3:0]sw; output reg [7:0] led; input flag; input ADC_sdata; output ADC_sclk,ADC_csn; output [7:0] slec_wei; output [7:0] slec_duan; wire [11:0] adc_res; wire adc_valid; wire [19:0]cout; always@(posedge clk)if(adc_valid) led<=adc_res[11:4]; PmodAD1 U0( .clk(clk), .rst(1’b0), .ADC_sdata(ADC_sdata), .ADC_sclk(ADC_sclk), .ADC_csn(ADC_csn), .adc_res(adc_res), .adc_valid(adc_valid) ); data_ad_pro U1( .sys_clk(clk), .rst_n(1’b1), .pre_data(adc_res[11:4]), .cout(cout) ); display U2( .sys_clk(clk), .rst_n(1’b1), .cout(cout), .sw(sw), .flag(flag), .slec_wei(slec_wei), .slec_duan(slec_duan) ); endmodule ———————2.module PmodAD1( clk,rst, ADC_sdata,ADC_sclk,ADC_csn,adc_res,adc_valid); input clk,rst, ADC_sdata; output reg ADC_sclk,ADC_csn; output reg [11:0] adc_res; output reg adc_valid; reg [7:0] cntr; always@(posedge clk) if(rst)cntr<=0;else if(cntr==34)cntr<=0;else cntr<=cntr+1; always@(posedge clk) case (cntr) 0: ADC_csn<=0; 33: ADC_csn<=1; endcase always@(posedge clk) case(cntr) 34,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,33:ADC_sclk<=1; default ADC_sclk<=0; endcase always@(posedge clk) case(cntr) 8: adc_res[11]<= ADC_sdata; 10:adc_res[10]<= ADC_sdata; 12:adc_res[9]<= ADC_sdata; 14:adc_res[8]<= ADC_sdata; 16:adc_res[7]<= ADC_sdata; 18:adc_res[6]<= ADC_sdata; 20:adc_res[5]<= ADC_sdata; 22:adc_res[4]<= ADC_sdata; 24:adc_res[3]<= ADC_sdata; 26:adc_res[2]<= ADC_sdata; 28:adc_res[1]<= ADC_sdata; 30:adc_res[0]<= ADC_sdata; endcase always@(posedge clk)adc_valid<=cntr==32; endmodule
时间: 2024-02-25 10:55:44 浏览: 116
(超级高清版)经典Verilog示例(100多个经典代码案例).pdf
4星 · 用户满意度95%
可以将两个模块放在同一个文件中,但需要注意的是,需要在两个模块之间添加一个模块分割符`//----`,否则会报错。同时,建议将两个模块中的端口名进行修改,以免出现冲突。下面是修改后的代码示例:
```
//----Top module----
`timescale 1ns / 1ps
module Top(
input clk,
input [3:0] sw,
output reg [7:0] led,
input flag,
input ADC_sdata,
output ADC_sclk,
output ADC_csn,
output [7:0] slec_wei,
output [7:0] slec_duan
);
wire [11:0] adc_res;
wire adc_valid;
wire [19:0] cout;
always@(posedge clk)
if(adc_valid)
led <= adc_res[11:4];
PmodAD1 U0(
.clk(clk),
.rst(1'b0),
.ADC_sdata(ADC_sdata),
.ADC_sclk(ADC_sclk),
.ADC_csn(ADC_csn),
.adc_res(adc_res),
.adc_valid(adc_valid)
);
data_ad_pro U1(
.sys_clk(clk),
.rst_n(1'b1),
.pre_data(adc_res[11:4]),
.cout(cout)
);
display U2(
.sys_clk(clk),
.rst_n(1'b1),
.cout(cout),
.sw(sw),
.flag(flag),
.slec_wei(slec_wei),
.slec_duan(slec_duan)
);
endmodule
//----PmodAD1 module----
module PmodAD1(
input clk,
input rst,
input ADC_sdata,
output reg ADC_sclk,
output reg ADC_csn,
output reg [11:0] adc_res,
output reg adc_valid
);
reg [7:0] cntr;
always@(posedge clk)
if(rst)
cntr <= 0;
else if(cntr == 34)
cntr <= 0;
else
cntr <= cntr + 1;
always@(posedge clk)
case(cntr)
0: ADC_csn <= 0;
33: ADC_csn <= 1;
endcase
always@(posedge clk)
case(cntr)
34, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 33: ADC_sclk <= 1;
default ADC_sclk <= 0;
endcase
always@(posedge clk)
case(cntr)
8: adc_res[11] <= ADC_sdata;
10: adc_res[10] <= ADC_sdata;
12: adc_res[9] <= ADC_sdata;
14: adc_res[8] <= ADC_sdata;
16: adc_res[7] <= ADC_sdata;
18: adc_res[6] <= ADC_sdata;
20: adc_res[5] <= ADC_sdata;
22: adc_res[4] <= ADC_sdata;
24: adc_res[3] <= ADC_sdata;
26: adc_res[2] <= ADC_sdata;
28: adc_res[1] <= ADC_sdata;
30: adc_res[0] <= ADC_sdata;
endcase
always@(posedge clk)
adc_valid <= cntr == 32;
endmodule
```
阅读全文