在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1896|回复: 2

[求助] verilog交通灯的测试程序

[复制链接]
发表于 2013-11-28 18:34:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
module traffic(CLK,EN,LAMPA,LAMPB,ACOUNT,BCOUNT);
  output[7:0] ACOUNT,BCOUNT;
  output[3:0] LAMPA,LAMPB;
  input CLK,EN;
  reg[7:0] numa,numb;
  reg tempa,tempb;
  reg[2:0] counta,countb;
  reg[7:0] ared,ayellow,agreen,aleft,bred,byellow,bgreen,bleft;
  reg[3:0] LAMPA,LAMPB;
  
  always @(EN)
  if(!EN)
    begin
      ared     <=8'b01010101;
      ayellow  <=8'b00000101;
      agreen   <=8'b01000000;
      aleft    <=8'b00010101;
      bred     <=8'b01100101;
      byellow  <=8'b00000101;
      bleft    <=8'b00010101;
      bgreen   <=8'b00110000;
    end
  assign ACOUNT=numa;
  assign BCOUNT=numb;
  
  always @(posedge CLK)
    begin
      if(EN)
        begin
          if(!tempa)
            begin
              tempa<=1;
              case(counta)
                0:begin numa<=agreen;   LAMPA<=2; counta<=1; end
                1:begin numa<=ayellow;  LAMPA<=4; counta<=2; end
                2:begin numa<=aleft;    LAMPA<=1; counta<=3; end
                3:begin numa<=ayellow;  LAMPA<=4; counta<=4; end
                4:begin numa<=ared;     LAMPA<=8; counta<=0; end
                default:                LAMPA<=8;
              endcase
            end
          else begin
            if(numa>1)
              if(numa[3:0]==0)begin
                              numa[3:0]<=4'b1001;
                              numa[7:4]<=numa[7:4]-1;
                            end
            else              numa[3:0]<=numa[3:0]-1;
              if(numa==2)tempa<=0;
            end
          end
        else  begin
          LAMPA<=4'b1000;
          counta<=0;tempa<=0;
        end
      end
      
  always @(posedge CLK)
    begin
      if(EN)
        begin
          if(!tempb)
            begin
              tempb<=1;
              case(countb)
                0:begin numb<=bred;    LAMPB<=8; countb<=1; end
                1:begin numb<=bgreen;  LAMPB<=2; countb<=2; end
                2:begin numb<=byellow; LAMPB<=4; countb<=3; end
                3:begin numb<=bleft;   LAMPB<=1; countb<=4; end
                4:begin numb<=byellow; LAMPB<=4; countb<=0; end
                default:               LAMPB<=8;
              endcase
            end
          else begin
            if(numb>1)
              if(numb[3:0]==0)begin
                              numb[3:0]<=9;
                              numb[7:4]<=numb[7:4]-1;
                            end
            else              numb[3:0]<=numb[3:0]-1;
              if(numb==2) tempb<=0;
            end
          end
        else  begin
          LAMPB<=4'b1000;
          tempb<=0; countb<=0;
        end
      end
    endmodule

源程序是这样的,请问一下测试程序怎么写?
发表于 2013-12-2 16:33:40 | 显示全部楼层
个人觉得貌似测试程序一般比源程序难写,如果您能写出这个源程序,测试程序应该可以搞定吧。
发表于 2013-12-8 10:51:25 | 显示全部楼层
回复 1# sweet不想长大


    就是写代码,把traffic模块的接口,都赋给一定的值,看看功能是否符合预期。模块都写出来了,应该testbench不难,有时间的话试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-3 02:10 , Processed in 0.033574 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表