推箱子游戲51單片機(jī)課設(shè)計(jì)(最全)_第1頁
推箱子游戲51單片機(jī)課設(shè)計(jì)(最全)_第2頁
推箱子游戲51單片機(jī)課設(shè)計(jì)(最全)_第3頁
推箱子游戲51單片機(jī)課設(shè)計(jì)(最全)_第4頁
推箱子游戲51單片機(jī)課設(shè)計(jì)(最全)_第5頁
已閱讀5頁,還剩53頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、51單片機(jī)課程設(shè)計(jì) 題 目:基于51單片機(jī)的推箱子游戲設(shè)計(jì) 目 錄1、課程設(shè)計(jì)目的12、課程設(shè)計(jì)題目和實(shí)現(xiàn)目標(biāo)13、設(shè)計(jì)方案14、proteus仿真原理圖75、程序設(shè)計(jì)96、調(diào)試總結(jié)287、設(shè)計(jì)心得體會(huì)28參考文獻(xiàn)29附錄:程序代碼-291、課程設(shè)計(jì)目的mcs-51單片機(jī)課程設(shè)計(jì)是與mcs51單片機(jī)課程相配套的實(shí)踐教學(xué)環(huán)節(jié)。mcs51單片機(jī)是一門實(shí)踐性很強(qiáng)的專業(yè)基礎(chǔ)課,通過課程設(shè)計(jì),達(dá)到進(jìn)一步理解單片機(jī)的硬件、軟件和綜合應(yīng)用方面的知識(shí),培養(yǎng)實(shí)踐能力和綜合應(yīng)用能力,開拓學(xué)習(xí)積極性、主動(dòng)性,學(xué)會(huì)靈活運(yùn)用已經(jīng)學(xué)過的知識(shí),并能不斷接受新的知識(shí)。培養(yǎng)大膽發(fā)明創(chuàng)造的設(shè)計(jì)理念,為今后就業(yè)打下良好的基礎(chǔ)。通過

2、課程設(shè)計(jì),掌握以下知識(shí)和技能:1. 單片機(jī)應(yīng)用系統(tǒng)的總體方案的設(shè)計(jì);2. 單片機(jī)應(yīng)用系統(tǒng)的硬件設(shè)計(jì);3. 單片機(jī)應(yīng)用系統(tǒng)的軟件程序設(shè)計(jì);4. 單片機(jī)開發(fā)系統(tǒng)的應(yīng)用和調(diào)試能力 2、 課程設(shè)計(jì)題目和實(shí)現(xiàn)目標(biāo)2.1 課程設(shè)計(jì)題目:基于51單片機(jī)的推箱子游戲設(shè)計(jì)2.2實(shí)現(xiàn)目標(biāo)設(shè)計(jì)一款在以51單片機(jī)為核心的硬件系統(tǒng)中運(yùn)行的推箱子游戲。游戲一共9關(guān),功能包括:(1)顯示游戲開機(jī)界面和游戲界面;(2)按鍵處理包括移動(dòng)小人和移動(dòng)箱子,通過移動(dòng)上下左右鍵來控制小人的移動(dòng),通過小人推動(dòng)箱子,把箱子推到指定的目的地為過關(guān),箱子只能推不能拉;(3)用于可以任意選關(guān),并能隨時(shí)退出、進(jìn)入游戲;(4)每一關(guān)都有時(shí)間計(jì)時(shí),顯

3、示當(dāng)前玩家的游戲耗時(shí)。3、設(shè)計(jì)方案根據(jù)設(shè)計(jì)目標(biāo),整個(gè)系統(tǒng)框圖如下:圖1 系統(tǒng)框圖3.1 控制模塊選用atmel公司 生產(chǎn)的at89c52為主控芯片,它是是一個(gè)低電壓,高性能cmos 8位單片機(jī),主要功能特性如下:1、 兼容mcs51指令系統(tǒng);2、8k可反復(fù)擦寫(大于1000次)flash 7、2個(gè)串行中斷,可編程uart串行通道;8、2個(gè)外部中斷源,共8個(gè)中斷源;9、2個(gè)讀寫中斷口線,3級(jí)加密位;10、 低功耗空閑和掉電模式,軟件設(shè)置睡眠和喚醒功能;本次課設(shè)選用pdip封裝的 at89c52芯片,其引腳功能如圖2所示,圖3為最小系統(tǒng): 圖2 引腳功能圖3 最小系統(tǒng)u1:at89c52,dipf

