资源描述:
《多功能秒表程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include//包含文件#include#defineucharunsignedchar//对数据类型的宏定义#defineuintunsignedint#defineHi0//点阵代表Hi#definexin4//点阵代表心形#definexiaol5#definexiaolm6sbitwei=P2^7;//数码管锁存允许定义sbitduan=P2^6;sbitxzhou=P3^0;//点阵锁存允许定义sbityzhou=P3^1;sbitDS=P3^4;//温度传感器I/
2、O口sbitSCL=P3^6;//EEPROM时钟sbitSDA=P3^7;//EEPROM数据ucharFM=0;//sbitFM=P3^2;//蜂鸣器定义sbitZSD=P3^3;//指示灯定义sbitk1=P2^5;//定义六颗按键sbitk2=P2^4;sbitk3=P2^3;sbitk4=P2^2;sbitk5=P2^1;sbitk6=P2^0;ucharkey1=1;//用于键盘扫描函数对六颗按键的识别ucharkey2=2;ucharkey3=3;ucharkey4=4;ucharkey5=5;uchar
3、key6=6;ucharfen,miao,miaoxs,wd,nk1;ucharntime;//ntime用于定时器中断函数累加到40表示百分之一秒uchari,address,ndisplay,time_END,nk2,changci;//i用于写入数据时地址连续相加,ndisplay用于显示某场比赛数据,time_END表示某场参加的人数uinttemp;//整合两个字节的温度到一个变量floatf_temp;uchartime[32];//8人次数据ucharye;//页unsignedcharcodetable
4、duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//不带冒号编码unsignedcharcodetabled[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//带冒号编码unsignedcharcodetablewei[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//数码管位编码unsignedcharcodetablex[]={0x0
5、0,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//点阵X轴编码,共阴极unsignedcharcodetabley[]={0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//点阵Y轴编码,共阳极voiddelay(uint);voiddisplay(uchar,uchar,uchar,uchar);voidleddiandisplay(uchar,uchar,ucahr);voidleddisplay(uchar);ucharkeysc
6、an(uchar);voidshortdelay(void);voidIICinit(void);voidstart(void);voidrespons(void);voidstop(void);voidwritebyte(uchar);ucharreadbyte(void);voidshortdelay(void)//IIC简短延时{;;;}voiddelay(uintxms)//简单延时函数{uinti,j;for(i=xms;i>0;i--)for(j=55;j>0;j--);}voiddsreset(void)
7、//温度传感器初始化{uinti;DS=0;i=103;while(i>0)i--;DS=1;i=4;while(i>0)i--;}bittmpreadbit(void)//读一位{uinti;bitdat;DS=0;i++;//i++用于延时DS=1;i++;i++;dat=DS;i=8;while(i>0)i--;return(dat);}uchartmpread(void)//读一个字节数据{uchari,j,dat;dat=0;for(i=1;i<=8;i++){j=tmpreadbit();dat=(j<<7
8、)
9、(dat>>1);//读出的数据最低位在最前面,这样刚好一个字节在DAT里}return(dat);}voidtmpwritebyte(uchardat)//写一个字节{uinti;ucharj;bittestb;for(j=1;j<=8;j++){testb=dat&0x01;dat=dat>>1;if(testb)//写1