课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc

上传人:土8路 文档编号:10294436 上传时间:2021-05-06 格式:DOC 页数:16 大小:2.61MB
返回 下载 相关 举报
课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc_第1页
第1页 / 共16页
课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc_第2页
第2页 / 共16页
课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc_第3页
第3页 / 共16页
课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc_第4页
第4页 / 共16页
课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc》由会员分享,可在线阅读,更多相关《课程设计基于FPGA的VGA图像汉字显示及PS2键盘控制设计与应用.doc(16页珍藏版)》请在三一文库上搜索。

1、 电子信息工程专业综合设计(报告)(课 程 设 计)题目 基于FPGA的VGA图像汉字显示及PS/2键盘控制设计与应用 二级学院 专 业 班 级 学生姓名 学 号 指导教师 时 间 基于FPGA的VGA图像汉字显示及PS/2键盘控制设计与应用摘 要:现在社会,以计算机技术为核心的信息技术迅速发展,以及信息的爆炸式增长,人类获得视觉信息的很大一部分是从各种各样的电子显示器件上获得的,对这些电子显示器件的要求也越来越高,在这些诸多因素的驱动下,显示技术也取得了飞速的发展。VGA(Video Graphics Array)是IBM在1987年随PS2机一起推出的一种视频传输标准,具有分辨率高、显示速

2、率快、颜色丰富等优点,在彩色显示器领域得到了广泛的应用。使用FPGA设计的VGA显示控制器具有很高的灵活性,可以根据其不同的类型、尺寸、适用场合特别是不同的工业产品,做一些特殊的设计,以最小的代价满足系统的要求,而且可以解决通用的显示控制器本身固有的一些缺点。VGA(视频图形阵列)作为一种标准的显示接口得到广泛的应用。本文依据VGA显示原理,介绍了利用 FPGA 实现对VGA图形控制器VHDL设计及PS/2键盘与按键对显示图象控制的方法。详细描述了各硬件模块的工作原理及实现途径,并给出了软件设计思路及部分代码。 关键词:VGA;FPGA;VHDL;PS/20. 引言 随着可编程逻辑器件的不断发

3、展及其价格的不断下降,EDA 开发软件的不断完善,可编程逻辑设计的应用优势逐渐显示出来, 特别是大规模可编程器件。 而 FPGA 具有功能强大,开发过程投资小、周期短等特点,成为当今硬件设计的首选方式之一。VGA(视频图形阵列)作为一种标准的显示接口得到广泛地应用。利用 FPGA 芯片和 EDA设计方法,可以灵活地根据用户需求,设计出针对性强的 VGA 显示控制器,不仅降低了生产成本也可以快速地对产品进行升级换代。 本文设计采用 Quartus II 9.0软件工具,并以 Altera公司的 Cyclone 系列 FPGA 的器件EP1C12F324C8为主实现硬件平台的设计。1 方案设计及工

4、作原理 1.1 VGA模块方案设计 采用模块化设计方法,我们对 VGA 图形控制器按功能进行层次划分。本设计的VGA控制器主要由以下模块组成:VGA 时序控制模块、ROM 内存地址控制模块、ROM内存模块、按键扫描控制模块。如图 1 所示。 图1.方案模块框图1.2工作原理 VGA时序控制 模块 ROM内存地址控制模块 ROM 按键扫描 控制模块 50MHz 5Hz addr data 首坐标xx、yy VGA 接口 RGB HS、VS D/A CRT 根据VGA的显示协议,可以选择不同的显示分辨率。本设计选择的是800*600的分辨率。根据相应协议,在“VGA时序控制模块”对行扫描信号HS和

5、场扫描信号VS进行相应的时序控制(具体控制详细信息见“VGA驱动原理”资料文档)。 “ROM内存地址控制模块”根据“按键扫描控制模块”获得的图片显示首坐标xx、yy信息和“VGA时序控制模块”传送过来的hcnt(列计数器值)、vcnt(行计数器值)及相关控制信号计算出正确的内存地址,从rom中取出所需要的像素点的三基色数据。1.3 PS/2接口电路的工作原理PS/2协议和接口最初是IBM公司开发并推广使用的一种应用于键盘/鼠标的协议和接口,PS/2键盘按键接口是6芯的插头与PC机的键盘相连接,插头、插座定义如图所示。键盘/鼠标接口的数据线和时钟线采用集电极开路结构,平时都是高电平当这些设备等待