4、封裝;c1,c2:22pf瓷片電容c3:10uf電解電容;x1:12m晶振r1:10k金屬膜電阻3.2 顯示模塊選用內(nèi)置t6963c控制控制器的12864圖形點(diǎn)陣液晶(以下簡(jiǎn)稱lcd12864)做為顯示模塊。t6963c控制器的最大特點(diǎn)具是有硬件初始值設(shè)置功能,顯示驅(qū)動(dòng)所需的參數(shù),例如:占空比系數(shù)、每行驅(qū)動(dòng)傳輸?shù)淖止?jié)數(shù)、字符的字體選擇等均由引腳電平設(shè)置。所以,液晶顯示模塊在上電時(shí)t6963c控制器就進(jìn)行初始化設(shè)置,軟件操作的主要精力就可以全部用于顯示界面的設(shè)計(jì)上。 市場(chǎng)上出售此控制器的液晶很多,本次課設(shè)選用深圳市晶日達(dá)科技有限公司生產(chǎn)kxm12864f.lcd12864和單片機(jī)以模擬方式連接,

5、即通過模擬操作時(shí)序的方法控制液晶顯示。具體的接線圖如圖4所示圖4 顯示模塊rp1:1k排阻,用于做p0口的上拉電阻;lcd1:kxm12864f3.3按鍵模塊16個(gè)輕觸按鍵連接成4*4矩陣鍵盤,做為按鍵模塊,如圖5所示圖5 4*4矩陣鍵盤最終系統(tǒng)的硬件系統(tǒng)如下:圖6 硬件系統(tǒng)4、 proteus仿真原理圖 在proteus搭建的仿真原理圖如下:圖7 硬件系統(tǒng)圖8 開機(jī)畫面圖9 游戲畫面圖10 游戲畫面5. 程序設(shè)計(jì)5.1 lcd12864顯示驅(qū)動(dòng)程序圖11 讀寫指令/數(shù)據(jù)時(shí)序圖準(zhǔn)備向lcd12864進(jìn)行操作時(shí),首先要讀取lcd12864的當(dāng)前的狀態(tài),只有l(wèi)cd12864不忙的時(shí)候才能讀寫操作和

6、數(shù)據(jù)。相關(guān)程序如下:/*函數(shù)名:status_bit_01()功能:狀態(tài)位sta1(讀/寫指令),sta0(讀/寫數(shù)據(jù))判斷入口參數(shù):返回值:狀態(tài)值i*/ unsigned char status_bit_01() unsigned char i; p0=0xff;cd=1;rd=0;for(i=10;i0;i-)if(p1&0x03)=0x03)break;rd=1;return i; /*函數(shù)名:write_data(unsigned char dat)功能:寫數(shù)據(jù)入口參數(shù):8位數(shù)據(jù)dat返回值:*/void write_data(unsigned char dat)while(statu

7、s_bit_01()=0);rd=1;cd=0;wr=0;p0=dat;wr=1;cd=1; /*函數(shù)名:write_cmd1(unsigned char cmd)功能:寫命令,無參數(shù)入口參數(shù):8位命令cmd返回值:*/void write_cmd1(unsigned char cmd)while(status_bit_01()=0);rd=1;cd=1;wr=0;p0=cmd;wr=1;cd=0; /*函數(shù)名:write_cmd2(unsigned char cmd)功能:寫單參數(shù)命令入口參數(shù):8位數(shù)據(jù)dat,8位命令cmd返回值:*/void write_cmd2(unsigned cha

8、r dat,unsigned char cmd)write_data(dat);write_cmd1(cmd);/*函數(shù)名:write_cmd2(unsigned char cmd)功能:寫雙參數(shù)命令入口參數(shù):8位數(shù)據(jù)data1,8位數(shù)據(jù)data2,8位命令cmd返回值:*/void write_cmd3(unsigned char data1,unsigned char data2,unsigned char cmd) write_data(data1); write_data(data2); write_cmd1(cmd);圖12 為lcd12864的指令集,向lcd12864寫入相關(guān)的指

