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
    

      

  • 相关阅读:
    下载文件
    Cookie方法
    阿拉伯数字转大写
    格式化日期
    正向代理与反向代理
    get post 区别
    gulp
    什么是javascript中的同步&&异步?
    懒加载
    js操作dom时发生了什么?
  • 原文地址:https://www.cnblogs.com/Neddy/p/2545314.html
Copyright © 2011-2022 走看看