Jump to content
Sign in to follow this  
Visti

Union Problem

Recommended Posts

V. 6.35. PIC16F876A

 

typedef union

{

unsigned int ad_info[5];

struct

{

unsigned int current;

unsigned int voltage;

unsigned int battemp;

unsigned int heatsink;

unsigned int max_i;

} ad_data;

} adinform;

 

adinform actual;

 

.

.

.

Code is a bit clumsy, but I hade to find out, what was going wrong.

With test values of 0x03 in hi_byte and 0xc0 in lo_byte I get

 

for(i=0;i<5;i++)

{

lo=lo_byte;

hi=hi_byte;

MAKESHORT(test,lo,hi); // test becomes 960 (0x3c0)

actual.ad_info=test;

test=actual.ad_info; // test becomes 192 (0x0c0)

}

 

What happens to MSB of ad_info?

Share this post


Link to post
Share on other sites

Visti,

 

I have verified this problem, it seems to be a compiler bug.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks.

I came across a minor flaw preparing for other routines in this program.

 

if(a>B) //(unsigned int types. Both parts of union and structure. Rather complicated)

{

// empty

}

 

It skipped the first two instructions following {} (label placed wrong).

 

Unable to reproduce at present, as I have removed all unions and structures and is using global addressing instead.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...