9、令,即可控制其顯示。圖12 lcd12864的指令集使用液晶前必須對(duì)其進(jìn)行初始化操作,初始化的內(nèi)容包括光標(biāo)指針設(shè)置,圖形區(qū)首地址,圖形區(qū)寬度,顯示方式設(shè)置,圖形方式顯示,標(biāo)形狀設(shè)置。相關(guān)程序如下:/*函數(shù)名:init_12864()功能:初始化lcd12864入口參數(shù):返回值:*/void init_12864()wr=1;rd=1;cd=1;rst=1;/初始化write_cmd3(0x01,0x00,0x21);/光標(biāo)指針設(shè)置write_cmd3(0x00,0x00,0x42);/圖形區(qū)首地址write_cmd3(16,0x00,0x43);/圖形區(qū)寬度 write_cmd1(0x88);

10、/顯示方式設(shè)置,正常顯示write_cmd1(0x98);/圖形方式顯示,不顯示字母,只打點(diǎn)write_cmd1(0xa0);/光標(biāo)形狀設(shè)置1 0 1 0 0 n2 n1 n05.2 按鍵掃描程序初始p1的電平為0x0f,當(dāng)有按鍵下時(shí),電平發(fā)生變化,開始程序開始掃描判斷哪個(gè)按鍵被按下,并返回按鍵號(hào),相關(guān)程序如下:/*函數(shù)名:keys_scan()功能:按鍵掃描入口參數(shù):返回值:按鍵號(hào)keyno */unsigned char keys_scan() unsigned char tmp;unsigned char keyno;if(p1 != 0x0f)p1 = 0x0f; delayms(1)

11、; tmp = p1 0x0f;switch(tmp)case 1: keyno = 0;break;case 2: keyno = 1;break;case 4: keyno = 2;break;case 8: keyno = 3;break;default:keyno = 16;p1 = 0xf0;delayms(1);tmp = (p1 4) 0x0f;switch(tmp)case 1:keyno += 0;break;case 2:keyno += 4;break;case 4:keyno += 8;break;case 8:keyno += 12;break;p1=0x0f;ret

12、urn keyno; 5.3 游戲元素設(shè)計(jì)出現(xiàn)在顯示畫面中的游戲元素總共有6種:墻壁,箱子,小人,目的地,空白,箱子在目的地。每個(gè)元素在液晶上以一個(gè)字符顯示,即88的點(diǎn)陣。在字模提取軟件設(shè)計(jì)各個(gè)元素,并獲得元素的顯示碼。顯示碼的每8位構(gòu)成字符的一行,8就行有8個(gè)字節(jié)。其中1表示該點(diǎn)顯示,0表示該點(diǎn)不顯示。圖13-是在字模提取軟件設(shè)計(jì)的各個(gè)元素, 圖13 小人 圖14 墻壁 圖15 箱子 圖16 目的地 圖17 箱子在目的地 圖18空白 定義一個(gè)二維數(shù)組elements8,存儲(chǔ)這些點(diǎn)陣信息。其中第一個(gè)地址為元素代號(hào)unsigned char code elements8=0x00,0x00,0x

13、00,0x00,0x00,0x00,0x00,0x00, /0空白0x3c,0x7e,0x66,0x3c,0x7e,0x99,0x3c,0x66, /1人物0x7f,0x7f,0x7f,0x00,0xef,0xef,0xef,0x00, /2磚頭0xff,0xc3,0xa5,0x99,0x99,0xa5,0xc3,0xff, /3箱子0x00,0x18,0x24,0x4a,0x52,0x24,0x18,0x00, /4目標(biāo)0xff,0xbd,0xdb,0xe7,0xe7,0xdb,0xbd,0xff, /5箱子到達(dá)目標(biāo) ;5.4元素的顯示由于t6963c液晶是按以列1字符(8點(diǎn)),行1點(diǎn)來定位

14、的,所以顯示時(shí),要先定位顯示字符位的列字符和行字符首地址,即行*0x80+列;再定義一個(gè)循環(huán)變量i,從0,到7,定位該字符位的8個(gè)點(diǎn)行,即行*0x80+列+i*0x10,定位到每個(gè)點(diǎn)行后,寫入對(duì)應(yīng)的元素字節(jié),即elements元素代號(hào)i,就可以在液晶的指定字符位置上顯示該元素了。相關(guān)元素顯示子函數(shù)如下:/*函數(shù)名:printelement()功能:指定字符位置,顯示元素入口參數(shù):列字符地址xh,行字符地址yh,元素代碼elnum返回值:*/void printelement(unsigned char xh, unsigned char yh,unsigned char elnum) unsi

