当前位置:   article > 正文

FPGA基于VGA的交通信号灯设计_交通信号灯设计代码

交通信号灯设计代码

前面一段时间fpga课整了个比较神奇的搭配?就交通信号灯(有上FPGA课的人应该知道这是一个比较基础的内容)配合VGA显示,弄了点东西忍不住分享一下。

总体上我这篇文章就重点讲解一下VGA显示模块和逻辑控制模块,像led和数码管模块我就不说了(也没啥东西可以说)

我先放个结果在这

话不多说先贴一段代码

  1. module control_place(
  2. input clk_1s,
  3. input rst,
  4. input control_auto,
  5. input contrl_re,
  6. output reg [5:0]time_data_10,
  7. output reg [5:0]time_data_0,
  8. output reg [1:0]light_in_NS,
  9. output reg [1:0]light_in_WE,
  10. output reg ss_time
  11. );
  12. initial
  13. begin
  14. // 00是绿灯,01是黄灯 ,10是红灯
  15. light_in_NS = 2'b01;
  16. light_in_WE = 2'b01;
  17. time_data_10 = 0;
  18. time_data_0 = 5;
  19. ss_time = 0;
  20. end
  21. //设定逻辑
  22. always@(posedge clk_1s or negedge rst)
  23. begin
  24. if (!rst) begin
  25. light_in_NS = 2'b01;
  26. light_in_WE <= 2'b01;
  27. time_data_10 <= 0;
  28. time_data_0 <= 5;
  29. ss_time <= 0;
  30. end
  31. else begin
  32. if((time_data_0 == 1|| time_data_0 == 0)&& time_data_10 == 0)
  33. if(control_auto)
  34. begin
  35. if(light_in_NS == 'b00)
  36. begin
  37. light_in_NS <= 'b01;
  38. light_in_WE <= 'b10;
  39. time_data_10 <= 0;
  40. time_data_0 = 5;
  41. end
  42. else if(light_in_NS == 'b01)
  43. begin
  44. light_in_NS <= 'b10;
  45. light_in_WE <= 'b00;
  46. time_data_10 <= 2;
  47. time_data_0 <= 5;
  48. ss_time = 0;
  49. end
  50. else if(light_in_WE == 'b00)
  51. begin
  52. light_in_NS <= 'b10;
  53. light_in_WE <= 'b01;
  54. time_data_10 <= 0;
  55. time_data_0 = 5;
  56. end
  57. else if(light_in_WE == 'b01)
  58. begin
  59. light_in_NS <= 'b00;
  60. light_in_WE <= 'b10;
  61. time_data_10 <= 2;
  62. time_data_0 <= 5;
  63. ss_time = 0;
  64. end
  65. end
  66. else
  67. begin
  68. if(contrl_re)
  69. begin
  70. if(light_in_NS == 'b00 || light_in_WE == 'b01)
  71. begin
  72. light_in_NS <= 'b00;
  73. light_in_WE <= 'b10;
  74. end
  75. else
  76. begin
  77. light_in_NS <= 'b10;
  78. light_in_WE <= 'b01;
  79. time_data_0 = 5;
  80. time_data_10 = 0;
  81. end
  82. end
  83. else
  84. begin
  85. if(light_in_WE == 'b00 || light_in_NS == 'b01)
  86. begin
  87. light_in_WE <= 'b00;
  88. light_in_NS <= 'b10;
  89. end
  90. else
  91. begin
  92. light_in_WE <= 'b10;
  93. light_in_NS <= 'b01;
  94. time_data_0 = 5;
  95. time_data_10 = 0;
  96. end
  97. end
  98. end
  99. else
  100. if(!control_auto)
  101. begin
  102. time_data_10 = 0;
  103. if(time_data_0 >= 5)
  104. time_data_0 = 5;
  105. end
  106. if(time_data_0 == 0)
  107. begin
  108. if(time_data_10 != 0)
  109. time_data_10 = time_data_10 - 1;
  110. time_data_0 = 9;
  111. end
  112. else if(time_data_0 == 5 &
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号