LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_arith.ALL;
ENTITY GSecNum IS
PORT(
LLoup1, HLoup1, KIoup1 : out std_logic_vector(6 downto 0);
LLoup2, HLoup2, KIoup2 : out std_logic_vector(6 downto 0);
Cjudge, Ejudge : out bit;
randB, submit, btn, sw : in std_logic;
clock : in bit);
END GSecNum;
ARCHITECTURE behavior OF GSecNum IS
SHARED VARIABLE LLinp1, LLinp2, Keyin1, Keyin2 : integer RANGE 0 TO 9 :=0;
SHARED VARIABLE HLinp1, HLinp2 : integer RANGE 0 TO 9 :=9;
SHARED VARIABLE number : integer RANGE 0 TO 100:=1;
SIGNAL cRand : bit :='0';
BEGIN
PROCESS(clock, btn, sw, randB, cRand, submit)
VARIABLE k1: integer RANGE 0 TO 9 := Keyin1;
VARIABLE k2: integer RANGE 0 TO 9 := Keyin2;
VARIABLE l1: integer RANGE 0 TO 9 := LLinp1;
VARIABLE l2: integer RANGE 0 TO 9 := LLinp2;
VARIABLE h1: integer RANGE 0 TO 9 := HLinp1;
VARIABLE h2: integer RANGE 0 TO 9 := HLinp2;
VARIABLE t, lo, hi : integer RANGE 0 TO 100 :=0;
BEGIN
IF cRand='0' THEN
IF rising_edge(btn) THEN
IF sw='0' THEN
IF k1 = 9 THEN
k1 :=0;
ELSE
k1:=k1+1;
END IF;
ELSIF sw='1' THEN
IF k2 = 9 THEN
k2 :=0;
ELSE
k2 :=k2+1;
END IF;
END IF;
END IF;
ELSIF cRand='1' THEN
k1 :=0;
k2 :=0;
END IF;
IF cRand='0' THEN
IF rising_edge(submit) THEN
Cjudge <='0';
Ejudge <='0';
t := k1+k2*10;
lo := l1+l2*10;
hi := h1+h2*10;
IF t=number THEN
Cjudge <='1';
ELSIF t<number AND t>lo THEN
l1 :=k1;
l2 :=k2;
Ejudge <='1';
ELSIF t>number AND t<hi THEN
h1 :=k1;
h2 :=k2;
Ejudge <='1';
END IF;
END IF;
ELSIF cRand='1' THEN
Cjudge <='0';
Ejudge <='0';
l1 :=0;
l2 :=0;
h1 :=9;
h2 :=9;
END IF;
LLinp1 :=l1;
LLinp2 :=l2;
HLinp1 :=h1;
HLinp2 :=h2;
Keyin1 :=k1;
Keyin2 :=k2;
END PROCESS;
PROCESS(randB, cRAND)
BEGIN
IF rising_edge(randB) AND cRand='0' THEN
cRand <='1';
ELSIF rising_edge(randB) AND cRand='1' THEN
cRand <='0';
END IF;
END PROCESS;
PROCESS(clock,cRand)
BEGIN
IF clock'event AND clock='1' THEN
IF cRand='1' THEN
IF number = 98 THEN
number :=1;
ELSE
number := number+1;
END IF;
END IF;
END IF;
END PROCESS;
PROCESS(clock)
BEGIN
IF clock'event AND clock='1' THEN
CASE LLinp1 IS
when 0 => LLoup1 <= "0000001";
when 1 => LLoup1 <= "1001111";
when 2 => LLoup1 <= "0010010";
when 3 => LLoup1 <= "0000110";
when 4 => LLoup1 <= "1001100";
when 5 => LLoup1 <= "0100100";
when 6 => LLoup1 <= "0100000";
when 7 => LLoup1 <= "0001101";
when 8 => LLoup1 <= "0000000";
when 9 => LLoup1 <= "0000100";
END CASE;
CASE LLinp2 IS
when 0 => LLoup2 <= "0000001";
when 1 => LLoup2 <= "1001111";
when 2 => LLoup2 <= "0010010";
when 3 => LLoup2 <= "0000110";
when 4 => LLoup2 <= "1001100";
when 5 => LLoup2 <= "0100100";
when 6 => LLoup2 <= "0100000";
when 7 => LLoup2 <= "0001101";
when 8 => LLoup2 <= "0000000";
when 9 => LLoup2 <= "0000100";
END CASE;
CASE HLinp1 IS
when 0 => HLoup1 <= "0000001";
when 1 => HLoup1 <= "1001111";
when 2 => HLoup1 <= "0010010";
when 3 => HLoup1 <= "0000110";
when 4 => HLoup1 <= "1001100";
when 5 => HLoup1 <= "0100100";
when 6 => HLoup1 <= "0100000";
when 7 => HLoup1 <= "0001101";
when 8 => HLoup1 <= "0000000";
when 9 => HLoup1 <= "0000100";
END CASE;
CASE HLinp2 IS
when 0 => HLoup2 <= "0000001";
when 1 => HLoup2 <= "1001111";
when 2 => HLoup2 <= "0010010";
when 3 => HLoup2 <= "0000110";
when 4 => HLoup2 <= "1001100";
when 5 => HLoup2 <= "0100100";
when 6 => HLoup2 <= "0100000";
when 7 => HLoup2 <= "0001101";
when 8 => HLoup2 <= "0000000";
when 9 => HLoup2 <= "0000100";
END CASE;
CASE Keyin1 IS
when 0 => KIoup1 <= "0000001";
when 1 => KIoup1 <= "1001111";
when 2 => KIoup1 <= "0010010";
when 3 => KIoup1 <= "0000110";
when 4 => KIoup1 <= "1001100";
when 5 => KIoup1 <= "0100100";
when 6 => KIoup1 <= "0100000";
when 7 => KIoup1 <= "0001101";
when 8 => KIoup1 <= "0000000";
when 9 => KIoup1 <= "0000100";
END CASE;
CASE Keyin2 IS
when 0 => KIoup2 <= "0000001";
when 1 => KIoup2 <= "1001111";
when 2 => KIoup2 <= "0010010";
when 3 => KIoup2 <= "0000110";
when 4 => KIoup2 <= "1001100";
when 5 => KIoup2 <= "0100100";
when 6 => KIoup2 <= "0100000";
when 7 => KIoup2 <= "0001101";
when 8 => KIoup2 <= "0000000";
when 9 => KIoup2 <= "0000100";
END CASE;
END IF;
END PROCESS;
END behavior;
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.