View previous topic :: View next topic |
Author |
Message |
hayri Guest
|
struct in struct |
Posted: Sun Jan 30, 2005 3:37 pm |
|
|
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
|
|
Posted: Sun Jan 30, 2005 6:15 pm |
|
|
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
|
|
Posted: Mon Jan 31, 2005 2:14 pm |
|
|
thanks a lot Ckielstra
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;
|
|
|
|
|