当前位置:首页 > FPGA实验报告
实验三、乒乓球实验
一、实验目的
1. 掌握时钟分频电路的HDL 设计; 2. 掌握CASE 语句的使用;
3. 掌握VHDL 模块化程序设计方式。
二、实验器材
1. KH-310 下载板; 2. KH-310 时钟模块;
3. KH-310 LED 显示模块; 4. KH-310 七段数码管模块。
三、实验内容
设计一个乒乓球游戏机,模拟乒乓球比赛基本过程和规则,并能自动裁判和计分。
四、文件档名
加载:corna.sof 烧录:corna.pof
工程项目文件:corna.qpf
五、实验原理
乒乓球游戏机是用8~16 个发光二极管代表乒乓球台,中间两个发光二极管兼作乒乓球网,用点亮的发光二极管按一定方向移动来表示球的运动。另外设置发球开关:Af、Bf;和接球开关Aj、Bj。利用若干七段数码管作为计分牌。
甲乙双方按乒乓球比赛规则来操作开关。当甲方按动发球开关Af 时,靠近甲方的第一个灯亮,然后顺序向乙方移动。当球过网后,乙方可以接球,接球后灯反方向运动,双方继续比赛,如果一方提前击球(过网击球)或未击到球,则判失分,对方加分。重新发球后继续比赛。
六、实验连线
图3.24
输入信号:
控制时钟CLK:可调时钟SW7 输入;
接发球输入Af,Aj,Bf,Bj:脉冲发生器EPI0~EPI3(Pin236 Pin238 Pin237 Pin239); 系统复位Clr:拨码开关I01; 输出信号:
乒乓球信号shift[15..0]:LED 显示模块O25~O40;
计分输出q[6..0]:七段数码管O56~O50(Pin79~Pin73)(JP1);
Sellread[3..0]:数码管选择SO61~SO58(Pin86~Pin83)(数码管跳线接左侧扫描方式)。
七、实验步骤
下载程序 ,将SW3 的IO1 拨到ON 后可进行比赛,PULS1 为甲方发球,PULS2 为甲方接球,PULS3 为乙方发球,PULS4 为乙方接球。LED 灯中,始终点亮的代表球网,将SW7 拨至第四段的位置。点击发球之后,双方可进行比赛,比赛规则参照实验原理部分。
八、实验程序
说明:下面的程序仅实现对当前局进行计分,需手工清除计分进行下一局比赛,同学们可以增加
局分显示,如一方记满11 分,当前局计分自动清零,局比分自动增加。 1. VHDL 程序
Library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity corna is port (
clr,af,aj,bf,bj,clk:in std_logic;
shift:out std_logic_vector(15 downto 0);
ah,al,bh,bl: out std_logic_vector(3 downto 0) ); end corna;
architecture corna_arc of corna is signal amark,bmark : integer; signal clk1:std_logic;
signal fen:std_logic_vector(9 downto 0); begin process
begin
wait until clk='1'; fen<=fen+1; clk1<=fen(7); end process; process(clr,clk1)
variable a,b : std_logic;
variable she: std_logic_vector(15 downto 0); begin
if clr='0' then a:='0'; b:='0';
she:=\ amark<=0; bmark<=0;
elsif clk1'event and clk1 ='1' then if a='0' and b='0' and af='1' then a:='1';
she:=\
elsif a='0' and b='0' and bf='1' then b:='1';
she:=\ elsif a='1' and b='0' then if she>128 then if bj='1' then amark<=amark+1; a:='0'; b:='0';
she:=\ else
she:='0'&she(15 downto 1); end if;
elsif she=0 then
amark<=amark+1; a:='0'; b:='0'; else
if bj='1' then a:='0'; b:='1'; else
she:='0'& she(15 downto 1); end if; end if;
elsif a='0' and b='1' then if she<256 and she/=0 then if aj='1' then bmark<=bmark+1; a:='0'; b:='0';
she:=\ else
she:=she(14 downto 0)&'0'; end if;
elsif she=0 then bmark<=bmark+1; a:='0'; b:='0'; else
if aj='1' then a:='1'; b:='0'; else
she:=she(14 downto 0)&'0'; end if; end if; end if; end if; shift<=she; end process;
process(clk,clr,amark,bmark)
variable aha,ala,bha,bla: std_logic_vector(3 downto 0); variable tmp1,tmp2: integer; begin
if clr='0' then aha:=\
共分享92篇相关文档