离散数学实验报告1
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
离散数学实验报告
实验名称:三人表决器的设计实验
姓名:丁施瑶
学号:20110801110
班级:计算机科学与技术一班
实验日期:2012年3月10日
实验内容:
1.实验题目:三人表决器的设计实验
2.三人表决器的功能描述:
三个人分别用手指拨动开关SW1、SW2、SW3来表示自己的意愿,如果对某决议同意,各人就把自己的指拨开关拨到高电平(上方),不同意就把自己的指拨开关拨到低电平(下方)。表决结果用LED(高电平亮)显示,如果决议通过那么实验板上L2亮;如果不通过那么实验板上L1亮;如果对某个决议有任意二到三人同意,那么此决议通过,L2亮;如果对某个决议只有一个人或没人同意,那么此决议不通过,L1亮。
3.三人表决器的逻辑功能:
表决结果与多数人意见相同。
设X0、X1、X2为三个人(输入逻辑变量),赞成为1,不赞成为0; Y0为表决结果(输出逻辑变量),多数赞成Y0为1,否则,Y0为0. 其真值表如表1所示。
表1 “三人表决器”真值表
输入逻辑变量输出逻辑变量
灯
由真值表写出逻辑表达式并化简得:Y0=X0*X1+X0*X2+X1*X2
4.参考代码/程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity bjq3 is
port (a,b,c:in std_logic;
y:out std_logic);
end;
architecture one of bjq3 is
begin
y<=(a and b ) or (a and c) or (b and c );
end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity bjq3 is
port (a,b,c:in std_logic;
y:out std_logic);
end;
architecture one of bjq3 is
signal m:std_logic_vector(2 downto 0);
begin
m<=a & b & c;
y<='0' when (m="000")or(m="001")or(m="010")or(m="100" ) else
'1';
end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity bjq3 is
port (a,b,c:in std_logic;
y:out std_logic);
end;
architecture one of bjq3 is
signal m: std_logic_vector(2 downto 0);
begin
m<=a&b&c;
with m select
y<='0'when "000"|"001"|"010"|"100",
'1'when others;
end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity bjq3 is
port (m:in std_logic_vector(2 downto 0); y:out std_logic);
end;
architecture one of bjq3 is
begin
process (m)
begin
case m is
when "000"|"001"|"010"|"100"=>y<='0'; when others =>y<='1';
end case;
end process;
end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity bjq3 is
port (m:in std_logic_vector(2 downto 0); y:out std_logic);
end;
architecture one of bjq3 is
begin
process (m)
begin
if m="000" then y<='0';
elsif m="001"then y<='0';
elsif m="010"then y<='0';
elsif m="011"then y<='1';
elsif m="100"then y<='0';
elsif m="101"then y<='1';
elsif m="110"then y<='1';
elsif m="111"then y<='1';
end if;
end process;
end;