# Pragma idata and # pragma udata in PIC

Source: Internet
Author: User

# Pragma idata and # pragma udata in PIC:

 Idata indicates the initialized data. Udata indicates that no data is initialized.

When a data block does not have enough space to store a continuous data (array), # pragma idata or # pragma udata can be used to define a new region for storing data blocks. However, # pragma idata or # pragma udata application space is still limited. Generally, it cannot exceed 256. If it exceeds, it can only be done with another idea.

Why cannot it be greater than 256?

   You can see the relevant IC link file. LKR, from which we can see how it defines the bank size. None of them is greater than 0xff, because the pic18 command is dubyte, that is, only 16 bits are available, however, in a ram command, there is only 8-bit data to represent the RAM address, and the others are the operation code or others. Therefore, its maximum addressing range is only 256. If it is greater than 256, it can only use other registers BSR to expand the address. This is also the source of the bank. In addition, because the storage space of arrays should be placed in a continuous space, it cannot be greater than 256. Because the storage space is greater than 256, commands cannot automatically address across banks, if you want to cross-bank, you can only set the bank area in advance.

 How can we check where the Defined variables are stored? You can view the generated. Map File.

 Map File generation settings: Project --> build options --> Project ---> mplink mplinker, select generate map file.

 

  

Their usage:

# Pragma idata dataarray // Start of a data block

Char dataarray [256] = {0 };

# Pragma idata// End of a data block

 

# Pragma udata dataarray1 // Start of a data block

Char dataarray1 [256];

# Pragma udata// End of a data block

The const keyword and Rom keyword in the PIC, # pragma Rom


In the mc18 compiler.

Const char array [300] = {0 };

This defines a variable that exceeds the maximum value of the bank and produces an error during compilation. Why?

Const indicates that the variable array is stored in the ROM area, but in the mc18 compiler, the variable points to the ram area, therefore, it stores data in the ram zone by default. That is, the const alone cannot store data in the ROM zone. In the mc18 compiler description, if you want to place data in the ROM area, you need to add the ROM keyword. As defined below

RomChar array [300] = {0 };

Const RomChar array [300] = {0.

 

Alternatively, use the following method:

# Pragma Rom udatasection

ConstRomChar array [300] = {0 };

# Pragma Rom

Code: used to store command code

ROM: used to store data constants. In map, the segment name is romdata.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.