以下是一个计数器程序,C7,..C0为变量,第二个进程中把该计数好值在时钟锁存脉冲STROBE下,锁存到Q7..Q0中,
程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;
entity corna is port(clr,clk,door:in std_logic; strobe:in std_logic; q7,q6,q5,q4,q3,q2,q1,q0:out std_logic_vector(3 downto 0)); end corna;
architecture behav of corna is begin process(door,clk) variable c0,c1,c2,c3,c4,c5,c6,c7:std_logic_vector(3 downto 0); begin if clk'event and clk='1' then if door='1' and clr='0' then --door=1,clr='0'计数 if c0<"1001" then --c0<9,加1计数 c0:=c0+1; else c0:="0000"; if c1<"1001" then --c1<9,加1计数 c1:=c1+1; else c1:="0000"; if c2<"1001" then --c2<9,加1计数 c2:=c2+1;
else c2:="0000"; if c3<"1001" then --c3<9,加1计数 c3:=c3+1;
else c3:="0000"; if c4<"1001" then --c4<9,加1计数 c4:=c4+1;
else c4:="0000"; if c5<"1001" then --c5<9,加1计数 c5:=c5+1;
else c5:="0000"; if c6<"1001" then --c6<9,加1计数 c6:=c6+1; else c6:="0000"; if c7<"1001" then --c7<9,加1计数 c7:=c7+1; else c7:="0000"; --alm<='1'; --超量程报警 end if; end if; end if; end if; end if; end if; end if; end if; else ---clr='1',清0 c7:="0000"; c6:="0000"; c5:="0000"; c4:="0000"; c3:="0000"; c2:="0000"; c1:="0000"; c0:="0000"; end if; end if; end process; process(strobe,c7,c6,c5,c4,c3,c2,c1,c0) begin if strobe'event and strobe='1' then q7<=c7; q6<=c6; q5<=c5; q4<=c4; q3<=c3; q2<=c2; q1<=c1; q0<=c0; end if; end if; end process; end behav;
错误如下:identifier"c7" has not been declared.... 如何定义C7...C0? 谢谢
|