VHDL课程设计之打地鼠游戏报告含代码_第1页
VHDL课程设计之打地鼠游戏报告含代码_第2页
VHDL课程设计之打地鼠游戏报告含代码_第3页
VHDL课程设计之打地鼠游戏报告含代码_第4页
VHDL课程设计之打地鼠游戏报告含代码_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

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

文档简介

1、题目:VHDL课程设计之打地鼠游戏 专 业 : 信息工程班 级 : 电联学生姓名 : 提交日期 :2015年03月05日目录一、设计任务与要求3 二、总体框图3 2.1 总体框图3 2.2 设计思路及各模块功能3 2.2.1 设计思路3 2.2.2 各模块功能3 三、选择器件4 四、模块功能实现74.1 分频器模块74.2 随机数产生模块184.3 随机数产生模块29 4.4 键盘控制模块10 4.5 计分器模块14 4.6 LCD1602 地鼠显示模块154.7 数码管显示模块17 五、总体设计电路图18 六、游戏说明书18 6.1 前言18 6.2 运行说明18 6.3 评分规则18 七、

2、心得体会19一、 设计任务与要求 设计一个挑战反应速度的“打地鼠”游戏机。要求:地鼠随机出现在任何位置,以按键代表锤子,击中地鼠,一旦击中,数码管计分器分数增加。按复位键重新开始游戏。二、 总体框图 2.1、打地鼠游戏机的总体框图如下图所示: 分频模块键盘模块随机数发生模块数码管显示模块计分模块LCD显示模块电路设计总体框图 2.2、设计思路及各模块功能: 2.2.1设计思路: 产生伪随机数使地鼠随机出现,外接LCD1602显示地鼠随机出现的位置,以一个特殊字符表示地鼠。游戏者按下按键,与地鼠出现的位置代表的伪随机数进行比较,若一致,计分器进行加分。按下ESC键进行复位,利用50MHz分频作为

3、基本信号源。2.2.2各模块功能介绍: 分频器模块 将50MHz的信号源分别分频为游戏所需频率的时钟信号1Hz。 伪随机数产生模块 产生伪随机数,使得地鼠出现位置随机。计分模块 接收来自键盘控制模块的信号,正确一次加一分。LCD显示模块 在1HZ时钟信号下,根据产生的伪随机数使得2*16的LCD屏上随机出现代表地鼠的字符。键盘控制模块 玩家按下地鼠出现的位置可能对应的按键,按键地址与地鼠出现的位置对应的伪随机进行比较,若一致,输出一个为1的correct信号。计分模块 接收来自键盘控制模块的信号,正确一次加一分。数码管显示模块 通过数码管,将计分模块的计分结果显示出来。 三、 器件选择 设计开

4、发软件:Quartus2 8.1/9.0l 主芯片:1. FPGA芯片: EP2C8Q208C8 EP2C8Q208C8:含8,256 Les; 165,888 RAM bits; 2个PLL; 18 Multipliers; 139个I/O口2.配置芯片: EPCS1 / EPCS4 FPGA串行配置芯片含1 M bit Flash / 4 M bit Flash EP2C5Q208C8:配置EPCS1EP2C8Q208C8:配置EPCS4 3. FLASH: AM29LV160DB 16M bit(2 M8 Bit/1 M16 Bit)4. SRAM: IS61LV25616 256K16

5、 Bit 5. I2C存储器电路: 24LC16B 16K bit(8 Blocks2568 Bit)6. SPI存储器电路: 93LC46B 1K bit(6416 Bit)7.有源晶振: 50 MHz8.电源芯片: LM1117-3.3V、LM1117-1.5V 9.调试接口: AS、JTAG调试接口10.核心板尺寸: 100mm79mml 外接LCD1602显示屏工业字符型液晶,能够同时显示16x02即32个字符。(16列2行)注:为了表示的方便 ,后文皆以1表示高电平,0表示低电平。1602液晶也叫1602字符型液晶,它是一种专门用来显示字母、数字、符号等的点阵型液晶模块。它由若干个5

6、X7或者5X11等点阵字符位组成,每个点阵字符位都可以显示一个字符,每位之间有一个点距的间隔,每行之间也有间隔,起到了字符间距和行间距的作用,正因为如此所以它不能很好地显示图形(用自定义CGRAM,显示效果也不好)。1602LCD是指显示的内容为16X2,即可以显示两行,每行16个字符液晶模块(显示字符和数字)。市面上字符液晶大多数是基于HD44780液晶芯片的,控制原理是完全相同的,因此基于HD44780写的控制程序可以很方便地应用于市面上大部分的字符型液晶。2管脚功能1602采用标准的16脚接口,其中:第1脚:GND为电源地第2脚:VCC接5V电源正极第3脚:V0为液晶显示器对比度调整端,