15、gned char i;int temp; for(i=0;i8;i+) /行地址加+1temp = yh* 0x80+i*0x10 + xh;write_cmd3(temp&0xff,temp/0xff,add_pos);write_cmd2(elementselnumi,noc_wr); 調(diào)用如下程序,對(duì)顯示元素進(jìn)行測(cè)試,圖19為顯示效果:printelement(0,1,1); /在第0列,第1行,顯示1號(hào)元素(小人)printelement(1,1,2); /在第1列,第1行,顯示2號(hào)元素(墻壁)printelement(2,1,3); /在第2列,第1行,顯示3號(hào)元素(箱子)prin

16、telement(3,1,4); /在第3列,第1行,顯示4號(hào)元素(目的地)printelement(4,1,5); /在第4列,第1行,顯示5號(hào)元素(箱子在目的地上)圖19 顯示效果5.5 游戲關(guān)卡界面設(shè)計(jì)游戲每關(guān)都是在88個(gè)字符組成的區(qū)域中進(jìn)行的,只要在每一個(gè)字符顯示相應(yīng)的元素,就可以組成游戲界面。定義一個(gè)三維數(shù)組code level88,存儲(chǔ)每一關(guān)每一個(gè)字符位上要顯示的元素。 各關(guān)卡的界面如下:/*第1關(guān)*/0,0,2,2,2,2,2,0,2,2,2,0,0,0,2,0,2,0,3,0,2,0,2,2,2,0,2,0,0,4,0,2,2,0,0,0,0,2,0,2,2,2,0,2,0,0

17、,0,2,0,2,1,0,0,2,2,2,0,2,2,2,2,2,0,0, 圖20 第1關(guān)游戲畫面/*第2關(guān)*/2,2,2,2,2,2,2,2,2,0,0,0,0,0,1,2,2,0,0,0,5,0,0,2,2,0,0,2,2,2,2,2,2,2,0,0,2,0,0,0,2,0,3,0,2,0,0,0,2,0,0,4,2,0,0,0,2,2,2,2,2,0,0,0, 圖21 第2關(guān)游戲畫面/*第3關(guān)*/0,0,2,2,2,2,0,0,0,0,2,4,4,2,0,0,0,2,2,0,4,2,2,0,0,2,0,0,3,4,2,0,2,2,0,3,0,0,2,2,2,0,0,2,3,3,0,2,2

18、,0,0,1,0,0,0,2,2,2,2,2,2,2,2,2, 圖22 第3關(guān)游戲畫面 /*第4關(guān)*/0,0,0,2,2,2,2,0,0,2,2,2,0,1,2,0,0,2,0,0,3,0,2,0,2,2,0,2,0,2,2,2,2,0,0,2,0,2,4,2,2,0,2,0,0,3,4,2,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2, 圖23 第4關(guān)游戲畫面/*第5關(guān)*/0,0,0,2,2,2,2,0,0,2,2,2,0,1,2,0,0,2,0,0,3,0,2,0,2,2,0,2,0,2,2,2,2,0,0,2,0,2,4,2,2,0,2,0,0,0,0,2,2,0,0,

19、0,0,0,0,2,2,2,2,2,2,2,2,2, 圖24 第5關(guān)游戲畫面/*第6關(guān)*/0,0,0,2,2,2,2,0,0,2,2,2,0,1,2,0,0,2,0,0,3,0,2,0,2,2,0,2,0,2,2,2,2,0,0,2,0,2,4,2,2,0,2,0,0,3,4,2,2,0,3,0,0,0,4,2,2,2,2,2,2,2,2,2, 圖25 第6關(guān)游戲畫面 /*第6關(guān)*/0,0,2,2,2,2,2,0,2,2,2,0,0,0,2,0,2,0,3,0,2,0,2,2,2,0,2,0,0,4,0,2,2,0,0,0,0,2,0,2,2,2,3,2,4,0,0,2,0,2,1,0,0,2

