[elektro] C kerdes

Fuzesi Arnold arnold.fuzesi.lista at gmail.com
Tue Jun 9 23:53:06 CEST 2009


vki látja hirtelen mit szurtam el?! egyszeruen nem jovok rá....

egy PIC-es forrast irnek at iziben AVR-re egy méréshez:

short fcscheck(){            //computes the fcs
int i,k,bt,inbyte, fcslo, fcshi;

     fcslo=fcshi=0xFF;          //intialize FCS values
     for (i = 0;i<(numbyte-2);i++){        //calculate the FCS for all except 
the last two bytes
   inbyte = bte[i];
   for(k=0;k<8;k++){          //perform this procedure for each bit in the byte
     bt = inbyte & 0x01;
     #asm          //embedded assembly language route to do a 16 bit rotate
         BCF    03,0
          RRF    fcshi,F
          RRF    fcslo,F
     #endasm
        if (((status & 0x01)^(bt)) ==0x01){
                fcshi = fcshi^0x84;
                fcslo = fcslo^0x08;
             }            //end of if
     rotate_right(&inbyte,1);               //set up to do the next bit
   }              //end of for
    }
    fcslo = fcslo^0xff;
    fcshi = fcshi^0xff;
    if ((bte[numbyte-1] == fcshi) && (bte[numbyte-2] == fcslo)) {
   return 1;
    }
         else return 0;          //if the computed values equal the last two 
data bytes
}                //return a 1, otherwise return a 0




short, int helyett unsigned char lett mindenhol

asm betet helyett:

	uint fcs=fcshi<<8 + fcslo;
	if(fcs&0x0001) status=0x01;
	else status=0x00;
	fcs>>=1;	
	fcshi=fcs>>8;
	fcslo=fcs&0x00ff;

rotate_right helyett:

	if(inbyte&0x01) status=1;
	else status=0;
	inbyte>>=1; //set up to do the next bit
	if(status)inbyte|=0x80;


Köszi,
Arnold



More information about the Elektro mailing list