for Q1.
library ieee;
use ieee.std_logic_1164.all;
entity shift is
port(C, SI : in std_logic;
SO : out std_logic);
end shift;
architecture beh of shift is
signal tmp: std_logic_vector(7 downto 0);
begin
process (C)
begin
if (C'event and C='1') then
for i in 0 to 6 loop
tmp(i+1) <= tmp(i);
end loop;
tmp(0) <= SI;
end if;
end process;
SO <= tmp(7);
end beh;
for Q2.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity count2 is
port(clk,r,le : in std_logic;
d : in integer;
q : out integer);
end count2;
architecture beh of count2 is
begin
process(clk,r,le)
variable var_cnt : integer range 0 to 256;
begin
case(r) is
when '1' =>
var_cnt :=0;
when '0' =>
if le ='1' then
var_cnt :=d;
elsif (clk'event and clk ='1') then
var_cnt := var_cnt +1;
end if;
when others =>
var_cnt := 0;
end case;
q<=var_cnt;
end process;
end beh;
someone can verify that for me..
|