Is there any way how to double bits in the 4 bits nibble in XC8 compiler or AVR ASM ? E.g. from 0b00001110 I need to get 0b11111100. It will help me to encode data (~(x^0b10101010) with Manchester code. x is doubled bits value

## ATtiny202 - bits doubling

Since it's only a nibble then make a 4 bit LUT with the 16 one byte results.

add:

0x00,0x03,0x0c,0x0f,

0x30,0x33,0x3c,0x3f,

0xc0,0xc3,0xcc,0xcf,

0xf0,0xf3,0xfc,0xff

You could probably do it with something resembling those clever multiply-based bit-reversal/interleaving hacks. If you had convenient 32bit multiplies. :-(

the table lookup sounds much more reasonable!

https://graphics.stanford.edu/~s...

Have you checked out Appnote TB3218 ? It shows a method of piping SPI thru a CCL to get Manchester out. Let the hardware do the heavy lifting.

Its only at around 1k bits/s - so swings and roundabouts really. Easy enough to determine the bit flip when outputting it.

Another way is just brute-forcing it:

bst r24, 3 bld r24, 6 bld r24, 7 bst r24, 2 bld r24, 4 bld r24, 5 bst r24, 1 bld r24, 2 bld r24, 3 bst r24, 0 bld r24, 1

I think (haven't checked) the table method will use slightly more flash than this, but the table lookup will also be faster.

I found a solution, I simply calculated the results and stored the values in an array:

volatile uint8_t XNOR[16] = {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA};

For value x = 0xA is the result 0x99 i.e.:

10101010 Mask

11001100 Replicated 4 bits 0xA (nibble) to full byte

------------

10011001 XNOR Result (see Binary Bitwise XNOR Calculator)

I just did what you asked for ;)

Add:

And for the other way perhaps look here :

www.avrfreaks.net/forum/cheesies...

OMG it's a 15 year old thread