谁能教教我FPGA中VGA显示模块的设计问题

 我来答
id1a5iabb
2011-04-04 · TA获得超过1690个赞
知道小有建树答主
回答量:2154
采纳率:50%
帮助的人:716万
展开全部
--------------------------------------------------------------------------------------
--实验题号 : lab5
--项目名称 : VGA实验
--文件名 : VGA_640480.vhd
--作者 :
--班号. :
--创建日期 :
--目标芯片 : EP1C6Q240C8
--电路模式 : 模式5
--演示说明 : 输入时钟为clock0,50Mhz
-- 输出接VGA
-- 请在通电后先reset
-- 键1信号上升沿改变字符颜色
-- 键2信号上升沿改变字符
-- 键3开关控制字符y方向移动
-- 键4开关控制字符x方向移动
-- 键5开关控制字符闪烁
-- 键6开关控制字符边框
-- 键8 reset
---------------------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity vga640480 is
port(
address : out STD_LOGIC_VECTOR(11 DOWNTO 0); --连接ROM地址
reset : in STD_LOGIC;
q : in STD_LOGIC; --ROM数据的返回
clk : buffer std_logic; --分频后的25M时钟
clk_0 : in STD_LOGIC; --50M时钟输入
r,g,b : out STD_LOGIC; --颜色信号
hs,vs : out STD_LOGIC; --行同步、场同步信号
in_frame_switch : in STD_LOGIC; --加边框开关
in_blink_switch : in STD_LOGIC; --闪烁开关
in_enlarge_switch : in STD_LOGIC; --大字符开关
in_num_change : in STD_LOGIC; --改变显示的数值
in_color_change : in STD_LOGIC; --改变显示的颜色
in_v_x,in_v_y : in STD_LOGIC; --显示字符的是否向x,y方向位移
vga_syn : out STD_LOGIC;
vga_clk : out STD_LOGIC;
vga_blank : out STD_LOGIC

);
end vga640480;

architecture behavior of vga640480 is
signal r1,g1,b1 : std_logic;
signal hs1,vs1 : std_logic;
signal vector_x : std_logic_vector(9 downto 0); --扫描点X坐标
signal vector_y : std_logic_vector(8 downto 0); --扫描点Y坐标
signal target_x : std_logic_vector(9 downto 0); --字符左上角X坐标
signal target_y : std_logic_vector(8 downto 0); --字符左上角Y坐标
signal blink : std_logic; --闪烁控制信号
Shared Variable scancount,blinkcount : integer; --扫描点计数、扫屏数计数
Shared Variable color : std_logic_vector(2 downto 0); --当前显示颜色rgb
Shared Variable num : std_logic_vector(1 downto 0); --当前显示数字

