找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3362|回复: 0
收起左侧

交通灯verilog源码-凌阳FPGA实验程序 含分频

[复制链接]
ID:300152 发表于 2018-3-31 22:55 | 显示全部楼层 |阅读模式
凌阳FPGA实验程序,包含分频,交通灯源码
0.png
单片机源程序如下:
  1. module traffic(CLK,EN,LAMPA,LAMPB,ACOUNT,BCOUNT);
  2. output[7:0] ACOUNT,BCOUNT;
  3. output[2:0] LAMPA,LAMPB;//lampa[2],lampa[1],lamp[0]as the red,green,yellow
  4.                         //lampb[2],lampb[1],lamp[0]--red,green,yellow
  5. input CLK,EN;//clk and enable(high is efficient)
  6. reg[7:0] numa,numb;
  7. reg tempa,tempb;
  8. reg[2:0] counta,countb;
  9. reg[7:0] ared,ayellow,agreen,bred,byellow,bgreen;
  10. reg[2:0] LAMPA,LAMPB;

  11. always @(EN)
  12. if(!EN)
  13.           begin
  14. ared<=8'b01000101;         
  15. ayellow<=8'b00000101;         
  16. agreen<= 8'b01000000;        
  17. bred<=8'b01000101;
  18. byellow<=8'b00000101;        
  19. bgreen<=8'b01000000;
  20.           end
  21. assign  ACOUNT=numa;
  22. assign  BCOUNT=numb;

  23. always @(posedge CLK)
  24.   begin
  25. if(EN)
  26. begin
  27. if(!tempa)
  28. begin
  29. tempa<=1;
  30. case(counta)
  31. 0:  begin numa<=ared;                LAMPA<=3'b100; counta<=1; end
  32. 1:  begin numa<=agreen;                LAMPA<=3'b010; counta<=2; end
  33. 2:  begin numa<=ayellow;        LAMPA<=3'b001; counta<=0; end
  34. default:                        LAMPA<=3'b100;
  35. endcase
  36. end
  37. else  begin
  38. if(numa>1)  
  39. if(numa[3:0]==0) begin
  40. numa[3:0]<=4'b1001;
  41. numa[7:4]<=numa[7:4]-1;
  42. end
  43. else                 numa[3:0]<=numa[3:0]-1;
  44. if (numa==2)  tempa<=0;
  45. end
  46. end
  47. else         begin
  48. LAMPA<=3'b100;
  49. counta<=0;   tempa<=0;
  50. end
  51.   end

  52. always @(posedge CLK)
  53. begin
  54.   if (EN)
  55.    begin
  56.     if(!tempb)
  57.      begin
  58.      tempb<=1;
  59.      case (countb)
  60. 0:  begin numb<=bgreen;                LAMPB<=3'b010; countb<=1; end
  61. 1:  begin numb<=byellow;        LAMPB<=3'b001; countb<=2; end
  62. 2:  begin numb<=bred;                LAMPB<=3'b100; countb<=0; end
  63. default:                        LAMPB<=3'b010;
  64.      endcase
  65.      end
  66.     else
  67.      begin
  68.       if(numb>1)
  69.        if(!numb[3:0])         begin
  70. numb[3:0]<=9;
  71. numb[7:4]<=numb[7:4]-1;
  72. end
  73. else          numb[3:0]<=numb[3:0]-1;
  74. if(numb==2)  tempb<=0;
  75.     end
  76.    end
  77. else          begin
  78. LAMPB<=3'b010;
  79. tempb<=0;   countb<=0;
  80. end
  81.   end
  82. endmodule
复制代码


交通灯Verilog.zip

1.36 MB, 下载次数: 31, 下载积分: 黑币 -5

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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