zoukankan      html  css  js  c++  java
  • SystemVerilog例子traffic light

    module traffic_light(
        output logic	green_light,
        				yellow_light,
        				red_light,
        input sensor,
        input [15:0] green_downcnt,
        input [15:0] yellow_downcnt,
        input clock,
        input resetN
        );
    parameter 	R_BIT = 0,
    			G_BIT = 1,
    			Y_BIT = 2;
    		
    enum logic [2:0] {RED	= 3'd001<<R_BIT,
    				 GREEN	= 3'b001<<G_BIT,
    				 YELLOW = 3'b001<<Y_BIT} State, Next;
    						
      @(posedge clock, negedge resetN)
    	if(!resetN) State <= RED;
    	else			State <= Next;
    	
    always_comb begin: set_next_state
    	Next = State;
    	unique case(1'b1)
    		State[R_BIT]:	if(sensor)				Next = GREEN;
    		State[G_BIT]:	if(green_downcnt == 0) 	Next = YELLOW;
    		State[Y_BIT]:	if(yellow_downcnt == 0)	Next = RED;
    	endcase
    end: set_next_state
    
    always_comb begin: set_output
    	{green_light, yellow_light, red_light} = 3'b000;
    	unique case(1'b1)
    		State[R_BIT]:	red_light		= 1'b1;

    		State[G_BIT]:	green_light		= 1'b1;
    		State[Y_BIT]:  	yellow_light	= 1'b1;
    	endcase
    end: set_output
    
    endmodule
    

      

  • 相关阅读:
    合并区间
    编译与运行
    传递信息
    划分字母区间
    无重叠区间
    用最少数量的箭引爆气球
    根据身高重建队列
    二叉树展开为链表
    动态添加按钮
    基础知识
  • 原文地址:https://www.cnblogs.com/Neddy/p/2545314.html
Copyright © 2011-2022 走看看