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

Cannot copy values from code array to another array which is a struct member (both global)

I have the following variables:


#define X ...
...
code unsigned char pin[X] = { ... }; // there are values here, no 0xFF
...
struct {
  unsigned char pin[X];
} info;


and I need to copy the values from pin into info.pin. However, even direct assignment doesn't change the info.pin values. i.e.:

info.pin[0] = pin[0];
info.pin[1] = pin[1];
info.pin[2] = pin[2];
...
info.pin[X - 1] = pin[X - 1];


the watch window shows info.pin values are still 0xFF and indeed when another code that needs info.pin checks (after the assignment above of course), the values are still 0xFF. What do I have to do to make the values copied?

Parents Reply Children
  • Same variable names (sigh!!).

    The other way around is to use pointers.

  • > You need to look at some disassembly for the piece of code to see what the compiler is making.
    Here are the first 4 assigments (since it's generally the same):

       653:     Sys_ebpUPINs[0] = cbaUPINs[0];
    C:0xAA4E    9003B3   MOV      DPTR,#cbaUPINs(0x03B3)
    C:0xAA51    E4       CLR      A
    C:0xAA52    93       MOVC     A,@A+DPTR
    C:0xAA53    900D02   MOV      DPTR,#0x0D02
    C:0xAA56    F0       MOVX     @DPTR,A
       654:     Sys_ebpUPINs[1] = cbaUPINs[1];
    C:0xAA57    9003B4   MOV      DPTR,#0x03B4
    C:0xAA5A    E4       CLR      A
    C:0xAA5B    93       MOVC     A,@A+DPTR
    C:0xAA5C    900D03   MOV      DPTR,#0x0D03
    C:0xAA5F    F0       MOVX     @DPTR,A
       655:     Sys_ebpUPINs[2] = cbaUPINs[2];
    C:0xAA60    9003B5   MOV      DPTR,#0x03B5
    C:0xAA63    E4       CLR      A
    C:0xAA64    93       MOVC     A,@A+DPTR
    C:0xAA65    900D04   MOV      DPTR,#0x0D04
    C:0xAA68    F0       MOVX     @DPTR,A
       656:     Sys_ebpUPINs[3] = cbaUPINs[3];
    C:0xAA69    9003B6   MOV      DPTR,#0x03B6
    C:0xAA6C    E4       CLR      A
    C:0xAA6D    93       MOVC     A,@A+DPTR
    C:0xAA6E    900D05   MOV      DPTR,#0x0D05
    C:0xAA71    F0       MOVX     @DPTR,A
    

  • > The other way around is to use pointers.
    No, that doesn't work either. When I said "even direct assignment..." that means I've tried every high level possibility. First I use a copy function, then pointer + loop, copy to local array first (this time the value gets copied, but still fails when copying values from local array to the array in the struct), finally I use direct assignment.

  • The assembly code looks fine.

    Do the locations 0x0D02 - 0x0D05... physically exist?
    Is the external RAM, on-chip XRAM or have you connected off-chip external RAM?

  • Found the problem, the address is actually a flash address instead of RAM, that's why simple copy by assigment doesn't work. Problem solved.