七人表决器,外加按键,LED灯和数码管显示。
相应外设的功能:
按键:表决通过人数(注意按键一般是按下为0,设计程序是需要注意逻辑)
LED:当4人以上通过即表示通过决议,LED灯亮。
数码管:显示通过的人数
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------------
entity biaojueqi is
port(
k1,K2,K3,K4,K5,K6,K7 : in std_logic; --输入:7个人
ledag : out std_logic_vector(6 downto 0); --数码管显示
m_Result : out std_logic --表决结果
);
end biaojueqi ;
--------------------------------------------------------------------
architecture behave of biaojueqi is
signal K_Num : std_logic_vector(2 downto 0);
signal K1_Num,K2_Num: std_logic_vector(2 downto 0);
signal K3_Num,K4_Num: std_logic_vector(2 downto 0);
signal K5_Num,K6_Num: std_logic_vector(2 downto 0);
signal K7_Num : std_logic_vector(2 downto 0);
begin
process(K1,K2,K3,K4,K5,K6,K7) --计算表决同意人数
begin
K1_Num<='0'&'0'&K1;
K2_Num<='0'&'0'&K2;
K3_Num<='0'&'0'&K3;
K4_Num<='0'&'0'&K4;
K5_Num<='0'&'0'&K5;
K6_Num<='0'&'0'&K6;
K7_Num<='0'&'0'&K7;
end process;
process(K1_Num,K2_Num,K3_Num,K4_Num,K5_Num,K6_Num,K7_Num)
begin
K_Num<=K1_Num+K2_Num+K3_Num+K4_Num+K5_Num+K6_Num+K7_Num;
end process;
process(K_Num) --根据人数输出结果
begin
if(K_Num>3) then
m_Result<='1';
else
m_Result<='0';
end if;
end process;
process(K_Num) --根据人数数码管显示表决通过人数
begin
case K_Num is
when "000"=>ledag<="0111111";
when "001"=>ledag<="0000110";
when "010"=>ledag<="1011011";
when "011"=>ledag<="1001111";
when "100"=>ledag<="1100110";
when "101"=>ledag<="1101101";
when "110"=>ledag<="1111101";
when "111"=>ledag<="0000111";
when others=>ledag<="0000000";
end case;
end process;
end behave;
设按键同意灯亮为输入高电平(逻辑为1),否则,不按键同意 为输入低电平(逻辑为0)。输出逻辑为1表示赞成;输出逻辑为0表示表示反对。 根据题意和以上设定,列逻辑状态表如表19-1。
小结:用Quarter ii时注意板子的型号,用单个数码管时注意接相应的引脚。开发板上扩展口对应的编号,到时候定义引脚要用。注意数码管是共阴极还是共阳极,可以用万能表的蜂鸣档测试一下便知道了。
来源:CSDN
作者:weixin_44891114
链接:https://blog.csdn.net/weixin_44891114/article/details/103506647