您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > CT107D_猜数字游戏_基于24c02_sonic_pcf8591_88点阵
/************************************************************************************************************************************************************************************************************************************************************************************************************************///猜数字游戏.c/*猜数字游戏1.开机界面:1602显示welcome88点阵从左上角沿边缘裹到中心2.等待1秒后,1602第一排显示当前数字,第二排显示4个星号3.用超声波传感器或者光敏电阻改变1602的显示(光敏电阻涉及pcf8591)4.1602的型号后面,显示提示语高或者低5.当数字符合设置值,根据所用时间,计算出成绩,并显示成绩=1000s-所用时间6.用按键选择功能,设置下次参数,或者不变如果设置:启动24c02,如果不设置,返回到欢迎界面*/#includereg52.h#includelcd.h#includeled88.h#includepcf8591.h#includesonic.h#include24c02.h#definerst573P2&=0x1f#defineledY4CP2|=0x80#definebeeY5CP2|=0xa0#definesmgY6CP2|=0xc0#definesmgY7CP2|=0xe0sbitP04=P0^4;sbitP06=P0^6;sbitP36=P3^6;#definerstKEY0P3=0x0f#definerstKEY1P3=0xf0#definekeyP3unsignedcharmima=77;voidinit107(){rst573;P36=0;//closeledP0=0xff;ledY4C;rst573;//closebeeP04=0;P06=0;beeY5C;rst573;//closesmgP0=0x00;smgY6C;rst573;}unsignedcharkey16(){unsignedchartemp,temp1,temp2;rstKEY0;if(key!=0x0f){delaynms(5);rstKEY0;if(key!=0x0f){temp1=key;rstKEY1;if(key!=0xf0){delaynms(5);rstKEY1;if(key!=0xf0){temp2=key;temp=temp1|temp2;switch(temp){case0x7e:return1;case0xbe:return2;case0xde:return3;case0xee:return4;case0x7d:return5;case0xbd:return6;case0xdd:return7;case0xed:return8;case0x7b:return9;case0xbb:return10;case0xdb:return11;case0xeb:return12;case0x77:return13;case0xb7:return14;case0xd7:return15;case0xe7:return16;}}elsereturn0;}elsereturn0;}elsereturn0;}elsereturn0;}voidwelcome(){unsignedcharwel[]=welcome!!!;unsignedcharstar[]=-----start------;unsignedchar*p;//cleanlcd(0x80);//cleanlcd(0xc0);//welcome!!!comlcd(0x80);for(p=wel;*p;p++)datlcd(*p);led88();led88();led88();led88();led88();//-----start------comlcd(0x80);for(p=star;*p;p++)datlcd(*p);delaynms(600);}voidpage1(){unsignedcharrow1[]=1.light2.sonic;unsignedcharrow2[]=3.setcode4.re;unsignedchar*p;comlcd(0x01);comlcd(0x80);for(p=row1;*p;p++)datlcd(*p);comlcd(0xc0);for(p=row2;*p;p++)datlcd(*p);}unsignedcharsetmima(){unsignedcharser1[]=setcode:;unsignedcharser2[]=ok!!;unsignedchar*p;unsignedchartemp;delaynms(600);do{temp=key16();}while(temp==3);comlcd(0x01);for(p=ser1;*p;p++)datlcd(*p);//cleanlcd(0xc0);comlcd(0xc0);datlcd('*');datlcd('*');do{temp=key16();}while(temp==0);delaynms(600);comlcd(0xc0);datlcd(temp+'0');mima=temp;mima*=10;do{temp=key16();}while(temp==0);delaynms(600);datlcd(temp+'0');mima+=temp;//把密码存进24c02write24c02(0x01,mima);delaynms(5);//显示ok,设置密码成功comlcd(0xc4);for(p=ser2;*p;p++)datlcd(*p);delaynms(1000);return4;//返回选择页面}unsignedcharwin(){unsignedcharw[]=-win--win--win-;unsignedchar*p;comlcd(0x01);comlcd(0x90);for(p=w;*p;p++){datlcd(*p);comlcd(0x07);delaynms(600);}comlcd(0x06);return4;}voidpage2(unsignedchartempp){unsignedintRvalue;unsignedchartemp1,temp2;temp1=tempp;comlcd(0x01);//cleanlcd(0x80);//cleanlcd(0xc0);comlcd(0xc0);datlcd('*');datlcd('*');datlcd('*');datlcd('*');while(1){if(temp1==1)Rvalue=readAD();if(temp1==2)Rvalue=sonic();if(temp1==3)temp1=setmima();if(temp1==4)return;if(Rvalue!=mima){comlcd(0x80);datlcd(Rvalue%10000/1000+'0');datlcd(Rvalue%1000/100+'0');datlcd(Rvalue%100/10+'0');datlcd(Rvalue%10+'0');delaynms(100);}else{temp1=win();}temp2=key16();if(temp2)if(temp2!=temp1)temp1=temp2;}}voidmain(){unsignedchartemp;init107();initlcd();//setlcdinit_timer0();//setforsonicADpcf8591();//setforADlightwelcome();//displaywelcome!!!-----start------mima=read24c02(0x01);delaynms(5);while(1){page1();do{temp=key16();}while(temp==0);page2(temp);}}/*while(1){Rvalue=readAD();//关于sonic和pcf8591的测试comlcd(0x80);datlcd(Rvalue%10000/1000+'0');datlcd(Rvalue%1000/100+'0');datlcd(Rvalue%100/10+'0');datlcd(Rvalue%10+'0');delaynms(100);}*//*pp=0;//关于24c02的测试for(p=aa;*p;p++){write24c02(pp++,*p);delaynms(1);}comlcd(0x80);for(pp=0;pp7;pp++){datlcd(read24c02(pp));delaynms(600);}while(1);*//*while(1){pp=key16();//关于按键的测试comlcd(0x80);if(pp)datlcd(pp+'0');}*//**************************************************************************************************************************************************************************************************************************************************************************************************************************///24c02.c#includereg52.hexternvoidstartIIC();externvoidstopIIC();externvoidresponse();externvoidwriteIIC(unsignedchartemp);externunsignedcharreadIIC();voidwrite24c02(unsignedcharaddr,unsignedchardat){startIIC();writeIIC(0xa0);//哼,是0xa0,不是0x30,浪费两天时间啦!!!!response();writeIIC(addr);response();writeIIC(dat);response();stopIIC();}unsignedcharread24c02(unsignedcharaddr){unsignedchartemp;startIIC();writeIIC(0xa0);//哼,是0xa0,不是0x30,浪费两天时间啦!!!!response();writeIIC(addr);response();startIIC();writeIIC(0xa1);//哼,是0xa1,不是0x31,浪费两天时间啦!!!!response();temp=readIIC();response();stopIIC();returntemp;}/****************************************************************************************************************************************************************************************
本文标题:CT107D_猜数字游戏_基于24c02_sonic_pcf8591_88点阵
链接地址:https://www.777doc.com/doc-3155948 .html