Trouble declaring variables - Add comment to bit in word

bisquit
2018-05-25
2018-05-29
  • bisquit - 2018-05-25

    Hey guys,

    I'm having some trouble declaring the variables in my project.
    I want to be able to set/reset the bits in a word and be able to reset the whole word at once.
    So far i got it working fine at %MW0, but when I try the same at any other adress it wont work.

    Can somebody help me a bit?

    IMG: 2018

    IMG: 2018

     
  • josepmariarams - 2018-05-26

    Try:

    MyMW:pointer to dword;

    MyMW:=adr(mx0);

    MyMW[0] is mx0
    MyMW[1] is mx1
    .
    .
    .

    Setting full

    MyMW[1]:=16#B1

    For example

    Sent from my Moto G (5S) Plus using Tapatalk

     

    Related

    Talk.ru: 1

  • Anonymous - 2018-05-27

    Originally created by: ph0010421

    I think a Union of 16 BITs (not BOOL) and a WORD is a better way to achieve this.

     
  • bisquit - 2018-05-28

    Josep M. Rams hat geschrieben:
    Try:
    MyMW:pointer to dword;
    MyMW:=adr(mx0);
    MyMW[0] is mx0
    MyMW[1] is mx1
    .
    .
    .
    Setting full
    MyMW[1]:=16#B1
    For example
    Sent from my Moto G (5S) Plus using Tapatalk

    ph0010421 hat geschrieben:
    I think a Union of 16 BITs (not BOOL) and a WORD is a better way to achieve this.

    Thank you for the suggestions guys! A union seems to work quite well.

    How do I add a comment to a bit in a union?

    For example: bit 1 in union 1 should be called "valve 5". And bit 1 in union 2 should be named different.

     

    Related

    Talk.ru: 1

  • Anonymous - 2018-05-28

    Originally created by: ph0010421

    Include a STRUCT in your union with the names you need. It sounds like this can replace the BITs

     
  • bisquit - 2018-05-28

    ph0010421 hat geschrieben:
    Include a STRUCT in your union with the names you need. It sounds like this can replace the BITs

    When I re-use a union by declaring the same union under different name. Then the bits will have the same name, right?

    Maybe my intentions aren't clear:

    For my program i need my bits in groups of 16, like a word. I want to set/reset these bits individually or all at once.
    I need a whole bunch of these groups. I'd like to add a comment to every individual bit in a group. (With different comments in different groups)
    A fixxed adress is not necessary.

    I need a fast/simple method of creating these groups

    This is what I've done so far:

    TYPE STR_BITS :
    STRUCT
       x00 : BIT;
       x01 : BIT;
       x02 : BIT;
       x03 : BIT;
       x04 : BIT;
       x05 : BIT;
       x06 : BIT;
       x07 : BIT;
       x08 : BIT;
       x09 : BIT;
       x10 : BIT;
       x11 : BIT;
       x12 : BIT;
       x13 : BIT;
       x14 : BIT;
       x15 : BIT;
    END_STRUCT
    END_TYPE
    
    TYPE UNION_BITS_WORD :
    UNION
       strBits : STR_BITS;
       wWord : WORD;
    END_UNION
    END_TYPE
    
    VAR
       union1 : UNION_BITS_WORD;    
       union2 : UNION_BITS_WORD;    
    END_VAR
    
     
  • bisquit - 2018-05-29

    I like the way how its working now with the struct and the union.
    Can somebody explain how I add a comment to one specific bit in one specific word?

    Something along the lines of this?

    GVL.W120.Wstruct.x00 // Word 120, Bit 00, Valve 5
    
     

Log in to post a comment.