找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 10894|回復(fù): 8
打印 上一主題 下一主題
收起左側(cè)

51單片機(jī)推箱子游戲 (lm3229)T6963C液晶屏顯示 帶仿真和中文資料

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
51單片機(jī)+(lm3229液晶屏)T6963C芯片主控 做的推箱子游戲 帶上下左右 選關(guān)和開(kāi)始按鈕.

推箱子游戲的proteus仿真原理圖(附件中可下載工程文件):



(lm3229)T6963C中文資料:

(lm3229)T6963C引腳圖:

目    錄
前   言2
注意事項(xiàng)2
第一章:T6963C一般介紹4
第二章:6963C的引腳說(shuō)明及其功能4
一、  T6963C外形圖4
二、  T6963C引腳說(shuō)明5
第三章:T6963C指令集6
第四章:內(nèi)藏T6963C控制器的液晶顯示器的外特性10
第五章、內(nèi)藏T6963C的液晶顯示模塊與MPU的接口方法12
第六章、T6963C控制器液晶模塊應(yīng)用程序示例16


推箱子游戲的51單片機(jī)源程序如下:
  1. #include <reg52.h>
  2. #include <Text1.h> //關(guān)卡的界面
  3. #include <Text2.h> //在此文件中定義了漢字編碼,用點(diǎn)陣液晶字模提取軟件
  4. #define uc unsigned char
  5. #define ui unsigned int
  6. #define d P0          //數(shù)據(jù)口
  7. sbit cd=P2^0;          //=0,數(shù)據(jù)通道;=1,命令通道
  8. sbit rd=P2^1;          //=0,讀選通有效
  9. sbit wr=P2^2;          //=0,寫(xiě)選通有效

  10. uc renh=6,renl=4,bu=0,startf=1,guan=1;

  11. static uc rammap[8][10];


  12. void lcddatw(uc dat)  //寫(xiě)數(shù)據(jù)
  13. {
  14. cd=0;
  15. wr=0;
  16. d=dat;
  17. wr=1;
  18. }

  19. void lcdcmd0(uc cmd)        //寫(xiě)命令
  20. {
  21. cd=1;
  22. wr=0;
  23. d=cmd;
  24. wr=1;
  25. }

  26. void lcdcmd1(uc dat1,uc cmd)  //寫(xiě)帶有一個(gè)參數(shù)的命令
  27. {
  28. lcddatw(dat1);
  29. lcdcmd0(cmd);
  30. }

  31. void lcdcmd2(uc dat1,uc dat2,uc cmd)  //寫(xiě)帶有兩個(gè)參數(shù)的命令
  32. {
  33. lcddatw(dat1);
  34. lcddatw(dat2);
  35. lcdcmd0(cmd);
  36. }

  37. void lcdinit()           //LCD初始化
  38. {
  39. lcdcmd2(0x00,0x10,0x40); //設(shè)置文本顯示區(qū)首地址
  40. lcdcmd2(30,0x00,0x41); //設(shè)置文本顯示區(qū)寬度
  41. lcdcmd2(0x00,0x00,0x42); //設(shè)置圖形顯示區(qū)首地址
  42. lcdcmd2(30,0x00,0x43); //設(shè)置圖形顯示區(qū)寬度
  43. lcdcmd0(0xa2); //設(shè)置光標(biāo)形狀
  44. lcdcmd0(0x80); //設(shè)置顯示方式,文本圖形“或”
  45. lcdcmd0(0x9e); //設(shè)置光標(biāo)閃爍,不顯示,文本與圖形顯示
  46. }

  47. void dischar(uc row,uc col,uc cha) //寫(xiě)ASCII碼字符,row字符行(=8圖形行),col字符列(=8圖形列),chaASCII碼
  48. {  //顯示ASCII碼時(shí),16行x30列
  49. ui address;
  50. uc dat1,dat2;
  51. address=row*30+col+0x1000; //計(jì)算文本顯示區(qū)地址
  52. dat1=address;
  53. dat2=address>>8;
  54. lcdcmd2(dat1,dat2,0x24);//地址指針定位
  55. lcdcmd1(cha,0xc4); //寫(xiě)字符,地址指針不變
  56. }

  57. //數(shù)字和漢字代碼寫(xiě)入自定義字符存儲(chǔ)區(qū)
  58. void setcgram(uc count)  //count是要寫(xiě)的漢字個(gè)數(shù)
  59. {//定義自定義字符在GCRAM中存儲(chǔ)區(qū)地址,自定義字符首地址0x80(固定值),一個(gè)字符8x8=8字節(jié),對(duì)應(yīng)字節(jié)地址0x0400
  60. ui i;
  61. lcdcmd2(0x03,0x00,0x22); //定義自定義字符(在GCRAM中)存儲(chǔ)區(qū)字節(jié)地址高5位為0x03,
  62. lcdcmd2(0x00,0x1c,0x24); //0x03<<11+0x0400=0x1c00(字節(jié)地址)
  63. for(i=0;i<16*8*12/8;i++)
  64. lcdcmd1(shucode[i],0xc0);        //寫(xiě)數(shù)字(每個(gè)16*8)*12(0-9,:)到GCRAM
  65. for(i=0;i<16*16*count/8;i++)
  66. lcdcmd1(hancode[i],0xc0);         //寫(xiě)漢字(每個(gè)16*16)*count到GCRAM
  67. }
  68.          //寫(xiě)漢字代碼,row行,col列,sit漢字在自定義字符中的位置,每個(gè)漢字相當(dāng)于4個(gè)字符(2行2列)
  69. void dishan(uc row,uc col,uc sit)//                sit位置用han[]描述
  70. {
  71. dischar(row,col,sit);//每個(gè)漢字按左上,左下,右上,右下存放
  72. dischar(row+1,col,sit+1);
  73. dischar(row,col+1,sit+2);
  74. dischar(row+1,col+1,sit+3);
  75. }
  76. //寫(xiě)數(shù)字代碼,row行,col列,sit數(shù)字在自定義字符中的位置,每個(gè)數(shù)字相當(dāng)于2個(gè)字符(2行1列)
  77. void disshu(uc row,uc col,uc sit)//        sit位置用shu[]描述
  78. {
  79. dischar(row,col,sit);//每個(gè)漢字按左上,左下,右上,右下存放
  80. dischar(row+1,col,sit+1);
  81. }

  82. void bushu()                //顯示步數(shù)
  83. {
  84.         uc b1=0,b2=0,b3=0;
  85.         if(bu>999)  {b1=9;b2=9;b3=9;}
  86.         else {b1=bu/100;b2=bu/10;b3=bu%10;}
  87.         disshu(10,23,shu[b1]);disshu(10,24,shu[b2]);disshu(10,25,shu[b3]);
  88.         dishan(10,26,han[6]);
  89. }

  90. void huamap()          //畫(huà)關(guān)卡地圖
  91. {
  92. uc i,j;
  93. for(i=0;i<8;i++)
  94. for(j=0;j<10;j++)
  95. {
  96.         dishan(2*i,2*j,han[map[guan-1][i][j]]);
  97.         rammap[i][j]=map[guan-1][i][j];
  98.         if(rammap[i][j]==0x07) rammap[i][j]=0x00;
  99. }
  100. dishan(4,22,han[4]);
  101. disshu(4,24,shu[0]);
  102. disshu(4,25,shu[guan]);
  103. dishan(4,26,han[5]);
  104. bushu();
  105. dishan(2*renh,2*renl,han[1]);
  106. }

  107. void disxg()                   //顯示選關(guān)提示
  108. {
  109. dishan(0,22,han[8]);
  110. dishan(0,24,han[9]);
  111. dishan(0,26,han[5]);
  112. disshu(0,28,shu[10]);
  113. }

  114. void shengli()                         //過(guò)關(guān)判斷
  115. {
  116. uc i,j,s1=0,s2=0;
  117. for(i=0;i<8;i++)
  118. for(j=0;j<10;j++)
  119. {
  120.         if(map[guan-1][i][j]==0x07)    //檢視目標(biāo)
  121.         {
  122.                 s1++;                                          //目標(biāo)計(jì)數(shù)
  123.                 if(rammap[i][j]==0x02) s2++;        //目標(biāo)上箱子計(jì)數(shù)
  124.         }
  125. }
  126. if(s1==s2)                 //目標(biāo)計(jì)數(shù)和目標(biāo)上箱子計(jì)數(shù)相同,則過(guò)關(guān)
  127. {
  128. dishan(2,20,han[10]);         //顯示過(guò)關(guān)提示
  129. dishan(2,22,han[11]);
  130. dishan(2,24,han[12]);
  131. dishan(2,26,han[5]);
  132. disshu(2,28,shu[11]);
  133. startf=0;                                 //停止游戲
  134. disxg();                                 //顯示選關(guān)提示
  135. }
  136. }

  137. void delay()                        //延時(shí)
  138. {
  139.         ui x;
  140.         for(x=0;x<1000;x++);
  141. }


  142. uc key()                   //檢測(cè)按鍵
  143. {
  144.         uc x,k=0;
  145.         P3=0xff;
  146.         x=P3;
  147.         if(x==0xff)           //沒(méi)按鍵跳出
  148.         goto over;
  149.         else
  150.         {
  151.                 delay();           //有按鍵,延時(shí)
  152.                 P3=0xff;
  153.                 x=P3;
  154.                 if(x==0xff)                //再測(cè)
  155.                 goto over;
  156.                 else
  157.                 {
  158.                         switch(x)           //獲取鍵值
  159.                         {
  160.                                 case 0xfe:k=1;break;
  161.                                 case 0xfd:k=2;break;
  162.                                 case 0xfb:k=3;break;
  163.                                 case 0xf7:k=4;break;
  164.                                 case 0xef:k=5;break;
  165.                                 case 0xdf:k=6;break;
  166.                                 case 0xbf:k=7;break;
  167.                                 case 0x7f:k=8;break;
  168.                                 default:break;
  169.                         }
  170.                         wait:           //等待按鍵釋放
  171.                         P3=0xff;
  172.                         x=P3;
  173.                         if(x==0xff) goto over;
  174.                         else goto wait;
  175.                 }
  176.         }
  177.         over:
  178.         return k;
  179. }

  180. void xuanguan(uc k)                 //選關(guān)處理
  181. {
  182.    if((k==1||k==3)&&guan<3) {guan++;renh=6;renl=4;huamap();}
  183.    if((k==2||k==4)&&guan>1) {guan--;renh=6;renl=4;huamap();}
  184. }

  185. void huifumubiao()                //恢復(fù)目標(biāo)顯示,(被人踩的目標(biāo))
  186. {
  187. uc i,j;
  188. for(i=0;i<8;i++)
  189. for(j=0;j<10;j++)
  190. {
  191.         if(map[guan-1][i][j]==0x07&&rammap[i][j]!=0x02)         //有目標(biāo)且沒(méi)有箱子
  192.         {
  193.                 if(renh!=i||renl!=j) dishan(2*i,2*j,han[7]);
  194.         }
  195. }       
  196. }

  197. void game(uc k)                        //游戲控制
  198. {
  199.         if(k==1)                        //向上
  200.         {
  201.                 if(rammap[renh-1][renl]==0x00)                    //上面是空白
  202.                 {
  203.                         dishan(2*renh,2*renl,han[0]);          //人原來(lái)的位置清0
  204.                         renh--;                                                          //上移一行
  205.                         dishan(2*renh,2*renl,han[1]);          //人新位置顯示
  206.                         bu++;                                                  //步數(shù)加1
  207.                 }
  208.                 else if((rammap[renh-1][renl]==0x02)&&(rammap[renh-2][renl]==0x00)) //上面是箱子,箱子上是空格
  209.                 {
  210.                         dishan(2*renh,2*renl,han[0]);dishan(2*(renh-1),2*renl,han[0]);
  211.                         renh--;
  212.                         dishan(2*renh,2*renl,han[1]);dishan(2*(renh-1),2*renl,han[2]);
  213.                         rammap[renh][renl]=0x00;rammap[renh-1][renl]=0x02;
  214.                         bu++;
  215.                 }
  216.         }
  217.         if(k==4)
  218.         {
  219.                 if(rammap[renh+1][renl]==0x00)
  220.                 {
  221.                         dishan(2*renh,2*renl,han[0]);
  222.                         renh++;
  223.                         dishan(2*renh,2*renl,han[1]);
  224.                         bu++;
  225.                 }
  226.                 else if((rammap[renh+1][renl]==0x02)&&(rammap[renh+2][renl]==0x00))
  227.                 {
  228.                         dishan(2*renh,2*renl,han[0]);dishan(2*(renh+1),2*renl,han[0]);
  229.                         renh++;
  230.                         dishan(2*renh,2*renl,han[1]);dishan(2*(renh+1),2*renl,han[2]);
  231.                         rammap[renh][renl]=0x00;rammap[renh+1][renl]=0x02;
  232.                         bu++;
  233.                 }
  234.         }
  235.            if(k==2)
  236.         {
  237.                 if(rammap[renh][renl-1]==0x00)
  238.                 {
  239.                         dishan(2*renh,2*renl,han[0]);
  240.                         renl--;
  241.                         dishan(2*renh,2*renl,han[1]);
  242.                         bu++;
  243.                 }
  244.                 else if((rammap[renh][renl-1]==0x02)&&(rammap[renh][renl-2]==0x00))
  245.                 {
  246.                         dishan(2*renh,2*renl,han[0]);dishan(2*renh,2*(renl-1),han[0]);
  247.                         renl--;
  248.                         dishan(2*renh,2*renl,han[1]);dishan(2*renh,2*(renl-1),han[2]);
  249.                         rammap[renh][renl]=0x00;rammap[renh][renl-1]=0x02;
  250.                         bu++;
  251.                 }
  252.         }
  253.            if(k==3)
  254.         {
  255.                 if(rammap[renh][renl+1]==0x00)
  256.                 {
  257.                         dishan(2*renh,2*renl,han[0]);
  258.                         renl++;
  259.                         dishan(2*renh,2*renl,han[1]);
  260.                         bu++;
  261.                 }
  262.                 else if((rammap[renh][renl+1]==0x02)&&(rammap[renh][renl+2]==0x00))
  263.                 {
  264.                         dishan(2*renh,2*renl,han[0]);dishan(2*renh,2*(renl+1),han[0]);
  265.                         renl++;
  266.                         dishan(2*renh,2*renl,han[1]);dishan(2*renh,2*(renl+1),han[2]);
  267.                         rammap[renh][renl]=0x00;rammap[renh][renl+1]=0x02;
  268.                         bu++;
  269.                 }
  270.         }
  271.         huifumubiao();
  272.         bushu();
  273.         shengli();
  274. }

  275. void clear()        //清屏
  276. ……………………

  277. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
