Ok guys lets get back to the OP. I have seen that solutions posted here
were for certain values or just transforming the given value to
manchester code.
I assume that Jhon wants to use *SPI protocol which requires a single
bit by bit addressing. [See the code from Jhon's post]
Following lines of code will transform any given value to manchester
code and this is what OP was looking for. Though jhon has to take care
of timing problem according to his machine or mcu if bitrate is
critical for application.
Regards
ali
*SPI - The Serial Peripheral Interface is a general-purpose
synchronous serial interface originally found on certain Motorola
microcontrollers. A virtually identical interface can now be found on
various other microcontrollers as well.
[
http://www.mmca.org/technology/glossary/]
#define bit_get(p,m) ((p) & (m))
#define BIT(x) (0x01 << (x))
int count =0;
void Out(char ch){
if(count++ % 4 == 0 )
printf(" %c" ,ch);
else
printf("%c" , ch);
}//Out
int main(){
//Here in array put what ever data you want , my machine was having 16
bit for unsigned int. If your value is greater than this then you need
some other data type;-)
unsigned int data[] = {0x00 , 0x33a , 0x00 , 0x12 , 0x01 , 0x0f , 0x00
, 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
int manchester;
int bitcounter;
int i;
for(i =0 ; i <= 7; i++){
switch(i){
case 0: { bitcounter = 8; printf(" \n0x00 = "); break; }//
case 1: { bitcounter = 9; printf(" \n0x33a = "); break;
}//delimiter
case 2: { bitcounter = 7; printf(" \n0x00 = "); break; }//
case 3: { bitcounter = 7; printf(" \n0x12 = "); break; }//
case 4: { bitcounter = 7; printf(" \n0x01 = "); break; }//
case 5: { bitcounter = 7; printf(" \n0x0f = "); break; }//
case 6: { bitcounter = 27; printf(" \nWordData 7 bytes 0x00 =
"); break; }//
case 7: { bitcounter = 27; printf(" \nWordData 7 bytes 0x00 =
"); break; }//
}//switch
for(; bitcounter != -1; bitcounter--){
if(bit_get(data
, BIT((bitcounter))) & 0xff )
{
Out('1');
Out('0');
}
else
{
Out('0');
Out('1');
}
}//bitcounter != -1
count=0;
}//for(i =0 ; i < 7; i++)
printf("\n \n");
return 0;
}//main