搜索
bottom↓
回复: 1

这个程序为什么编译不通过呢??

[复制链接]

出0入0汤圆

发表于 2010-2-17 17:26:45 | 显示全部楼层 |阅读模式
module segment(
    clk,
    rst_n,
    sw0,
    sw1,
    sw2,
    sw3,
    //output
    hc_cp,
    hc_si
    );
   
  input   clk;
  input   rst_n;
  input   sw0,sw1,sw2,sw3; //Active low
  output  hc_cp;
  output  hc_si;
  
  reg [3:0]data;
  integer count;
  integer shuaxin;
  always @ (posedge clk or negedge rst_n)begin
    if (!rst_n)begin
                 count <= 0;
             data <= 4'h0;
        end     
        else begin
                 if(count==16_000_000)begin
                        count<=0;
                        data <= data + 1'b1;
                 end       
                 else begin
                        count <= count +1'b1;
                 end
        end               
  end             
  
  always @ (posedge clk or negedge rst_n)begin
    if (!rst_n)begin
                shuaxin<=0;
    end  
    else begin
                if(shuaxin==5000)begin
                            shuaxin<=0;                  
                                hc164_driver hc164_driver_inst(
                                  .clk         ( clk ),
                                  .rst_n       ( rst_n ),
                                  .led         ( 0 ),
                                  .dot         ( 0 ),
                                  .seg_value   ( {4'd1,data,4'd2,4'd3} ),
                                  .hc_cp       ( hc_cp ),
                                  .hc_si       ( hc_si )  
                                );       
                                         
                end
                else
                        shuaxin<=shuaxin + 1'b1;
        end               
end
  

endmodule

// hc164_driver模块
module hc164_driver(
    clk,  rst_n,    led,    dot,    seg_value,    hc_cp,    hc_si    );
  input           clk;
  input           rst_n;  
  input   [3 :0]  led;
  input   [3 :0]  dot;      
  input   [15:0]  seg_value;
  output  reg     hc_cp;           //HC164 Clock input active Rising edges
  output          hc_si;          //HC164 Data input
  reg     [5 :0]  tx_cnt;
  reg   [6:0]   hex2led;        //hex-to-seven-segment decoder output
  reg   [3:0]   hc_data_34bit;  
  reg           hc_data_31bit;   
  
  wire  [15:0]  hc_data = {led,hc_data_34bit,hex2led[6:2],  hc_data_31bit,    hex2led[1:0]  };
  wire  [15:0]  hc_data_inv = { hc_data[0],
                          hc_data[1],hc_data[2],hc_data[3], hc_data[4],
                          hc_data[5],hc_data[6],hc_data[7], hc_data[8],
                        hc_data[9],hc_data[10],hc_data[11], hc_data[12],
                        hc_data[13], hc_data[14], hc_data[15]  };
  reg [15:0]  clk_cnt;
  always @ ( posedge clk or negedge rst_n )
    if ( !rst_n ) clk_cnt <= 16'd0;
    else  clk_cnt <= clk_cnt + 1'b1;
  reg [1:0] seg_led_num;
  always @ ( posedge clk or negedge rst_n )
    if (!rst_n ) seg_led_num <= 2'b00;
    else if ( clk_cnt == 16'hFFFF ) seg_led_num <= seg_led_num + 1'b1;

  reg   [3:0] hex;
  always @ ( * )
    case ( seg_led_num )
      2'b00: hex = seg_value[15:12];
      2'b01: hex = seg_value[11:8];
      2'b10: hex = seg_value[7:4];
      2'b11: hex = seg_value[3:0];
    endcase
    always @ ( * )
    begin
      case (hex)                        //数值
              4'h1  : hex2led = 7'b0010_100;        //1   
              4'h2  : hex2led = 7'b1011_011;        //2   
              4'h3  : hex2led = 7'b1011_110;        //3   
              4'h4  : hex2led = 7'b0111_100;        //4   
              4'h5  : hex2led = 7'b1101_110;        //5   
              4'h6  : hex2led = 7'b1101_111;        //6   
              4'h7  : hex2led = 7'b1010_100;        //7   
              4'h8  : hex2led = 7'b1111_111;        //8   
              4'h9  : hex2led = 7'b1111_100;        //9   
              4'hA  : hex2led = 7'b1111_101;        //A   
              4'hB  : hex2led = 7'b0101_111;        //b   
              4'hC  : hex2led = 7'b1100_011;        //C   
              4'hD  : hex2led = 7'b0011_111;        //d   
              4'hE  : hex2led = 7'b1101_011;        //E   
              4'hF  : hex2led = 7'b1101_001;        //F   
            default : hex2led = 7'b1110_111;        //0   
    endcase
  end
   always @ ( * )
    case ( seg_led_num )
      2'b00:hc_data_34bit[3:0] = 4'b0111;
      2'b01:hc_data_34bit[3:0] = 4'b1011;
      2'b10:hc_data_34bit[3:0] = 4'b1101;
      2'b11:hc_data_34bit[3:0] = 4'b1110;
    endcase  
  always @ ( * )
    case ( seg_led_num )
      2'b00:hc_data_31bit = dot[3];
      2'b01:hc_data_31bit = dot[2];
      2'b10:hc_data_31bit = dot[1];
      2'b11:hc_data_31bit = dot[0];
    endcase  
  always @ ( posedge clk or negedge rst_n )
    if (!rst_n ) tx_cnt <= 6'd0;
    else if ( clk_cnt[15] ) tx_cnt <= 6'd0;      
    else if ((!clk_cnt[15]) && (tx_cnt <= 6'd32 )) tx_cnt <= tx_cnt + 1'b1;

  always @ ( posedge clk or negedge rst_n )
    if (!rst_n)  hc_cp <= 1'b0;
    else if ( clk_cnt[15] ) hc_cp <= 1'b0;
    else if ((!clk_cnt[15]) && (tx_cnt < 6'd32 )) hc_cp <= !hc_cp;

  assign  hc_si = hc_data_inv[tx_cnt[4:1]];
   
endmodule

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2010-2-17 17:27:59 | 显示全部楼层
Error (10170): Verilog HDL syntax error at segment.v(45) near text "hc164_driver_inst";  expecting "<=", or "="

我把下面这个放到最后就通过了,初学,请大家指教

hc164_driver hc164_driver_inst(
  .clk         ( clk ),
  .rst_n       ( rst_n ),
  .led         ( 0 ),
  .dot         ( 0 ),
  .seg_value   ( {4'd1,data,4'd2,4'd3} ),
  .hc_cp       ( hc_cp ),  
  .hc_si       ( hc_si )   
);
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-16 03:57

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表