开发工具:
文件大小: 14kb
下载次数: 0
上传时间: 2012-06-05
详细说明: 程序可行library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity mudecoder is port(binaryin:in std_logic_vector(1 to 5); --5位二进制码的输入端口 bcdout1:out std_logic_vector(1 to 7); --七段译码器输出端口 bcdout2:out std_logic_vector(1 to 7) ); end mudecoder ; architecture m of mudecoder is signal tembinaryin:std_logic_vector(1 to 5); begin process(binaryin) begin tembinaryin<=binaryin; case tembinaryin is --把0到9的5位二进制码转换成七段译码 when"00000"=>bcdout1<="111111 0";bcdout2<="1111110"; when"00001"=>bcdout1<="1111110";bcdout2<="0110000"; when"00010"=>bcdout1<="1111110";bcdout2<="1101101"; when"00011"=>bcdout1<="1111110";bcdout2<="1111001"; when"00100"=>bcdout1<="1111110";bcdout2<="0110011"; when"00101"=>bcdout1<="1111110";bcdout2<="1011011"; when"00110"=>bcdout1<="1111110";bcdout2<="1011111"; when"00111"=>bcdout1<="1111110";bcdout2<="1110000"; when"01000"=>bcdout1<="1111110";bcdout2<="1111111"; when"01001"=>bcdout1<="1111110";bcdout2<="1111011"; --把10到19的5位二进制码转换成七段译码 when"01010"=>bcdout1<="0110000";bcdout2<="1111110"; when"01011"=>bcdout1<="0110000";bcdout2<="0110000"; when"01100"=>bcdout1<="0110000";bcdout2<="1101101"; when"01101"=>bcdout1<="0110000";bcdout2<="1111001"; when"01110"=>bcdout1<="0110000";bcdout2<="0110011"; when"01111"=>bcdout1<="0110000";bcdout2<="1011011"; when"10000"=>bcdout1<="0110000";bcdout2<="1011111"; when"10001"=>bcdout1<="0110000";bcdout2<="1110000"; when"10010"=>bcdout1<="0110000";bcdout2<="1111111"; when"10011"=>bcdout1<="0110000";bcdout2<="1111011"; --把20到21的5位二进制码转换成七段译码 when"10100"=>bcdout1<="1101101";bcdout2<="1111110"; when"10101"=>bcdout1<="1101101";bcdout2<="0110000"; --如果5位二进制码不在0到21范围内,那么两个七段译码器都显示0 when others=>bcdout1<="1101101";bcdout2<="1111110"; end case; end process; end m; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; --引用必要的库函数和包集合 entity pingponggame is --实体名为pingponggame port(reset:in std_logic; clk:in std_logic; startbutton:in std_logic; --开始游戏输入端口 serve:in std_logic_vector(1 to 2); --发球输入端口 hit1,hit2:in std_logic; --甲和乙的击球输入端口 --控制8个发光二极管的输出端口 light:out std_logic_vector(1 to 8); score11,score12,score21,score22:out std_logic_vector(1 to 7)); --4个用于控制4个7段译码器的输出端口 end pingponggame; architecture game of pingponggame is type pingpong is (waitserve,light1on,ballmoveto2,allow2hit, light8on,ballmoveto1,allow1hit); ---设置7个状态,为枚举数据类型,记为pingpong signal state:pingpong; signal i:integer range 0 to 8; signal count1,count2:std_logic_vector(1 to 5):="00000"; ---内部计数器,是5位二进制变量 component mudecoder is port(binaryin: in std_logic_vector(1 to 5); bcdout1:out std_logic_vector(1 to 7); bcdout2:out std_logic_vector(1 to 7) ); end component; ---调用记分译码器 begin process(clk) --状态机进程 begin --进程开始 if reset='1' then --异步置位 i<=0;count1<="00000";count2<="00000"; elsif clk'event and clk='1' then --当处于时钟inclock上升沿时 if count1="10101"or count2="10101"then i<=0;count1<="00000";count2<="00000"; elsif startbutton='0' then i<=0;count1<="00000";count2<="00000"; else --以下case语句是程序中最关键的状态机部分 case state is when waitserve=> --进程处于等待发球状态 case serve is when "10"=> i<=1;state<=light1on; when "01"=> i<=8;state<=light8on; when "11"=>i<=0; when others=> i<=0; end case; when light> --进程处于第一盏灯亮状态 i<=2; if hit2='1' then i<=0; count1<=count1+1;state<=waitserve; else state<=ballmoveto2; end if; when light> --进程处于第八盏灯亮状态 i<=7; if hit1='1' then i<=0; count2<=count2+1;state<=waitserve; else state<=ballmoveto1; end if; when ballmoveto1=> --进程处于球向甲移动状态 if hit1='1' then i<=0; count2<=count2+1;state<=waitserve; elsif i=2 then i<=1; state<=allow1hit; else i<=i-1; end if; when ballmoveto2=> --进程处于球向乙移动状态 if hit2='1'then i<=0; count1<=count1+1;state<=waitserve; elsif i=7 then i<=8; state<=allow2hit; else i<=i+1; ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.