6、发送数据时,它首先检查clock是否为高。如果为低,则认为PC抑制了通讯,此时它缓冲数据直到获得总线的控制权。如果clock为高电平,设备则开始向PC发送数据。一般都是由ps2设备产生时钟信号。发送按帧格式。数据位在clock为高电平时准备好,在clock下降沿被PC读入。图3所示是按下Q键的时序图“Q”键的扫描码从键盘发送到计算机(通道A是时钟信号,通道B是数据信号)。因本设计只需进行控制,所以PS/2模块并未设计转码功能。2 模块设计及仿真 2.1 VGA显示模块 图片想要在显示器上显示出来,它主要需要5个信号,行同步信号(HS)、场同步信号(VS)和RGB三基色信号。VGA时序控制模块是

7、须严格按照VGA时序标准产生相应的脉冲信号。对这5个信号的时序驱动,VGA显示器要严格遵守“VGA工业标准”,即640*480*60Hz模式,否则会损坏VGA显示器。VGA工业标准要求的频率是:时钟频率为25.175MHz,行频为31469Hz,场频为59.94Hz。图为行HS、场VS时序图图 行HS、场VS时序图显示模块是整个显示控制器的重要组成部分,各个模块的输出数据都要经过模块处理后送到显示器。显示模块在VGA显示控制器中起至关重要的作用。显示模块的输出信号通过D/A转换器的转换连到VGA接口,它是控制器和显示器进行通信的桥梁。该模块以可以VHDL语言实现。2.2 ROM内存地址控制模块

8、 整个显示思路是在640*480分辨率的显示器上开辟一128*128的显示区域来 显示图片,因为显示的图片的大小为128*128。在此区域以外显示指定颜色,例如黑色、蓝色等,作为一个背景色显示。在本模块中,通过在对ROM内存地址的控制,实现了图片显示功能。以下通过一段关键代码详细讲解其实现原理。2.2.1romaddr_control的计算原理:romaddr_control o:=o+1;j:=0;-w when x01B = o:=d-1;j:=0;-s when x01C = o:=0;j:=j-1;-a when x023 = o:=0;j:=j+1;-d (其中O为图片纵坐标控制变量

9、,J为横坐标控制变量)即可完成WASD对图片移动的控制。对应操作为:W:图片上移。S:图片下移。A:图片右移。D:图片左移。2.4 按键控制模块 按键控制采用的电平触发机制,1Hz左右的扫描频率,适合于人们的使用习惯。其中按键的功能里包括了:a.上下、左右的移动;b.移动中的加速减速停止启动;c.屏保模式自由移动和停止选择按钮。具体语句为if(clkmevent and clkm=1) then if(key1=0)then d:=d+1;e:=e+1;end if; if(key2=0)then d:=d-1;e:=e-1;end if; if(key3=0)then d:=d+1;e:=0

10、;end if; if(key4=0)then d:=0;e:=e+1;end if;(其中D为图片纵坐标控制变量,E为横坐标控制变量)即可完成由开发板上的S1S4按键对图片的控制。对应操作为:KEY1(S1):图片自动移动开始与加速。KEY2(S2):图片自动移动减速与停止。KEY3(S3):图片左移与加速。KEY4(S4):图片右移与加速。2.5.汉字显示模块 本模块实现方法为对特定区域进行黑白两色点阵显示汉字。显示区域为屏幕94*16。点阵数据程序直接编写,不额外添加ROM存储。 本模块设置了两个变量对显示区域横纵轴进行函数运算。即line1,Pixel :integer range 0