推箱子LM3229.rar (309.46 KB, 下載次數(shù): 180)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏9 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:62509 發(fā)表于 2020-7-9 01:20 | 只看該作者
很好的呀!我試了一下可以用的。就是畫(huà)面太集中了,看起來(lái)覺(jué)得太小。另外關(guān)數(shù)太少了,你剛來(lái)興趣,它沒(méi)了!點(diǎn)個(gè)贊吧!
回復(fù)

使用道具 舉報(bào)

板凳
ID:473186 發(fā)表于 2020-7-9 08:27 | 只看該作者
你覺(jué)得吧是你自己的問(wèn)題,你完全可以自按自己的思路接著往下開(kāi)發(fā)
回復(fù)

使用道具 舉報(bào)

地板
ID:62509 發(fā)表于 2020-7-9 09:27 | 只看該作者
zhengchong60,還是你厲害呀!
回復(fù)

使用道具 舉報(bào)

5#
ID:251061 發(fā)表于 2020-7-12 08:37 | 只看該作者
能寫(xiě)游戲,一定是高手,拜莫
回復(fù)

使用道具 舉報(bào)

6#
ID:884564 發(fā)表于 2021-4-28 16:27 | 只看該作者
真是學(xué)習(xí)好資料,下了,謝謝!!
回復(fù)

使用道具 舉報(bào)

7#
ID:278096 發(fā)表于 2024-10-14 08:44 | 只看該作者
感謝分享,確實(shí)可以運(yùn)行
回復(fù)

使用道具 舉報(bào)

8#
ID:59185 發(fā)表于 2024-12-20 21:52 | 只看該作者
大神,讓我膜拜!
回復(fù)

使用道具 舉報(bào)

9#
ID:59185 發(fā)表于 2024-12-20 21:54 | 只看該作者
真是厲害,牛掰
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表