Compiler does not allow me to have bit type in a record, or a pointer to bit type. Looking at bit type of DI_1 described in compiler generated U file I have found that this:
is translated to a compiler friendly form like this:
As expected, it seams that it is not a simple pointer but a record of a byte pointer and a bit number in that byte. I am trying to trick compiler to accept this bit (or bit8) type in a array of records (as const or structconst), but without any success at all. I could store this bit8 type in a record as word and byte but I do not know how to cast to/from it.
I would like to have something like this:
and then later in code to use it for read/write from/to that bit:
I already have this working with a pointer to a byte type in ram and eeprom, but bit type is giving me a headache.
If anyone has any idea I am all ears... :argue:
Code
DI_1 [@PORT_STABLE1, 0]: bit;
is translated to a compiler friendly form like this:
Code
VAR DI_1, BIT8, RAM, $F0000;55;
As expected, it seams that it is not a simple pointer but a record of a byte pointer and a bit number in that byte. I am trying to trick compiler to accept this bit (or bit8) type in a array of records (as const or structconst), but without any success at all. I could store this bit8 type in a record as word and byte but I do not know how to cast to/from it.
I would like to have something like this:
Code
type
PBit = pointer to bit;
p = pointer;
TTagStruct = record
No : word;
Tag: PBit;
end;
var
{$PDATA}
DI_1[@PinA, 0]: bit;
DI_2[@PinA, 1]: bit;
const // or structconst
MX: array[1..2] of TTagStruct = ((No: 8; Tag: @DI_1),
(No: 23; Tag: @DI_2));
PBit = pointer to bit;
p = pointer;
TTagStruct = record
No : word;
Tag: PBit;
end;
var
{$PDATA}
DI_1[@PinA, 0]: bit;
DI_2[@PinA, 1]: bit;
const // or structconst
MX: array[1..2] of TTagStruct = ((No: 8; Tag: @DI_1),
(No: 23; Tag: @DI_2));
and then later in code to use it for read/write from/to that bit:
Code
p := pointer(MX[1].Tag); // ptr to bit type in ram
if p^ then
WriteLn(Serout, 'that bit is on');
else
WriteLn(Serout, 'that bit is off');
endif;
if p^ then
WriteLn(Serout, 'that bit is on');
else
WriteLn(Serout, 'that bit is off');
endif;
I already have this working with a pointer to a byte type in ram and eeprom, but bit type is giving me a headache.
If anyone has any idea I am all ears... :argue: