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

📄 seller.v

📁 基于verilog HDL的自动售货机控制电路设计: 可以对5种不同种类的货物进行自动售货,价格分别为A=1.00,B=1.50,C=1.80,D=3.10,E=5.00 。售货机可以接受1元,5角
💻 V
字号:
`timescale 1ns / 1ps
////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer:
//
// Create Date:    17:09:13 06/05/06
// Design Name:    
// Module Name:    SELLER
// Project Name:   
// Target Device:  
// Tool versions:  
// Description:
//
// Dependencies:
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
////////////////////////////////////////////////////////////////////////////////
module SELLER(clk,reset,
              IY,IWJ,IYJ,
				  Ia,Ib,Ic,Id,Ie,In,
				  BCD_YUAN,BCD_JIAO,
				  Sa,Sb,Sc,Sd,Se,
				  yuan,jiao,
				  price,count,
				  overflow);
input clk;
input reset;
input IY;
input IWJ;
input IYJ;
input Ia;
input Ib;
input Ic;
input Id;
input Ie;
input In;
output[6:0] BCD_YUAN;
output[6:0]BCD_JIAO;
output Sa;
output Sb;
output Sc;
output Sd;
output Se;
output yuan;
output jiao;
output price;
output count;
output overflow;

reg Sa,Sb,Sc,Sd,Se,yuan,jiao;
reg overflow;
reg[4:0] product;
reg [7:0] price;
reg[7:0] count;
wire[3:0] ten;					
wire[3:0] one;		

reg [1:0] state;
reg[1:0] next;

parameter start = 2'b00;
parameter process = 2'b01;
parameter change = 2'b11;
parameter a = 8'h10;
parameter b = 8'h15;
parameter c = 8'h18;
parameter d = 8'h31;
parameter e = 8'h50;

assign ten = count[7:4];
assign one = count[3:0];

decode47 d1(ten,BCD_YUAN);
decode47 d2(one,BCD_JIAO);

initial begin
	 	count = 8'h00;
		price = 8'h00;
		state = start;
		next = start;
		product = 5'b00000;
		Sa = 0;
		Sb = 0;
		Sc = 0;
		Sd = 0;
		Se = 0;
		yuan = 0;
		jiao = 0;
		overflow=0;
        end
		
always @( posedge clk )
	 begin
	 	Sa = 0;
		Sb = 0;
		Sc = 0;
		Sd = 0;
		Se = 0;
	 	yuan = 0;
		jiao = 0;
		
		 if (reset==1)
				 begin
				 	  Sa = 0;
					  Sb = 0;
		           Sc = 0;
		           Sd = 0;
		           Se = 0;
		           yuan = 0;
		           jiao = 0;
					  count = 8'h00;
		           price = 8'h00;
		           state = start;
		           next = start;
		           product = 5'b00000;
				  	  overflow=0;
				  end
		
		case( state )
		start: begin
					count = 0;
					next = start;
					product = 0;
					
					if( Ia || Ib || Ic || Id || Ie  )
						begin		if( Ia ) begin price = a; product = 5'b00001;	end
							else  if( Ib ) begin price = b; product = 5'b00010;	end
							else  if( Ic ) begin price = c; product = 5'b00100;	end
							else  if( Id ) begin price = d; product = 5'b01000;	end
							else  if( Ie ) begin price = e; product = 5'b10000;	end
							next = process;
						end	 							
					else	if( IY || IWJ || IYJ )
								begin		if( IY )		count[7:4] = 1;
									      else	if( IWJ )		count[3:0] = 5;
									      else 	if( IYJ )		count[3:0] = 1;
									      next = change;
								end
				 end
		process: begin
					next = process;
					if( In )		next = change;
					if( IY ) 	count[7:4] = count[7:4] + 1;
					if( IWJ )		begin	
										count[3:0] = count[3:0] + 5;
										if( count[3:0] > 9 )
											begin		count[3:0] = count[3:0] + 6;
														count[7:4] = count[7:4] + 1;
											end
									end
					if( IYJ ) 	begin		
										if( count[3:0] == 9 )
											begin		count[3:0] = 0;
														count[7:4] = count[7:4] + 1;
											end
										else	count[3:0] = count[3:0] + 1;
									end
					
					if (count>8'h99) 
					        begin 
							        overflow=1;
							        next=change;
									  { Se, Sd, Sc, Sb, Sa }=5'b00000;
									  price=0;
									  yuan=0;
									  jiao=0;

							  end
					else if( count == price )
							  begin	 	
							  { Se, Sd, Sc, Sb, Sa } = product;
								next=start;
							  end
					
					else if (count>price)
	 						 begin
								 { Se, Sd, Sc, Sb, Sa } = product;
							   if ( count[3:0] < price[3:0] )
									begin	  count = count - price;
											  count[3:0] = count[3:0] - 6;
									end
							   else  count = count - price; 
  							  next=change;						
						    end
					end

		change:	   begin
							next = change;
							if( count[7:4] > 0 )	 
							         begin		
										     yuan = 1;
											  count[7:4] = count[7:4] - 1;
										end
						  if( count[3:0] > 0 )	
						            begin		
										     jiao = 1;
									        count[3:0] = count[3:0] - 1;							
										end														
						end
	  default:	next = start;
	  endcase
	  	  state = next;
	 end
endmodule


module decode47( in, out );
    input[3:0] in;
    output[6:0] out;
    reg[6:0] out;
	 always @( in )
	   begin  
		  	case(in)
	4'b0000:out = 7'b1000000;
	4'b0001:out = 7'b1111001;
	4'b0010:out = 7'b0100100;
	4'b0011:out = 7'b0110000;
	4'b0100:out = 7'b0011001;
	4'b0101:out = 7'b0010010;
	4'b0110:out = 7'b0000010;
	4'b0111:out = 7'b1111000;
	4'b1000:out = 7'b0000000;
	4'b1001:out = 7'b0010000;
	4'b1010:out = 7'b0001000;
	4'b1011:out = 7'b0000011;
	4'b1100:out = 7'b1000110;
	4'b1101:out = 7'b0100001;
	4'b1110:out = 7'b0000110;
	4'b1111:out = 7'b0001110;
			default: out = 7'b0000000;
			endcase
	   end
endmodule 

⌨️ 快捷键说明

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