then mminite1:=\
mminite2:=mminite2+1; if mminite2=\
then mminite2:=\ end if; end if;
end if; ---------分校验 if s3='1' then
mhour11:=mhour11+1; mhour21:=mhour21+1;
if mhour11=\ mhour12:=mhour12+1;
end if;
if mhour11=\and mhour12=\
then mhour11:=\
end if;
if mhour21=\ mhour22:=mhour22+1;
end if;
if mhour21=\mhour22=\
then mhour21:=\
end if;
end if;-------时校验
else msecond1:=msecond1+1;-----正常计时工作 if msecond1=\
then msecond1:=\
msecond2:=msecond2+1; if msecond2=\
then msecond2:=\
mminite1:=mminite1+1; if mminite1=\
then mminite1:=\
mminite2:=mminite2+1; if mminite2=\
then mminite2:=\ mhour11:=mhour11+1; mhour21:=mhour21+1;
if mhour11=\ mhour12:=mhour12+1;
end if;
if mhour11=\and mhour12=\
then mhour11:=\
end if;-------12小时制 if mhour21=\ mhour22:=mhour22+1;
end if;
if mhour21=\mhour22=\
then mhour21:=\
end if;----------24小时制
end if; end if; end if; end if;
if (msecond1=\and (msecond2=\and (mminite1=\and (mminite2=\
then cout<='1'; else cout<='0'; end if; end if; end if;
second1<=msecond1; second2<=msecond2; minite1<=mminite1; minite2<=mminite2;
if change='0' then hour1<=mhour11;hour2<=mhour12;
else hour1<=mhour21;hour2<=mhour22;------12/24小时制转换 end if;
end process;
end architecture one;
三:系统以及各个模块的仿真波形
顶层文件仿真波形
四、系统调试运行结果说明与分析
实验箱选择模式6。CLK接入1HZ的信号,数字钟开始计数,按下SET键进行时,分,秒的校准(分别按下S1,S2,S3进行校准),按下CHANGE键进行12/24小时制的切换,数码显示1,2,3,4,5,6分别显示秒,分和小时。
五:结论与体会
通过调试,该系统能够完成预期的目标,并且计时较为准确,各部分功能完
成的也很好。这是继第一次实验后的又一成功,尽管程序还不是自己编写的,但是使我们看到了数电实验丰富的内容和独特的魅力。
(三)乒乓游戏机
一:系统功能概述
① 两人乒乓球游戏能够模拟乒乓球比赛的基本过程和规则,并能自动裁判计分,在游戏中,以一排发光管交替发光知识乒乓球的行进路径,其行进速度可有输入的时钟信号clk控制。 ② Catcher是乒乓球街球控制模块,即发光管亮到最后一个的瞬间,若检测到对应的表示球拍的键的信号,立即将“球”反向运行:如果没有检测到该键信号,将给出出错音,同时为对方加分,并将计分现实出来。 ③ Cout4和cout10分被是失球计数器的高低位计数模块。Direction是乒乓球行进方向控制模块,主要由发球键控制。Sound是失球提示发声模块。
二:系统组成以及系统各部分的设计
总控制模块(BALLCTRL.VHD)
library ieee;
use ieee.std_logic_1164.all; entity ballctrl is
port(clr:in std_logic;
——系统复位
bain:in std_logic; bbin:in std_logic; serclka:in std_logic; serclkb:in std_logic;
clk:in std_logic; bdout:out std_logic; serve:out std_logic; serclk:out std_logic; ballclr:out std_logic; ballen:out std_logic); end entity ballctrl;
architecture behave of ballctrl is signal bd:std_logic; signal ser:std_logic; begin
bd<=bain or bbin;
ser<=serclka or serclkb; serclk<=ser; bdout<=bd; process(clr,clk,bd) begin
if(clr='1')then serve<='1'; ballclr<='1'; Else if(bd='1')then ballclr<='1'; if(ser='1')then ballen<='1'; serve<='0'; else
ballen<='0'; serve<='1'; end if; else
ballclr<='0'; end if; end if;
end process;
end architecture behave;
——左球拍 ——右球拍 ——左球拍准确接球或发球 ——右球拍准确接球或发球 ——乒乓球灯移动时钟 ——球拍接球脉冲 ——发球状态信号 ——球拍准确接球信号 ——乒乓球灯清零信号 ——乒乓球灯使能
——球拍准确接球信号 ——球拍接球脉冲
——系统复位
——系统处在发球状态 ——乒乓球灯清零 ——系统正常 ——球拍发球或接球时 ——乒乓球灯清零
——球拍发球或准确接球 ——乒乓球灯使能允许 ——系统处在接球状态
——乒乓球等被禁止 ——系统处在发球状态
——没有发球或接球时乒乓灯不清零
乒乓球灯模块(BALLPATH.VHD)
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity ballpath is
port(clk:in std_logic; ——乒乓球灯前进时钟 clr:in std_logic; ——乒乓球灯清零 way:in std_logic; ——乒乓球灯前进方向 en:in std_logic; ——乒乓球灯使能
ballout:out std_logic_vector(7 downto 0)); ——乒乓球灯用来观察乒乓球的路线 end entity ballpath;
architecture behave of ballpath is
signal lamp:std_logic_vector(9 downto 0); begin
process(clk,clr,en) begin
if(clr='1')then ——清零 lamp<=\ elsif en='0'then
elsif(clk'event and clk='1')then ——使能允许,乒乓球灯前进 if(way='1')then ——乒乓球灯右移 lamp(9 downto 1)<=lamp(8 downto 0); lamp(0)<='0'; Else ——乒乓球灯左移 lamp(8 downto 0)<=lamp(9 downto 1); lamp(9)<='0'; end if; end if;
ballout<=lamp(8 downto 1); end process;
end architecture behave;
乒乓球拍模块(CATCHER.VHD)
library ieee;
use ieee.std_logic_1164.all; entity catcher is
port(ball:in std_logic; net:in std_logic; serclk复位
bclk:in std_logic; serve:in std_logic; couclk:out std_logic; serclk:out std_logic); end entity catcher;
architecture behave of catcher is begin
——接球点,即乒乓球灯的末端
——乒乓球灯的中点,乒乓球过中点时,couclr,
——球拍接球信号 ——发球信号
——正确接球信号,接到球时为1