免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验说明:两人乒乓球游戏机是用9个发光二极管代表乒乓球台,用点亮的发光二极管按一定的方向移动来表示球的运动。在游戏机的两侧各设置一个开关,即击球开关Hit A,HitB。 甲乙二人按乒乓球比赛规则来操作开关。当甲按动击球开关时,靠近甲的第一个二极管亮,然后发光二极管由甲向乙依次点亮,代表乒乓球的移动。当球过网(中 点)时,乙方可以击球。若乙方提前或是没击中球则判乙方失分,甲方的计分牌自动加分。然后重新发球,比赛继续。比赛直到一方分数达到11分时,比赛结束。实验要求:1.用两个开关表示HitA,HitB,当开关值为1时表示击球。 2.设置一个复位信号RESET.当reset有效时,计分牌清0。 3.用两个数码管来表示计分牌,当一方为11(即b)时,比赛结束。(数码管用静态模式)-library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity pingpang is Port ( clk : in STD_LOGIC; -时钟,与球飞行速度有关 hita : in STD_LOGIC; -A选手击球键 hitb : in STD_LOGIC; -B选手击球键 reset: in STD_LOGIC; -低电平异步复位,高电平比赛进行中 led0 : out STD_LOGIC_VECTOR (3 downto 0); -B选手得分 led1 : out STD_LOGIC_VECTOR (3 downto 0); led2 : out STD_LOGIC_VECTOR (3 downto 0); -A选手得分 led3 : out STD_LOGIC_VECTOR (3 downto 0); light :out STD_LOGIC_VECTOR (8 downto 0) -显示球飞行位置 );end pingpang;architecture Behavioral of pingpang issignal ascore1,ascore0,bscore1,bscore0:std_logic_vector(3 downto 0); -得分signal num:integer range 0 to 11; -正亮着的light序号 -0表示b侧落地,5表示网,10表示a侧落地,11表示全准备发球Begin process(clk,reset,hita,hitb)variable dir:integer range 0 to 2; -0:A=B; 1:B=A; 2:准备发球begin if reset=0 then -低电平异步复位,高电平比赛进行中 num=11; dir:=2; ascore1=0000; ascore0=0000; bscore1=0000; bscore0=0000; elsif rising_edge(clk) then if dir=2 and ascore11010 and bscore11011 then -准备发球,若已显示名次,则比赛结束,不再发球 if(hita=1) then -A发球 num=9; dir:=0; elsif(hitb=1) then -B发球 num=1; dir:=1; else num0 then -A=B,未落台 if hita=1 then -A连续击球两次 num=11; if(bscore1=0000) then -B得分 if(bscore0=1001) then bscore0=0000; bscore1=0001; else bscore0=bscore0+1; end if; elsif (bscore1=0001) then -B胜利,显示名次和分数 bscore0=0001;-1 bscore1=1011;-b end if; dir:=2; -进入发球状态 elsif hitb=1 then if num5 then -B正常击球 num=num+1; dir:=1; else -B提前击球 num=11; if(ascore1=0000) then -A得分 if(ascore0=1001) then ascore0=0000; ascore1=0001; else ascore0=ascore0+1; end if; elsif (ascore1=0001) then -A胜利,显示名次和分数 ascore0=0001;-1 ascore1=1010;-a end if; dir:=2; -进入发球状态 end if; else num=num-1; -球继续飞行 dir:=0; end if; elsif dir=1 and numA,未落台 if hitb=1 then -B连续击球两次 num=11; if(ascore1=0000) then -A得分 if(ascore0=1001) then ascore0=0000; ascore1=0001; else ascore0=ascore0+1; end if; elsif (ascore1=0001) then -A胜利,显示名次和分数 ascore0=0001;-1 ascore15 then -B正常击球 num=num-1; dir:=0; else -B提前击球 num=11; if(bscore1=0000) then -B得分 if(bscore0=1001) then bscore0=0000; bscore1=0001; else bscore0=bscore0+1; end if; elsif (bscore1=0001) then -B胜利,显示名次和分数 bscore0=0001;-1 bscore1=1011;-b end if; dir:=2; -进入发球状态 end if; else num=num+1; -球继续飞行 dir:=1; end if; elsif dir=0 and num=0 then -B侧落台 num=11; if(ascore1=0000) then if(ascore0=1001) then -A得分 ascore0=0000; ascore1=0001; else ascore0=ascore0+1; end if; elsif (ascore1=0001) then -A胜利,显示名次和分数 ascore0=0001;-1 ascore1=1010;-a end if; dir:=2; -进入发球状态 elsif dir=1 and num=10 then -A侧落台 num=11; if(bscore1=0000) then -B得分 if(bscore0=1001) then bscore0=0000; bscore1=0001; else bscore0=bscore0+1; end if; elsif (bscore1=0001) then -B胜利,显示名次和分数 bscore0=0001;-1 bscore1=1011;-b end if; dir:=2; -进入发球状态 end if; end if;end process; process(num) begin lightlight(0)light(1)light(2)light
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 房地产物业存量运营降本增效方案
- 公立医院科研平台建设设计
- 职场高效时间管理实操培训课件
- 溶洞地下水环境监测技术规范
- 高压管道焊接检验报告
- 七年级生物下册 第四单元 第七章 第一节 分析人类活动对生态系统的影响教学设计2 (新版)新人教版
- 医院门诊精细化管理方案
- 新课标版六年级上册道德与法治教学计划
- 《地质调查员常用勘查仪器操作培训手册》
- 垃圾处理场站从业人员安全培训计划
- 光伏发电站光伏方阵检修规程
- JJG 365-2008电化学氧测定仪
- 高等教育经济类自考-03333电子政务概论笔试(2018-2023年)真题摘选含答案
- 快递费成本分析报告
- 电动车充电桩维修培训课件
- 台球厅暂停营业通知(4篇)
- 人教版二年级上册《道德与法治》全册教案
- 初三数学开学第一课
- 河南省生产经营单位安全教育和培训档案样式
- 骨质疏松性骨折及其药物治疗
- GB/T 26144-2010法兰和对夹连接钢制衬氟塑料蝶阀
评论
0/150
提交评论