This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

and again the question of variables

There is an SRC variable of 16 bits, how to create two 8-bit variables, so that one is addressed to the upper part and the second to the lower part of the SRC variable?
type construction

uint16_t src;
uint8_t b1 = * ((uint8_t *) & src);
uint8_t b2 = * (((uint8_t *) & src) +1);


should work but at compilation produces:

MAIN.c (16): error: # 28: expression must have a constant value
  uint8_t b1 = * ((uint8_t *) & src);
MAIN.c (17): error: # 28: expression must have a constant value
  uint8_t b2 = * (((uint8_t *) & src) +1);
MAIN.c: 0 warnings, 2 erros


How to correctly address the variables B1 and B2 that, when changing these variables, the corresponding value in the SRC variable and vice versa change.
Sorry for my english :)

Parents
  • Maybe I'm not so explain my desire ...
    Parsing a 16-bit number occurs in an interrupt and EXTREME tacts are completely unnecessary ...
    The proposed version fits perfectly into the work of the main program conveniently and quickly enough, but for interrupts, these are extra delays within the interrupt.

    uint16_t src;
    uint8_t b1, b2; //? how to initialize correctly?
    int main (void)
     {
    b1 = 0x5; // performs a simultaneous change in the variable in the high-order byte of the SRC = 0x0500
    b2 = 0xa; // executes a simultaneous change in the variable in the lower part of the byte SRC = 0x050A
    src = 0xadd; // sets immediately and B1 = AA and B2 = DD
    }
    

Reply
  • Maybe I'm not so explain my desire ...
    Parsing a 16-bit number occurs in an interrupt and EXTREME tacts are completely unnecessary ...
    The proposed version fits perfectly into the work of the main program conveniently and quickly enough, but for interrupts, these are extra delays within the interrupt.

    uint16_t src;
    uint8_t b1, b2; //? how to initialize correctly?
    int main (void)
     {
    b1 = 0x5; // performs a simultaneous change in the variable in the high-order byte of the SRC = 0x0500
    b2 = 0xa; // executes a simultaneous change in the variable in the lower part of the byte SRC = 0x050A
    src = 0xadd; // sets immediately and B1 = AA and B2 = DD
    }
    

Children