[sdiy] help...no make8() function in Arduino...converting PIC to AVR
Ove Ridé
nitro2k01 at gmail.com
Wed Apr 11 17:53:18 CEST 2012
On 11 April 2012 17:25, dan snazelle <subjectivity at hotmail.com> wrote:
> can someone help me ?
>
> i am trying to convert some PIC code to AVR
>
> it is going fine except for 2 things
>
> there is no make8() function and there is no _mul()
>
>
> so code lines like this:
>
>
> tmp1 = _mul (acc1, val1);
Do you have a definition of what the function is supposed to do
exactly? It might help if you could tell me the types of the three
variables.
I suspect it's either just an accelerated form of multiplication, or
multiplication of two bytes which returns the higher byte of the
answer. Again, some context would be useful.
You can always try defining a macro so you don't have to edit the code
in a million places. Something like
#define _mul(x,y) ((x)*(y))
or
#define _mul(x,y) ((x)*(y)>>8)
Yes, the excessive parentheses are needed in order to guarantee
correct behavior!
> tmpbyte1 = make8(tmp1, 1);
make8 is apparently a macro/function to pick out a byte from a bigger
data type. Something like the following should suffice:
#define make8(val, offset) ( ( (val)>>((offset)*8) ) & 0xFF)
Again, yes, it sucks in terms of readability to have all those
parentheses there, but the C preprocessor just does string
substitution and for example something like 2*make8(1+x,2) would break
because of operator precedence, without the parentheses.
But C for PIC8's sucks, and you should probably look into completely
reorganizing the code if you plan on permanently switching to AVR. AVR
has much better C support and you don't need as much of these
architecture specific tricks.
--
/Ove
Blog: <http://blog.gg8.se/>
"Here is Evergreen City. Evergreen is the color of green forever."
More information about the Synth-diy
mailing list