资源描述:
《基于freescale、三轴加速度传感器、lcd的贪食蛇游戏设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、//说明:该程序是基于freescaleMCU、三轴加速度传感器、ili9320LCD所写的贪食蛇游//戏,上传代码拥有全部的设计思路以及大部分函数主体//=================================================================//宏定义按键//=================================================================#defineKey_Up1#defineKey_Down4#defineKey_Left2#defineKey_Right
2、3#defineucharunsignedchar//=================================================================//使用结构体定义变量使程序的名称更加的清楚//=================================================================struct{ucharX;ucharY;ucharYes;}Food;//食物结构体#defineSNAKE_Max_Long20//最大长度struct{ucharX[SNAKE_Max_Lo
3、ng];ucharY[SNAKE_Max_Long];ucharLong;ucharLife;ucharScore;//蛇的分数ucharLevel;//蛇的等级}Snake;//蛇结构体ucharKey_V_temp=0;//取出上次按键值ucharKey_Value=0;staticintl=0;staticuint16KEY_Init[3]={0,0,0};staticuint16KEY_BASE[3]={0,0,0};score[20]={"0","10","20","30","40","50","60","70","80","90","100
4、","110","120","130","140","150","160","170","180","190"};intlevel[20]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};staticconstbyteChannels[]={13,14,15};/*Contentsforthedevicecontrolregister*/staticwordMMA_7260_OutV[3];staticbyteSumChan;staticbyteOutFlg;voidMMA_7260_Init_
5、3(void){OutFlg=FALSE;/*Nomeasuredvalue*//*ATD0CTL4:SMP2=0,SMP1=0,SMP0=0,PRS4=0,PRS3=0,PRS2=1,PRS1=0,PRS0=1*/ATD0CTL4=5;/*Setsampletimeandprescaler*//*ATD0CTL3:DJM=0,S8C=0,S4C=0,S2C=0,S1C=1,FIFO=0,FRZ1=0,FRZ0=0*/ATD0CTL3=8;/*SetATDcontrolregister3*//*ATD0CTL0:??=0,??=0,??=0,??=0,
6、WRAP3=1,WRAP2=1,WRAP1=1,WRAP0=1*/ATD0CTL0=15;/*Setwraparound*//*ATD0CTL1:ETRIGSEL=0,SRES1=1,SRES0=0,SMP_DIS=1,ETRIGCH3=1,ETRIGCH2=1,ETRIGCH1=1,ETRIGCH0=1*/ATD0CTL1=95;/*Setresolutionanddischarge*//*ATD0CTL2:??=0,AFFC=1,ICLKSTP=0,ETRIGLE=0,ETRIGP=0,ETRIGE=0,ASCIE=0,ACMPIE=0*/ATD0
7、CTL2=64;/*SetATDcontrolregister2*/}//-----------------------------------------------------staticvoidMMA_7260_Measure_3(void){for(SumChan=0;SumChan<3;SumChan++){ATD0CTL5=Channels[SumChan];/*Startmeasurementofnextchannel*/while(!ATD0STAT0_SCF){}/*WaitforADconversioncomplete*/MMA_7
8、260_OutV[SumChan]=ATD0DR0;/*Savemeasuredvalue*/