找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2677|回复: 2
收起左侧

抢答器vhdl源程序

[复制链接]
ID:260092 发表于 2017-12-11 14:18 | 显示全部楼层 |阅读模式
动定义为“开始”(即enable)的开关后,一排指示灯变亮,之后抢答开始,有4个扳动开关代表4个抢答器,数码管将显示出最先被扳动的开关的序号,同时发出声音,表示抢答成功。若未按“开始”前,有任意开关被扳动,则数码管显示被扳动开关的序号,并发出另一种声音,表示有人抢答
0.png
vhdl源程序如下:
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;

  5. --  Uncomment the following lines to use the declarations that are
  6. --  provided for instantiating Xilinx primitive components.
  7. --library UNISIM;
  8. --use UNISIM.VComponents.all;

  9. entity qiangdaqi is
  10. port(enable:in std_logic;
  11.      --reset:in std_logic;
  12.           a:in std_logic;
  13.           b:in std_logic;
  14.           c:in std_logic;
  15.           d:in std_logic;
  16.           clk:in std_logic;
  17.           spkout:out std_logic;
  18.           cs:buffer std_logic_vector(1 downto 0);
  19.           --cs:buffer std_logic;
  20.           led:out std_logic_vector(7 downto 0);
  21.           seg:out std_logic_vector(3 downto 0);
  22.           segment:out std_logic_vector(7 downto 0)
  23.           );
  24. end qiangdaqi;

  25. architecture Behavioral of qiangdaqi is
  26. -- signal led1,led0:std_logic_vector(7 downto 0);
  27. signal flag:std_logic;
  28. signal output:std_logic_vector(3 downto 0);
  29. signal start:std_logic;
  30. signal index:std_logic_vector(5 downto 0);
  31. signal count: std_logic_vector(25 downto 0);
  32. signal fclk:std_logic;
  33. --signal led1:std_logic_vector(7 downto 0);

  34. component input is
  35.     port(--en:in std_logic;
  36.               clk:in std_logic;
  37.                         --reset:in std_logic;
  38.               a:in std_logic;
  39.                         b:in std_logic;
  40.                         c:in std_logic;
  41.                         d:in std_logic;
  42.                         output:out std_logic_vector(3 downto 0);
  43.                         flag:out std_logic);
  44. end component;

  45. component light is
  46.     port(--en:in std_logic;
  47.               clk:std_logic;
  48.                         input:in std_logic_vector(3 downto 0);
  49.                         flag:in std_logic;
  50.                         seg:out std_logic_vector(3 downto 0);
  51.                         ledout:out std_logic_vector(7 downto 0));
  52. end component;

  53. component control is
  54.     port(start:in std_logic;
  55.               a:in std_logic;
  56.                         b:in std_logic;
  57.                         c:in std_logic;
  58.                         d:in std_logic;
  59.                         clk:in std_logic;
  60.                         spkout:out std_logic;
  61.                         index:buffer std_logic_vector(5 downto 0)
  62.          );
  63. end component;

  64. --component lcd is
  65.    -- port(clk:in std_logic;
  66.                 --        enable:in std_logic;
  67.                 --        led:out std_logic_vector(7 downto 0);
  68.                 --        cs:buffer std_logic_vector(1 downto 0);
  69.                 --        start:out std_logic
  70. --                        );
  71. --end component;

  72. begin
  73. --cs<=cs1;
  74. --led<=led1;
  75. process(fclk,enable)
  76. begin
  77. --cs<="00";
  78. --led<="11111111";
  79.      if fclk'event and  fclk='1' then
  80.         if  enable='0' then
  81.                       cs<="01";
  82.                                 --led<="11111111";
  83.                                 if(fclk='1') then
  84.                  led<="11111110";
  85.                                 end if;
  86.                                 if(fclk='0') then
  87.                  led<="11111100";
  88.                                 end if;
  89.                                 if(fclk='1') then
  90.                  led<="11111000";
  91.                                 end if;
  92.                                 if(fclk='0') then
  93.                  led<="11110000";
  94.                                 end if;
  95.                                 if(fclk='1') then
  96.                  led<="11100000";
  97.                                 end if;
  98.                                 if(fclk='0') then
  99.                  led<="11000000";
  100.                                 end if;
  101.                                 if(fclk='1') then
  102.                  led<="10000000";
  103.                                 end if;
  104.                                 if(fclk='0') then
  105.                  led<="00000000";
  106.                                 end if;
  107.                  start <='1';
  108.                         else
  109.             start<='0';
  110.                                 cs<="00";
  111.                       --led<="11111111";
  112.                         end if;
  113.           end if;
  114. end process;

  115. process(clk)
  116. begin
  117.          if (clk'event and clk='1') then
  118.           if(count=50000000)        then
  119.             count<="00000000000000000000000000";
  120.           else
  121.                  count<=count+1;
  122.      end if;
  123.         end if;
  124. end process;

  125. fclk <= count(25);

  126. --process(fclk)
  127. --begin
  128. --if(fclk'event and fclk='1') then
  129.    --counter<="000";



  130. --process(clk,enable)
  131. --begin
  132. --if(clk'event and clk='1') then
  133.   -- if(enable'event and enable='0') then
  134.      --   cs<="01";
  135.           --   led<="11111110";
  136.           --   led<="11111100";
  137.           --   led<="11111000";
  138. ……………………

  139. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码


所有资料51hei提供下载:
抢答器.rar (4.32 KB, 下载次数: 42)
回复

使用道具 举报

ID:260092 发表于 2017-12-11 14:20 | 显示全部楼层
eached for the definition of "start" (enable) the switch, a row of bright lights changed, after Responder, a four flick of a switch on behalf of four Responder, digital controls are to be shown first to be reached for the switch serial number, also issued voices saying Responder success. If the failure to "start" before it was switched on the flick, Digital Display was the flick of a switch the serial numbers, and issued another voice, someone Responder.
回复

使用道具 举报

ID:323384 发表于 2019-6-3 12:13 | 显示全部楼层
真棒真棒真棒
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表