Hi
once i receive a serial code i have to put it in a variable from right to left or left to right.If the bit-string is shorter than 32 bit it is easy ,it should work even in this trivial way:
unsigned int rx_bit_var,final_var;
for(i=0;i<bit_str_lngth;i++)
{
rx_bit_var=RecvFuction();//i waste a int for a bit ,it can be 0x00000001 or 0x00000000
final_var |=rx_bit_var;
final_var <<=1;
}
but what if the string is 100 bits long?
In a 9S08 i would dare to rotate variables through carry.
Is there any hardware in low end Kinetis microcontroller that can ease ths process?
It would be possible to profite of some register in serial modules as SPI,I2C or UART?
Many thanks
Hi, Diego,
I think you can use the bits segment variable in C language:
typedef union
{
unsigned int word0,word1;
struct Bit {
unsigned int half_Ba0: 4;
unsigned int half_Bb0: 4;
unsigned int half_Bc0: 4;
unsigned int half_Bd0: 4;
unsigned int half_Ba1: 1;
unsigned int half_Bb1: 2;
unsigned int half_Bc1: 3;
unsigned int half_Bd1: 4;
unsigned int half_Ba2: 4;
unsigned int half_Bb2: 4;
unsigned int half_Bc2: 4;
unsigned int half_Bd2: 4;
unsigned int half_Ba3: 1;
unsigned int half_Bb3: 2;
unsigned int half_Bc3: 3;
unsigned int half_Bd3: 4;
} B;
}u_var;
u_var word;
void main()
{
word.word0=0x12345678;
word.B.half_Bd1=0x07;
.........
}
I have tried above code, I can pass compilation with KDS tools.
Hope it can help you
BR
Xiangjun rong