基于VHDL语言的VGA显示与控制

基于VHDL语言的VGA显示与控制
基于VHDL语言的VGA显示与控制

EDA大作业实验报告

基于VHDL语言的VGA显示与控制

1111000079 田宇

1111000081 王坤

目录

1.VGA显示原理 (3)

1.1VGA逐行扫描显示 (3)

1.2VGA时序分析 (3)

2.时序部分的代码实现 (3)

2.1 时序部分主要代码 (3)

2.2 时序部分的实现 (4)

2.2.1 行时序 (4)

2.2.2 场时序 (5)

3.控制部分的代码实现 (5)

3.1 控制部分主要代码 (5)

3.2 控制部分的实现 (12)

3.2.1彩条与彩格 (12)

3.2.2 字体显示 (12)

4. 硬件平台实验 (12)

1.VGA显示原理

1.1VGA逐行扫描显示

逐行扫描是扫描从屏幕左上角一点开始,从左像右逐点扫描,每扫描完一行,电子束回到屏幕的左边下一行的起始位置,在这期间,CRT对电子束进行消隐,每行结束时,用行同步信号进行同步;当扫描完所有的行,形成一帧,用场同步信号进行场同步,并使扫描回到屏幕左上方,同时进行场消隐,开始下一帧。

1.2VGA时序分析

(图-1)

2.时序部分的代码实现

2.1 时序部分主要代码

if ck'event and ck='1' then H<=H+1;

if H>15 and H<110 then Hs<='1';

elsif H>=110 then Hs<='0';

if H>=160 and H<800 then Hen<='1';

elsif H=800 then Hen<='0';

H<=0;

end if;

end if;

end if;

if Hs'event and Hs='1' then V<=V+1;

if V>11 and V<14 then Vs<='1';

elsif V>=14 then Vs<='0';

if V>=45 and V<525 then Ven<='1';

elsif V=525 then Ven<='0';

V<=0;

end if;

end if;

end if;

此部分代码为时序部分主要代码。

2.2 时序部分的实现

2.2.1 行时序

H:行

HS:行消隐信号

Hen:允许显示

由时序图(图-1)可以看出,行时序中需要有行消隐、行同步、显示前后沿等。其中有效显示信号为640个周期。

2.2.2 场时序

与行时序相类似。

3.控制部分的代码实现

3.1 控制部分主要代码

process(clk_d,sw)

begin

if clk_d'event and clk_d='1' then

if sw="11" then

sw_t<=sw_t+1;

end if;

if sw="01" then

sw_t<=sw_t-1;

end if;

end if;

end process;

process(sw_t)

begin

if sw_t="0000" then R<=Rd(s);G<=Gd(s);B<=Bd(s);

elsif sw_t="0001" then

R<=Rd(s+1);G<=Gd(s+1);B<=Bd(s+1);

elsif sw_t="0010" then

R<=Rd(s+2);G<=Gd(s+2);B<=Bd(s+2);

elsif sw_t="0011" then

R<=Rd(s+3);G<=Gd(s+3);B<=Bd(s+3);

if s=5 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

end if;

elsif sw_t="0100" then

R<=Rd(s+4);G<=Gd(s+4);B<=Bd(s+4);

if s=3 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(0);G<=Gd(1);B<=Bd(3);

end if;

elsif sw_t="0101" then

R<=Rd(s+5);G<=Gd(s+5);B<=Bd(s+5);

if s=2 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(2);B<=Bd(0);

end if;

elsif sw_t="0110" then

R<=Rd(s+6);G<=Gd(s+6);B<=Bd(s+6);

if s=1 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(0);G<=Gd(0);B<=Bd(3);

end if;

elsif sw_t="0111" then

R<=Rd(s+7);G<=Gd(s+7);B<=Bd(s+7);

if s=3 and t=5 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(0);G<=Gd(0);B<=Bd(0);

end if;

elsif sw_t="1000" then R<=Rd((s+t)rem

8);G<=Gd((s+t)rem 8);B<=Bd((s+t)rem 8);

elsif sw_t="1001" then R<=Rd((s+t)rem

7);G<=Gd((s+t)rem 7);B<=Bd((s+t)rem 7);

elsif sw_t="1010" then R<=Rd((s+t)rem

6);G<=Gd((s+t)rem 6);B<=Bd((s+t)rem 6);

elsif sw_t="1011" then R<=Rd((s+t)rem

5);G<=Gd((s+t)rem 5);B<=Bd((s+t)rem 5);

elsif sw_t="1100" then R<=Rd((s+t)rem

4);G<=Gd((s+t)rem 4);B<=Bd((s+t)rem 4);

elsif sw_t="1101" then R<=Rd((s+t)rem

3);G<=Gd((s+t)rem 3);B<=Bd((s+t)rem 3);

elsif sw_t="1110" then R<=Rd((s+t)rem

2);G<=Gd((s+t)rem 2);B<=Bd((s+t)rem 2);

elsif sw_t="1111" then R<=Rd((s+t)rem

1);G<=Gd((s+t)rem 1);B<=Bd((s+t)rem 1);

-- if s=5 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

-- end if;

-- if s=4 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

-- end if;

-- if s=3 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

-- end if;

-- if s=2 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

-- end if;

-- if s=1 and t=4 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

-- end if;

-- if s=3 and t=5 and (n=0 or m=0 or n=79 or m=59 or n=1 or m=1 or n=78 or m=58) then R<=Rd(3);G<=Gd(3);B<=Bd(3);

-- end if;

end if;

if s=2 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=4 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=5 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=5 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=4 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=2 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

end if;

if s=2 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=4 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=5 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=6 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=1 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=2 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=3 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=4 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=5 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

end if;

if s=1 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=1 and t=2 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=1 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=1 and t=4 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=1 and t=5 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=1 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=6 and t=1 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=6 and t=2 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=6 and t=3 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

if s=6 and t=4 then R<=Rd(3);G<=Gd(3);B<=Bd(3); end if;

end if;

if s=6 and t=6 then R<=Rd(3);G<=Gd(3);B<=Bd(3);

end if;

if m=7 and n=5 and(m=15 or n=10) then

R<=Rd(3);G<=Gd(3);B<=Bd(3);

end if;

end if;

end process;

3.2 控制部分的实现

3.2.1 彩条与彩格

通过对行信号、场信号计数,打印出彩条。通过拨码开关,控制彩条向左走或向右走。

通过REM对信号求余,打印出彩格。

3.2.2 字体显示

与彩格控制类似。

4. 硬件平台实验

相关主题
相关文档
最新文档