楼主一看就是搞商用车的,呵呵! 给你两个函数,时将SAE ID与CAN2.0B ID转换的: //-------------protocol transfer between MCU(freescale 68hc08GZ series) and SAE----------- void ID_MCUtoSAE(unsigned char ID_MCU[4],unsigned char ID_SAE[4]) { ID_SAE[0]=(ID_MCU[0]&0xf8)>>3; //priority ID_SAE[1]=((ID_MCU[0]&0x07)<<5)+((ID_MCU[1]&0xe0)>>3)+((ID_MCU[1]&0x06)>>1); //PDU format ID_SAE[2]=((ID_MCU[1]&0x01)<<7)+((ID_MCU[2]&0xfe)>>1); //PDU specific ID_SAE[3]=((ID_MCU[2]&0x01)<<7)+((ID_MCU[3]&0xfe)>>1); //SA } void ID_SAEtoMCU(unsigned char ID_SAE[4],unsigned char ID_MCU[4]) { ID_MCU[0]=(ID_SAE[0]<<3)+ ((ID_SAE[1]&0xe0)>>5); //IDR0 ID_MCU[1]=((ID_SAE[1]&0x1c)<<3)+0x18+ ((ID_SAE[1]&0x03)<<1)+ ((ID_SAE[2]&0x80)>>7);//IDR1 ID_MCU[2]=(ID_SAE[2]<<1)+ (ID_SAE[3]>>7); //IDR2 ID_MCU[3]=(ID_SAE[3]<<1)&0xfe; //IDR3 } |