基于FPGA的VGA棋盘格图像显示
lol堕落天使-坎坷
library IEEE;
use _logic_;
use
_LOGIC_;
entity vgaplay is
port (
clk : in std_logic;
dispmode: in
std_logic_vector(1 downto 0);
vga_clk : out
std_logic;
vga_hs : out std_logic;
vga_vs : out std_logic;
vga_syn: out
std_logic;
vga_blank: out std_logic;
vga_r : buffer std_logic_vector(7 downto 0);
vga_g : buffer std_logic_vector(7 downto 0);
vga_b : buffer std_logic_vector(7 downto 0)
);
end vgaplay;
architecture ONE of
vgaplay is
signal clk25m :std_logic;
signal hcnt : std_logic_vector(9 downto 0);
signal vcnt : std_logic_vector(9 downto 0);
signal a: std_logic_vector(7 downto
0):=
signal b: std_logic_vector(7 downto
0):=
begin
vga_syn<='1';
process(clk)
begin
if clk'event and
clk='1'then
clk25m<=not clk25m;
vga_clk<=clk25m;
end if;
end process;
--this is Horizonal counter
process(clk25m) begin
if
(rising_edge(clk25m)) then
if(hcnt < 800)
then
hcnt <= hcnt + 1;
else
hcnt <= (others => '0');
end if;
end if;
end process;
--this is
Vertical counter
process(clk25m)
begin
if (rising_edge(clk25m)) then
if (hcnt
= 640+8 ) then
if(vcnt < 525) then
vcnt <= vcnt + 1;
else
vcnt
<= (others => '0');
end if;
end
if;
end if;
end process;
--this is hs pulse
process(clk25m) begin
if (rising_edge(clk25m)) then
if((hcnt>= 640+8+8) and (hcnt<640+8+8+96 )) then
vga_hs <= '0';
else
vga_hs <=
'1';
end if;
end if;
end process;
--this is vs pulse
process(vcnt)
begin
if ((vcnt >= 480+8+2) and (vcnt <
480+8+2+2)) then
vga_vs <= '0';
else
vga_vs <= '1';
end if;
end
process;
process(clk25m)
begin
if (rising_edge(clk25m)) then
if((hcnt>640) or vcnt>524) then
vga_blank
<= '0';
else
vga_blank <= '1';
end if;
end if;
end process;
process(clk25m)
begin
if
(rising_edge(clk25m)) then
case dispmode is
when
if hcnt<100 then
vga_r<=
vga_g<=
vga_b<=
elsif hcnt<200 then
vga_r<=
vga_g<=
vga_b<=
elsif hcnt<300
then
vga_r<=
vga_g<=
vga_b<=
elsif hcnt<400 then
vga_r<=
vga_g<=
vga_b<=
elsif hcnt<500 then
vga_r<=
vga_g<=
vga_b<=
else
vga_r<=
vga_g<=
vga_b<=
end if;
when
if vcnt<100 then
vga_r<=
vga_g<=
vga_b<=
elsif vcnt<200 then
vga_r<=
vga_g<=
vga_b<=
elsif vcnt<300 then
vga_r<=
vga_g<=
vga_b<=
elsif
vcnt<400 then
vga_r<=
vga_g<=
vga_b<=
elsif vcnt<500 then
vga_r<=
vga_g<=
vga_b<=
else
vga_r<=
vga_g<=
vga_b<=
end if;
when
if vcnt<100 then
if hcnt<100 then
vga_r<=b;
vga_g<=a;
vga_b<=a;
elsif
hcnt<200 then
vga_r<=a;
vga_g<=b;
vga_b<=a;
elsif
hcnt<300 then
vga_r<=a;
vga_g<=a;
vga_b<=b;
elsif
hcnt<400 then
vga_r<=b;
vga_g<=b;
vga_b<=a;
elsif
hcnt<500 then
vga_r<=b;
vga_g<=a;
vga_b<=b;
else
vga_r<=a;
vga_g<=b;
vga_b<=b;
end if;
elsif vcnt<200 then
if
hcnt<100 then
vga_r<=a;
vga_g<=b;
vga_b<=a;
elsif
hcnt<200 then
vga_r<=a;
vga_g<=a;
vga_b<=b;
elsif
hcnt<300 then
vga_r<=b;
vga_g<=b;
vga_b<=a;
elsif hcnt<400 then
vga_r<=b;
vga_g<=a;
vga_b<=b;
elsif hcnt<500 then
vga_r<=a;
vga_g<=b;
vga_b<=b;
else
vga_r<=b;
vga_g<=a;
vga_b<=a;
end if;
elsif vcnt<300
then
if hcnt<100 then
vga_r<=a;
vga_g<=a;
vga_b<=b;
elsif hcnt<200 then
vga_r<=b;
vga_g<=b;
vga_b<=a;
elsif hcnt<300 then
vga_r<=b;
vga_g<=a;
vga_b<=b;
elsif
hcnt<400 then
vga_r<=a;
vga_g<=b;
vga_b<=b;
elsif hcnt<500 then
vga_r<=b;
vga_g<=a;
vga_b<=a;
else
vga_r<=a;
vga_g<=b;
vga_b<=a;
end if;
elsif vcnt<400
then
if hcnt<100 then
vga_r<=b;
vga_g<=b;
vga_b<=a;
elsif hcnt<200 then
vga_r<=b;
vga_g<=a;
vga_b<=b;
elsif hcnt<300 then
vga_r<=a;
vga_g<=b;
vga_b<=b;
elsif
hcnt<400 then
vga_r<=b;
vga_g<=a;
vga_b<=a;
elsif hcnt<500 then
vga_r<=a;
vga_g<=b;
vga_b<=a;
else
vga_r<=a;
vga_g<=a;
vga_b<=b;
end if;
else
if hcnt<100 then
vga_r<=b;
vga_g<=a;
vga_b<=b;
elsif hcnt<200 then
vga_r<=a;
vga_g<=b;
vga_b<=b;
elsif hcnt<300 then
vga_r<=b;
vga_g<=a;
vga_b<=a;
elsif hcnt<400 then
vga_r<=a;
vga_g<=b;
vga_b<=a;
elsif hcnt<500 then
vga_r<=a;
vga_g<=a;
vga_b<=b;
else
vga_r<=b;
vga_g<=b;
vga_b<=a;
end if;
end if;
when
if hcnt<100 xor vcnt<100 then
vga_r<=
vga_g<=
vga_b<=
elsif
hcnt<200 xor vcnt<200 then
vga_r<=
vga_g<=
vga_b<=
elsif hcnt<300 xor
vcnt<300 then
vga_r<=
vga_g<=
vga_b<=
elsif hcnt<400 xor vcnt<400 then
vga_r<=
vga_g<=
vga_b<=
elsif
hcnt<500 xor vcnt<500 then
vga_r<=
vga_g<=
vga_b<=
else
vga_r<=
vga_g<=
end case;
end if;
end
process;
end ONE;
end
if;
vga_b<=