用VHDL语言实现四人智力竞赛抢答器的设计,高分寻高人解答
一、问题描述:设计一个4人参加的智力竞赛抢答计时器。电路具有回答问题时间控制功能。要求回答问题时间小于等于100妙(显示为0~99),时间显示采用倒计时方式。当达到限定时...
一、问题描述:
设计一个4人参加的智力竞赛抢答计时器。电路具有回答问题时间控制功能。要求回答问题时间小于等于100妙(显示为0~99),时间显示采用倒计时方式。当达到限定时间时,发出声响以示警告;当有某一参赛者首先按下抢答开关时,相应显示灯亮并伴有声响,此时抢答器不再接受其他输入信号。
二、功能要求:
1、用feng模块将选手按下按键信号输出高电平给锁存模块lockb,进行锁存的同时发出aim信号实现声音提示,并使count模块进行答题时间的倒计时,在计满100妙后送出声音提示;
2、用ch41a模块将抢答结果转换为二进制数;
3、用sel模块产生数码管片选信号;
4、用ch42a模块将对应数码管片选信号,送出需要的显示信号;
5、用七段译码器dispa模块进行译码。
要求给出完整,且已经经过调试正确的代码,代码中说明文字要详细,标出相关模块。以及详细原理图
高手 速度!分不是问题 如果回答的好 会继续加分 展开
设计一个4人参加的智力竞赛抢答计时器。电路具有回答问题时间控制功能。要求回答问题时间小于等于100妙(显示为0~99),时间显示采用倒计时方式。当达到限定时间时,发出声响以示警告;当有某一参赛者首先按下抢答开关时,相应显示灯亮并伴有声响,此时抢答器不再接受其他输入信号。
二、功能要求:
1、用feng模块将选手按下按键信号输出高电平给锁存模块lockb,进行锁存的同时发出aim信号实现声音提示,并使count模块进行答题时间的倒计时,在计满100妙后送出声音提示;
2、用ch41a模块将抢答结果转换为二进制数;
3、用sel模块产生数码管片选信号;
4、用ch42a模块将对应数码管片选信号,送出需要的显示信号;
5、用七段译码器dispa模块进行译码。
要求给出完整,且已经经过调试正确的代码,代码中说明文字要详细,标出相关模块。以及详细原理图
高手 速度!分不是问题 如果回答的好 会继续加分 展开
5个回答
展开全部
各模块VHDL源代码
1、抢答鉴别模块FENG的VHDL源程序
--feng.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY FENG IS
PORT(CP,CLR:IN STD_LOGIC;
Q :OUT STD_LOGIC);
END FENG;
ARCHITECTURE FENG_ARC OF FENG IS
BEGIN
PROCESS(CP,CLR)
BEGIN
IF CLR='0'THEN
Q<='0';
ELSIF CP'EVENT AND CP='0'THEN
Q<='1';
END IF;
END PROCESS;
END FENG_ARC;
2、片选信号产生模块SEL的VHDL源程序
--sel.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY SEL IS
PORT(CLK:IN STD_LOGIC;
a:OUT INTEGER RANGE 0 TO 7);
END SEL;
ARCHITECTURE SEL_ARC OF SEL IS 片选信号产生模块SEL
BEGIN
PROCESS(CLK)
VARIABLE AA:INTEGER RANGE 0 TO 7;
BEGIN
IF CLK'EVENT AND CLK='1'THEN
AA:=AA+1;
END IF;
A<=AA;
END PROCESS;
END SEL_ARC;
3、锁存器模块LOCKB的VHDL源程序
-lockb.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY LOCKB IS
PORT(D1,D2,D3,D4:IN STD_LOGIC;
CLK,CLR:IN STD_LOGIC;
Q1,Q2,Q3,Q4,ALM:OUT STD_LOGIC);
END LOCKB;
ARCHITECTURE LOCK_ARC OF LOCKB IS
BEGIN
PROCESS(CLK)
BEGIN
IF CLR='0'THEN
Q1<='0';
Q2<='0';
Q3<='0';
Q4<='0';
ALM<='0'; 模块LOCKB
ELSIF CLK'EVENT AND CLK='1'THEN
Q1<=D1;
Q2<=D2;
Q3<=D3;
Q4<=D4;
ALM<='1';
END IF;
END PROCESS;
END LOCK_ARC;
4、转换模块CH41A的VHDL源程序
--ch41a..vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY CH41A IS
PORT(D1,D2,D3,D4:IN STD_LOGIC;
Q:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END CH41A;
ARCHITECTURE CH41_ARC OF CH41A IS 转换模块CH41A
BEGIN
PROCESS(D1,D2,D3,D4)
VARIABLE TMP:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
TMP:=D1&D2&D3&D4;
CASE TMP IS
WHEN "0111"=>Q<="0001";
WHEN "1011"=>Q<="0010";
WHEN "1101"=>Q<="0011";
WHEN "1110"=>Q<="0100";
WHEN OTHERS=>Q<="1111";
END CASE;
END PROCESS;
END CH41_ARC;
5、3选1模块CH31A的VHDL源程序
--ch31a.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY CH31A IS
PORT(SEL:IN STD_LOGIC_VECTOR(2 DOWNTO 0);
D1,D2,D3:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
Q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END CH31A;
ARCHITECTURE CH31_ARC OF CH31A IS
BEGIN
PROCESS(SEL,D1,D2,D3)
BEGIN
CASE SEL IS
WHEN "000"=>Q<=D1;
WHEN "001"=>Q<=D2;
WHEN "111"=>Q<=D3;
WHEN OTHERS=>Q<="1111";
END CASE;
END PROCESS;
END CH31_ARC;
6、倒计时模块COUNT的VHDL源程序
倒计时模块COUNT如图16-7所示,该模块实现答题时间的倒计时,在计满100s后送出声音提示。
--count.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY COUNT IS
PORT(CLK,EN:IN STD_LOGIC; 倒计时 模块COUNT
H,L:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
SOUND:OUT STD_LOGIC);
END COUNT;
ARCHITECTURE COUNT_ARC OF COUNT IS
BEGIN
PROCESS(CLK,EN)
VARIABLE HH,LL:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
IF CLK'EVENT AND CLK='1'THEN
IF EN='1'THEN
IF LL=0 AND HH=0 THEN
SOUND<='1';
ELSIF LL=0 THEN
LL:="1001";
HH:=HH-1;
ELSE
LL:=LL-1;
END IF;
ELSE
SOUND<='0';
HH:="1001";
LL:="1001";
END IF;
END IF;
H<=HH;
L<=LL;
END PROCESS;
END COUNT_ARC;
7、显示译码模块DISP的VHDL源程序
--disp.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DISP IS 显示译码模块DISP
PORT(D:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
Q:OUT STD_LOGIC_VECTOR(6 DOWNTO 0));
END DISP;
ARCHITECTURE DISP_ARC OF DISP IS
BEGIN
PROCESS(D)
BEGIN
CASE D IS
WHEN"0000"=>Q<="0111111";
WHEN"0001"=>Q<="0000110";
WHEN"0010"=>Q<="1011011";
WHEN"0011"=>Q<="1001111";
WHEN"0100"=>Q<="1100110";
WHEN"0101"=>Q<="1101101";
WHEN"0110"=>Q<="1111101";
WHEN"0111"=>Q<="0100111";
WHEN"1000"=>Q<="1111111";
WHEN"1001"=>Q<="1101111";
WHEN OTHERS=>Q<="0000000";
END CASE;
END PROCESS;
END DISP_ARC;
1、抢答鉴别模块FENG的VHDL源程序
--feng.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY FENG IS
PORT(CP,CLR:IN STD_LOGIC;
Q :OUT STD_LOGIC);
END FENG;
ARCHITECTURE FENG_ARC OF FENG IS
BEGIN
PROCESS(CP,CLR)
BEGIN
IF CLR='0'THEN
Q<='0';
ELSIF CP'EVENT AND CP='0'THEN
Q<='1';
END IF;
END PROCESS;
END FENG_ARC;
2、片选信号产生模块SEL的VHDL源程序
--sel.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY SEL IS
PORT(CLK:IN STD_LOGIC;
a:OUT INTEGER RANGE 0 TO 7);
END SEL;
ARCHITECTURE SEL_ARC OF SEL IS 片选信号产生模块SEL
BEGIN
PROCESS(CLK)
VARIABLE AA:INTEGER RANGE 0 TO 7;
BEGIN
IF CLK'EVENT AND CLK='1'THEN
AA:=AA+1;
END IF;
A<=AA;
END PROCESS;
END SEL_ARC;
3、锁存器模块LOCKB的VHDL源程序
-lockb.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY LOCKB IS
PORT(D1,D2,D3,D4:IN STD_LOGIC;
CLK,CLR:IN STD_LOGIC;
Q1,Q2,Q3,Q4,ALM:OUT STD_LOGIC);
END LOCKB;
ARCHITECTURE LOCK_ARC OF LOCKB IS
BEGIN
PROCESS(CLK)
BEGIN
IF CLR='0'THEN
Q1<='0';
Q2<='0';
Q3<='0';
Q4<='0';
ALM<='0'; 模块LOCKB
ELSIF CLK'EVENT AND CLK='1'THEN
Q1<=D1;
Q2<=D2;
Q3<=D3;
Q4<=D4;
ALM<='1';
END IF;
END PROCESS;
END LOCK_ARC;
4、转换模块CH41A的VHDL源程序
--ch41a..vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY CH41A IS
PORT(D1,D2,D3,D4:IN STD_LOGIC;
Q:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END CH41A;
ARCHITECTURE CH41_ARC OF CH41A IS 转换模块CH41A
BEGIN
PROCESS(D1,D2,D3,D4)
VARIABLE TMP:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
TMP:=D1&D2&D3&D4;
CASE TMP IS
WHEN "0111"=>Q<="0001";
WHEN "1011"=>Q<="0010";
WHEN "1101"=>Q<="0011";
WHEN "1110"=>Q<="0100";
WHEN OTHERS=>Q<="1111";
END CASE;
END PROCESS;
END CH41_ARC;
5、3选1模块CH31A的VHDL源程序
--ch31a.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY CH31A IS
PORT(SEL:IN STD_LOGIC_VECTOR(2 DOWNTO 0);
D1,D2,D3:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
Q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END CH31A;
ARCHITECTURE CH31_ARC OF CH31A IS
BEGIN
PROCESS(SEL,D1,D2,D3)
BEGIN
CASE SEL IS
WHEN "000"=>Q<=D1;
WHEN "001"=>Q<=D2;
WHEN "111"=>Q<=D3;
WHEN OTHERS=>Q<="1111";
END CASE;
END PROCESS;
END CH31_ARC;
6、倒计时模块COUNT的VHDL源程序
倒计时模块COUNT如图16-7所示,该模块实现答题时间的倒计时,在计满100s后送出声音提示。
--count.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY COUNT IS
PORT(CLK,EN:IN STD_LOGIC; 倒计时 模块COUNT
H,L:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
SOUND:OUT STD_LOGIC);
END COUNT;
ARCHITECTURE COUNT_ARC OF COUNT IS
BEGIN
PROCESS(CLK,EN)
VARIABLE HH,LL:STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
IF CLK'EVENT AND CLK='1'THEN
IF EN='1'THEN
IF LL=0 AND HH=0 THEN
SOUND<='1';
ELSIF LL=0 THEN
LL:="1001";
HH:=HH-1;
ELSE
LL:=LL-1;
END IF;
ELSE
SOUND<='0';
HH:="1001";
LL:="1001";
END IF;
END IF;
H<=HH;
L<=LL;
END PROCESS;
END COUNT_ARC;
7、显示译码模块DISP的VHDL源程序
--disp.vhd
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DISP IS 显示译码模块DISP
PORT(D:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
Q:OUT STD_LOGIC_VECTOR(6 DOWNTO 0));
END DISP;
ARCHITECTURE DISP_ARC OF DISP IS
BEGIN
PROCESS(D)
BEGIN
CASE D IS
WHEN"0000"=>Q<="0111111";
WHEN"0001"=>Q<="0000110";
WHEN"0010"=>Q<="1011011";
WHEN"0011"=>Q<="1001111";
WHEN"0100"=>Q<="1100110";
WHEN"0101"=>Q<="1101101";
WHEN"0110"=>Q<="1111101";
WHEN"0111"=>Q<="0100111";
WHEN"1000"=>Q<="1111111";
WHEN"1001"=>Q<="1101111";
WHEN OTHERS=>Q<="0000000";
END CASE;
END PROCESS;
END DISP_ARC;
展开全部
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------------
entity exp19 is
port( Clk : in std_logic; --时钟信号
Rst : in std_logic; --复位信号
Kr : in std_logic_vector(3 downto 0); --键盘行
Kc : buffer std_logic_vector(3 downto 0); --键盘列
SPK : out std_logic; --扬声器输出
KEY_State : out std_logic; --按键指示
Door : buffer std_logic; --门状态
Display : out std_logic_vector(7 downto 0); --七段码管显示
SEG_SEL : buffer std_logic_vector(2 downto 0)); --七段码管片选
end exp19;
--------------------------------------------------------------------
architecture behave of exp19 is
signal keyr,keyc : std_logic_vector(3 downto 0);
signal kcount : std_logic_vector(2 downto 0);
signal kflag1,kflag2 : std_logic;
signal buff1,buff2,buff3,buff4,buff5,buff6 : integer range 0 to 15;
signal push_num : integer range 0 to 15; --按键次数
signal Disp_Temp : integer range 0 to 15;
signal Disp_Decode : std_logic_vector(7 downto 0);
signal SEC1,SEC10 : integer range 0 to 9;
signal Clk_Count1 : std_logic_vector(3 downto 0); --1KHz时钟分频计数器
signal Clk_Count2 : std_logic_vector(9 downto 0); --2Hz时钟分频计数器
signal Clk1KHz : std_logic;
signal Clk2Hz : std_logic;
signal Clk1Hz : std_logic;
signal Error_Num : integer range 0 to 3;
signal Error_Flag : std_logic;
signal Error_Count : std_logic_vector(2 downto 0);
signal Music_Count : std_logic_vector(2 downto 0);
begin
process(Clk)
begin
if(Clk'event and Clk='1') then
if(Clk_Count1<10) then
Clk_Count1<=Clk_Count1+1;
else
Clk_Count1<="0001";
end if;
end if;
end process;
Clk1KHz<=Clk_Count1(2);
process(Clk1KHz)
begin
if(Clk1KHz'event and Clk1KHz='1') then
if(Clk_Count2<1000) then
Clk_Count2<=Clk_Count2+1;
else
Clk_Count2<="0000000001";
end if;
end if;
end process;
Clk2Hz<=Clk_Count2(9);
process(Clk2Hz)
begin
if(Clk2Hz'event and Clk2Hz='1') then
Clk1Hz<=not Clk1Hz;
end if;
end process;
process(Clk1KHz) --扫描键盘
begin
if(Clk1KHz'event and Clk1KHz='1') then
if(Kr="1111") then
kflag1<='0';
kcount<=kcount+1;
if(kcount=0) then
kc<="1110";
elsif(kcount=1) then
kc<="1101";
elsif(kcount=2) then
kc<="1011";
else
kc<="0111";
end if;
else
kflag1<='1';
keyr<=Kr;
keyc<=Kc;
end if;
kflag2<=kflag1;
end if;
end process;
KEY_State<=kflag1;
process(Clk1KHz,Rst) --扫描键盘
begin
if(Rst='0') then
push_num<=0;
elsif(Clk1KHz'event and Clk1KHz='1') then
if(push_num=6) then
push_num<=0;
elsif(kflag1='0' and kflag2='1') then
push_num<=push_num+1;
end if;
end if;
end process;
process(Clk1KHz,Rst) --密码校验
begin
if(Rst='0') then
Door<='0';
Error_Num<=0;
Error_Flag<='0';
elsif(Clk1KHz'event and Clk1KHz='1') then
if(push_num=5 and Error_Num<3) then
--修改此处的值可修改门的密码,此处密码为123456
if(buff1=1 and buff2=2 and buff3=3 and buff4=4 and buff5=5 and buff6=6) then
Door<='1';
else
Door<='0';
end if;
elsif(push_num=6 and Error_Num<3) then
if(Door='0') then
Error_Flag<='1';
Error_Num<=Error_Num+1;
else
Error_Flag<='0';
Error_Num<=0;
end if;
elsif(Error_Count=4) then
Error_Flag<='0';
elsif(Error_Flag='1') then
Door<=not Error_Count(0);
end if;
end if;
end process;
process(Clk2Hz,Rst)
begin
if(Rst='0' or Error_Flag<='0') then
Error_Count<="000";
elsif(Clk2Hz'event and Clk2Hz='1' and Error_Flag<='1') then
Error_Count<=Error_Count+1;
end if;
end process;
process(Clk) --报警声音分频
begin
if(Clk'event and Clk='1') then
Music_Count<=Music_Count+1;
end if;
end process;
process(Clk) --超出错误次数,开始报警
begin
if(Error_Num>=3) then
if(Clk1Hz='1') then
SPK<=Music_Count(2);
else
SPK<=Music_Count(1);
end if;
end if;
end process;
process(Clk1KHz,Rst) --显示右移
begin
if(Rst='0' or push_num=0) then --复位时,全灭
buff1<=15;
buff2<=15;
buff3<=15;
buff4<=15;
buff5<=15;
elsif(Clk1KHz'event and Clk1KHz='1') then
if(kflag1='1' and kflag2='0' and (((keyr="1110" or keyr="1011")and keyc/="0111")or keyr="1101")) then
buff1<=buff2;
buff2<=buff3;
buff3<=buff4;
buff4<=buff5;
buff5<=buff6;
end if;
end if;
end process;
process(Clk1KHz,Rst) -- 获取键值
begin
if(Rst='0' or push_num=6) then --全灭
buff6<=15;
elsif(Clk1KHz'event and Clk1KHz='1') then
if(kflag1='1' and kflag2='0') then
if(keyr="1110") then
case keyc is
when "1110"=>buff6<=1;
when "1101"=>buff6<=4;
when "1011"=>buff6<=7;
when others=>buff6<=buff6; --no change
end case;
elsif(keyr="1101") then
case keyc is
when "1110"=>buff6<=2;
when "1101"=>buff6<=5;
when "1011"=>buff6<=8;
when "0111"=>buff6<=0;
when others=>buff6<=buff6; --no change
end case;
elsif(keyr="1011") then
case keyc is
when "1110"=>buff6<=3;
when "1101"=>buff6<=6;
when "1011"=>buff6<=9;
when others=>buff6<=buff6; --no change
end case;
end if;
end if;
end if;
end process;
process(SEG_SEL)
begin
case (SEG_SEL+1) is
when "000"=>Disp_Temp<=10; --'-'
when "001"=>Disp_Temp<=buff1;
when "010"=>Disp_Temp<=buff2;
when "011"=>Disp_Temp<=buff3;
when "100"=>Disp_Temp<=buff4;
when "101"=>Disp_Temp<=buff5;
when "110"=>Disp_Temp<=buff6;
when "111"=>Disp_Temp<=10; --'1'
end case;
end process;
process(Clk)
begin
if(Clk'event and Clk='1') then --扫描累加
SEG_SEL<=SEG_SEL+1;
Display<=Disp_Decode;
end if;
end process;
process(Disp_Temp) --显示转换
begin
case Disp_Temp is
when 0=>Disp_Decode<="00111111"; --'0'
when 1=>Disp_Decode<="00000110"; --'1'
when 2=>Disp_Decode<="01011011"; --'2'
when 3=>Disp_Decode<="01001111"; --'3'
when 4=>Disp_Decode<="01100110"; --'4'
when 5=>Disp_Decode<="01101101"; --'5'
when 6=>Disp_Decode<="01111101"; --'6'
when 7=>Disp_Decode<="00000111"; --'7'
when 8=>Disp_Decode<="01111111"; --'8'
when 9=>Disp_Decode<="01101111"; --'9'
when 10=>Disp_Decode<="01000000"; --'-'
when others=>Disp_Decode<="00000000"; --全灭
end case;
end process;
end behave;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------------
entity exp19 is
port( Clk : in std_logic; --时钟信号
Rst : in std_logic; --复位信号
Kr : in std_logic_vector(3 downto 0); --键盘行
Kc : buffer std_logic_vector(3 downto 0); --键盘列
SPK : out std_logic; --扬声器输出
KEY_State : out std_logic; --按键指示
Door : buffer std_logic; --门状态
Display : out std_logic_vector(7 downto 0); --七段码管显示
SEG_SEL : buffer std_logic_vector(2 downto 0)); --七段码管片选
end exp19;
--------------------------------------------------------------------
architecture behave of exp19 is
signal keyr,keyc : std_logic_vector(3 downto 0);
signal kcount : std_logic_vector(2 downto 0);
signal kflag1,kflag2 : std_logic;
signal buff1,buff2,buff3,buff4,buff5,buff6 : integer range 0 to 15;
signal push_num : integer range 0 to 15; --按键次数
signal Disp_Temp : integer range 0 to 15;
signal Disp_Decode : std_logic_vector(7 downto 0);
signal SEC1,SEC10 : integer range 0 to 9;
signal Clk_Count1 : std_logic_vector(3 downto 0); --1KHz时钟分频计数器
signal Clk_Count2 : std_logic_vector(9 downto 0); --2Hz时钟分频计数器
signal Clk1KHz : std_logic;
signal Clk2Hz : std_logic;
signal Clk1Hz : std_logic;
signal Error_Num : integer range 0 to 3;
signal Error_Flag : std_logic;
signal Error_Count : std_logic_vector(2 downto 0);
signal Music_Count : std_logic_vector(2 downto 0);
begin
process(Clk)
begin
if(Clk'event and Clk='1') then
if(Clk_Count1<10) then
Clk_Count1<=Clk_Count1+1;
else
Clk_Count1<="0001";
end if;
end if;
end process;
Clk1KHz<=Clk_Count1(2);
process(Clk1KHz)
begin
if(Clk1KHz'event and Clk1KHz='1') then
if(Clk_Count2<1000) then
Clk_Count2<=Clk_Count2+1;
else
Clk_Count2<="0000000001";
end if;
end if;
end process;
Clk2Hz<=Clk_Count2(9);
process(Clk2Hz)
begin
if(Clk2Hz'event and Clk2Hz='1') then
Clk1Hz<=not Clk1Hz;
end if;
end process;
process(Clk1KHz) --扫描键盘
begin
if(Clk1KHz'event and Clk1KHz='1') then
if(Kr="1111") then
kflag1<='0';
kcount<=kcount+1;
if(kcount=0) then
kc<="1110";
elsif(kcount=1) then
kc<="1101";
elsif(kcount=2) then
kc<="1011";
else
kc<="0111";
end if;
else
kflag1<='1';
keyr<=Kr;
keyc<=Kc;
end if;
kflag2<=kflag1;
end if;
end process;
KEY_State<=kflag1;
process(Clk1KHz,Rst) --扫描键盘
begin
if(Rst='0') then
push_num<=0;
elsif(Clk1KHz'event and Clk1KHz='1') then
if(push_num=6) then
push_num<=0;
elsif(kflag1='0' and kflag2='1') then
push_num<=push_num+1;
end if;
end if;
end process;
process(Clk1KHz,Rst) --密码校验
begin
if(Rst='0') then
Door<='0';
Error_Num<=0;
Error_Flag<='0';
elsif(Clk1KHz'event and Clk1KHz='1') then
if(push_num=5 and Error_Num<3) then
--修改此处的值可修改门的密码,此处密码为123456
if(buff1=1 and buff2=2 and buff3=3 and buff4=4 and buff5=5 and buff6=6) then
Door<='1';
else
Door<='0';
end if;
elsif(push_num=6 and Error_Num<3) then
if(Door='0') then
Error_Flag<='1';
Error_Num<=Error_Num+1;
else
Error_Flag<='0';
Error_Num<=0;
end if;
elsif(Error_Count=4) then
Error_Flag<='0';
elsif(Error_Flag='1') then
Door<=not Error_Count(0);
end if;
end if;
end process;
process(Clk2Hz,Rst)
begin
if(Rst='0' or Error_Flag<='0') then
Error_Count<="000";
elsif(Clk2Hz'event and Clk2Hz='1' and Error_Flag<='1') then
Error_Count<=Error_Count+1;
end if;
end process;
process(Clk) --报警声音分频
begin
if(Clk'event and Clk='1') then
Music_Count<=Music_Count+1;
end if;
end process;
process(Clk) --超出错误次数,开始报警
begin
if(Error_Num>=3) then
if(Clk1Hz='1') then
SPK<=Music_Count(2);
else
SPK<=Music_Count(1);
end if;
end if;
end process;
process(Clk1KHz,Rst) --显示右移
begin
if(Rst='0' or push_num=0) then --复位时,全灭
buff1<=15;
buff2<=15;
buff3<=15;
buff4<=15;
buff5<=15;
elsif(Clk1KHz'event and Clk1KHz='1') then
if(kflag1='1' and kflag2='0' and (((keyr="1110" or keyr="1011")and keyc/="0111")or keyr="1101")) then
buff1<=buff2;
buff2<=buff3;
buff3<=buff4;
buff4<=buff5;
buff5<=buff6;
end if;
end if;
end process;
process(Clk1KHz,Rst) -- 获取键值
begin
if(Rst='0' or push_num=6) then --全灭
buff6<=15;
elsif(Clk1KHz'event and Clk1KHz='1') then
if(kflag1='1' and kflag2='0') then
if(keyr="1110") then
case keyc is
when "1110"=>buff6<=1;
when "1101"=>buff6<=4;
when "1011"=>buff6<=7;
when others=>buff6<=buff6; --no change
end case;
elsif(keyr="1101") then
case keyc is
when "1110"=>buff6<=2;
when "1101"=>buff6<=5;
when "1011"=>buff6<=8;
when "0111"=>buff6<=0;
when others=>buff6<=buff6; --no change
end case;
elsif(keyr="1011") then
case keyc is
when "1110"=>buff6<=3;
when "1101"=>buff6<=6;
when "1011"=>buff6<=9;
when others=>buff6<=buff6; --no change
end case;
end if;
end if;
end if;
end process;
process(SEG_SEL)
begin
case (SEG_SEL+1) is
when "000"=>Disp_Temp<=10; --'-'
when "001"=>Disp_Temp<=buff1;
when "010"=>Disp_Temp<=buff2;
when "011"=>Disp_Temp<=buff3;
when "100"=>Disp_Temp<=buff4;
when "101"=>Disp_Temp<=buff5;
when "110"=>Disp_Temp<=buff6;
when "111"=>Disp_Temp<=10; --'1'
end case;
end process;
process(Clk)
begin
if(Clk'event and Clk='1') then --扫描累加
SEG_SEL<=SEG_SEL+1;
Display<=Disp_Decode;
end if;
end process;
process(Disp_Temp) --显示转换
begin
case Disp_Temp is
when 0=>Disp_Decode<="00111111"; --'0'
when 1=>Disp_Decode<="00000110"; --'1'
when 2=>Disp_Decode<="01011011"; --'2'
when 3=>Disp_Decode<="01001111"; --'3'
when 4=>Disp_Decode<="01100110"; --'4'
when 5=>Disp_Decode<="01101101"; --'5'
when 6=>Disp_Decode<="01111101"; --'6'
when 7=>Disp_Decode<="00000111"; --'7'
when 8=>Disp_Decode<="01111111"; --'8'
when 9=>Disp_Decode<="01101111"; --'9'
when 10=>Disp_Decode<="01000000"; --'-'
when others=>Disp_Decode<="00000000"; --全灭
end case;
end process;
end behave;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己不去做,叫人做永远都不会。只有动手过,才有其意义
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哦....这样啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
希望 你找到答案
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询