古詩詞大全網 - 經典古詩 - 畢業設計 基於FPGA的圖形控制器的設計

畢業設計 基於FPGA的圖形控制器的設計

已發至您郵箱,請註意查收。

---------------------------------------------------------------------------------------------

--實驗題號:?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;