/**********************
JumpMan v1.
型号:STC15F2K60S2 主频:11.0592MHz
************************/
#include <STC15F2K60S2.H>
#define uchar unsigned char
#define uint unsigned int
#include "stdlib.h"
int Life=8;
int Score=0;
int count=0;
int count_time=200;
int level=1;
/*---------引脚别名定义---------*/
sbit sbtKey1 = P3 ^ 2;
sbit sbtKey2 = P3 ^ 3;
sbit sbtKey3 = P1 ^ 7;
sbit sbtLedSel = P2 ^ 3;
sbit sbtBeep = P3 ^ 4; //蜂鸣器
sbit sbtSel0 = P2 ^ 0; //
sbit sbtSel1 = P2 ^ 1; //
sbit sbtSel2 = P2 ^ 2; //位选的三个引脚控制位
/*---------变量定义---------*/
uchar ucTimerH, ucTimerL; //定义定时器的重装值
uchar code arrMusic[] =
{
0x21,0x08,0x23,0x08, //音乐代码,歌曲为《see u again》,格式为: 音符, 节拍
0x25,0x08,0x26,0x08,
0x23,0x08,0x26,0x08,
0x25,0x10,0x21,0x08,
0x21,0x08,0x22,0x08, //音符的十位代表是低中高八度,1代表高八度,2代表中八度,3代表高八度
0x22,0x08,0x21,0x08, //个位代表简谱的音符,例如0x15代表低八度的S0,0x21代表中八度的DO。
0x23,0x10,0x23,0x08, //节拍则是代表音长,例如:0x10代表一拍,0x20代表两拍,0x08代表1/2拍
0x25,0x08,0x26,0x08, //音符的十位代表是低八度,中八度还是高八度,1代表低八度,2代表中八度,3代表高八度
0x27,0x08,0x26,0x08, //个位代表简谱的音符,例如0x15代表低八度的S0,0x21代表中八度的DO。
0x25,0x08,0x23,0x08, //节拍则是代表音长,例如:0x10代表一拍,0x20代表两拍,0x08代表1/2拍
0x22,0x08,0x22,0x10, //音符的十位代表是低八度,中八度还是高八度,1代表低八度,2代表中八度,3代表高八度
0x21,0x08,0x22,0x10, //个位代表简谱的音符,例如0x15代表低八度的S0,0x21代表中八度的DO
0x23,0x08,0x22,0x08, 节拍则是代表音长,例如:0x10代表一拍,0x20代表两拍,0x08代表1/2拍
0x21,0x20,0x00,
};
uchar code arrMusicToTimerNum[] =
{ //此数组数据为各个音符在定时器中的重装值,第一列是高位,第二列是低位
0xf8, 0x8c, //低八度,低1
0xf9, 0x5b,
0xfa, 0x15, //低3
0xfa, 0x67,
0xfb, 0x04, //低5
0xfb, 0x90,
0xfc, 0x0c, //低7
0xfc, 0x44, //中央C调
0xfc, 0xac, //中2
0xfd, 0x09,
0xfd, 0x34, //中4
0xfd, 0x82,
0xfd, 0xc8, //中6
0xfe, 0x06,
0xfe, 0x22, //高八度,高1
0xfe, 0x56,
0xfe, 0x6e, //高3
0xfe, 0x9a,
0xfe, 0xc1, //高5
0xfe, 0xe4,
0xff, 0x03 //高7
};
/*---------延时子函数---------*/
void DelayMs( unsigned int xms )
{
uint i, j;
for( i = xms; i > 0; i-- )
for( j = 124; j > 0; j-- );
}
/*---------取址子函数---------*/
//取出tem音符在arrMusicToTimerNum数组中的位置值
uchar GetPosition( uchar tem )
{
uchar ucBase, ucOffset, ucPosition;//定义曲调,音符和位置
ucBase = tem / 16; //高4位是曲调值,基址
ucOffset = tem % 16; //低4位是音符,偏移量
if( ucBase == 1 ) //当曲调值为1时,即是低八度,基址为0
ucBase = 0;
else if( ucBase == 2 ) //当曲调值为2时,即是中八度,基址为14
ucBase = 14;
else if( ucBase == 3 ) //当曲调值为3时,即是高八度,基址为28
ucBase = 28;
//通过基址加上偏移量,即可定位此音符在arrMusicToTimerNum数组中的位置
ucPosition = ucBase + ( ucOffset - 1 ) * 2;
return ucPosition; //返回这一个位置值
}
/*---------播放音乐功能函数---------*/
void PlayMusic()
{
uchar ucNoteTmp, ucRhythmTmp, tem;
// ucNoteTmp为音符,ucRhythmTmp为节拍
uchar i = 0;
while( 1 )
{
ucNoteTmp =