Mojou úlohou je vziať 2 vstupy z klávesnice, ktoréje číslo od 0 do 9 a pridať ich. Problém je v UCHOVÁVANIE týchto čísiel chcete uložiť najprv stlačením (vstup č.) Do "a" a druhým stlačením (vstup č.) Do "b", ale s použitím nasledujúceho kódu prvých skladov lisov v písmenách a a b. 2. lis nie je použiteľný. tu scan_code = scancode stlačeného tlačidla (výstup kódu rozhrania klávesnice) a = binárne číslo (napríklad ak prvýkrát stlačíte "1", potom kód skontroluje scancode a priradí binárnu hodnotu "1" a). Každý, kto môže pomôcť?
process (clk, scan_code, cin)
variable scancode1 : std_logic_vector (7 downto 0) := "00000000";
variable cin2 : std_logic_vector(2 downto 0);
begin
if(clk"event and clk = "1") then
scancode1 := scan_code;
a <= "0000";
b <="0000";
if (scancode1 = "00010110") then
a <= "0001";
elsif (scancode1 = "00011110") then
a <="0010";
elsif (scancode1 = "00100110") then
a <="0011";
elsif (scancode1 = "00100101") then
a <="0100";
elsif (scancode1 = "00101110") then
a <="0101";
elsif(scancode1 = "00110110") then
a <="0110";
elsif (scancode1 = "00111101") then
a <="0111";
elsif (scancode1 = "00111110") then
a <="1000";
elsif (scancode1 = "01000110") then
a <="1001";
elsif (scancode1 = "01000101") then
a <="0000";
end if;
if (scancode1 = "01010101") then --scancode for + sign
a <=a;
end if;
if (scancode1 = "00010110") then
b <="0001";
elsif (scancode1 = "00011110") then
b <="0010";
elsif (scancode1 = "00100110") then
b <="0011";
elsif (scancode1 = "00100101") then
b <="0100";
elsif (scancode1 = "00101110") then
b <="0101";
elsif(scancode1 = "00110110") then
b <="0110";
elsif (scancode1 = "00111101") then
b <="0111";
elsif (scancode1 = "00111110") then
b <="1000";
elsif (scancode1 = "01000110") then
b <="1001";
elsif (scancode1 = "01000101") then
b <="0000";
end if;
sum(0) <= a(0) xor b(0) xor cin;
cin2(0) := (a(0) and b(0)) or (cin and (a(0) xor b(0)));
sum(1) <= a(1) xor b(1) xor cin2(0);
cin2(1) := (a(1) and b(1)) or (cin2(0) and (a(1) xor b(1)));
sum(2) <= a(2) xor b(2) xor cin2(1);
cin2(2) := (a(2) and b(2)) or (cin2(1) and (a(2) xor b(2)));
sum(3) <= a(3) xor b(3) xor cin2(2);
cout <= (a(3) and b(3)) or (cin2(2) and (a(3) xor b(3)));
end if;
end process;
odpovede:
0 pre odpoveď č. 1"a" a "b" sa aktualizujú súčasne s vaminapísal to tak, že (rovnaké "scancodes" sú kontrolované na "a" a "b" na tom istom clockedge). premýšľajte o použití spúšťača udalostí ako v nasledujúcom príklade:
...
if reset="1" then
a<=(others => "0");
b<=(others => "0");
event_last<="0";
event_nr<=0;
elsif rising_edge(clk) then
event_last<=event;
-- trigger on "rising edge" of event
if event="1" and event_last="0" then
case event_nr is
-- first event is "a"
when 0 =>
event_nr<=1;
if (scancode1 = "00010110") then
a <= "0001";
...
-- second event is "b"
when others =>
event_nr<=0;
if (scancode1 = "00010110") then
b <= "0001";
...
end case;
...
...