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

📄 pingpang.txt

📁 乒乓球游戏机实验报告实验人: 大火虎设计课题: 用VHDL设计一个乒乓球游戏机,用开关来摸拟球手及裁判,用LED来模拟乒乓球,采用每局十一球赛制,比分由七段显示器显示. 设计思路: 采用按功能分块,将
💻 TXT
字号:
library IEEE;
USE IEEE.STD_LOGIC_1164.all;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;


ENTITY statemachine IS
	port(
		CLK	: in std_logic;
		reset	: in std_logic;
		startA,hitA,startB,hitB	:in std_logic;
		scoreA,scoreB	:in integer range 0 to 21;
		clear,increaseA,increaseB	:out std_logic;
		tablelight	:out std_logic_vector(0 to 8);
		Awin,Bwin	:out std_logic
	    );
	end;
	
		
	ARCHITECTURE behavior OF statemachine IS 
	type state_type is						

	(waitstate,AtoB,BtoA,Ascore,Bscore,finalresult);
	signal state:state_type;
	signal tablestate:integer range 0 to 8;
	begin
		process(clk,reset)
	begin
		if reset='1' then
		state<=waitstate;
		clear<='1';
		Awin<='0';
		Bwin<='0';
	elsif rising_edge(clk) then
	case state is
		when waitstate=>
		clear<='0';
		increaseA<='0';
		increaseB<='0';
		if ((scoreA=21) or (scoreB=21)) then
		
		 state<=finalresult;
		else
		 if startA='1' then
		    state<=AtoB;
		    tablestate<=0;
		 else
			if startB='1' then
			   state<=BtoA;
			   tablestate<=8;
			else
			    state<=waitstate;
			end if;
		 end if;
		end if;
		when AtoB=>
			if hitB='1' then
				if tablestate<=4 then
				 state<=Ascore;
				else
				 state<=BtoA;
				end if;
			else
				if tablestate=8 then
				 state<=Ascore;
				else
				 tablestate<=tablestate+1;
				end if;
			end if;
		when BtoA=>
			if hitA='1' then
				if tablestate>=4 then
				 state<=Bscore;
				else
				 state<=AtoB;
				end if;
			else
				if tablestate=0 then
				 state<=Bscore;
				else
				 tablestate<=tablestate-1;
				end if;
			end if;
		when Ascore=>
			increaseA<='1';
			state<=waitstate;
		when Bscore=>
			increaseB<='1';
			state<=waitstate;
		when finalresult=>
			if (scoreA=21) then
				Awin<='1';
			else
				Bwin<='1';
			end if;
		when others=>
			state<=waitstate;
		end case;
		end if;
	end process;


	process(clk)
	begin
		if falling_edge(clk) then
			if ( (state=AtoB) or (state=BtoA) ) then
			 case tablestate is
			  when 0=>tablelight<="100000000"; 	
			  when 1=>tablelight<="010000000";
			  when 2=>tablelight<="001000000";
			  when 3=>tablelight<="000100000";
			  when 4=>tablelight<="000010000";
			  when 5=>tablelight<="000001000";
			  when 6=>tablelight<="000000100";
			  when 7=>tablelight<="000000010";
			  when 8=>tablelight<="000000001";
			  when others=>tablelight<="00000000";
			 end case;
			else
			 tablelight<="000000000";
			end if;
		end if;
	end process;
	end;		

⌨️ 快捷键说明

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