fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4.  
  5. #define __SFR_OFFSET 0
  6. #define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(&buffer[0] + mem_addr))
  7. #define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
  8. #define DDRD _SFR_IO8(0x0A)
  9.  
  10. uint8_t buffer[256];
  11.  
  12. int main(void) {
  13. memset(&buffer[0], 0, 256);
  14. DDRD = 0x40;
  15. printf("value: %x\n", (int)DDRD);
  16. *(volatile uint8_t*)(&buffer[0] + (0x0A + 0)) = 0x41;
  17. printf("value: %x\n", (int)DDRD);
  18.  
  19. // now let's do what you are doing in your struct
  20. unsigned int dataDirectionRegister = DDRD; // value of register is copied into variable
  21. dataDirectionRegister = 0x80; // variable is changed but not real register
  22. printf("register: %x, variable: %x\n", (int)DDRD, dataDirectionRegister);
  23.  
  24. // you must save an address to do what you need
  25. volatile uint8_t* realDataDirectionRegister = &DDRD;
  26. *realDataDirectionRegister = 0x80;
  27. printf("register: %x, variable: %x\n", (int)DDRD, (int)*realDataDirectionRegister);
  28.  
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
value: 40
value: 41
register: 41, variable: 80
register: 80, variable: 80