#include<p24fxxxx.h> unsigned int Result; unsigned char datab[]={ 0x01,0x02,0x03,0x04, 0x05,0x06,0x07,0x08, 0x09,0x0A,0x0B,0x0C, 0x0D,0x0E,0x0F,0x10, 0x11,0x12,0x13,0x14, 0x15 }; unsigned int CRC_HW_calculateB(unsigned char *,unsigned int); main() { Nop(); Result2=CRC_HW_calculateB(datab,sizeof(datab)); Nop(); Nop(); while(1); } unsigned int CRC_HW_calculateB(unsigned char *temp,unsigned int Len) { unsigned int Carry,j; unsigned char *ptr,Flag; ptr=(unsigned char *)&CRCDAT; CRCCON = 0x0000F; // ="Length of polynomial-1" CRCXOR = 0x1021; // generator Polynomial CRCWDAT= 0x0000; // Initialize CRCWDAT with 0 Flag=0x00; for(j=0;j<Len;j++) { *ptr =*temp++; //write data into FIFO Flag=Flag^0x01;//Flag for odd or even bytes if(CRCCONbits.CRCFUL==1)//check if FIFO is full { CRCCONbits.CRCGO=1; //start CRC engine while(CRCCONbits.CRCMPT!=1);//check if FIFO is empty CRCCONbits.CRCGO=0; //stop CRC engine } } if(CRCCONbits.CRCGO!=1) CRCCONbits.CRCGO=1; if(Flag==0) CRCDAT = 0x0000; //appending PLEN+1 zeros (multiply by 2^16) else *ptr=0x00;//appending (PLEN+1)/2 zeros (multiply by 2^8) while(CRCCONbits.CRCMPT!=1);//check if FIFO is empty Nop(); Nop(); Nop(); Nop(); Nop(); CRCCONbits.CRCGO=0; //stop CRC engine Nop(); if(Flag==1) // if odd number of bytes, { //append (PLEN+1)/2 zeros (multiply by 2^8) for(j = 0; j < 8; j ++) { Carry =( CRCWDAT & 0x8000); CRCWDAT <<= 1; if(Carry) CRCWDAT ^= 0x1021; } } return CRCWDAT; }
我用的就是官方提供的程序! 我找了珠海 深圳 上海的FAE 答复均是硬件肯定没问题,让他们再调试调试,这都两个星期了,给香港北京的技术支持!到现在也没解决,各位不相信的话自己可以去尝试! |