CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

struct in struct

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hayri
Guest







struct in struct
PostPosted: Sun Jan 30, 2005 3:37 pm     Reply with quote

Code:

struct
{
   byte A_last;
   byte B_last;
   byte C_last;
   byte D_last;
   struct A {int1 changed; int1 pressed;};
   struct B {int1 changed; int1 pressed;};
   struct C {int1 changed; int1 pressed;};
   struct D {int1 changed; int1 pressed;};
} Buttons;

void InitButtons()
{
   buttons.A_last = 255;
   buttons.B_last = 255;
   buttons.C_last = 255;
   buttons.D_last = 255;
   buttons.A.changed = false;
   buttons.A.pressed = false;
   buttons.B.changed = false;
   buttons.B.pressed = false;
   buttons.C.changed = false;
   buttons.C.pressed = false;
   buttons.D.changed = false;
   buttons.D.pressed = false;
}


here is InitButtons() asm code....


.................... void InitButtons()
.................... {
.................... buttons.A_last = 255;
*
0D7C: MOVLW FF
0D7E: MOVWF 74
.................... buttons.B_last = 255;
0D80: MOVWF 75
.................... buttons.C_last = 255;
0D82: MOVWF 76
.................... buttons.D_last = 255;
0D84: MOVWF 77
.................... buttons.A.changed = false;
0D86: BCF 73.0
.................... buttons.A.pressed = false;
0D88: BCF 73.1
.................... buttons.B.changed = false;
0D8A: BCF 73.0
.................... buttons.B.pressed = false;
0D8C: BCF 73.1
.................... buttons.C.changed = false;
0D8E: BCF 73.0
.................... buttons.C.pressed = false;
0D90: BCF 73.1
.................... buttons.D.changed = false;
0D92: BCF 73.0
.................... buttons.D.pressed = false;
0D94: BCF 73.1
.................... }
0D96: GOTO 1704 (RETURN)


as you can see in asm code

.................... buttons.A.changed = false;
0D86: BCF 73.0

.................... buttons.B.changed = false;
0D8A: BCF 73.0

buttons.A.changed and buttons.B.changed (and others) converted to exactly same asm code (BCF 73.0). both of code uses same memory and everything goes wrong.

i want to differend bytes, bits. (example)
buttons.A.changed = false; --> BCF 73.0
buttons.B.changed = false; --> BCF 73.2

what is i'm doing wrong?
can i use structs in another struct to get this?

thanks.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Jan 30, 2005 6:15 pm     Reply with quote

change
Code:
struct
{
   byte A_last;
   byte B_last;
   byte C_last;
   byte D_last;
   struct A {int1 changed; int1 pressed;};
   struct B {int1 changed; int1 pressed;};
   struct C {int1 changed; int1 pressed;};
   struct D {int1 changed; int1 pressed;};
} Buttons;
to
Code:
struct
{
   byte A_last;
   byte B_last;
   byte C_last;
   byte D_last;
   struct {int1 changed; int1 pressed; A};
   struct {int1 changed; int1 pressed; B};
   struct {int1 changed; int1 pressed; C};
   struct {int1 changed; int1 pressed; D};
} Buttons;
hayri
Guest







PostPosted: Mon Jan 31, 2005 2:14 pm     Reply with quote

thanks a lot Ckielstra Smile

it is absolutely my fool...

this one also worked well. (but used different bytes for each struct - bits 70.0, 71.0 ... only for information)

Code:


typedef struct
{
   int1 changed;
   int1 pressed;
}btn;

struct
{
   byte A_last;
   byte B_last;
   byte C_last;
   byte D_last;
   btn A;
   btn B;
   btn C;
   btn D;
} Buttons;

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group