给出一个大概:
本电路是一控制模块,
输入:
set_pw:密码设置;input_pw:用户密码输入; ok:确认;cancel:取消;quit:退出;reset:复位;key[11..0]:当前输入数据的BCD码
输出:
open:开门信号;alarm:报警信号;
signal err:bit_vector(1 downto 0),指示密码是否正确。err="10",密码正确;err="11",密码错误;err="0x",没有处理完。
signal password:bit_vector(11 downto 0),保存开门密码。
constant PD bit_vector<="000100100011",为初始密码。
采用双进程状态机设计。一共设置5个状态s0,s1,s2,s3,s4。
进程p1负责状态的变换:
p1:process(set_pw,input_pw,ok,err,quit,reset)
begin
case c_state is
when s0=> c_state<=s1 when set_pw'event and set_pw='1' else
s2 when input_pw'event and input'pw='1' else
s0;
when s1=> if (ok'event and ok='1') or (quit'event and quit='1') then c_state<=s0;
end if;
when s2=> c_state<=s3 when err='10' else
s4 when err='11' else
s0 when quit'event and quit='1' else
s0;
when s3=> if (ok'event and ok='1') or (quit'event and quit='1') then c_state<=s0;
end if;
when s4=> if reset'event and reset='1' then c_state<=s0;
ens if;
when others=> c_state=s0;
end case;
end process p1;
进程p2负责状态的工作。
p2:process(c_state,ok,cancel,quit)
variable in_pd:bit_vector(11 downto 0);
begin
case c_state is
when s0=> open<='0';alarm='0';
when s1=>
when s2=>
when s3=> open<='1';
when s4=> alarm<='1';
when others=> null;
end case;
end process p2;
其中s1时将输入的密码作为开门密码;s2时比较输入的密码和开门密码,求出err。需要使用几个变量,比较简单,我就不列出了。
根据外围电路,可能需要一个移位缓存器模块。(3位密码输入,一共12位BCD码)。
有疑问大家一起讨论。defish_xmx@hotmail.com