开心果 发表于 2012-4-3 14:51:05

模块调用问题。

我是刚学的verilog,写了一个秒表程序,但是一直编译不过去,哪位大侠帮我看看啊!!!
module nixie_light(clk_n,wei,dat_n,cs_n,digit_n);
input clk_n;
input dat_n;
input wei;
output digit_n,cs_n;
parameter                     
    MSK_0       = 8'h40,       // '0'
    MSK_1       = 8'h79,       // '1'
    MSK_2       = 8'h24,       // '2'
    MSK_3       = 8'h30,       // '3'
    MSK_4       = 8'h19,       // '4'
    MSK_5       = 8'h12,       // '5'
    MSK_6       = 8'h02,       // '6'
    MSK_7       = 8'h78,       // '7'
    MSK_8       = 8'h00,       // '8'
    MSK_9       = 8'h10;       // '9'
//=================================================================================================
reg       cnt2;                                    
reg        submsk;                                       
reg        cs_n;
reg        digit_n;
always @(posedge clk_n)
begin
   cnt2 <= cnt2 + 1'b1;                           
   if (cnt2 == 17'd0)
                        begin
                        cs_n<=8'hf0;
                        submsk<=dat_n;
                        end
end
always @(submsk)
case (submsk)
    4'h0:       digit_n <= MSK_0;
    4'h1:       digit_n <= MSK_1;
    4'h2:       digit_n <= MSK_2;
    4'h3:       digit_n <= MSK_3;
    4'h4:       digit_n <= MSK_4;
    4'h5:       digit_n <= MSK_5;
    4'h6:       digit_n <= MSK_6;
    4'h7:       digit_n <= MSK_7;
    4'h8:       digit_n <= MSK_8;
    4'h9:       digit_n <= MSK_9;
    default:    digit_n <= MSK_0;
endcase
always @(wei)
case (wei)
    3'd0:       cs_n <= 7'hfe;
    3'd1:       cs_n <= 7'hfd;
    3'd2:       cs_n <= 7'hfb;
    3'd3:       cs_n <= 7'hf7;
    3'd4:       cs_n <= 7'hef;
    3'd5:       cs_n <= 7'hdf;
    3'd6:       cs_n <= 7'hbf;
    3'd7:       cs_n <= 7'h7f;
    default:    cs_n <= 7'hfe;
endcase
endmodule


module timepiece(clk,cs,digit_o);
input clk;
output cs;
output digit_o;

reg count;
reg time_clk;
reg date;
always @(posedge clk)
                if(count==28'h17D7840)
                        begin
                                count<=1'b0;
                                time_clk<=~time_clk;
                        end
                else count<=count+1'b1;
reg minute_s;
reg minute_g;
//reg hour_s;
//reg hour_g;
always @(posedge time_clk)
        begin
                                if(minute_g==9)
                                begin
                                        minute_g<=0;
                                        if(minute_s<=5)
                                                minute_s<=0;
                                        else
                                                minute_s<=minute_s+1;
                                end
                                else
                                        minute_g<=minute_g+1;
                                               
        end                                       
reg        submsk;                                       
reg        cs;
reg        digit_o;
nixie_light(clk,1,minute_s,cs,digit_o);
nixie_light(clk,2,minute_g,cs,digit_o);
       
endmodule       




编译后的错误是
Error (10663): Verilog HDL Port Connection error at timepiece.v(96): output or inout port "cs_n" must be connected to a structural net expression
Error (10663): Verilog HDL Port Connection error at timepiece.v(96): output or inout port "digit_n" must be connected to a structural net expression

zombes 发表于 2012-4-3 18:46:41

reg        digit_n;
output digit_n;

先改成一致看行不行

tao2000 发表于 2012-4-4 10:46:50

reg        cs;
reg        digit_o;
这两句去掉
还有就是调用nixie_light模块没有给出调用名称

开心果 发表于 2012-4-4 20:34:34

回复 2# zombes

谢谢哦!!我慢慢改程序改对了!!这个程序里又太多错误了,最大的错误就是
nixie_light(clk,1,minute_s,cs,digit_o);
nixie_light(clk,2,minute_g,cs,digit_o);
不能多次对cs,digit_o赋值,我用状态机解决了这个问题,

开心果 发表于 2012-4-4 20:36:49

回复 3# tao2000


    呵呵呵谢谢啊!!问题已经解决了!!问题太多,而且调用模块可以省略你说的调用名字的
页: [1]
查看完整版本: 模块调用问题。