I am using Pic16f877 microcontroller for my project. I am trying to declare a char Array as

char dataPkt[256] = {0};

While compiling, i received an error

error: (1250) could not find space (256 bytes) for variable dataPkt

Can anyone guide me how to resolve this error ??

  • 2
    \$\begingroup\$ That device only has 368 bytes of RAM and you are trying to reserve 256 of them. I suspect you have other variable declarations too? You need to live within your budget ;-) \$\endgroup\$ Sep 14 '15 at 9:08
  • \$\begingroup\$ @RogerRowland, thanks for your comments. I tried with 100. And I m not using enough variables too.Than too the error remains the same. Can you guide me alternate way to overcome the issue ? \$\endgroup\$
    – skg
    Sep 14 '15 at 11:03
  • 2
    \$\begingroup\$ If you look at page 13 of the datasheet, you'll see that there are multiple banks of memory. For your array, you need contiguous bytes in a single bank. The largest bank is 96 bytes. The others are 80 bytes. There's little chance of finding the space you need in a single bank. \$\endgroup\$ Sep 14 '15 at 11:08
  • \$\begingroup\$ RTFM! - - - - - \$\endgroup\$ Sep 14 '15 at 11:08
  • \$\begingroup\$ @Roger: There's actually as many as 112 bytes available consecutively (110h-17Fh, inclusive)... who knows if the compiler is smart enough to treat it as a single block when needed.... and of course the multimapped region is usually too valuable to waste like that. \$\endgroup\$
    – Ben Voigt
    Sep 14 '15 at 16:23

There is no substitute for understanding the machine at the low level. Whether using a compiler or not, you have to actually READ THE DATASHEET.

As Figure 2-3 on page 13 clearly shows, there is no way to get 256 contiguous bytes of RAM.

Other observations:

  1. MPLABX is the IDE, so is useless in specifying what compiler or assembler you are using.

  2. Allocating a buffer for a whole packet sounds like big-processor thinking on little processors. There is no OS with canned drivers that is going to read/write whole packets from/to some communication interface. Ultimately, code is going to handle each byte separately anyway. Buffering a packet of bytes, then reading and handling them out of the packet individually anyway makes little sense.

  • \$\begingroup\$ thanks for your reply. What if I use pointer instead of array ?? There is no compile error. Will it also have bytes limitation ??? \$\endgroup\$
    – skg
    Sep 14 '15 at 11:19
  • 3
    \$\begingroup\$ @skg: A array and a pointer are two completely different things. You need to learn some basics of programming and what a machine does under the hood before continuing. \$\endgroup\$ Sep 14 '15 at 11:21
  • \$\begingroup\$ @skg, I think it's best for you to look into the "Understanding Small Microcontrollers" book (available online for free). \$\endgroup\$ Sep 14 '15 at 14:52
  • \$\begingroup\$ "big-processor thinking" This is exactly the issue. +1 \$\endgroup\$
    – Ben Voigt
    Sep 14 '15 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.