20、,2,2,0,2,2,2,2,2,0,0, 圖26 第7關(guān)游戲畫面/*第7關(guān)*/0,2,2,2,2,0,0,0,2,2,0,0,2,0,0,0,2,1,3,0,2,0,0,0,2,2,3,0,2,2,0,0,2,2,0,3,0,2,0,0,2,4,3,0,0,2,0,0,2,4,4,5,4,2,0,0,2,2,2,2,2,2,0,0, 圖27 第8關(guān)游戲畫面/*第9關(guān)*/0,0,0,2,2,2,2,0,0,2,2,2,0,0,2,0,2,2,0,1,3,0,2,0,2,0,4,3,0,0,2,0,2,0,4,5,0,2,2,0,2,0,4,3,0,2,0,0,2,2,0,0,2,2,0,0,0

21、,2,2,2,2,0,0,0, 圖28 第9關(guān)游戲畫面;5.6 開機(jī)畫面開機(jī)畫面是用畫圖程序制作的一個(gè)128像素64像素的單色位圖,并用取模軟件提取該圖像的點(diǎn)陣信息,共1024字節(jié)。使用t6963c的寫數(shù)據(jù)地址自動(dòng)加1的命令寫入上述全部1024字節(jié)的數(shù)據(jù),顯示開機(jī)畫面。圖29 開機(jī)界面圖30 字模提取圖31 proteus中顯示效果圖像的點(diǎn)陣碼:/*- 寬度x高度=128x64 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

22、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

23、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

24、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xe0,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x7c,0xc0,0x06,0x30,0xc6,0

25、x00,0x1f,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x01,0x86,0xc7,0xf0,0x06,0x1f,0xc7,0xf8,0x30,0x00,0x01,0xc0,0x00,0x00,0x00,0x00,0x01,0x87,0x86,0x18,0x0c,0x01,0x80,0x0c,0x30,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,0x01,0x87,0x82,0x18,0x1c,0x01,0x80,0x0e,0x30,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x01,0x87,0x06,0

26、x0c,0x18,0x01,0x00,0x06,0x30,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x0f,0x87,0x07,0x0f,0x10,0x03,0x00,0x0c,0x30,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,0x0c,0x06,0x00,0x01,0x90,0x43,0x00,0x0c,0x1f,0xff,0x01,0x80,0x00,0x00,0x00,0x00,0x0c,0x06,0x00,0x01,0x98,0xc3,0x08,0x38,0x00,0x3e,0x03,0x00,0x00,0x00,0x00,0

27、x00,0x0c,0x0c,0x00,0x01,0x8f,0xc3,0x1c,0x38,0x00,0x3c,0x06,0x00,0x00,0x00,0x00,0x00,0x0c,0x0c,0x00,0x03,0x1f,0xc7,0xfc,0x7c,0x7f,0xf6,0x0f,0xe0,0x00,0x00,0x00,0x00,0x0f,0x88,0x1e,0x1f,0x1c,0x7f,0x67,0xdc,0xc0,0x03,0x18,0x30,0x00,0x00,0x00,0x00,0x01,0x8c,0x00,0x03,0x18,0x01,0x80,0x0c,0xc0,0x01,0xf0,0

28、x30,0x00,0x00,0x00,0x00,0x03,0x87,0x80,0x03,0x10,0x00,0x80,0x0c,0xc0,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x0e,0x01,0x80,0x03,0x10,0x00,0x9f,0x0c,0xc0,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x0c,0x01,0x80,0x03,0x18,0x0f,0x80,0x0c,0xc0,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x0c,0x01,0x9e,0x1f,0x0e,0x1b,0x80,0

29、x0c,0xc0,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x0c,0x03,0x00,0x03,0x0e,0x31,0x00,0x0c,0x7f,0xf0,0x7f,0xe0,0x00,0x00,0x00,0x00,0x0c,0x06,0x00,0x03,0x1c,0x30,0x9f,0x0c,0x00,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x07,0x86,0x00,0x03,0x38,0x30,0xc0,0x0c,0x00,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x01,0x86,0x1e,0

30、x1f,0x30,0x18,0xc0,0x0c,0x01,0xf0,0x60,0x00,0x00,0x00,0x00,0x00,0x07,0x86,0x00,0x01,0xb0,0x0f,0x80,0x0c,0x03,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x0c,0x06,0x00,0x01,0x98,0x07,0x1f,0x0c,0x03,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x0c,0x06,0x00,0x01,0x8c,0x06,0x00,0x0c,0x03,0x00,0x60,0x00,0x00,0x00,0x00,0

31、x00,0x0c,0x06,0x00,0x03,0x07,0x06,0x00,0x0c,0x03,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x0c,0x06,0x0f,0xff,0x03,0x06,0x00,0x0c,0x03,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x0c,0x0f,0x18,0x00,0x03,0x07,0x00,0x18,0x03,0x00,0xc0,0x00,0x00,0x00,0x00,0x00,0x07,0xf9,0xf0,0x00,0x01,0xfd,0xff,0xf0,0x01,0xff,0x80,0

32、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

33、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

34、x00,0x00,0x00,0x00,0xfd,0xfe,0x18,0x7f,0x3f,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x8d,0xb6,0x18,0x31,0xb6,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x8c,0x30,0x1c,0x31,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x30,0x3c,0x31,0x86,0x00,0x00,0x00,0

35、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x30,0x3c,0x3f,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x30,0x36,0x36,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x30,0x3e,0x36,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x30,0x66,0x33,0

36、x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x8c,0x30,0x63,0x33,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x8c,0x30,0x63,0x31,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xf8,0x78,0xf7,0xf9,0xcf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

37、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0

38、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,5.7 游戲流程游戲中,程序循環(huán)執(zhí)行按鍵掃描程序,并做出相應(yīng)判斷。整個(gè)程序中,最關(guān)鍵的部分是要根據(jù)玩家的輸入,控制小人、箱子的移動(dòng)。定義一個(gè)二維數(shù)組,用于保存當(dāng)前游戲狀態(tài)每

39、個(gè)字符位的元素,當(dāng)玩家按鍵輸入時(shí),改變?cè)摂?shù)組中相應(yīng)得數(shù)據(jù),再將此二維數(shù)組每個(gè)數(shù)據(jù)代碼的元素顯示出來,就可以出現(xiàn)小人,箱子移動(dòng)的效果。每關(guān)開始,進(jìn)行游戲初始化。將關(guān)卡數(shù)據(jù)寫入上述二維數(shù)組中,并記入小人的位置(man_x,man_y)。程序只要根據(jù)小人移動(dòng)方向周圍的元素信息,結(jié)合游戲規(guī)則,只要判斷能夠移動(dòng)箱子、小人的情況,才顯示出來,而不用對(duì)不能移動(dòng)的情況進(jìn)行判定,這大大簡(jiǎn)化了程序的編寫。游戲流程框圖如下(以向上移動(dòng)為例,其他方向類似):圖32 流程框圖1圖33 流程框圖2圖34 流程框圖3小人、箱子移動(dòng)示意圖(按列看,不同的列對(duì)應(yīng)上述流程的不同情況):圖35 移動(dòng)示意圖5. 8完成本關(guān)每進(jìn)行一次

40、移動(dòng)后就進(jìn)行是否過關(guān)的判定。將記錄本關(guān)每個(gè)字符位狀態(tài)的數(shù)組與存儲(chǔ)本關(guān)原始信息的數(shù)組的對(duì)應(yīng)數(shù)據(jù)進(jìn)行比較,若發(fā)現(xiàn)目的地上沒有箱子,則不算過關(guān),程序退出,進(jìn)入等待按鍵輸入程序,若所有的目的地都有箱子,則游戲過關(guān),初始化下一關(guān)游戲,顯示下一關(guān)游戲界面。/*函數(shù)名:level_suc()功能:判斷是否通過本關(guān)卡入口參數(shù):返回值:*/void level_suc()unsigned char i,j,k=1;for(i = 0; i 8; i+) /行if(k=0) break;for(j = 0; j 8; j+)/列 if(levellevelgij=4|levellevelgij=5)/循環(huán)掃描目標(biāo)