begin
-----------------------------------------------------------------------
process(clk_0) --对50M输入信号二分频
begin
if(clk_0'event and clk_0='1') then
clk <= not clk;
end if;
end process;

-----------------------------------------------------------------------
process(clk,reset) --行区间像素数(含消隐区)
begin
if reset='0' then
vector_x <= (others=>'0');
elsif clk'event and clk='1' then
if vector_x=799 then
vector_x <= (others=>'0');
else
vector_x <= vector_x + 1;
end if;
end if;
end process;

-----------------------------------------------------------------------
process(clk,reset) --场区间行数(含消隐区)
begin
if reset='0' then
vector_y <= (others=>'0');
elsif clk'event and clk='1' then
if vector_x=799 then
if vector_y=524 then
vector_y <= (others=>'0');
else
vector_y <= vector_y + 1;
end if;
end if;
end if;
end process;

-----------------------------------------------------------------------
process(clk,reset) --行同步信号产生(同步宽度96,前沿16)
begin
if reset='0' then
hs1 <= '1';
elsif clk'event and clk='1' then
if vector_x>=656 and vector_x<752 then
hs1 <= '0';
else
hs1 <= '1';
end if;
end if;
end process;

-----------------------------------------------------------------------
process(clk,reset) --场同步信号产生(同步宽度2,前沿10)
begin
if reset='0' then
vs1 <= '1';
elsif clk'event and clk='1' then
if vector_y>=490 and vector_y<492 then
vs1 <= '0';
else
vs1 <= '1';
end if;
end if;
end process;
-----------------------------------------------------------------------
process(clk,reset) --行同步信号输出
begin
if reset='0' then
hs <= '0';
elsif clk'event and clk='1' then
hs <= hs1;
end if;
end process;

-----------------------------------------------------------------------
process(clk,reset) --场同步信号输出
begin
if reset='0' then
vs <= '0';
elsif clk'event and clk='1' then
vs <= vs1;
end if;
end process;

-----------------------------------------------------------------------
process(clk,reset) --扫描点计数、扫屏数计数,以及闪烁控制、字符显示位置控制
begin
if reset='0' then
target_x <= "0101000000";
target_y <= "011100000";
blink <= '0';
scancount := 0;
blinkcount := 0;
elsif clk'event and clk='1' then
scancount := scancount + 1;
if scancount >= 525*800 then
blinkcount := blinkcount + 1;
if (blinkcount = 20) then
blink <= NOT blink;
blinkcount := 0;
end if;
target_x <= target_x + in_v_x;
target_y <= target_y + in_v_y;
if target_x>=640-32 then
target_x <= "0000000000";
end if;
if target_y>=480-32 then
target_y <= "000000000";
end if;
scancount := 0;
end if;
end if;
end process;

-----------------------------------------------------------------------
process(in_num_change,reset) --改变数字
begin
if reset='0' then
num := "00";
elsif in_num_change'event and in_num_change='1' then
num := num + "01";
end if;
end process;

-----------------------------------------------------------------------
process(in_color_change,reset) --改变颜色
begin
if reset='0' then
color := "001";
elsif in_color_change'event and in_color_change='1' then
if color="111" then
color := "001";
else
color := color + "001";
end if;
end if;
end process;

----------------------------------------------------
process(reset,clk,vector_x,vector_y) -- XY坐标定位控制
Variable temp_x : std_logic_vector(9 downto 0);
Variable temp_y : std_logic_vector(8 downto 0);
Variable size : integer;
begin
if reset='0' then
r1 <= '0';
g1 <= '0';
b1 <= '0';
elsif(clk'event and clk='1')then
if in_enlarge_switch='0' then --控制字符边长
size := 32;
else
size := 64;
end if;
--字符边框
if ((vector_x = target_x - 1 or vector_x = target_x + size + 3) and vector_y >= target_y - 1 and vector_y <= target_y + size + 3)
or ((vector_y = target_y - 1 or vector_y = target_y + size + 3) and vector_x >= target_x - 1 and vector_x <= target_x + size + 3) then
r1 <= color(2) AND (blink or NOT in_blink_switch) AND in_frame_switch;
g1 <= color(1) AND (blink or NOT in_blink_switch) AND in_frame_switch;
b1 <= color(0) AND (blink or NOT in_blink_switch) AND in_frame_switch;
else
r1 <= '0';
g1 <= '0';
b1 <= '0';
end if;
--显示字符
if vector_x >= target_x and vector_x < target_x + size and vector_y >= target_y and vector_y < target_y + size then
temp_y := vector_y-target_y;
temp_x := vector_x-target_x;
if in_enlarge_switch='0' then
address <= num & temp_y(4 downto 0) & temp_x(4 downto 0);
else
address <= num & temp_y(5 downto 1) & temp_x(5 downto 1);
end if;
if q = '0' then
r1 <= color(2) and (blink or NOT in_blink_switch);
g1 <= color(1) and (blink or NOT in_blink_switch);
b1 <= color(0) and (blink or NOT in_blink_switch);
else
r1 <= '0';
g1 <= '0';
b1 <= '0';
end if;
end if;
end if;
end process;

-----------------------------------------------------------------------
--色彩输出
r <= r1 and hs1 and vs1;
g <= g1 and hs1 and vs1;
b <= b1 and hs1 and vs1;

vga_blank <= hs1 and vs1;
vga_clk <= clk;
vga_syn <= '0';

end behavior;
追问
这个我也看过了,和我的要求不一样
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式