I forgot to say that if I declare the union as follow in "global.h" (without extern):
__saddr union bts
{ unsigned char byte;
struct
{ unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned...
Hi everyone,
I'm finishing a code for a NEC uProcessor and I'm having problems with unions. At the beginning of writing this code I wrote everything in 1 file, but after I decided to divide this code in various modules.
I have some unions that are used in different modules, so I have to...
Hi,
I finally could solve the problem... This is the code I use.
__saddr union mess0x100
{
struct
{
unsigned short rpm:16;
unsigned short res3:16;
union speed_sensor1
{ unsigned short speed:12;
struct
{
unsigned char dummy;
unsigned char dummy2:4...
Well, I'm using a NEC uP of 8 bits, and the compiler is the IAR Embedded Workbench.
Salem, you're right. I'm having problems because of the compiler is allocating bits from LSB to MSB when I need MSB to LSB.
xwb, I'll be aware of the 'packed' option.
Thanks, I'll let you know how it ends...
Well, I've tried to solve it and it almost works correctly, but not all.
*********************************
__saddr union mess0x100
{
struct
{unsigned char sensor:4;
unsigned short speed:12;
unsigned char res0:8;
unsigned short rpm:16;
unsigned char res1:1;
unsigned char...
Thanks for your reply.
What you've done it's not exactly what I want .This code works correctly but is not useful because I receive 4 kinds of messages, and each of them have 8 bytes, where the variables can be 1 byte or only some bits (as the 'seed' variable I showe you before). So if I have...
Hi,
I'm writing a code and I have a problem with structs and unions.
I read 8 bytes (RXBnD[8]) from an external system, and each of these 8 bytes are structured in 8 bits:
********************************
__saddr union aux_bits2
{
struct
{unsigned char b0:1;
unsigned char b1:1...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.