41、位置都有箱子在,此關(guān)卡就通過if(level_tempij=5)k=1;/此位置箱子在目標(biāo)位置上elsek=0;/有目標(biāo)位置沒有箱子break;if(k=1)/所有目標(biāo)位置都有箱子if(levelg8)levelg+=1;else levelg=0; /通關(guān)后重新從第一關(guān)開始timtcount=0; /計(jì)時(shí)清零th0=(65536-50000)/256;tl0=(65536-50000)%256;tcount=0;gamebg(levelg);5.9 選關(guān)按相應(yīng)的選關(guān)鍵,會(huì)改變記錄游戲關(guān)卡的變量levelg,對(duì)游戲重新初始化,即可記錄所選關(guān)卡。相關(guān)程序如下:case 5:if(levelg!=

42、8)levelg+;gamebg(levelg); /顯示第一關(guān)timtcount=0;th0=(65536-50000)/256;tl0=(65536-50000)%256;tcount=0;break;/下一關(guān)case 6:if(levelg!=0)levelg-; gamebg(levelg); /顯示第一關(guān)timtcount=0;th0=(65536-50000)/256;tl0=(65536-50000)%256;tcount=0;break; /上一關(guān)5.10 計(jì)時(shí)利用右半瓶的88字節(jié)的空間,顯示當(dāng)前游戲計(jì)時(shí)和當(dāng)前關(guān)卡。界面設(shè)計(jì)如下:圖36 計(jì)時(shí)界面其中漢字站4個(gè)字符,數(shù)字占兩個(gè)字

