本帖最后由 le062 于 2010-12-27 17:03 编辑
我要做个智力抢答器,下面是抢答判断的代码
我用了个VARIABLE SC:INTEGER 用来锁存判断
但是仿真的时候 当 CLR=0 AND RST=0,输出A1, B1, C1, D1就都是不定值了LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY QDJB IS
PORT (CLR,RST: IN STD_LOGIC;
A, B, C, D: IN STD_LOGIC;
A1, B1, C1, D1: OUT STD_LOGIC;
G: OUT STD_LOGIC_VECTOR (3 DOWNTO 0));
END QDJB;
ARCHITECTURE ART OF QDJB IS
CONSTANT W1: STD_LOGIC_VECTOR:="1010";
CONSTANT W2: STD_LOGIC_VECTOR:="1011";
CONSTANT W3: STD_LOGIC_VECTOR:="1100";
CONSTANT W4: STD_LOGIC_VECTOR:="1101";
CONSTANT FOUL: STD_LOGIC_VECTOR:="1111";
BEGIN
PROCESS(CLR,RST)
VARIABLE SC:INTEGER:=00;
BEGIN
IF(CLR='1'OR RST='1')THEN
IF(A='0'AND B='0'AND C='0'AND D='0')THEN
A1<='0'; B1<='0'; C1<='0'; D1<='0';G<="1110";SC:=01;
ELSIF((A='1'AND (SC=01))OR (SC=02))THEN
A1<='1'; B1<='0'; C1<='0'; D1<='0';G<=FOUL;SC:=02;
ELSIF((B='1'AND (SC=01))OR (SC=03))THEN
A1<='0'; B1<='1'; C1<='0'; D1<='0';G<=FOUL;SC:=03;
ELSIF((C='1'AND (SC=01))OR (SC=04))THEN
A1<='0'; B1<='0'; C1<='1'; D1<='0';G<=FOUL;SC:=04;
ELSIF((D='1'AND (SC=01))OR (SC=05))THEN
A1<='0'; B1<='0'; C1<='0'; D1<='1';G<=FOUL;SC:=05;
END IF;
ELSE
IF ((A='1'AND (SC=01))OR (SC=06))THEN
A1<='1'; B1<='0'; C1<='0'; D1<='0';G<=W1;SC:=06;
ELSIF((B='1'AND (SC=01))OR (SC=07))THEN
A1<='0'; B1<='1'; C1<='0'; D1<='0';G<=W2;SC:=07;
ELSIF((C='1'AND (SC=01))OR (SC=08))THEN
A1<='0'; B1<='0'; C1<='1'; D1<='0';G<=W3;SC:=08;
ELSIF((D='1'AND (SC=01))OR (SC=09))THEN
A1<='0'; B1<='0'; C1<='0'; D1<='1';G<=W4;SC:=09;
ELSE A1<='0'; B1<='0'; C1<='0'; D1<='0';G<="0000";
END IF;
END IF;
END PROCESS;
END ART;
我是改别人代码的 这个抢答锁存功能一直搞不定
谢谢
--
问题搞定 其实没啥问题 |