7、接正电源时对比度最弱,接地电源时对比度最高(对比度过高时会 产生“鬼影”,使用时可以通过一个10K的电位器调整对比度)。第4脚:RS为寄存器选择,高电平1时选择数据寄存器、低电平0时选择指令寄存器。第5脚:RW为读写信号线,高电平(1)时进行读操作,以51为例的简单原理图低电平(0)时进行写操作。第6脚:E(或EN)端为使能(enable)端,高电平(1)时读取信息,负跳变时执行指令。第714脚:D0D7为8位双向数据端。第1516脚:空脚或背灯电源。15脚背光正极,16脚背光负极。特性3.3V或5V工作电压,对比度可调内含复位电路提供各种控制命令,如:清屏、字符闪烁、光标闪烁、显示移位等多种

8、功能有80字节显示数据存储器DDRAM内建有192个5X7点阵的字型的字符发生器CGROM8个可由用户自定义的5X7的字符发生器CGRAM特征应用微功耗、体积小、显示内容丰富、超薄轻巧,常用在袖珍式仪表和低功耗应用系统中。操作控制注:关于E=H脉冲开始时初始化E为0,然后置E为1。l 外接PS/2键盘进行控制四、功能模块4.1 分频器模块分频器模块接收晶振提供的50MHz时钟信号,通过计数将其分频为1s的时钟脉冲信号并输出。输出秒脉冲的VHDL程序如下:LIBRARY IEEE;USE IEEE.std_logic_1164.ALL;use ieee.std_logic_unsigned.al

9、l;ENTITY divider ISPORT( clk:IN STD_LOGIC; rst_n:IN STD_LOGIC; clk_1HZ:BUFFER STD_LOGIC);END divider;ARCHITECTURE behav OF divider ISBEGIN PROCESS(clk,rst_n) VARIABLE count:INTEGER range 0 TO 50000000; BEGIN IF rst_n=0 THEN count:=0; ELSIF clkevent AND clk=1 THEN IF count=25000000 THEN count:=0; clk

10、_1HZ=NOT clk_1HZ; ELSE count:=count+1; END IF; END IF; END PROCESS;END behav;4.2 随机数产生模块1以下程序为产生4位伪随机数的代码,取ram为一个4位数,将第1位和第4位进行同或得结果feedback,将ram的前3位和feedback合并取代原来4位的ram,新的ram即是得到的一个伪随机数,不停的反复就可得到一组序列为16的伪随机数。这个伪随机数产生器的伪随机数传递给LCD显示屏。Library IEEE ;use IEEE.std_logic_1164.all ;use IEEE.std_logic_arit

11、h.all ;entity bee is port ( clk : in std_logic ; reset : in std_logic ; data_out : out UNSIGNED(3 downto 0) ); end bee ;architecture rtl of bee is signal feedback : std_logic ; signal ram : UNSIGNED(3 downto 0) ; begin feedback = ram(3) xnor ram(0) ; latch_it : process(clk,reset) begin if (reset = 1

12、) then ram 0) ;elsif (clk = 1 and clkevent) thenram = ram(2 downto 0) & feedback ;end if;end process;data_out = ram(3 downto 0);end RTL;4.3 随机数产生模块2原理同随机数产生模块1,产生的伪随机数传递给键盘控制模块。Library IEEE ;use IEEE.std_logic_1164.all ;use IEEE.std_logic_arith.all ;entity lai2 is port ( clk : in std_logic ; reset :

13、 in std_logic ; data_out : out UNSIGNED(3 downto 0) ); end lai2 ;architecture rtl of lai2 is signal feedback : std_logic ; signal ram : UNSIGNED(3 downto 0) ; begin feedback = ram(3) xnor ram(0) ; latch_it : process(clk,reset) begin if (reset = 1) then ram 0) ;elsif (clk = 1 and clkevent) thenram =

14、ram(2 downto 0) & feedback ;end if;end process;data_out = ram(3 downto 0);end RTL;4.4 键盘控制模块根据得到伪随机产生模块传递的信号num1,将此时按下的按键地址与伪随机数所代表的0地址进行比较,若一致,则输出为1的correct信号给下面的计分器模块。library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity ps2scan is port( c

15、lk: in STD_LOGIC; rst_n: in STD_LOGIC; num1: in std_logic_vector(3 downto 0); ps2k_clk: in STD_LOGIC; ps2k_data: in STD_LOGIC; LCD_Data:in std_logic_vector (8 downto 0); correct:out std_logic;signal resss:out std_logic; led: out STD_LOGIC_VECTOR (5 downto 0) ); end entity ps2scan; architecture ps2re

16、ceive of ps2scan is signal ps2k_clk_r: STD_LOGIC_VECTOR (2 downto 0); signal neg_ps2k_clk: STD_LOGIC; signal temp_data: STD_LOGIC_VECTOR (7 downto 0); signal num: STD_LOGIC_VECTOR (3 downto 0); signal ps2_byte_r: STD_LOGIC_VECTOR (7 downto 0); signal count:std_logic_vector(3 downto 0);begin - proces