43、符。點(diǎn)陣碼也是用字模軟件提取的,顯示方式與游戲元素的顯示方式相同。顯示效果如圖所示:圖37 計(jì)時(shí)界面顯示效果使用定時(shí)器0的計(jì)時(shí)功能,每到1秒,觸發(fā)中斷程序,計(jì)時(shí)變量timtcount就加1,在對(duì)其進(jìn)行數(shù)字分解,將各位在響應(yīng)的位置上顯示出來。void t0_tt() interrupt 1th0=(65536-50000)/256;tl0=(65536-50000)%256;tcount+;if(tcount=20)tcount=0;timtcount+;time_change(timtcount);void time_change(unsigned int ttime)unsigned cha

44、r a1,a2,a3,a4,a5;unsigned char i,j;a1=ttime/10000;a2=ttime/1000%10;a3=ttime/100%10;a4=ttime/10%10;a5=ttime%10;for(j=0;j16;j+) /a1for(i=0;i1;i+)setc_xy(9+i,32+j);write_cmd2(shuzia1j,inc_wr); for(j=0;j16;j+) /a2for(i=0;i1;i+)setc_xy(10+i,32+j);write_cmd2(shuzia2j,inc_wr); for(j=0;j16;j+) /a3for(i=0;i1

45、;i+)setc_xy(11+i,32+j);write_cmd2(shuzia3j,inc_wr); /for(j=0;j16;j+) /a4for(i=0;i1;i+)setc_xy(12+i,32+j);write_cmd2(shuzia4j,inc_wr); /for(j=0;j16;j+) /a5for(i=0;i1;i+)setc_xy(13+i,32+j);write_cmd2(shuzia5j,inc_wr); 6、調(diào)試總結(jié)下面列些了在進(jìn)行proteus仿真過程中出現(xiàn)幾個(gè)問題,通過解決這些問題是我提高了調(diào)試能力。1. 忘記將c文件調(diào)添加進(jìn)工程中,導(dǎo)致定義的函數(shù)不能被調(diào)用;2. 由按鍵掃描,獲取按鍵編號(hào),再通過按鍵編號(hào)執(zhí)行相關(guān)操作。記錄按鍵編號(hào)的變量要及時(shí)復(fù)位,否則在沒有按鍵按下時(shí),程序出現(xiàn)誤操作;3. 圖形液晶顯示器的最大特性是要先定位,在寫數(shù)據(jù),而且是按1字節(jié)寫入的,所以行是按位尋址,列是按字節(jié)尋址,即行有64行,列有8列。顯示時(shí)常常沒有注意到這個(gè),導(dǎo)致定位不準(zhǔn)確,沒有出現(xiàn)應(yīng)有的圖形;4. 調(diào)試時(shí)常常出現(xiàn)multiple public definitions的錯(cuò)誤而能編譯。經(jīng)過多方查找,解決了這個(gè)問題,并個(gè)深刻的明白.h文件和.c文件的關(guān)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論