11、 to 15;3结果分析和调试 因为模块较多,调试过程中出现中出现了不少问题。1、 按预想情况,图片在触及屏幕边沿是反弹,实际情况是直接消失,一段时间后重新出现在初始位置开始运动。在进行思考测试后,发现是原来的由HITCASE代表图片撞击屏幕位置,然后编写CASE语句对XY进行改变的运算有所欠缺且十分复杂,难以寻找错误。后改用对图片坐标判断,然后进行XY运算后功能正常,同时使得程序更加简单易读。2、 在测试图片显示的过程中,由于对VGA显示原理没有完全理解。出现了图片显示紊乱的错误。在对行场时序扫描部分查阅资料后,对程序语句进行了重新编写后,图片即显示正常。3、 编写程序时,出现过模块无效的错

12、误。检查后发现为自己对模块调用方法的陌生。查阅资料后在程序中加入了中间量进行中转后,实现了模块间的调用连接。4、 测试中,出现过键盘无法正常识别弹起状态的错误。后检查发现并没有编写弹起标志位,加入FLAG变量与通码一起进行运算后成功解决。经过多次调试以及同学、老师的帮助下,解决了上诉遇到的问题 ,由于时间有限 ,实现初步功能,没有达到完美效果,基本符合本次设计要求。4体会与感受 在为期三周的课程设计中,进一步巩固了曾经所学的EDA相关知识,并且第一次了解学习了VGA相关原理。经过本次课程设计,对VHDL语言有了更进一步了解,也丰富了一个电子信息工程学生的专业知识,锻炼了动手能力和思辨能力 。此

13、次课程设计师对我们理论的一次大检验也是理论运用与实际的完美展现。5. 参考文献1 侯伯亨.VHDL硬件描述语言与数字逻辑电路设计M.西安:西安 电子科技大学 出版社,1999. 2 李国洪、沈明山。可编程器件EDA技术与实践 机械工业出版社,20043 赵世霞、杨丰、刘揭生。 VHDL与微机接口设计 北京:清华大学出版社 2004 4 林敏.VHDL数字系统设计与高层次综合M.北京:电子工业出版社,2001. 5 卢毅.VHDL与数字电路设计M.北京:科学出版社,2001. 6 张琴.向先波.徐国率 PS/2键盘在基于PIC单片机的远程多温度点巡检系统中的应 用 期刊论文 -机械与电子2006

14、(08) 7 苗新法.王秀隼 PS/2键盘在嵌入式系统中的应用研究 期刊论文 -兰州交通大学学 报2007(01) 8 徐晓.汪道辉 标准PS/2键盘与单片机的接口设计 期刊论文 -中国测试技术 2005(01) 9、 郑炜.须文波.胡晋 单片机系统中PS/2键盘驱动程序设计 期刊论文 -单片机与嵌 入式系统200510 北京理工大学ASIC研究所,VHDL语言100例详解,清华大学出版社 ,北京,1999 :302-310 11 altera 公司 ,datasheet of ep1k30,美国,1999:401006 附录(程序、元件清单和制作效果)1、顶层文件IMG.VHDLIBRARY

15、 ieee; -图象显示顶层程序 USE ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;ENTITY img IS port ( clk50MHz ,clk1,clk2,data: IN STD_LOGIC; key1,key2,key3,key4: in std_logic;hs, vs : OUT STD_LOGIC;r,g: OUT STD_LOGIC;b: out STD_LOGIC); END img; ARCHITECTURE modelstru OF img IS component vga640480 -VGA

16、显示控制模块 PORT(clk : IN STD_LOGIC; rgbin ,rgbin1: IN STD_LOGIC_VECTOR(2 downto 0); hs, vs : OUT STD_LOGIC;r, g, b: OUT STD_LOGIC;hcntout, vcntout : OUT STD_LOGIC_VECTOR(9 downto 0) ); end component;component keyboard -VGA显示控制模块 port ( clk: in std_logic; -系统时钟输入 kb_clk: in std_logic; -ps/2键盘时钟输入 kb_data

17、: in std_logic; -ps/2键盘数据输入 keycode: out std_logic_vector(7 downto 0); -ps/键盘键值输出 flag: out std_logic ); end component;component imgrom -图象数据ROM,数据线12位;地址线14位 PORT(clock : IN STD_LOGIC; address : IN STD_LOGIC_VECTOR(13 downto 0); q : OUT STD_LOGIC_VECTOR(2 downto 0) ); end component;component rom2 -

