L

#### LukÃ¡Å¡ KrÃ¡l

CODE:

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity kral_roc_cit is

Port ( clk : in STD_LOGIC;

reset : in STD_LOGIC;

Red : out STD_LOGIC;

Green : out STD_LOGIC;

Blue : out STD_LOGIC;

hs : out STD_LOGIC;

vs : out STD_LOGIC);

end kral_roc_cit;

architecture Behavioral of kral_roc_cit is

signal count_pixel : STD_LOGIC_VECTOR (10 downto 0) := (others=>'0') ;

signal count_radek : STD_LOGIC_VECTOR (9 downto 0) := (others=>'0');

signal R : STD_LOGIC := '0';

signal G : STD_LOGIC := '0';

signal B : STD_LOGIC := '0';

signal h_sync : STD_LOGIC := '0';

signal v_sync : STD_LOGIC := '0';

constant h_active : integer := 800;

constant h_front_porch : integer := 56;

constant h_back_porch : integer := 64;

constant h_total : integer := 1040;

constant v_active : integer := 600;

constant v_front_porch : integer := 37;

constant v_back_porch : integer := 23;

constant v_total : integer := 666;

begin

-- PoÄÃtÃ¡nÃ pozice na Å™Ã¡dku

process (clk)

begin

if reset = '1' then

count_pixel <= (others=>'0');

elsif clk'event and clk = '1' then

if count_pixel = (h_total - 1) then

count_pixel <= (others=>'0');

else

count_pixel <= count_pixel + 1;

end if;

end if;

end process;

-- Synchronizace Å™Ã¡dku

process (clk)

begin

if reset = '1' then

h_sync <= '0';

elsif clk'event and clk = '1' then

if count_pixel = (h_active + h_front_porch -1) then

h_sync <= '1';

elsif count_pixel = (h_total - h_back_porch - 1) then

h_sync <= '0';

end if;

end if;

end process;

-- PoÄÃtÃ¡nÃ pozice v rÃ¡mci

process (clk)

begin

if reset = '1' then

count_radek <= (others=>'0');

elsif clk'event and clk = '1' then

if ((count_radek = v_total - 1) and (count_pixel = h_total - 1)) then

count_radek <= (others=>'0');

elsif count_pixel = (h_total - 1) then

count_radek <= count_radek + 1;

end if;

end if;

end process;

-- Synchronizace rÃ¡mcÅ¯

process (clk)

begin

if reset = '1' then

v_sync <= '0';

elsif clk'event and clk = '1' then

if count_radek = (v_active + v_front_porch -1) and

count_pixel = (h_total - 1) then

v_sync <= '1';

elsif count_radek = (v_total - v_back_porch - 1) and

count_pixel = (h_total - 1) then

v_sync <= '0';

end if;

end if;

end process;

-- BarvenÃ ÄtvercÅ¯

process (clk)

begin

if clk'event and clk = '1' then

-- BarvenÃ Ätverce (1. - green - tÅ™etÃ Å™Ã¡dek )

if (count_pixel >= "00010011011" ) -- 100 + h_front_porch -1 (155)

and (count_pixel <= "00011111111" ) -- 200 + h_front_porch -1 (255)

and (count_radek >= "0101100100" ) -- 320 + v_front_porch -1 (356)

and (count_radek <= "0111001000" ) -- 420 + v_front_porch -1 (456)

then

G <= '1';

-- BarvenÃ Ätverce (2. - yellow - prvnÃ Å™Ã¡dek)

elsif (count_pixel >= "00011111111" ) -- 200 + h_front_porch -1 (255)

and (count_pixel <= "00101100011" ) -- 300 + h_front_porch -1 (355)

and (count_radek >= "0001001100" ) -- 40 + v_front_porch -1 (76)

and (count_radek <= "0010110000" ) -- 140 + v_front_porch -1 (176)

then

R <= '1';

G <= '1';

-- BarvenÃ Ätverce (3. - white - druhÃ½ Å™Ã¡dek)

elsif (count_pixel >= "00101100011" ) -- 300 + h_front_porch -1 (355)

and (count_pixel <= "00111000111" ) -- 400 + h_front_porch -1 (455)

and (count_radek >= "0011011000" ) -- 180 + v_front_porch -1 (216)

and (count_radek <= "0100111100" ) -- 280 + v_front_porch -1 (316)

then

R <= '1';

G <= '1';

B <= '1';

-- BarvenÃ Ätverce (4. - cyan - prvnÃ Å™Ã¡dek)

elsif (count_pixel >= "00111000111" ) -- 400 + h_front_porch -1 (455)

and (count_pixel <= "01000101011" ) -- 500 + h_front_porch -1 (555)

and (count_radek >= "0001001100" ) -- 40 + v_front_porch -1 (76)

and (count_radek <= "0010110000" ) -- 140 + v_front_porch -1 (176)

then

G <= '1';

B <= '1';

-- BarvenÃ Ätverce (5. - white - ÄtvrtÃ½ Å™Ã¡dek)

elsif (count_pixel >= "01000101011" ) -- 500 + h_front_porch -1 (555)

and (count_pixel <= "01010001111" ) -- 600 + h_front_porch -1 (655)

and (count_radek >= "0111110000" ) -- 460 + v_front_porch -1 (496)

and (count_radek <= "1001010100" ) -- 560 + v_front_porch -1 (596)

then

G <= '1';

B <= '1';

R <= '1';

-- BarvenÃ Ätverce (6. - green - druhÃ½ Å™Ã¡dek)

elsif (count_pixel >= "01010001111" ) -- 600 + h_front_porch -1 (655)

and (count_pixel <= "01011110011" ) -- 700 + h_front_porch -1 (755)

and (count_radek >= "0011011000" ) -- 180 + v_front_porch -1 (216)

and (count_radek <= "0100111100" ) -- 280 + v_front_porch -1 (316)

then

G <= '1';

else

G <= '0';

B <= '0';

R <= '0';

end if;

end if;

end process;

-- PÅ™ipojenÃ vÃ½stupÅ¯

Red <= R ;

Green <= G ;

Blue <= B ;

hs <= h_sync ;

vs <= v_sync ;

end Behavioral;