When do I use xdata?

前端 未结 5 1425
借酒劲吻你
借酒劲吻你 2021-02-14 15:44

I am new at embedded system programming. I am working on a device that uses an 8051 chipset. I have noticed in the sample programs that when defining variables, sometimes they u

5条回答
  •  走了就别回头了
    2021-02-14 16:40

    xdata tells the compiler that the data is stored in external RAM so it has to use a different instruction to read and write that memory instead of internal RAM.

    Accessing external data does take longer. I usually put interrupt variables in internal RAM and most large arrays in external RAM.

    As to the state of the external RAM after a hard reset (not power cycle): That would depend on the hardware setup. Does a reset line go to the external chip? Also some chips come with XDATA within the CPU chip. Read that again. Some chips have an 8051 CPU plus some amount of XDATA within the IC.

    static and xdata do not overlap. Static tells the compiler how to allocate a variable (on a stack or at a memory location). Xdata tells the compiler how to get to that variable. Static can also restrict the name space of that variable to just that file. You can have an xdata static variable that is local to just a function, and have a static variable that is local to a function but uses internal RAM.

提交回复
热议问题