資源簡介
此實驗詳解見博客:https://blog.csdn.net/weixin_40874586/article/details/87939748
資源包括:實驗源代碼,實驗報告及實驗錄屏
代碼片段和文件信息
#include?
#include?????
?
sbit?Beep?=??P1^5;?
#define?LCDPORT?P0//數(shù)據(jù)引腳
#define?uchar?unsigned?char
#define?uint?unsigned?int
?
sbit?LCD12864_RS??=??P2^6;?//RS控制引腳
sbit?LCD12864_RW??=??P2^5;?//RW控制引腳
sbit?LCD12864_EN??=??P2^7;?//EN控制引腳
sbit?LCD12864_PSB??=??P1^2;??//模式選擇引腳,ST7920控制器,1為8位并行接口,0為串行接口
sbit?wela????=??P2^6;
sbit?dula????=??P2^7;
//開場顯示
uchar?code?welcome[]?=?{“**迷宮**“};
uchar?code?tip_one[]?=?{“任意鍵啟動游戲“};
//閉場顯示
uchar?code?bye[]={“恭喜逃離“};
uchar?code?tip_two[]={“任意鍵重啟游戲“};
//?對按鍵進(jìn)行定義
sbit?k1=P3^1; ?//定義P31口是k1
sbit?k2=P3^0;?
sbit?k3=P3^2;
sbit?k4=P3^3;
uint?is_Blue=0;//用來記錄藍(lán)牙數(shù)據(jù)
uint?numx_up;//記錄x軸坐標(biāo)??player[0][0]/8
uint?numy_up;//記錄y軸坐標(biāo)??player[0][1]
uint?loca_up=0;//記錄當(dāng)前是x坐標(biāo)的第幾位?(7-player[0][0]%8)
uchar?Ordata_up;//用來和數(shù)據(jù)進(jìn)行與的值
uint?numx_down;//記錄x軸坐標(biāo)??player[0][0]/8
uint?numy_down;//記錄y軸坐標(biāo)??player[0][1]
uint?loca_down=0;//記錄當(dāng)前是x坐標(biāo)的第幾位?(7-player[0][0]%8)
uchar?Ordata_down;//用來和數(shù)據(jù)進(jìn)行與的值
uint?ok_move=0;//移動允許
uint?direct_t=3;
uint?is_destination=0;//目的地檢測函數(shù),到達(dá)目的地?為1,沒有?為0;
uint?is_open=0;//是否開啟游戲函數(shù)
uint?step=0;//用來記錄步數(shù),在LED屏上顯示
uint?is_stopMusic=0;
unsigned?char?n=0;??//n為節(jié)拍常數(shù)變量????
unsigned?char?code?music_tab[]?={???
0xff
????????????????????0x390x300x330x300x300x200x300x200x330x200x390x200x330x10
????????????????????0x300x100x330x200x300x300x400x300x330x200x390x200x400x200x00
};???
???
void?int0()??interrupt?1???//采用中斷0?控制節(jié)拍????
{??TH0=0xd8;???
???TL0=0xef;???
???n--;???
}???
???
void?delay_Sound?(unsigned?char?m)???//控制頻率延時????
{???
?unsigned?i=3*m;???
?while(--i);???
}???
???
void?delayMs_Sound(unsigned?char?a)??//豪秒延時子程序????
{???
??while(--a);??????????????????//采用while(--a)?不要采用while(a--);?
}??
?
void?LCD12864_Init(void);??//LCD12864初始化函數(shù)
void?LCD12864_WriteInfomation(unsigned?char?ucDatabit?bComOrData);???//向LCD12864寫入數(shù)據(jù),bComOrData為1時寫入的是數(shù)據(jù),0時寫入的是命令
void?LCD12864_CheckBusy(void);//忙檢測函數(shù)
void?LCD12864_DisplayImage(unsigned?char?code?*ucImageuint?direction);
void?Delay(unsigned?int?uiCount);
void?ronghe();//融合函數(shù)
void?OpenGame();
void?ClearScreen();
void?main();
void?LEDDisplayTheEnd();
void?delay_1(uint?i);
?void? UsartInit();
???
void?Sound()
{
??unsigned?char?pm;???//m為頻率常數(shù)變量????
??unsigned?char?i=0;???
?
?TMOD&=0x0f;???
??TMOD|=0x01;???
?TH0=0xd8;
??TL0=0xef;???
??IE=0x82;???
??
??TR0=0;
??
play:???
???while(1)???
????{???
??????
????a:?p=music_tab[i];???
???????if(p==0x00)???????{?i=0?delayMs_Sound(1000);?goto?play;}?????//如果碰到結(jié)束符延時1秒回到開始再來一遍????
???????else?if(p==0xff)??{?i=i+1;delayMs_Sound(100)TR0=0;?goto?a;}??//若碰到休止符延時100ms繼續(xù)取下一音符????
????????????else?????????{m=music_tab[i++]?n=music_tab[i++];}??//取頻率常數(shù)?和?節(jié)拍常數(shù)????
?????????????TR0=1;?????????????????????????????????????????????//開定時器1????
???????????while(n!=0)?Beep=~Beepdelay_Sound(m);?????????????????????????//等待節(jié)拍完成?通過P1口輸出音頻(可多聲道哦!)????
???????TR0=0;??????????????????????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????26629??2019-02-26?18:31??迷宮.c
?????文件????41173629??2019-01-16?14:07??迷宮.mp4
?????文件?????4301840??2019-02-26?18:35??迷宮實驗.doc
評論
共有 條評論