简易钢琴游戏实验报告副本.docx
- 文档编号:2197904
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:26
- 大小:245.61KB
简易钢琴游戏实验报告副本.docx
《简易钢琴游戏实验报告副本.docx》由会员分享,可在线阅读,更多相关《简易钢琴游戏实验报告副本.docx(26页珍藏版)》请在冰点文库上搜索。
简易钢琴游戏实验报告副本
简易钢琴游戏实验报告---副本
北京邮电大学
实验报告
实验名称:
简易钢琴游戏
学院:
信息与通信工程学院
班级:
2011211118
姓名:
____####
学号:
_2011210###
日期:
2013.11.9
一、实验名称:
简易钢琴游戏
二、实验任务要求:
基本要求:
1、用8×8点阵进行游戏显示。
2、BTN1~BTN7七个按键模拟钢琴演奏时的“1234567”七个音符。
点阵的第一列
对应音符“1”,第二列对应音符“2”,依此类推,低中高音自定。
3、光点在点阵第一行随机出现,逐点下落,下落速度为0.2秒/行,如图1所示。
countdown分别进行除10和对10取模操作,进入数码管显示模块得到分数和倒计时显示;输出的toneindex进入生成音节的分频预置数的tonetaba。
Tonetaba把分频预置数的码tone输入speaker来控制12MHZ的脉冲分频,得到所需要的音符频率。
2、系统模块
3、分块设计:
●主模块:
当reset=‘1’时,进行复位。
然后检测按键是否按下,不按下则不发声不加分;若是停止按键,则是停止发声。
若有按键(address),则依次从点阵的最下一行开始检测按键是否正确(检测到第六行后应同时检测当前检测行的前五行为全0,以保证点阵上同时有两点时上面的一点不会被错误的消掉),按键正确则grade(得分)加分。
每隔0.2秒点阵个各行赋值依次下移一行。
Countdown(倒计时)每一秒减一,同时给点阵光点出现的初始位置赋一次值。
将输出的grade和countdown分别进行除10和对10取模操作,分别对应其十位和个位。
●数码管显示模块:
建立0-9十个数字相应的表,使用1M的时钟对输入的分数和倒计时分别扫描显示(show)。
●点阵显示模块:
使用1M时钟一次扫描点阵每一行的值,然后赋给col进行显示。
●蜂鸣器模块:
将传入的toneindex建表(tonetable)依次转化为相应的分频预置数,然后把12M的时钟按分频预置数进行分频,再进行二分频以使声音更清晰。
三、仿真波形及波形分析
1、1M分频:
图示为一个50分频器,本实验中使用的是50M的输入时钟,则可以分成一个1M的时钟,同时还分了一个12M的时钟,这里未给出。
2、按键转换
按键转换模块,从图中我们可以看出,根据输入的按键(address)分别转化为相应的toneindex,为后续用12M的时钟分成相应的音调做准备。
比如,address=”0001000”时代表的是按btn4,则转换成”100”;当无按键的时候,即address=”0000000”时,toneindex=”000”蜂鸣器不发声。
3、转换成音调分频预置数
将输入的toneindex转化为相应的预置分频数,我们可以看到,当toneindex为111时,对应的预置分频数为1717
4、按预置数分频(1717)
我们可以通过这个波形图检测当分频预置数为1717时,分频比为12*(2047-1717)*2=7920,则对应的音调为12M/7920等于1975HZ。
对应高音7.
5、数码管显示
从图中我们可以看到数字0,对应的show为”1111110”,其他的1-9的数字都是依次对应show的值。
同时,通过一个1M的时钟进行扫描,使数码管无闪烁现象。
6、点阵显示
从图中我们可以看到,以1M的时钟逐行扫描点阵,使点阵看起来不会闪烁。
用row来控制各行的选通。
比如。
Row=”11111011”时,只有第三行有显示。
五、源程序
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
EntityPinaoMasteris
port(
clk:
instd_logic;--输入50M时钟
address:
instd_logic_vector(6downto0);--按键
reset:
instd_logic;--复位开始
beep:
outstd_logic;--蜂鸣器
cat:
outstd_logic_vector(5downto0);--数码管选通
row:
outstd_logic_vector(7downto0);--行选通
col:
outstd_logic_vector(6downto0);--列赋值
show:
outstd_logic_vector(6downto0));--数码管显示
EndentityPinaoMaster;
ArchitectureoneofPinaoMasteris
signalclk1:
std_logic;
signalclk2:
std_logic;
signalpreclk:
std_logic;
signalfullspks:
std_logic;
signalscantmp:
std_logic_vector(2downto0);
signalLighttmp:
std_logic_vector(1downto0);
signaltoneindex:
std_logic_vector(2downto0);
signalcountdown:
integerrange0to30;
signalgrade:
integerrange0to99;
signalG1,G0,T1,T0:
integerrange0to9;
signaltone:
std_logic_vector(10downto0);
signalcol0:
std_logic_vector(6downto0);
signalcol1:
std_logic_vector(6downto0);
signalcol2:
std_logic_vector(6downto0);
signalcol3:
std_logic_vector(6downto0);
signalcol4:
std_logic_vector(6downto0);
signalcol5:
std_logic_vector(6downto0);
signalcol6:
std_logic_vector(6downto0);
signalcol7:
std_logic_vector(6downto0);
signaltime1:
std_logic_vector(6downto0);
signaltime0:
std_logic_vector(6downto0);
signalgrade1:
std_logic_vector(6downto0);
signalgrade0:
std_logic_vector(6downto0);
begin
clk12M:
process(clk)--12M分频,用于音调的设置
variablecnt:
integerrange0to1;
variabletmp:
std_logic;
begin
if(clk'eventandclk='1')then
if(reset='1')then
cnt:
=0;
elsifcnt>=1then
cnt:
=0;
tmp:
=nottmp;
else
cnt:
=cnt+1;
endif;
endif;
clk1<=tmp;
endprocessclk12M;
clk1M:
process(clk)--1M分频,用于扫描
variablecnt:
integerrange0to24;
variabletmp:
std_logic;
begin
if(clk'eventandclk='1')then
if(reset='1')then
cnt:
=0;
elsifcnt>=24then
cnt:
=0;
tmp:
=nottmp;
else
cnt:
=cnt+1;
endif;
endif;
clk2<=tmp;
endprocessclk1M;
main:
process(clk2,reset)--主进程,对按键进行判断,并产生与分数、倒计时以及蜂鸣器相关的变化
variablecnt1:
integerrange0to199999;--20万计数器将1M时钟做成0.2s的下降时间间隔
variablecnt2:
integerrange0to5;--将0.2s变成1s首行重新赋值间隔
begin
if(reset='1')then--复位
cnt1:
=0;
cnt2:
=0;
grade<=0;--分数初始化为0
countdown<=30;--倒计时初始化为30
col0<="0000000";
col1<="0000000";
col2<="0000000";
col3<="0000000";
col4<="0000000";
col5<="0000000";
col6<="0000000";
col7<="0000000";--点阵初始化
elsif(clk2'eventandclk2='1')then
if(cnt1=199999)then
cnt1:
=0;
cnt2:
=cnt2+1;
col0<=col1;
col1<=col2;
col2<=col3;
col3<=col4;
col4<=col5;
col5<=col6;
col6<=col7;
col7<="0000000";--0.2s逐行下降
else
cnt1:
=cnt1+1;
if(address="0000000")then--判断没有按键则不发音或者停止按键则停止发音
toneindex<="000";
elsif(address=col0)then--从点阵的做下面一行开始判断按键是否正确
col0<="0000000";--若按键正确,把该行置0
grade<=grade+1;--分数加1
caseaddressis--将按键转化为相应的toneindex,为音调的分频做准备
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col1)then
col1<="0000000";
grade<=grade+1;
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col2)then
col2<="0000000";
grade<=grade+1;
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col3)then
col3<="0000000";--第4行和第5行光点正确加2分
grade<=grade+2;
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col4)then
col4<="0000000";
grade<=grade+2;
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col5andcol0="0000000")then--判断按键与第六行对应且第一行全为0
col5<="0000000";
grade<=grade+3;--第6行和第7行正确加3分
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col6andcol1="0000000")then--判断按键与第七行对应且第二行全为0
col6<="0000000";
grade<=grade+3;
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
elsif(address=col7andcol2="0000000")then--判断按键与第八行对应且第三行全为0
col7<="0000000";
grade<=grade+3;
caseaddressis
when"0000001"=>toneindex<="001";
when"0000010"=>toneindex<="010";
when"0000100"=>toneindex<="011";
when"0001000"=>toneindex<="100";
when"0010000"=>toneindex<="101";
when"0100000"=>toneindex<="110";
when"1000000"=>toneindex<="111";
whenothers=>toneindex<="000";
endcase;
endif;
G1<=grade/10;G0<=grademod10;--grade/10给分数的十位赋值,grade对10取模给分数的个位赋值
endif;
if(cnt2=5)then
cnt2:
=0;
if(countdown/=0)then--判断倒计时不为0,则countdown继续减一
countdown<=countdown-1;
endif;
casecountdownis--光点的初始位置,可以存歌曲
when30=>col7<="0001000";
when29=>col7<="0100000";
when28=>col7<="0000010";
when27=>col7<="0000100";
when26=>col7<="0000001";
when25=>col7<="0100000";
when24=>col7<="0010000";
when23=>col7<="1000000";
when22=>col7<="0001000";
when21=>col7<="0010000";
when20=>col7<="0000100";
when19=>col7<="0000010";
when18=>col7<="0000001";
when17=>col7<="0000100";
when16=>col7<="0001000";
when15=>col7<="0100000";
when14=>col7<="0001000";
when13=>col7<="0000001";
when12=>col7<="0010000";
when11=>col7<="0000100";
when10=>col7<="0010000";
when9=>col7<="1000000";
when8=>col7<="0000010";
when7=>col7<="0010000";
when6=>col7<="0000100";
when5=>col7<="0100000";
when4=>col7<="0000010";
when3=>col7<="0000001";
when2=>col7<="0000010";
when1=>col7<="0100000";
whenothers=>col7<="0000000";
endcase;
endif;
T1<=countdown/10;T0<=countdownmod10;--countdown/10给倒计时的十位赋值,grade对10取模给倒计时的个位赋值
endif;
endprocessmain;
--数码管显示模块
ShowTime1:
process(T1)--显示倒计时的十位
begin
caseT1is--0-9数字的对应
when9=>time1<="1111011";--9
when8=>time1<="1111111";--8
when7=>time1<="1110000";--7
when6=>time1<="1011111";--6
when5=>time1<="1011011";--5
when4=>time1<="0110011";--4
when3=>time1<="1111001";--3
when2=>time1<="1101101";--2
when1=>time1<="0110000";--1
when0=>time1<="1111110";--0
whenothers=>time1<="1111110";
endcase;
endprocessShowTime1;
ShowTime0:
process(T0)--显示倒计时的个位
begin
caseT0is
when9=>time0<="1111011";--9
when8=>time0<="1111111";--8
when7=>time0<="1110000";--7
when6=>time0<="1011111";--6
when5=>time0<="1011011";--5
when4=>time0<="0110011";--4
when3=>time0<="1111001";--3
when2=>time0<="1101101";--2
when1=>time0<="0110000";--1
when0=>time0<="1111110";--0
whenothers=>time0<="1111110";
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 简易 钢琴 游戏 实验 报告 副本