17、s(clk,rst_n) begin if (rst_n = 0) then ps2k_clk_r = 000; elsif (clkevent AND clk = 1) then ps2k_clk_r = ps2k_clk_r(1 downto 0) & ps2k_clk; end if; end process; - neg_ps2k_clk = 1 when ps2k_clk_r(2 downto 1) = 10 else 0; - process(clk,rst_n) begin if (rst_n = 0) then num = x0; temp_data = x00; elsif

18、(clkevent AND clk = 1) then if (neg_ps2k_clk = 1) then num temp_data(0) temp_data(1) temp_data(2) temp_data(3) temp_data(4) temp_data(5) temp_data(6) temp_data(7) null; end case; end if; if (num = xb) then num = x0; end if; end if; end process; - process(clk,rst_n) VARIABLE count1:INTEGER range 0 TO

19、 1; begin if (rst_n = 0) then ps2_byte_r = x00; elsif (clkevent AND clk = 1) then if (num = xb) then ps2_byte_r = temp_data; end if; end if; end process; - process(ps2_byte_r)begin-correct=0;if (ps2_byte_r=x29) then resss-0if(ps2_byte_r=x6b) thencorrect=1;else correct-1if(ps2_byte_r=x74) thencorrect

20、=1;else correct-2if(ps2_byte_r=x73) thencorrect=1;else correct-3if(ps2_byte_r=x74) thencorrect=1;else correct-4if(ps2_byte_r=x69) thencorrect=1;else correct-5if(ps2_byte_r=x79) thencorrect=1;else correct-6if(ps2_byte_r=x73) thencorrect=1;else correct-7if(ps2_byte_r=x73) thencorrect=1;else correct-8i

21、f(ps2_byte_r=x79) thencorrect=1;else correct-9if(ps2_byte_r=x69) thencorrect=1;else correct-10if(ps2_byte_r=x74) thencorrect=1;else correct-11if(ps2_byte_r=x6b) thencorrect=1;else correct-12if(ps2_byte_r=x72) thencorrect=1;else correct-13if(ps2_byte_r=x73) thencorrect=1;else correct-14if(ps2_byte_r=

22、x7a) thencorrect=1;else correctnull;end case;resss=1;end if;end process;end architecture ps2receive; 4.5 计分器模块判断得到来自键盘控制模块的correct信号是否为1,来确定计分器是否需要加1,并实现在数码管上显示出来。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY grade ISPORT( - clk_1:IN STD_LOGIC;clk_1HZ : in std_logic

23、; rst_n : in std_logic;correct: in std_logic; - light : buffer std_logic_vector(2 downto 0); seg_en : buffer std_logic; clr: buffer std_logic; seg_data : buffer std_logic_vector(15 downto 0);END grade;architecture behav of grade is signal cnt : std_logic_vector(3 downto 0); signal tim : std_logic_ve

24、ctor(3 downto 0):=1111;beginprocess (clk_1HZ,rst_n)begin if (clk_1HZevent and clk_1HZ=1) then-clr = 1;if correct=1 thencnt1001) then seg_data = 000000000001&( cnt-1010); else seg_data = 000000000000&cnt; end if; end if; end process; end behav;4.6 LCD1602 地鼠显示模块首先分频得到一个5Hz的时钟信号,LCD在5Hz时钟信号的驱动下,完成五步操作

25、,第一步,设置8位格式,第二步,整体显示,关光标,光标闪烁,第三步,清屏,第四步,根据得到来自伪随机数产生模块的伪随机数信号numin,读地址,移动光标位置,第五步,在光标位置写特殊字符,代表地鼠出现。library ieee;use IEEE.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity lcdd isport(clk, reset: in std_logic;numin:in std_logic_vector(3 downto 0);LCD_Data: buffer std_logic_vector(8 downto 0

26、);en: out std_logic;rw: out std_logic;judge: out std_logic_vector(8 downto 0);LCD_Clk: buffer std_logic);end lcdd;architecture gongneng of lcdd issignal s : integer range 0 to 5000000;begin-50MHz to 5Hzprocess(clk, reset)beginif reset = 0 thenLCD_Clk = 0;s = 0;elsif clkevent and clk = 1 thenif s = 5

27、000000 thens = 0;LCD_Clk = not LCD_Clk;elses = s + 1;end if;end if;end process;rw =0;en = LCD_Clk;process(LCD_Clk)variable cnt1:std_logic_vector(2 downto 0):=000;begin if Reset=0then LCD_Data=000000001; - Resetzanting-LCD_Data8.0, 其中LCD_Data8对应1602的RS,-LCD_Data7.0对应1602的八根数据线elsif rising_edge(LCD_Cl

28、k) thenif cnt1LCD_DataLCD_DataLCD_Datacase numin iswhen 0000=LCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_DataLCD_Datanull;end case;when 101=LCD_Datanull;end case;end if;end process;process(LCD_Data)beginif (LCD_Data(8 downto 7)=01)thenjudge=LCD_Data;end if;end process;end gongn

温馨提示

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

评论

0/150

提交评论