//**************************mlx90614***********************************//commandmode命令模式/********************************RAM*******************************/#defineRamAccess0x00//对RAM操作#defineEepomAccess0x20//对EEPRAM操作#defineMode0x60//进入命令模式#defineExitMode0x61//退出命令模式#defineReadFlag0xf0//读标志#defineEnterSleep0xff//进入睡眠模式//ramaddressreadonlyRAM地址(只读)#defineAbmientTempAddr0x03//周围温度#defineIR1Addr0x04#defineIR2Addr0x05#defineLineAbmientTempAddr0x06//环境温度/*0x00000x4074165000.01/单元-40125*/#defineLineObj1TempAddr0x07//目标温度,红外温度/*0x27ad-0x7fff0x3559226100.02//单元-70.01-382.190.01452.2*//********************************EEPROM*******************************/#defineLineObj2TempAddr0x08//eepomaddressEEPROM地址#defineTObjMaxAddr0x00//测量范围上限设定#defineTObjMinAddr0x01//测量范围下限设定#definePWMCtrlAddr0x02//PWM设定#defineTaRangeAddr0x03//环境温度设定#defineKeAddr0x04//频率修正系数#defineConfigAddr0x05//配置寄存器#defineSMbusAddr0x0e//器件地址设定#defineReserverd1Addr0x0f//保留#defineReserverd2Addr0x19//保留#defineID1Addr0x1c//ID地址1#defineID2Addr0x1d//ID地址2#defineID3Addr0x1e//ID地址3#defineID4Addr0x1f//ID地址4/*=================函数声明===================*/voidstart();//MLX90614发起始位子程序voidstop();//MLX90614发结束位子程序ucharReadByte(void);//MLX90614接收字节子程序voidsend_bit(void);//MLX90614发送位子程序/*==================启动信号=========================*/voidstart(void)//停止条件是SCK=1时,SDA由1到0{SDA=1;delay(4);SCK=1;delay(4);SDA=0;delay(4);SCK=0;delay(4);}/*===================停止信号=====================*/voidstop(void)//停止条件是SCK=1时,SDA由0到1{SCK=0;delay(4);SDA=0;delay(4);SCK=1;delay(4);SDA=1;}/*=======================发送一个字节========================*/voidSendByte(ucharnumber){uchari,n,dat;n=Nack_number;//可以重发次数Send_again://goto语句标识符dat=number;for(i=0;i8;i++)//8位依次发送{if(dat&0x80)//取最高位{bit_out=1;/发1}else{bit_out=0;//发0}send_bit();//发送一个位dat=dat1;//左移一位}read_bit();//接收1位应答信号if(bit_in==1)//无应答时重发{stop();if(n!=0){n--;//可以重发Nack_number=10次gotoRepeat;//重发}else{gotoexit;//退出}}else{gotoexit;}Repeat:start();//重新开始gotoSend_again;//重发exit://退出}/*===================发送一个位=================*/voidsend_bit(void){if(bit_out==1){SDA=1;//发1}else{SDA=0;//发0}_nop_();SCK=1;//上升沿delay(4);delay(4);SCK=0;delay(4);delay(4);}/*=================接收一个字节==========================*/ucharReadByte(void){uchari,dat;dat=0;//初值为0for(i=0;i8;i++){dat=dat1;//左移read_bit();//接收一位if(bit_in==1){dat=dat+1;//为1时对应位加1}}SDA=0;//发送应答信号0send_bit();returndat;//带回接收数据}/*=============接收一个位==============*/voidread_bit(void){SDA=1;//数据端先置1bit_in=1;SCK=1;//上升沿delay(4);delay(4);bit_in=SDA;//读数据_nop_();SCK=0;delay(4);delay(4);}/*=============延时==============*/voiddelay(uintn){uintj;for(j=0;jn;j++){_nop_();}}