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 support@ccsinfo.com

Operations with bits

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



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

Operations with bits
PostPosted: Fri Apr 14, 2017 8:11 am     Reply with quote

Hi, I have this problem, I read the 8 bits from a port:

var=A7 A6 A5 A4 A3 A2 A1 A0
I want get this A0 A1 A2 A3 A4 A5 A6 A7
and after, 0 0 0 0 A0 A1 A2 A3

so, the result is invert and move.

I know its possible with
Code:
temp = input_a();
if (bit_test(temp,0)) bit_set(var,7)
...

but, this take on many time, and this steep running at the interruption ext
someone idea? thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 9:39 am     Reply with quote

Code library post comparing several methods of bit reversal:
http://www.ccsinfo.com/forum/viewtopic.php?t=23364

Followup comments:
http://www.ccsinfo.com/forum/viewtopic.php?t=42151
Note that FvM's method requires a RAM array of 256 bytes. It's the
Purdick method, but in RAM instead of in ROM. You need a PIC with
enough RAM to use this method.
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 10:42 am     Reply with quote

PCM programmer wrote:
Code library post comparing several methods of bit reversal:
http://www.ccsinfo.com/forum/viewtopic.php?t=23364

Followup comments:
http://www.ccsinfo.com/forum/viewtopic.php?t=42151
Note that FvM's method requires a RAM array of 256 bytes. It's the
Purdick method, but in RAM instead of in ROM. You need a PIC with
enough RAM to use this method.

thanks

I use this, but I see is similar

Code:
 DTMF_CMD = 0x0;                             
   Temp = input_b();                           
   if (bit_test(Temp,1)) bit_set(DTMF_CMD,3);  // Leer bit 1 (B1) de Temp y guardar en el bit 3 DTMF_CMD   3---
   if (bit_test(Temp,2)) bit_set(DTMF_CMD,2);  // Leer bit 2 (B2) de Temp y guardar en el bit 2 DTMF_CMD   -2--
   if (bit_test(Temp,3)) bit_set(DTMF_CMD,1);  // Leer bit 3 (B3) de Temp y guardar en el bit 1 DTMF_CMD   --1-
   if (bit_test(Temp,4)) bit_set(DTMF_CMD,0);  // Leer bit 4 (B4) de Temp y guardar en el bit 0 DTMF_CMD   ---0 


But this take many time Sad

Its similar to:
Code:

int8 reverse( int8 backwards )
{
  int8 result=0;
  int8 x;

  x = 8;
  do
  {
    if (bit_test(backwards,7))
      bit_set(result,0);

     rotate_left( &backwards,1);
     rotate_right( &result, 1);
  } while (--x);

  return result;
}

Well, I thought this was more easy... jejeje
Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:11 am     Reply with quote

the version like this:
Code:

 DTMF_CMD = 0x0;                             
   Temp = input_b();                           
   if (bit_test(Temp,1)) bit_set(DTMF_CMD,3);  // Leer bit 1 (B1) de Temp y guardar en el bit 3 DTMF_CMD   3---
   if (bit_test(Temp,2)) bit_set(DTMF_CMD,2);  // Leer bit 2 (B2) de Temp y guardar en el bit 2 DTMF_CMD   -2--
   if (bit_test(Temp,3)) bit_set(DTMF_CMD,1);  // Leer bit 3 (B3) de Temp y guardar en el bit 1 DTMF_CMD   --1-
   if (bit_test(Temp,4)) bit_set(DTMF_CMD,0);  // Leer bit 4 (B4) de Temp y guardar en el bit 0 DTMF_CMD   ---0 

Will execute much faster.

You need to look at the actual execution time, rather than the code size.
The 'looped' version gives a very similar size, but takes several times as long to execute....
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 1:40 pm     Reply with quote

OK, a possible hardware solution...
Since I see 'DTMF', is it possible to rewire the peripherals attached to the PIC to get the bits 'right way round'??

Jay
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 1:56 pm     Reply with quote

temtronic wrote:
OK, a possible hardware solution...
Since I see 'DTMF', is it possible to rewire the peripherals attached to the PIC to get the bits 'right way round'??

Jay


I was going to suggest the same thing. If this is such an issue, it may be worth a revised PCB.
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 9:46 pm     Reply with quote

newguy wrote:
temtronic wrote:
OK, a possible hardware solution...
Since I see 'DTMF', is it possible to rewire the peripherals attached to the PIC to get the bits 'right way round'??

Jay


I was going to suggest the same thing. If this is such an issue, it may be worth a revised PCB.


Yes, the better option is fixed the PCB... :( I no wanted do... but read the bits this way is not good.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:44 pm     Reply with quote

A lot also depends on what chip is involved.
The fastest solution is the 256 entry lookup table already mentioned.
Now on any of the larger chips this is not a terrible cost, and honestly in an interrupt handler is probably the only solution to consider.....
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