18、图象数据ROM,数据线12位;地址线14位 PORT(clock : IN STD_LOGIC; address : IN STD_LOGIC_VECTOR(13 downto 0); q : OUT STD_LOGIC_VECTOR(2 downto 0) ); end component;component mid1port ( clk : in std_logic;qin1 : in std_logic_vector(2 downto 0);xx: in std_logic_vector(8 downto 0);yy: in std_logic_vector(8 downto 0); h

19、cntin : in std_logic_vector(9 downto 0); vcntin : in std_logic_vector(9 downto 0);qout : out std_logic_vector(2 downto 0);romaddr_control : out std_logic_vector(13 downto 0); end component;component midport ( clk : in std_logic;qin : in std_logic_vector(2 downto 0);key1,key2,key3,key4: in std_logic;

20、hcntin : in std_logic_vector(9 downto 0); vcntin : in std_logic_vector(9 downto 0);qout : out std_logic_vector(2 downto 0);code:in std_logic_vector(7 downto 0);flag:in std_logic;romaddr_control : out std_logic_vector(13 downto 0); end component; signal rgb : STD_LOGIC_VECTOR(2 downto 0); signal rgb1

21、 : STD_LOGIC_VECTOR(2 downto 0); signal rgb2 : STD_LOGIC_VECTOR(2 downto 0); signal rgb3 : STD_LOGIC_VECTOR(2 downto 0); signal clk25MHz : std_logic; signal clk1Hz : std_logic; signal romaddr : STD_LOGIC_VECTOR(13 downto 0);signal romaddr1 : STD_LOGIC_VECTOR(13 downto 0); signal romaddr2 : STD_LOGIC

22、_VECTOR(13 downto 0); signal hpos, vpos : std_logic_vector(9 downto 0);signal txx :std_logic_vector(8 downto 0);signal tyy :std_logic_vector(8 downto 0);signal code1:std_logic_vector(7 downto 0);signal flag1: std_logic;BEGIN process(clk50MHz) begin if clk50MHzevent and clk50MHz = 1 then clk25MHz clk

23、25MHz, rgbin = rgb1, rgbin1 = rgb3,hs = hs, vs = vs, r=r, g=g, b=b, hcntout = hpos, vcntout = vpos); i_rom2: rom2 PORT MAP(clock = clk25MHz, address = romaddr1, q =rgb2); i_rom : imgrom PORT MAP(clock = clk25MHz, address = romaddr, q = rgb); i_mid : mid PORT MAP(clk = clk25MHz, qin = rgb, hcntin = h

24、pos, vcntin = vpos, qout =rgb1,romaddr_control = romaddr,code=code1,flag=flag1,key1=key1,key2=key2,key3=key3,key4=key4); i_mid1 : mid1 PORT MAP(clk = clk25MHz, xx = txx, yy= tyy ,qin1 = rgb2, hcntin = hpos, vcntin = vpos, qout =rgb3,romaddr_control = romaddr1); i_keyboard :keyboard port map(clk=clk5

25、0MHz,kb_clk=clk2, kb_data=data,keycode=code1,flag=flag1);end;2、VGA显示模块library IEEE; use IEEE.std_logic_1164.all; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity vga640480 is port ( clk : in STD_LOGIC; hs : out STD_LOGIc; vs : out STD_LOGIc; r : out STD_LOGIC; g : out STD_LOGIC; b : out STD_LOGIC; rgbin,rgbi

26、n1: in std_logic_vector(2 downto 0); hcntout : out std_logic_vector(9 downto 0); vcntout : out std_logic_vector(9 downto 0) ); end vga640480; architecture ONE of vga640480 is signal hcnt : std_logic_vector(9 downto 0); signal vcnt : std_logic_vector(9 downto 0); begin - Assign pin hcntout = hcnt; vc

27、ntout = vcnt; -this is Horizonal counter process(clk) begin if (rising_edge(clk) then if(hcnt 800) then hcnt = hcnt + 1; else hcnt 0); end if; end if; end process; -this is Vertical counter process(clk) begin if (rising_edge(clk) then if (hcnt = 640+8 ) then if(vcnt 525) then vcnt = vcnt + 1; else v

28、cnt 0); end if; end if; end if; end process; -this is hs pulse process(clk) begin if (rising_edge(clk) then if(hcnt= 640+8+8) and (hcnt640+8+8+96 ) then hs = 0; else hs = 480+8+2) and (vcnt 480+8+2+2) then vs = 0; else vs = 1; end if; end process; process(clk) begin if (rising_edge(clk) then if(hcnt

29、=640 and vcnt=480)thenr=rgbin(2)or rgbin1(2);g=rgbin(1)or rgbin1(1);b=rgbin(0)or rgbin1(0);elser=0; g=0; b=0; end if; end if;end process;end ONE;3、ROM地址及图片运动控制模块library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity mid is port (clk : in std_

30、logic;key1,key2,key3,key4: in std_logic;qin : in std_logic_vector(2 downto 0); -xx: in std_logic_vector(9 downto 0); -yy: in std_logic_vector(8 downto 0);hcntin : in std_logic_vector(9 downto 0); vcntin : in std_logic_vector(9 downto 0);qout : out std_logic_vector(2 downto 0);code:in std_logic_vecto

31、r(7 downto 0);flag:in std_logic;romaddr_control : out std_logic_vector(13 downto 0); end mid;architecture one of mid issignal hcnt : std_logic_vector(9 downto 0); signal vcnt : std_logic_vector(9 downto 0); signal qout_temp : std_logic_vector(2 downto 0);- signal romaddr_temp : std_logic_vector(13 d

32、ownto 0);signal count_temph : std_logic_vector(9 downto 0);signal count_tempv : std_logic_vector(9 downto 0);signalclk_count: std_logic_vector(24 downto 0);signal tx: std_logic_vector(9 downto 0);signal ty: std_logic_vector(8 downto 0);signal m,t: std_logic ;signalclkm:std_logic;-signal tempxx: inte

33、ger range 0 to 640;-signal tempyy: integer range 0 to 480;constant wide: integer:=128;constant long: integer:=128;begin- Assign pin hcnt = hcntin; vcnt = vcntin;qout = qout_temp;romaddr_control = (vcnt(6 downto 0)-count_tempv(6 downto 0) & (hcnt(6 downto 0)-count_temph(6 downto 0); process(clk) begi

34、n if (rising_edge(clk) thenif(vcnt = ty) and( hcnt=tx ) )then count_temph=hcnt;count_tempv=vcnt; end if;if(vcnt ty+long) then qout_temptx)and (hcnttx + wide ) then -qout_temp=qin;-input logo.hexelseqout_temptx) and (hcntty-1)and (vcnt ty+long-1 ) and ( vcnt ty+long+2 ) ) then qout_tempty)and ( vcnt

35、tx-1)and (hcnttx + wide-2 )and (hcnttx + wide+1 ) then qout_temp=100; end if;end if; -end if; end process;div: process(clk)beginif (clkevent and clk=1) thenif(clk_count 1100110111111110011000000)thenclk_count = clk_count + 1;clkm = 0;elseclk_count =0000000000000000000000001;clkm o:=o+1;j:=0;-w 119 w

36、hen x01B = o:=d-1;j:=0;-s 115 when x01C = o:=0;j:=j-1;-a 973 when x023 = o:=0;j:=j+1;-d 100 when others = null; end case; end if; if(clkmevent and clkm=1) then if(key1=0)then d:=d+1;e:=e+1;end if; if(key2=0)then d:=d-1;e:=e-1;end if; if(key3=0)then d:=d+1;e:=0;end if; if(key4=0)then d:=0;e:=e+1;end

37、if;end if;if (rising_edge(clk) then z:=z+1;if(z=111110) then z:=0; if(m=0)then y:=y+d; else y:=y-d; end if; if(t=640-wide)then t=1; end if; if(x=1) then t=480-long)then m=1; end if; if(y=1) then m=0;end if; end if; end if; tx=x; ty=y;end process; end one;4、键盘控制模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;-entity keyboard isport ( clk: in std_logic; -系统时钟输入 kb_clk: in std_logic; -ps/2键盘时钟输入 kb_data: in std_logic;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1