unsigned long int DSPC01::pressure(void) { unsigned long int press_temp=0; IIC_Start(); communicate_status = IIC_WriteByte(0x21); if( communicate_status == COMMUNI_SUCCEED) { press_temp = IIC_ReadByte(); press_temp*=256; press_temp*=256; IIC_ACK(); press_temp+= (unsigned int)(IIC_ReadByte()<<8); IIC_ACK(); press_temp+= IIC_ReadByte(); IIC_NoAck(); IIC_Stop(); } return press_temp; }
long int DSPC01::altitude(void) { long int alt_temp=0; IIC_Start(); communicate_status = IIC_WriteByte(0x21); if( communicate_status == COMMUNI_SUCCEED) { alt_temp = IIC_ReadByte(); alt_temp*=256; alt_temp*=256; IIC_ACK(); alt_temp+= (unsigned int)(IIC_ReadByte()<<8); IIC_ACK(); alt_temp+= IIC_ReadByte(); IIC_NoAck(); IIC_Stop(); } if (alt_temp>8388608) //negative! alt_temp=8388608-alt_temp; return alt_temp; }
unsigned int DSPC01::compass(void) { unsigned int comp=0; IIC_Start(); communicate_status = IIC_WriteByte(0x21); if( communicate_status == COMMUNI_SUCCEED) { comp+= (unsigned long int)(IIC_ReadByte()<<8); IIC_ACK(); comp+=IIC_ReadByte(); IIC_NoAck(); IIC_Stop(); } return comp; }
long int DSPC01::temperature(void) { long int temp=0; IIC_Start(); communicate_status = IIC_WriteByte(0x21); if( communicate_status == COMMUNI_SUCCEED) { temp +=(unsigned int)(IIC_ReadByte()<<8); IIC_ACK(); temp +=IIC_ReadByte(); IIC_NoAck(); IIC_Stop(); } if (temp>32768) temp = 32768-temp; return temp; }
/******************************************************************************* **函 数: IIC_ReadDataN **功 能: IIC在指定地址连续读N个数据 **参 数: Addr --地址 ** pData --接收数据指针 ** len --接收数据长度 **返 回: void *******************************************************************************/ void IIC_ReadDataN(u8 Addr,u8 *pData,u8 len) { u8 i,*pTemp= pData; IIC_Start(); IIC_SendByte(DEVICE_ADDR); IIC_WaitAck(); IIC_SendByte(Addr); IIC_WaitAck(); IIC_Start(); IIC_SendByte(DEVICE_ADDR+1); IIC_WaitAck(); for(i=0;i<len-1;i++) { *(pTemp++) = IIC_GetByte(); IIC_ACK(); } *(pTemp++) = IIC_GetByte(); IIC_NACK(); IIC_Stop(); }