欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    单片机俄罗斯方块程序(共14页).doc

    • 资源ID:13708684       资源大小:41KB        全文页数:14页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    单片机俄罗斯方块程序(共14页).doc

    精选优质文档-倾情为你奉上#include"reg52.h"#define WINDOW_XADDR_START0x0050 / Horizontal Start Address Set#define WINDOW_XADDR_END0x0051 / Horizontal End Address Set#define WINDOW_YADDR_START0x0052 / Vertical Start Address Set#define WINDOW_YADDR_END0x0053 / Vertical End Address Set#define GRAM_XADDR 0x0020 / GRAM Horizontal Address Set#define GRAM_YADDR 0x0021 / GRAM Vertical Address Set#define GRAMWR 0x0022 / memory write#define uint unsigned int#define uchar unsigned charsbit CS=P22;/片选sbit RES=P21;/复位sbit RS=P24;/数据/命令选择sbit RW=P25; const uint col9=0x0000,0xFFFF,0x001F,0xFFE0,0xF800,0xF81F,0x07E0,0x7FFF,0x051F; /Black White BlueYellow Red Magenta Green Cyan Blue2const uint boxes7= /方块样式存储数组 0x0f00,0x0740,0x0e20,0x0e40,0x0c60,0x06c0,0x0660 ;uint fi23=0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003, 0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003, 0xffff,0xffff,0xffff;uchar a,b; uint t,p; uint score; uchar speed,leve,time; /游戏速度 uchar pcolor,color;void Init_Timer1(void) TMOD |= 0x10; /使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响 TH1=0x3c; /给定初值,这里使用定时器最大值从0开始计数一直到65535溢出 TL1=0xb0; EA=1; /总中断打开 ET1=1; /定时器中断打开 TR1=1; /定时器开关打开void delay(unsigned int i) /延时函数while(i-);uchar keyscan(void) /键盘扫描函数,使用行列反转扫描法 uchar k; P1=0xff; k=P1; if(k!=0xff) delay(100); if(k!=0xff) k=P1;if(k=0xfd) return 1; if(k=0xfb)return 2;if(k=0xf7) return 3;if(k=0xef) return 4; return 8; void delayms(uint count) int i,j; for(i=0;i<count;i+) for(j=0;j<260;j+); void Write_Cmd(uchar DH,uchar DL) CS=0;RS=0;P0=DH;RW=0;RW=1;P0=DL;RW=0;RW=1;CS=1;void Write_Data(uchar DH,uchar DL) CS=0;RS=1;P0=DH;RW=0; RW=1;P0=DL;RW=0;RW=1;CS=1;void Write_Cmd_Data (uchar x,uint y)uchar m,n;m=y>>8;n=y;Write_Cmd(0x00,x);Write_Data(m,n);void Write_Data_U16(uint y)unsigned char m,n;m=y>>8;n=y;Write_Data(m,n);static void LCD_SetPos(uint x0,uint x1,uint y0,uint y1) Write_Cmd_Data(WINDOW_XADDR_START,x0); Write_Cmd_Data(WINDOW_XADDR_END,x1); Write_Cmd_Data(WINDOW_YADDR_START,y0); Write_Cmd_Data(WINDOW_YADDR_END,y1); Write_Cmd_Data(GRAM_XADDR,x0); Write_Cmd_Data(GRAM_YADDR,y0); Write_Cmd (0x00,0x22);/LCD_WriteCMD(GRAMWR);void ILI9325_Initial(void) CS=1;delayms(5);RES=0;delayms(5);RES=1;delayms(5); delayms(100); Write_Cmd_Data(0x0001,0x0100); Write_Cmd_Data(0x0002,0x0700); Write_Cmd_Data(0x0003,0x1030); Write_Cmd_Data(0x0004,0x0000); Write_Cmd_Data(0x0008,0x0207); Write_Cmd_Data(0x0009,0x0000); Write_Cmd_Data(0x000A,0x0000); Write_Cmd_Data(0x000C,0x0000); Write_Cmd_Data(0x000D,0x0000); Write_Cmd_Data(0x000F,0x0000);/power on sequence VGHVGL Write_Cmd_Data(0x0010,0x0000); Write_Cmd_Data(0x0011,0x0007); Write_Cmd_Data(0x0012,0x0000); Write_Cmd_Data(0x0013,0x0000); /vgh Write_Cmd_Data(0x0010,0x1290); Write_Cmd_Data(0x0011,0x0227); /delayms(100); /vregiout Write_Cmd_Data(0x0012,0x001d); /0x001b /delayms(100); /vom amplitude Write_Cmd_Data(0x0013,0x1500); /delayms(100); /vom H Write_Cmd_Data(0x0029,0x0018); Write_Cmd_Data(0x002B,0x000D); /gamma Write_Cmd_Data(0x0030,0x0004); Write_Cmd_Data(0x0031,0x0307); Write_Cmd_Data(0x0032,0x0002);/ 0006 Write_Cmd_Data(0x0035,0x0206); Write_Cmd_Data(0x0036,0x0408); Write_Cmd_Data(0x0037,0x0507); Write_Cmd_Data(0x0038,0x0204);/0200 Write_Cmd_Data(0x0039,0x0707); Write_Cmd_Data(0x003C,0x0405);/ 0504 Write_Cmd_Data(0x003D,0x0F02); /ram Write_Cmd_Data(0x0050,0x0000); Write_Cmd_Data(0x0051,0x00EF); Write_Cmd_Data(0x0052,0x0000); Write_Cmd_Data(0x0053,0x013F); Write_Cmd_Data(0x0060,0xA700); Write_Cmd_Data(0x0061,0x0001); Write_Cmd_Data(0x006A,0x0000); / Write_Cmd_Data(0x0080,0x0000); Write_Cmd_Data(0x0081,0x0000); Write_Cmd_Data(0x0082,0x0000); Write_Cmd_Data(0x0083,0x0000); Write_Cmd_Data(0x0084,0x0000); Write_Cmd_Data(0x0085,0x0000); / Write_Cmd_Data(0x0090,0x0010); Write_Cmd_Data(0x0092,0x0600); Write_Cmd_Data(0x0093,0x0003); Write_Cmd_Data(0x0095,0x0110); Write_Cmd_Data(0x0097,0x0000); Write_Cmd_Data(0x0098,0x0000); Write_Cmd_Data(0x0007,0x0133);uchar dir_y(uchar k) return (1-k%2)*(k/2*2-1);uchar dir_x(uchar k) return (k%2)*(k/2*2-1);void ClearScreen(void) uint i,j; LCD_SetPos(0,240,0,320);/320x240 for (i=0;i<320;i+) for (j=0;j<240;j+) if(j=59|i>=310) Write_Data_U16(col8); else Write_Data_U16(col0); void SET(char x,char y,uchar k) uint i,bColor; bColor=colk; LCD_SetPos(30+x*15,43+x*15,10+y*15,23+y*15); for (i=0;i<225;i+) Write_Data_U16(bColor);void SET1(uint z,uchar k)char i;i=0; while(i<16) if(z&0x8000) SET(i%4+a,i/4+b,k); z<<=1;i+; uchar NUM(uchar n)switch(n)case 0:return 0x3f;break; case 1:return 0x06;break; case 2:return 0x5b;break; case 3:return 0x4f;break; case 4:return 0x66;break; case 5:return 0x6d;break; case 6:return 0x7d;break; case 7:return 0x07;break; case 8:return 0x7f;break; case 9:return 0x6f;break;return 0x00;void OUTNUM(char x,char y,uchar n)int a,b,i;a=30+x*15,b=10+y*15;LCD_SetPos(a,a+14,b,b+31); for (i=0;i<512;i+) Write_Data_U16(col0);if(n&0x80)LCD_SetPos(a+14,a+15,b+30,b+31); for(i=0;i<4;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+4,a+11,b+16,b+17); for(i=0;i<16;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+2,a+3,b+4,b+15); for(i=0;i<24;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+2,a+3,b+18,b+29); for(i=0;i<24;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+4,a+11,b+30,b+31); for(i=0;i<16;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+12,a+13,b+18,b+29); for(i=0;i<24;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+12,a+13,b+4,b+15); for(i=0;i<24;i+) Write_Data_U16(col8); n<<=1;if(n&0x80)LCD_SetPos(a+4,a+11,b+2,b+3); for(i=0;i<16;i+) Write_Data_U16(col8); void PRSCORE(void) uint k;char i,n,q; k=score;i=1; while(k) n=NUM(k%10); OUTNUM(i,2,n); k/=10;i-; OUTNUM(-2,12,0x38); q=speed;i=0; while(q) n=NUM(q%10); OUTNUM(i,12,n); q/=10;i-; uchar CANMOVE(uchar q)/判定方块是否能朝 q 方向移动 uchar i,j,z;uint k; if(!p) return 0; i=a+dir_x(q);j=b+dir_y(q); z=0;k=0; while(z<4) k=k+(fij+z<<i)&0xf000)>>(4*z); z+; if(k&p) return 0; else return 1;void MOVE(uchar q)/朝 q 方向移动方块 SET1(p,0); a+=dir_x(q);b+=dir_y(q); SET1(p,color);void SYS(void)/将可活动的方块都变为不可活动的方块 uchar z;uint k; z=0;k=p; while(z<4) fib+z|=(k&0xf000)>>a); k<<=4;z+; p=0;void TURN(void)/方块变形 uint k,p1;uchar z; switch(p) case 0x0f00: p1=0x4444;break;case 0x4444: p1=0x0f00;break; case 0x0740: p1=0x0622;break;case 0x0622: p1=0x02e0;break;case 0x02e0: p1=0x4460;break;case 0x4460: p1=0x0740;break; case 0x0e20: p1=0x2260;break;case 0x2260: p1=0x0470;break;case 0x0470: p1=0x0644;break;case 0x0644: p1=0x0e20;break; case 0x0e40: p1=0x4c40;break;case 0x4c40: p1=0x4e00;break;case 0x4e00: p1=0x4640;break;case 0x4640: p1=0x0e40;break; case 0x0c60: p1=0x2640;break;case 0x2640: p1=0x0c60;break; case 0x06c0: p1=0x4620;break;case 0x4620: p1=0x06c0;break; case 0x0660: p1=0x0660;break; z=0;k=0; while(z<4) k=k+(fib+z<<a)&0xf000)>>(4*z); z+; if(!(k&p1) SET1(p,0);p=p1;SET1(p,color); uchar SCORED(void)/满行消去,返回加分 uchar i,j,k,s=0,bcolor; bcolor=time%8+1; for(k=19;k>0;k-)if(fik=0xffff) for(i=2;i<14;i+) for(j=k;j>0;j-) if(fij<<i)&0x8000)(fij-1<<i)&0x8000) if(fij<<i)&0x8000) SET(i,j,0); else SET(i,j,bcolor); for(j=k;j>0;j-) fij=fij-1;k+;s+; return s; void putbox(void)/随机取一个方块,输出到左边并等待下次放出 char i;uint k; t=boxestime%7; pcolor=time%8+1; i=0;k=t; while(i<16) if(k&0x8000) SET(i%4-2,i/4+5,pcolor); else SET(i%4-2,i/4+5,0); k<<=1;i+; uchar getbox(void)/取上次存储的方块,放出,返回能否放出方块(不能则返回0,游戏结束) if(!p)p=t;a=6,b=0; color=pcolor; SET1(p,color); if(fi0!=0xc003) return 0; else return 1;void main(void) uchar k,cm,cn,ins; a=6,b=0;p=0; score=1; time=0;leve=1;speed=leve+score/200; ILI9325_Initial(); ClearScreen(); PRSCORE(); Init_Timer1();while(1)k=keyscan();if(k=1&&leve>1) leve-;speed=leve+score/200;PRSCORE();if(k=3&&leve<9) leve+;speed=leve+score/200;PRSCORE();if(k=4) break;if(k!=8) delay(30000);putbox(); getbox();while(1)cm=time;ins=speed*speed/10-3*speed+28;do k=keyscan();if(k=1) if(CANMOVE(1) MOVE(1);if(k=3) if(CANMOVE(3) MOVE(3);if(k=2) if(CANMOVE(2) MOVE(2);continue;if(k=4) TURN();if(k!=8) delay(30000);if(k=4) delay(30000); cn=time;if(cn>cm&&cn-cm>ins) break;if(cn<cm&&cn+100-cm>ins) break; while(p);if(CANMOVE(2) MOVE(2);else SYS();/方块自动下移,不可下移时把可移动方块变为不可移动 k=SCORED(); /满行消去,返回加分 if(k) score+=(k+1)*(k+1);speed=leve+score/200; PRSCORE(); if(!p) k=getbox(); if(!k) break; putbox(); /无法放出方块己方游戏结束 void Timer1_isr(void) interrupt 3 using 1 TH1=0x3c; /重新赋值 TL1=0xb0; time+; if(time>100) time=0;专心-专注-专业

    注意事项

    本文(单片机俄罗斯方块程序(共14页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开