Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Array declaration problem in Mplab Higtech compiler

Status
Not open for further replies.

Dinuwilson

Advanced Member level 4
Joined
Aug 20, 2011
Messages
100
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
1,985
when i write program for pic 16f877a micro controller using Higtech compiler initially i declare an array ( int a[45]) it works perfectly. when i change the array size to (int a[60]) it shows errors. i add the image of the error and my program.. please help me to solve the problem
 

Attachments

  • error in array.JPG
    error in array.JPG
    153.6 KB · Views: 82
Last edited:

First of all, are you compiling the same code, as it shows double.c as the name of the file, where error has occurred. And I think the code size is limited of your compiler
 
You should be aware the PIC16F877A has only 368 bytes of SRAM by which to store variables and arrays.

An array of integers, int a[60], requires 120 bytes alone, almost a third of the available SRAM. Depending other variables, arrays, etc defined within your code, you can easily exceed the 368 bytes.

Also the linker script may need to be modified to allocated 120 bytes in a single block.

I would recommend posting your code with CODE Tags, so that it maybe examined for more specific advice.

BigDog
 
thanks for your replay ,this is my code


Code:
#include<pic.h>
void main()
{
  int a[60];// array size
  TRISB=0X00;
  PORTB=0X00;
}

in my program i want two arrays of size [100]. is it possible?
 

Code:
#include<pic.h>
void main()
{
  int a[60];// array size
  TRISB=0X00;
  PORTB=0X00;
}

in my program i want two arrays of size [100]. is it possible?

Unfortunately, Not utilizing the PIC16F877A. Unless the arrays are Constant, which would be stored in FLASH Program Memory rather than SRAM.

As I mentioned before, the PIC16F877A only has 368 bytes of SRAM, divided into four separate banks as shown below highlighted in RED:

Reference: PIC16F87XA Datasheet, Section: 2.2 Data Memory Organization, Page: 16
2.2 Data Memory Organization

The data memory is partitioned into multiple banks
which contain the General Purpose Registers and the
Special Function Registers. Bits RP1 (Status<6>) and
RP0 (Status<5>) are the bank select bits.

Each bank extends up to 7Fh (128 bytes). The lower
locations of each bank are reserved for the Special
Function Registers. Above the Special Function Registers
are General Purpose Registers, implemented as
static RAM. All implemented banks contain Special
Function Registers. Some frequently used Special
Function Registers from one bank may be mirrored in
another bank for code reduction and quicker access.



The largest single available block of SRAM is only 96 bytes located in bank 0, which is why an array of integers, consisting of 45 elements, requiring 90 bytes of storage is possible, however an array of 60 elements requiring 120 bytes of storage is NOT possible.

You would need to upgrade to another PIC, possibly the PIC18F family to accommodate arrays requiring 200 bytes of storage each or more.


Also when coding for the Hi-Tech series of compilers, use the following:

Code:
#include <htc.h>

Rather than:

Code:
#include <pic.h>

BigDog
 
thanks for your replay sir........

- - - Updated - - -

i have one more doubt.... how you understand an array of 60 elements requiring 120 bytes of storage?
 

A char is single byte and int 2 bytes so its 120 bytes for 60 integers.
 

i have one more doubt.... how you understand an array of 60 elements requiring 120 bytes of storage?

The amount of storage required for integral types is compiler dependent.

Reference: HI-TECH C® for PIC10/12/16 User’s Guide, Section: 3.4 SUPPORTED DATA TYPES AND VARIABLES, Page: 54



Both an unsigned and signed int type requires 16-bit or 2 bytes of storage, therefore an array comprised of the 60 such elements would require 120 bytes of storage.

It should also be noted that while there collectively exists sufficient storage for the array in question, the 120 bytes does not exist continuously in a single bank.


BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top