这是我上个学期,小学期的课程设计。
本设计有有LCD显示、蜂鸣器唱歌、矩阵键盘、LED矩阵。
文件包括proteus仿真,与源码keil4工程。
单片机源程序:
- #include<reg52.h>
- #include<stdlib.h>
- sbit RS=P2^0;
- sbit EN=P2^1;
- sbit Speak=P2^2;
- sbit button1=P2^3; //选择模式键
- sbit button2=P2^4; //确认键、返回键、暂停键、下一关开始键
- sbit Buzzer=P2^6;
- sbit hole1=P2^7; //1号洞
- sbit SDA=P1^1; //24c02数据线
- sbit SCL=P1^0; //24c02时钟线
- unsigned char Count; //Play_Song使用
- unsigned char i,j;
- unsigned char temp; //随机数种子
- unsigned char result; //随机数临时变量
- unsigned char score; //保存临时分数
- unsigned char tempname[2];//保存临时分数的名字
- unsigned char time; //保存时间(30秒倒计时)
- unsigned char num; //1秒钟判断变量
- unsigned char flag1; //1标识得分,led全灭,不进行scankey操作
- unsigned char flag2; //1标识得分Buzzer响方式1
- unsigned char flag3; //1标识地鼠出洞时间到,开始下一轮地鼠出洞
- unsigned char flag4; //1标识关卡时间到
- unsigned char flag5; //1标志暂停
- unsigned char level; //关卡等级
- unsigned char holenum; //保存随机生成的洞号
- unsigned char topscore[3]={0}; //保存3个最高分
- unsigned char name[3][2]={"AA","BB","CC"}; //保存3个最高分名字
- unsigned char code hole[]={0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//P3口控制的洞
- unsigned char code str1[]={"Welcome!"}; //欢迎标语
- unsigned char code str2[]={"1.start 2.score"};
- unsigned char code str3[]={"3.exit"};
- unsigned char code str4[]={"See You! "}; //exit界面
- unsigned char code str5[]={"Ready?"};
- unsigned char code str6[]={"GO!"};
- unsigned char code str7[]={"Your Soccer: "}; //查看分数
- unsigned char code str8[]={"Time: Score: "};
- unsigned char code str9[]={" Team: SONGE "}; //队名
- unsigned char code str10[]={"Game Over!"};
- unsigned char code str11[]={"You Win! GO?"};
- unsigned char code str12[]={"You Lose!"};
- unsigned char code str13[]={"top1:"};
- unsigned char code str14[]={"Congratulations"};
- unsigned char code str15[]={"hole: level:"};
- unsigned char code str16[]={"top2:"};
- unsigned char code str17[]={"top3:"};
- unsigned char code str18[]={"Your Name:"}; //记录姓名
- //*************************1602函数声明*******************************//
- void displayWelcome(); //显示欢迎界面
- void displayPrepare(); //显示选项
- void Game(); //游戏真正进行
- void displayGame(); //开始游戏
- void displayExit(); //显示退出界面
- void displaytime();
- void displayChoose(); //显示选择界面
- void displayover();
- void scankey();
- void pause();
- void displayScoreNext();
- //***************************基础函数*****************************//
- void delayms(unsigned int xms) //延时xms 毫秒
- {
- unsigned int i,j;
- for(i=xms; i>0; i--)
- for(j=110; j>0; j--);
- }
- void delayus(unsigned int ums) //延时ums 个3微秒
- {
- unsigned int i,j;
- for(i=0; i<ums; i++)
- for(j=0; j<3; j++);
- }
- void Time_init() //定时器初始化,11.0592MZ晶振 初始选择:定时器0用于播放音乐,定时器1关闭
- { //进入游戏:定时器1用于LCD显示分数
- TMOD = 0x11; //16位定时器 退出游戏:定时器0播放音乐,定时器1关闭
- TH0 = 0xDC;
- TL0 = 0x00;
- TH1=(65536-45872)/256;
- TL1=(65536-45872)%256;
- EA=1; //开总中断
- ET0=1; //开定时器0中断
- ET1=1; //开定时器1中断
- }
- void Time0() interrupt 1 //定时器0中断 播放音乐
- {
- TH0 = 0xDC;
- TL0 = 0x00;
- Count++; //长度加1
- }
- void Time1() interrupt 3 //定时器1中断 游戏中显示分数
- {
- TH1=(65536-45872)/256;
- TL1=(65536-45872)%256; //每50ms中断一次
- num++;
- if(num%20==0) //近似1秒钟
- {
- time--;
- }
- if(num==(60-20*level)) //出洞结束,level1:3s; level2:2s; level3:1s
- {
- num=0;
- flag3=1;
- }
- if(time==0) //一关结束
- {
- time=30;
- flag4=1;
- }
- }
- //***********************播放音乐*********************************//
- unsigned char code SONG[] ={ //祝你平安
- 0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20,
- 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x00, //27个数字
- //0x20,0x20,0x20,0x20,0x1c,0x20,0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,
- //0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20,
- //0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20,
- //0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10,
- //0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20,
- //0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20,
- //0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,
- //0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10,
- //0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80,
- //0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20,
- //0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,
- //0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10,
- //0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,//第217个数字
- //路边的野花不要采
- // 0x30,0x1C,0x10,0x20,0x40,0x1C,0x10,0x18,0x10,0x20,0x10,0x1C,0x10,0x18,0x40,0x1C,
- // 0x20,0x20,0x20,0x1C,0x20,0x18,0x20,0x20,0x80,0xFF,
- 0x20,0x30,0x1C,0x10,0x18,0x20,
- 0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,
- 0x30,0x80,0xFF,0x20,0x20,0x00,
- //0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,
- //0x20,0x2B,0x40,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,
- //0x20,0x2B,0x40,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,
- //0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,0x30,0x80,0x20,0x30,0x1C,0x10,0x20,
- //0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x15,0x1F,
- //0x05,0x20,0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,
- //0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,
- //0x20,0x26,0x20,0x20,0x20,0x30,0x30,0x20,0x30,0x1C,0x10,0x18,0x40,0x1C,0x20,0x20,
- //0x20,0x26,0x40,0x13,0x60,0x18,0x20,0x15,0x40,0x13,0x40,0x18,0x80,
- };
- void Play_Song(unsigned char i) //i=1 播放 路边的野花不要采
- { //i=0 播放 祝你平安
- unsigned char Temp1,Temp2;
- unsigned int Addr;
- Count = 0; //中断计数器清0
- Addr = i * 27; //音乐地址
- TR0=1; //开启定时器0
- while(1)
- {
- Temp1 = SONG[Addr++];
- if (Temp1 == 0xFF) //休止符
- {
- TR0 = 0; //关闭定时器0
- delayus(100);
- }
- else if (Temp1 == 0x00) //歌曲结束符
- {
- TR0=0; //关闭定时器0
- return;
- }
- else //正常播放歌曲
- {
- Temp2 = SONG[Addr++];
- TR0 = 1;
- while(1)
- {
- Speak = ~Speak;
- delayus(Temp1);
- if(Temp2 == Count)
- {
- Count = 0;
- break;
- }
- }
- }
- }
- }
- void playBuzzer()
- {
-
- if(flag2==1) //得分响
- {
- for(i=0;i<20;i++)
- { Speak=1;
- delayms(1);
- Speak=0;
- delayms(1);
- }
- Speak=0;Buzzer=0;delayms(500);Buzzer=1;delayms(100);
- }
- else
- {
-
- }
- }
- //******************************24C02环节*************************************//
- void init()
- {
- SDA=1;
- delayms(5);
- SCL=1;
- delayms(5);
- }
- void start() //开始信号
- {
- SDA=1;
- delayms(5);
- SCL=1;
- delayms(5);
- SDA=0;
- delayms(5);
- }
- void stop() //停止信号
- {
- SDA=0;
- delayms(5);
- SCL=1;
- delayms(5);
- SDA=1;
- delayms(5);
- }
- void respons() //应答
- {
- unsigned char i;
- SCL=1;
- delayms(5);
- while((SDA==1)&&(i<250))
- i++;
- SCL=0;
- delayms(5);
- }
- void write_byte(unsigned char date)//写字节
- {
- unsigned char i,temp,j;
- temp=date;
- for(i=0; i<8; i++)
- {
- j=0x80&temp;
- temp=temp<<1;
- SCL=0;
- delayms(5);
- SDA=(bit)j;
- delayms(5);
- SCL=1;
- delayms(5);
- }
- SCL=0;
- delayms(5);
- SDA=1;
- delayms(5);
- }
- unsigned char read_byte()//读字节
- {
- unsigned char i,k;
- SCL=0;
- delayms(2);
- SDA=1;
- for(i=0; i<8; i++)
- {
- SCL=1;
- delayms(5);
- k=(k<<1)|SDA;
- SCL=0;
- delayms(5);
- }
- return k;
- }
- void write_add(unsigned char address,unsigned char date)//往地址写数据
- {
- start();
- write_byte(0xa0); //控制字写1010 000 0(写操作)
- respons();
- write_byte(address);//存储单元地址
- respons();
- write_byte(date);
- respons();
- stop();
- }
- unsigned char read_add(unsigned char address) //往地址中读数据
- {
- unsigned char date;
- start();
- write_byte(0xa0); //控制字 写
- respons();
- write_byte(address); //单元地址
- respons();
- start();
- write_byte(0xa1); //控制字读1010 000 1(读操作)
- respons();
- date=read_byte(); //数据
- SDA=1; //非应答
- delayus(5);
- SCL=1;
- delayus(5);
- stop();
- return date;
- }
- void getRecord() //读取前三名分数
- {
- topscore[0]=read_add(0);//第一名
- name[0][0]=read_add(1);
- name[0][1]=read_add(2);
- topscore[1]=read_add(3);//第二名
- name[1][0]=read_add(4);
- name[1][1]=read_add(5);
- topscore[2]=read_add(6);//第三名
- name[2][0]=read_add(7);
- name[2][1]=read_add(8);
- }
- void Record() //更新前三并记录分数
- {
- write_add(0,topscore[0]);//第一名
- write_add(1,name[0][0]);
- write_add(2,name[0][1]);
- write_add(3,topscore[1]);//第二名
- write_add(4,name[1][0]);
- write_add(5,name[1][1]);
- write_add(6,topscore[2]);//第三名
- write_add(7,name[2][0]);
- write_add(8,name[2][1]);
- }
- void Judge() //判断分数高低
- {
- if(score>topscore[0])
- {
- topscore[2]=topscore[1];//第二名赋给第三名
- name[2][0]=name[1][0];
- name[2][1]=name[1][1];
- topscore[1]=topscore[0];//第一名赋给第二名
- name[1][0]=name[0][0];
- name[1][1]=name[0][1];
- topscore[0]=score; //临时变量赋给第一名
- name[0][0]=tempname[0];
- name[0][1]=tempname[1];
- }else if(score>topscore[1])
- {
- topscore[2]=topscore[1];//第二名赋给第三名
- name[2][0]=name[1][0];
- name[2][1]=name[1][1];
- topscore[1]=score; //临时变量赋给第二名
- name[1][0]=tempname[0];
- name[1][1]=tempname[1];
- }else if(score>topscore[2])
- {
- topscore[2]=score; //临时变量赋给第三名
- name[2][0]=tempname[0];
- name[2][1]=tempname[1];
- }
- }
- //*******************************1602环节*************************************//
- void wr_com(unsigned char com) //写指令
- {
- delayms(5);
- RS=0;
- EN=0;
- P0=com;
- delayms(5);
- EN=1;
- delayms(5);
- EN=0;
- }
- void wr_dat(unsigned char dat) //写数据
- {
- delayms(5);
- RS=1;
- EN=0;
- P0=dat;
- delayms(5);
- EN=1;
- delayms(5);
- EN=0;
- }
- void lcd_init() //1602初始化设置//
- {
- delayms(1);
- wr_com(0x38); //设置16*2显示,5*7点阵,8位数据接口
- wr_com(0x01); //显示清0,数据指针清0
- wr_com(0x06); //写一个字符后地址加一
- wr_com(0x0c); //设置开显示,不显示光标
- getRecord();
- }
- void displayWelcome() //显示欢迎界面
- {
- wr_com(0x80+0x03);
- delayms(1);
- for(i=0; i<9; i++)
- {
- wr_dat(str1[i]);
- delayus(1);
- }
- wr_com(0xc0+0x01);
- delayms(1);
- for(i=0; i<13; i++)
- {
- wr_dat(str9[i]);
- delayus(1);
- }
- for(i=0; i<10; i++) //开关显示完成闪烁
- {
- if(j==0)
- {
- wr_com(0x08); //关显示
- delayms(100);
- }else
- {
- wr_com(0x0c); //开显示
- delayms(100);
- }
- j=~j;
- }
- Play_Song(0);
- delayms(100);
- }
- void displayPrepare() //显示选项
- {
- wr_com(0x01); //清屏
- delayms(5);
- wr_com(0x80);
- delayms(5);
- for(i=0; i<15; i++)
- {
- wr_dat(str2[i]);
- delayus(5);
- }
- wr_com(0x80+0x40);
- delayms(5);
- for(i=0; i<6; i++)
- {
- wr_dat(str3[i]);
- delayus(5);
- }
- for(i=0; i<9; i++)
- {
- switch(i%3)
- {
- case 0:hole1=0;P3=0x00;delayms(100);
- case 1:hole1=0;P3=0x55;delayms(100);
- case 2:hole1=1;P3=0xaa;delayms(100);
- }
- }
- hole1=0;
- P3=0x00;
- }
- void displaytime() //游戏过程中刷新显示时间、分数
- {
- wr_com(0x80+0x05); //显示倒计时
- delayus(5);
- wr_dat(0x30+time/10);
- delayus(5);
- wr_dat(0x30+time%10);
- delayus(5);
- wr_com(0x80+0x0e); //显示分数
- delayus(5);
- wr_dat(0x30+score/10);
- delayus(5);
- wr_dat(0x30+score%10);
- delayus(5);
- wr_com(0xc0+0x0e); //显示关卡
- delayus(5);
- wr_dat(0x30+(level+1));
- delayus(5);
- }
- void recordName() //记录姓名
- {
- wr_com(0x01);
- delayus(5);
- wr_com(0x80);
- delayus(5);
- for(i=0; i<10; i++) //Your Name:
- {
- wr_dat(str18[i]);
- delayus(5);
- }
- i='A';
- wr_dat(i);
- delayus(5);
- wr_com(0x10); //光标左移
- delayus(5);
- wr_com(0x0f); //光标闪烁
- delayus(5);
-
-
- while(1) //输入第一个字母
- {
- wr_com(0x80+0x0a);
- delayus(5);
- wr_dat(i);
- delayus(5);
- if(button1==0)
- {
- delayms(10);
- if(button1==0)
- {
- while(!button1);
- i++;
- if(i>'Z')
- i='A';
- }
- }
- if(button2==0)//确认,开始输入第二个字母
- {
- tempname[0]=i;
- break;
- }
- }
- i='A'; //输入第二个字母
- wr_dat(i);
- delayus(5);
- while(1)
- {
- wr_com(0x80+0x0b);
- delayus(5);
- wr_dat(i);
- delayus(5);
- if(button1==0)
- {
- delayms(10);
- if(button1==0)
- {
- while(!button1);
- i++;
- if(i>'Z')
- i='A';
- }
- }
- if(button2==0)//确认,输入完毕
- {
- tempname[1]=i;
- break;
- }
- }
- wr_com(0x0c); //关闭光标
- delayus(5);
- displayChoose();
- }
- void displayover() //显示一轮游戏结束画面
- {
- TR1=0; //关闭定时器1
- wr_com(0x01);
- delayms(5);
- wr_com(0x80);
- delayms(5);
- for(i=0; i<10; i++) //Game Over
- {
- wr_dat(str10[i]);
- delayus(5);
- }
- wr_com(0xc0);
- delayus(5);
-
- if(score>=(10*(1+level))) //不同level分数要求不同,win了
- {
- if(level==3) //通关了
- {
- level=0;
- wr_com(0x80);
- delayus(5);
- for(i=0; i<15; i++)
- {
- wr_dat(str14[i]);
- delayus(5);
- }
- wr_com(0xc0);
- delayus(5);
- for(i=0; i<8; i++)
- {
- wr_dat(str11[i]);
- delayus(5);
- }
- while(1)
- {
- if(button2==0)
- {
- delayms(10);
- if(button2==0)
- {
- while(!button2);
- recordName();
- }
- }
- }
- }
- else //升级了
- {
- for(i=0; i<12; i++) //You Win!
- {
- wr_dat(str11[i]);
- delayus(5);
- }
-
- while(1)
- {
-
- if(button2==0)
- {
- delayms(10);
- if(button2==0)
- {
- while(!button2);
- level++;
- displayGame();
- }
- }
- }
- }
- }
- else //You Lose!
- {
- for(i=0; i<9; i++)
- {
- wr_dat(str12[i]);
- delayus(5);
- }
- }
- while(1) //失败了
- {
- if(button2==0)
- {
- delayms(10);
- if(button2==0)
- {
- while(!button2);
- if(score!=0) //0分不记录
- recordName();
- displayChoose();
- }
- }
- }
- }
- void scankey() //扫描按键,判断是否得分
- {
- if((hole1==0) && (P3==0x00))//打中地鼠
- {
- delayms(5);
- flag1=1; //标志得分不进行scankey
- flag2=1; //标识得分buzzer
- score++;
- playBuzzer();
- hole1=0;
- P3=0x00;
- }
- }
- unsigned char random() //随机数
- {
- temp++;
- result=rand()%9+1;
- return result;
- }
- void displayhole() //hole地鼠显示
- {
- holenum=random();
- if(holenum==0)
- holenum++;
- wr_com(0xc0+0x06);
- delayus(5);
- wr_dat(0x30+holenum);
- delayus(5);
- switch(holenum)
- {
- case 0: break;
- case 1: //1号洞亮
- hole1=1;
- P3=hole[1];
- break;
- case 2: //2号洞亮
- hole1=0;
- P3=hole[2];
- break;
- case 3: //3号洞亮
- hole1=0;
- P3=hole[3];
- break;
- case 4: //4号洞亮
- hole1=0;
- P3=hole[4];
- break;
- case 5: //5号洞亮
- hole1=0;
- P3=hole[5];
- break;
- case 6: //6号洞亮
- hole1=0;
- P3=hole[6];
- break;
- case 7: //7号洞亮
- hole1=0;
- P3=hole[7];
- break;
- case 8: //8号洞亮
- hole1=0;
- P3=hole[8];
- break;
- case 9: //9号洞亮
- hole1=0;
- P3=hole[9];
- break;
- }
- }
- void pause() //暂停/恢复游戏
- {
- if(button2==0) //暂停键
- {
- delayms(5); //去抖动
- if(button2==0)
- {
- while(!button2);
- TR1=~TR1;
- flag5=~flag5;
- return;
- }
- }
- }
- void Gameinit() //游戏开始时数据初始化
- {
- flag1=0;//scankey标识
- flag2=0;//蜂鸣器标志位
- flag3=0;//出洞结束标识
- flag4=0;//timeover标识
- time=30;
- if(level==0) //重新开始闯关,则清零得分
- score=0;
- wr_com(0x01); //清屏
- delayus(5);
- wr_com(0x80);
- delayus(5);
- for(i=0; i<15; i++) //固定内容显示
- {
- wr_dat(str8[i]);
- delayus(5);
- }
- wr_com(0xc0);
- delayus(5);
- for(i=0; i<14; i++)
- {
- wr_dat(str15[i]);
- delayus(5);
- }
- }
- void Game() //游戏真正进行!!!!!!!!!!
- {
- Gameinit();
- displaytime(); //显示时间、分数、洞、关卡
- TR1=1; //开启定时器1
- while(1)
- {
- displayhole(); //地鼠出洞
- while(!flag3)//地鼠出洞时间 level:3s; level2:2s; level3:1s
- {
- if(flag5==0)
- {
- if(flag1==0)
- scankey();
- displaytime();
- }
- pause(); //暂停键判断
- };
- if(flag2==0)//没有打中地鼠
- {
- playBuzzer();
- }
- if(flag4==1)//时间到,结束game
- {
- displayover();
- }
- flag1=0;//scankey标识
- flag2=0;//蜂鸣器标志位
- flag3=0;//出洞结束标识
- flag4=0;//timeover标识
- }
- }
- void displayGame() //开始游戏
- {
- wr_com(0x01); //清屏
- delayms(5);
- wr_com(0x80+0x04);
- delayms(5);
- for(i=0; i<6; i++) //显示Ready
- {
- wr_dat(str5[i]);
- delayus(5);
- }
- wr_com(0xc0+0x06);
- delayms(5);
- for(i=5; i>0; i--) //显示倒数5秒
- {
- wr_dat(0x30+i);
- for(j=0; j<10; j++)
- delayms(100);
- wr_com(0xc0+0x06);
- delayms(5);
- }
- wr_com(0xc0+0x06);
- delayms(5);
- for(i=0; i<3; i++) //显示GO
- {
- wr_dat(str6[i]);
- delayus(5);
- }
- delayms(200);
- Game(); //开始游戏!
- }
- void displayScore() //显示得分记录
- {
- getRecord();//从24C02中获取数据
- wr_com(0x01);
- delayms(5);
- wr_com(0x80);
- delayms(5);
- for(i=0; i<12; i++) //显示当前得分
- {
- wr_dat(str7[i]);
- delayus(5);
- }
- wr_dat(0x30+score/10);
- delayms(5);
- wr_dat(0x30+score%10);
- delayms(5);
- wr_com(0xc0);
- delayus(5);
- for(i=0; i<5; i++) //第二行显示top1
- {
- wr_dat(str13[i]);
- delayus(5);
- }
- wr_com(0xc0+0x06); //top1
- delayus(5);
- wr_dat('4');
- delayus(5);
- wr_dat('0');
- delayus(5);
- wr_com(0xc0+0x09);
- delayus(5);
- wr_dat('A');
- delayus(5);
- wr_dat('Q');
- delayus(5);
- while(1) //进入第二页键
- {
- if(button2==0)
- {
- delayms(10); //去抖动
- if(button2==0)
- {
- while(!button2);
- displayScoreNext();
- break;
- }
- }
- }
- }
- void displayScoreNext() //显示分数第二页
- {
- wr_com(0x01);
- delayms(5);
- wr_com(0x80);
- delayus(5);
- for(i=0; i<5; i++) //第一行显示top2
- {
- wr_dat(str16[i]);
- delayus(5);
- }
- wr_com(0x80+0x06);
- delayus(5);
- wr_dat('3');
- delayus(5);
- wr_dat('9');
- delayus(5);
- wr_com(0x80+0x09);
- delayus(5);
- wr_dat('A');
- delayus(5);
- wr_dat('W');
- delayus(5);
-
- wr_com(0xc0);
- delayus(5);
- for(i=0; i<5; i++) //第二行显示top3
- {
- wr_dat(str17[i]);
- delayus(5);
- }
- wr_com(0xc0+0x06);
- delayus(5);
- wr_dat('3');
- delayus(5);
- wr_dat('8');
- delayus(5);
- wr_com(0xc0+0x09);
- delayus(5);
- wr_dat('A');
- delayus(5);
- wr_dat('E');
- delayus(5);
- while(1) //返回键
- {
- if(button2==0)
- {
- delayms(10); //去抖动
- if(button2==0)
- {
- while(!button2);
- break;
- }
- }
- }
-
- }
- void displayExit() //显示退出界面
- {
- wr_com(0x01); //清屏
- delayms(5);
- wr_com(0x80+0x01);
- delayms(5);
- for(i=0; i<8; i++)
- {
- wr_dat(str4[i]);
- delayus(5);
- }
- wr_com(0xc0+0x01);
- delayms(5);
- for(i=0; i<13; i++)
- {
- wr_dat(str9[i]);
- delayus(5);
- }
- while(1)
- {
- Play_Song(1);
- delayms(200);
- }
- }
- void displayChoose() //显示选择界面
- {
- if(score!=0)//0分不记录
- {
- Judge();//判断并重新排序
- Record();//记录到24C02中
- }
- displayPrepare();
- wr_com(0x80);
- delayms(5);
- wr_com(0x0f); //光标闪烁
- delayms(5);
- i=0;
- while(1)
- {
- if(button1==0) //选择模式键
- {
- delayms(10); //去抖动
- if(button1==0)
- {
- while(!button1); //松开按钮
- i++;
- if(i==3)
- i=0;
- switch(i)
- {
- case 0:wr_com(0x80);delayms(5);break; //移动光标到相应位置
- case 1:wr_com(0x80+0x08);delayms(5);break;
- case 2:wr_com(0x80+0x40);delayms(5);break;
- }
- }
- }
- if(button2==0) //确认键
- {
- delayms(10); //去抖动
- if(button2==0)
- {
- while(!button2); //松开
- wr_com(0x0c); //关闭光标
- delayus(5);
- switch(i)
- {
- case 0:displayGame(); break;
- case 1:displayScore(); break;
- case 2:displayExit(); break;
- }
- return;
- }
- }
- }
- }
- void main()
- {
- lcd_init(); //lm016
- //displayWelcome();
- Time_init(); //interrupt
- init(); //E2PROM
- displayWelcome();
- while(1)
- {
- displayChoose();
- }
- }
复制代码
全部资料51hei下载地址:
单片机模拟打地鼠设计 .zip
(115.25 KB, 下载次数: 127)
|