CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help! I want a function equivalent to that in ccs...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
albe01



Joined: 02 Jul 2010
Posts: 30
Location: italy

View user's profile Send private message

Help! I want a function equivalent to that in ccs...
PostPosted: Fri Jul 16, 2010 7:20 am     Reply with quote

hello to everyone, I want a function equivalent to that
I did many tests, but have not found anything equivalent working
i use a pic 18F4525 and this function work only on the 16F

Code:
 
#asm   //embedded assembly language route to do a 16 bit rotate
BCF    03,0
RRF    fcshi,F   
RRF    fcslo,F
#endasm
suggestions are welcome
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Fri Jul 16, 2010 8:43 am     Reply with quote

The function you have there, performs a _shift_, not a rotation. If you look, the bit off the bottom is lost, and a zero is shifted in from the carry (which is why it is cleared in the first instruction).
Look at the code generated by the CCS 'shift_right' function:
Code:

....................    shift_right(&val,2,0);
00C3:  BCF    03.0
00C4:  RRF    47,F
00C5:  RRF    46,F

identical (except I'm using 'val', rather than 'fcs'.
The CCS instruction happily works on the PIC18, knowing that the carry flag is now in the register at address 0xFD8, rather than '3' on the PIC16, and that the PIC18 has separate rotate instructions to handle the carry, so has to use RRCF, rather than RRF.
Use the CCS instruction, it'll help make the code portable to different processors....

Best Wishes
KnowMore



Joined: 05 Jul 2010
Posts: 9
Location: Vietnam

View user's profile Send private message

PostPosted: Fri Jul 16, 2010 10:28 am     Reply with quote

Code:
rotate_right( )

--------------------------------------------------------------------------------
Syntax:
 rotate_right (address, bytes)

 
 
Parameters:
 address is a pointer to memory, bytes is a count of the number of bytes to work with.

 
 
Returns:
 undefined

 
 
Function:
 Rotates a bit through an array or structure. The address may be an array identifier or an address to a byte or  structure (such as &data). Bit 0 of the lowest BYTE in RAM is considered the LSB.

 
 
Availability:
 All devices

 
 
Requires:
 Nothing

 
 
Examples:
 struct {

   int cell_1 : 4;

   int cell_2 : 4;

   int cell_3 : 4;

   int cell_4 : 4; } cells;

rotate_right( &cells, 2);

rotate_right( &cells, 2);

rotate_right( &cells, 2);

rotate_right( &cells, 2);

// cell_1->4, 2->1, 3->2 and 4-> 3

 
 
Example Files:
 None

 
 
Also See:
 rotate_left(), shift_left(), shift_right()

 


I see CCS C Compiler has got.
_________________
GOOD TODAY IS ENEMY OF BETTER TOMORROW
albe01



Joined: 02 Jul 2010
Posts: 30
Location: italy

View user's profile Send private message

PostPosted: Fri Jul 16, 2010 11:35 am     Reply with quote

ok but I do not understand the code replacement :(
albe01



Joined: 02 Jul 2010
Posts: 30
Location: italy

View user's profile Send private message

PostPosted: Fri Jul 16, 2010 11:52 am     Reply with quote

this is the complete function:
Code:



//------------------------------------------------------- FUNCT FCSCHECK OK
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                     
BCF STATUS,C     
RRCF    fcshi,F           
RRCF    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

         

//------------------------------------------- VOID PRINTOUT OK

void printout(){                             //function to display the received packet
int L,m;                              //int L,m;
for (m=7;m<13;m++){                          //print the source callsign
if (bte[m] != 0x40) (putc(bte[m]>>1));       //note spaces (40) are not printed
}
putc('-');
putc(((bte[13] & 0x7F)>>1));                 //print source SSID
putc('>');
for (m=0;m<6;m++){                           //print the destination callsign
if (bte[m] != 0x40) (putc(bte[m]>>1)); 
}       //end of for
putc('-');
putc(((bte[6] & 0x7F)>>1));                  //print the dest SSID
L = 7;
if ((bte[13] & 0x01) != 1){                  //print any path that may exist
do{
putc(',');
L=L+7;
for (m=L;m<(L+6);m++){
if (bte[m] != 0x40) (putc(bte[m]>>1));
}                                            //end of for
putc('-');
putc(((bte[(L+6)] & 0x7F)>>1));
}while ((bte[L+6] & 0x01) != 1);
}                                            //end of if
putc(':');
putc(' ');
L=L+9;                                       //add 9 to move past the last callsign, cntl and PID
while (L< numbyte-2){                        //print the text (not including fcs bytes)
putc(bte[L]);
L++;
}         //end of while
printf("\n\r");                              //add carriage return/line feed at the end
}                                            //end of printout()
void main()
{
output_high(DCD_LED);    //blink LED to know PROGRAM is running
delay_ms(1200);
output_low(DCD_LED);
printf("Test Message\r\n\n");
while (TRUE)  {
get_packet();
if(fcs_check())  {
output_high(RCV_LED);
printout();
output_low(RCV_LED);
} //end if
}//end while(TRUE) loop
} //end main() 
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group