课程设计基于FPGA的VGA图像汉字显示及_PS_2键盘控制设计与应用.doc_第1页
课程设计基于FPGA的VGA图像汉字显示及_PS_2键盘控制设计与应用.doc_第2页
课程设计基于FPGA的VGA图像汉字显示及_PS_2键盘控制设计与应用.doc_第3页
课程设计基于FPGA的VGA图像汉字显示及_PS_2键盘控制设计与应用.doc_第4页
课程设计基于FPGA的VGA图像汉字显示及_PS_2键盘控制设计与应用.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

电子信息工程专业综合设计(报告)(课 程 设 计)题目 基于fpga的vga图像汉字显示及ps/2键盘控制设计与应用 二级学院 专 业 班 级 学生姓名 学 号 指导教师 时 间 基于fpga的vga图像汉字显示及ps/2键盘控制设计与应用摘 要:现在社会,以计算机技术为核心的信息技术迅速发展,以及信息的爆炸式增长,人类获得视觉信息的很大一部分是从各种各样的电子显示器件上获得的,对这些电子显示器件的要求也越来越高,在这些诸多因素的驱动下,显示技术也取得了飞速的发展。vga(video graphics array)是ibm在1987年随ps2机一起推出的一种视频传输标准,具有分辨率高、显示速率快、颜色丰富等优点,在彩色显示器领域得到了广泛的应用。使用fpga设计的vga显示控制器具有很高的灵活性,可以根据其不同的类型、尺寸、适用场合特别是不同的工业产品,做一些特殊的设计,以最小的代价满足系统的要求,而且可以解决通用的显示控制器本身固有的一些缺点。vga(视频图形阵列)作为一种标准的显示接口得到广泛的应用。本文依据vga显示原理,介绍了利用 fpga 实现对vga图形控制器vhdl设计及ps/2键盘与按键对显示图象控制的方法。详细描述了各硬件模块的工作原理及实现途径,并给出了软件设计思路及部分代码。 关键词:vga;fpga;vhdl;ps/20. 引言 随着可编程逻辑器件的不断发展及其价格的不断下降,eda 开发软件的不断完善,可编程逻辑设计的应用优势逐渐显示出来, 特别是大规模可编程器件。 而 fpga 具有功能强大,开发过程投资小、周期短等特点,成为当今硬件设计的首选方式之一。vga(视频图形阵列)作为一种标准的显示接口得到广泛地应用。利用 fpga 芯片和 eda设计方法,可以灵活地根据用户需求,设计出针对性强的 vga 显示控制器,不仅降低了生产成本也可以快速地对产品进行升级换代。 本文设计采用 quartus ii 9.0软件工具,并以 altera公司的 cyclone 系列 fpga 的器件ep1c12f324c8为主实现硬件平台的设计。1 方案设计及工作原理 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和场扫描信号vs进行相应的时序控制(具体控制详细信息见“vga驱动原理”资料文档)。 “rom内存地址控制模块”根据“按键扫描控制模块”获得的图片显示首坐标xx、yy信息和“vga时序控制模块”传送过来的hcnt(列计数器值)、vcnt(行计数器值)及相关控制信号计算出正确的内存地址,从rom中取出所需要的像素点的三基色数据。1.3 ps/2接口电路的工作原理ps/2协议和接口最初是ibm公司开发并推广使用的一种应用于键盘/鼠标的协议和接口,ps/2键盘按键接口是6芯的插头与pc机的键盘相连接,插头、插座定义如图所示。键盘/鼠标接口的数据线和时钟线采用集电极开路结构,平时都是高电平当这些设备等待发送数据时,它首先检查clock是否为高。如果为低,则认为pc抑制了通讯,此时它缓冲数据直到获得总线的控制权。如果clock为高电平,设备则开始向pc发送数据。一般都是由ps2设备产生时钟信号。发送按帧格式。数据位在clock为高电平时准备好,在clock下降沿被pc读入。图3所示是按下q键的时序图“q”键的扫描码从键盘发送到计算机(通道a是时钟信号,通道b是数据信号)。因本设计只需进行控制,所以ps/2模块并未设计转码功能。2 模块设计及仿真 2.1 vga显示模块 图片想要在显示器上显示出来,它主要需要5个信号,行同步信号(hs)、场同步信号(vs)和rgb三基色信号。vga时序控制模块是须严格按照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内存地址控制模块 整个显示思路是在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为图片纵坐标控制变量,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;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 to 15;3结果分析和调试 因为模块较多,调试过程中出现中出现了不少问题。1、 按预想情况,图片在触及屏幕边沿是反弹,实际情况是直接消失,一段时间后重新出现在初始位置开始运动。在进行思考测试后,发现是原来的由hitcase代表图片撞击屏幕位置,然后编写case语句对xy进行改变的运算有所欠缺且十分复杂,难以寻找错误。后改用对图片坐标判断,然后进行xy运算后功能正常,同时使得程序更加简单易读。2、 在测试图片显示的过程中,由于对vga显示原理没有完全理解。出现了图片显示紊乱的错误。在对行场时序扫描部分查阅资料后,对程序语句进行了重新编写后,图片即显示正常。3、 编写程序时,出现过模块无效的错误。检查后发现为自己对模块调用方法的陌生。查阅资料后在程序中加入了中间量进行中转后,实现了模块间的调用连接。4、 测试中,出现过键盘无法正常识别弹起状态的错误。后检查发现并没有编写弹起标志位,加入flag变量与通码一起进行运算后成功解决。经过多次调试以及同学、老师的帮助下,解决了上诉遇到的问题 ,由于时间有限 ,实现初步功能,没有达到完美效果,基本符合本次设计要求。4体会与感受 在为期三周的课程设计中,进一步巩固了曾经所学的eda相关知识,并且第一次了解学习了vga相关原理。经过本次课程设计,对vhdl语言有了更进一步了解,也丰富了一个电子信息工程学生的专业知识,锻炼了动手能力和思辨能力 。此次课程设计师对我们理论的一次大检验也是理论运用与实际的完美展现。5. 参考文献1 侯伯亨.vhdl硬件描述语言与数字逻辑电路设计m.西安:西安 电子科技大学 出版社,1999. 2 李国洪、沈明山。可编程器件eda技术与实践 机械工业出版社,20043 赵世霞、杨丰、刘揭生。 vhdl与微机接口设计 北京:清华大学出版社 2004 4 林敏.vhdl数字系统设计与高层次综合m.北京:电子工业出版社,2001. 5 卢毅.vhdl与数字电路设计m.北京:科学出版社,2001. 6 张琴.向先波.徐国率 ps/2键盘在基于pic单片机的远程多温度点巡检系统中的应 用 期刊论文 -机械与电子2006(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 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显示控制模块 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: 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 -图象数据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); hcntin : 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;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 : 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_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 clk25mhz, 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 = hpos, 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=clk50mhz,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,rgbin1: 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; vcntout = 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 vcnt 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=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_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_vector(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 downto 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: integer 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) begin 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 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 when 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 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; -ps/2键盘数据输入 keycode: out std_logic_vector(7 downto 0);-ps/键盘键值输出 flag: out std_logic ); end keyboard;-architecture behave of keyboard is signal dataerror :std_logic; -数据帧出错信号 signal shiftdata :st

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论