View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
Operations with bits |
Posted: Fri Apr 14, 2017 8:11 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Fri Apr 14, 2017 10:42 am |
|
|
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
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19383
|
|
Posted: Fri Apr 14, 2017 11:11 am |
|
|
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.... |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9178 Location: Greensville,Ontario
|
|
Posted: Fri Apr 14, 2017 1:40 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Fri Apr 14, 2017 1:56 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Fri Apr 14, 2017 9:46 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19383
|
|
Posted: Fri Apr 14, 2017 11:44 pm |
|
|
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..... |
|
![](templates/subSilver/images/spacer.gif) |
|