library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity cxjc is
port(cp,cx:in std_logic;
y:out std_logic);
end cxjc;
architecture rtl of cxjc is
type state is (s0,s1,s2,s3);
signal n:state;
begin
process(cp,cx)
begin
if cp'event and cp='1' then
case n is
when s0 => if cx='1' then
n<=s1; y<='0';
else n<=s0; y<='0'; end if;
when s1 => if cx='1' then
n<=s2; y<='0';
else n<=s0; y<='0'; end if;
when s2 => if cx='0' then
n<=s3; y<='0';
else n<=s0; y<='0'; end if;
when s3 => if cx='1' then
n<=s0; y<='1';
else n<=s0; y<='0'; end if;
when others=>null;
end case;
end if;
end process ;
end rtl;
这是以前用VHDL语言写的一个数字序列检测器,当检测到“1101”时,则y输出一个高电平。
根据你的情况,可以把四位检测位改到八位,道理一样。可以把输出Y接到LED1的正端。在仿真时,CLK设置为1KHZ就可以了。
其它功能嘛,谈谈我的想法。在process开始的地方,用一个IF语句加一个使能端S1;然后,至于数码管的驱动,我不知道你用的是共阴的、共阳的,还是BCD码,还有,你要用几位数显示错误码的个数,它们的驱动方式是不一样的。共阴的,高电平有效;共阳的,低电平有效;要是BCD码驱动的,就简单了,可以直接显示出你的二进制数。一位的简单,多位数的要用到扫描程序。
希望对你有用,祝你早日做成功。
电驴上有VHDL的视频,你可以下下来参考下,好久没用过了,最基本的东西都不会了,《郭天祥CPLD 系统设计及VHDL 语言的视频教程》(CPLD/FPGA),好好学习吧。
需要使用状态机设计
参考下密码锁的设计就行
找本书 看看自己搞搞