⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 green.v

📁 This is an extension of sign example. You can design your own traffic sign by using Verilog. And the
💻 V
字号:

module 		green(clk,reset,col,scan,count); 
input		clk,reset;
output		[15:0]scan;
output		[15:0]col;
output		[4:0]count;
reg		[4:0]count;
reg		[15:0]scan;
reg		[15:0]col;
reg		[4:0]scan_choice;
reg		[15:0]nextState,state,word_choice,word;
reg		[4:0]delay,big;
parameter 		 ST00 = 5'b00000, ST01 = 5'b00001, ST02 = 5'b00010, ST03 = 5'b00011,
                	ST04 = 5'b00100, ST05 = 5'b00101, ST06 = 5'b00110, ST07 = 5'b00111,
                	ST08 = 5'b01000, ST09 = 5'b01001, ST10 = 5'b01010, ST11 = 5'b01011,
                	ST12 = 5'b01100, ST13 = 5'b01101, ST14 = 5'b01110, ST15 = 5'b01111,
                	ST16 = 5'b10000, ST17 = 5'b10001, ST18 = 5'b10010, ST19 = 5'b10011,
                	ST20 = 5'b10100, ST21 = 5'b10101, ST22 = 5'b10110, ST23 = 5'b10111,
                	ST24 = 5'b11000, ST25 = 5'b11001, ST26 = 5'b11010, ST27 = 5'b11011,
                	ST28 = 5'b11100, ST29 = 5'b11101, ST30 = 5'b11110, ST31 = 5'b11111;
//====================================================================================
always@(posedge clk)
begin
	if(reset == 1)
	begin
		state = 0;
		count = 15;
		big=0;
	end
	
	else
	begin
		if(delay < 15)
		begin
			delay = delay + 1;			
		end
		
		else
		begin
			state = nextState;
			delay = 0;			
		end
	end
end

//========== next state logic ==========
always@(state )
begin
	case(state)
        ST00:nextState = ST01;
        ST01:nextState = ST02;
        ST02:nextState = ST03;
        ST03:nextState = ST04;
        ST04:nextState = ST05;
        ST05:nextState = ST06;
        ST06:nextState = ST07;
        ST07:nextState = ST08;
	ST08:nextState = ST09;
	ST09:nextState = ST10;
       	ST10:nextState = ST11;
       	ST11:nextState = ST12;
       	ST12:nextState = ST13;
       	ST13:nextState = ST14;
       	ST14:nextState = ST15;
       	ST15:nextState = ST00; 
	endcase	
end

always@(posedge clk)
begin 
	if(scan_choice < 15)
	begin
		scan_choice = scan_choice + 1;		
		word_choice = word_choice + 1;				
	end
	else
	begin
		word_choice = state;		//come to current state
		scan_choice = 0;			//in the begining,
		word_choice = 0;
	end  
end	

always@(scan_choice or word_choice or state)
begin
	case(scan_choice) 
		0 :scan=16'b1000000000000000;
		1 :scan=16'b0100000000000000;
		2 :scan=16'b0010000000000000;
		3 :scan=16'b0001000000000000;
		4 :scan=16'b0000100000000000;
		5 :scan=16'b0000010000000000;
		6 :scan=16'b0000001000000000;
		7 :scan=16'b0000000100000000;
		8 :scan=16'b0000000010000000;
		9 :scan=16'b0000000001000000;
	 	10:scan=16'b0000000000100000;
		11:scan=16'b0000000000010000;
		12:scan=16'b0000000000001000;
		13:scan=16'b0000000000000100;
		14:scan=16'b0000000000000010;
		15:scan=16'b0000000000000001;	
	endcase
	
	//=========== motion 1 ================
	if((state==1 || state==4 || state==7 || state==10 || state==13) && state!=0)
	begin	
	case(word_choice)
		0: word=16'b0000000000000000;	
		1: word=16'b0000000000000000;
		2: word=16'b0001000000000000;
		3: word=16'b0010011000110000;
		4: word=16'b0010111100101000;
		5: word=16'b0010011000100100;	
		6: word=16'b0001000000100010;
		7: word=16'b0000000000100010;
		8: word=16'b0000000000100010;
		9: word=16'b0001000000100010;
		10:word=16'b0010011000100100;	
		11:word=16'b0010111100101000;
		12:word=16'b0010011000110000;
		13:word=16'b0001000000000000;
		14:word=16'b0000000000000000;
		15:word=16'b0000000000000000;			
		default:word=16'b0000000000000000;
	endcase
	end
	
	//************* motion 2 ****************
	else if((state==2 || state==5 || state==8 || state==11 || state==14) && state!=0)
	begin
	case(word_choice)
		0: word=16'b0000000000000000;	
		1: word=16'b0000000000000000;
		2: word=16'b0001000000000000;
		3: word=16'b0010011000100000;
		4: word=16'b0010100000100000;
		5: word=16'b0010011000100000;	
		6: word=16'b0001000000111110;
		7: word=16'b0000000000100001;
		8: word=16'b0000000000100001;
		9: word=16'b0001000000111110;
		10:word=16'b0010011000100000;	
		11:word=16'b0010100000100000;
		12:word=16'b0010011000100000;
		13:word=16'b0001000000000000;
		14:word=16'b0000000000000000;
		15:word=16'b0000000000000000;			
		default:word=16'b0000000000000000;
	endcase
	end
	
	//************* motion 3 ****************
	else if((state==3 || state==6 || state==9 || state==12 || state==15) && state!=0)
	begin
	case(word_choice)
		0: word=16'b0000000000000000;	
		1: word=16'b0100000000000000;
		2: word=16'b1000010000000000;
		3: word=16'b0100010000000010;
		4: word=16'b0010010000000100;
		5: word=16'b0001000000001000;	
		6: word=16'b0000100000010000;
		7: word=16'b0000000000100000;
		8: word=16'b0000000000100000;
		9: word=16'b0000100000010000;
		10:word=16'b0001000000001000;	
		11:word=16'b0010010000000100;
		12:word=16'b0100010000000010;
		13:word=16'b1000010000000000;
		14:word=16'b0100000000000000;
		15:word=16'b0000000000000000;			
		default:word=16'b0000000000000000;
	endcase
	end
	
	
	//************* stop ****************
	else
	begin	
	case(word_choice)
		0: word=16'b0000000000000000;	
		1: word=16'b0000000000000000;
		2: word=16'b0000000000000000;
		3: word=16'b0000000000000000;
		4: word=16'b0000000001000100;
		5: word=16'b0011100010101000;	
		6: word=16'b0111110100010000;
		7: word=16'b0111111111100000;
		8: word=16'b0111110010010000;
		9: word=16'b0011100100001000;
		10:word=16'b0000001000000100;	
		11:word=16'b0000010000000000;
		12:word=16'b0000100000000000;
		13:word=16'b0001000000000000;
		14:word=16'b0000000000000000;
		15:word=16'b0000000000000000;			
		default:word=16'b0000000000000000;
	endcase		
	end	
	col = word;
	if(count>0) count=count-1;
	else count=15;	
	//===================================			
end
endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -