CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Maximum array size?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
thomas
Guest







Maximum array size?
PostPosted: Sun Jun 15, 2003 2:49 pm     Reply with quote

Hello,

I am using PIC16F876 with CCS version 3.0. When I write "int array[256];" It flags an error, saying that the maximum subscription is exceeded. What is the maxium size for an array? How do allocate 256 byte? This PIC has more than 256 bytes of RAM. Is it not?
Thanks!
Thomas
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515263
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: Maximum array size?
PostPosted: Sun Jun 15, 2003 5:44 pm     Reply with quote

Thomas,
I'm quoting this from the CCS help:
"A subscript to a RAM array must be at least 1 and not more than 128 elements. Note that large arrays might not fit in a bank. ROM arrays may not occupy more than 256 locations. Arrays are limited to 5 dimensions."

Note that although PIC16F87 has 368 bytes of memory, it's divided in 4 banks. Compiler can't allocate an array over more than one bank, so your array sizes are limited to the bank size.

Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515267
Mike Broom
Guest







Re: Maximum array size?
PostPosted: Mon Jun 16, 2003 6:05 am     Reply with quote

:=Hello,
:=
:=I am using PIC16F876 with CCS version 3.0. When I write "int array[256];" It flags an error, saying that the maximum subscription is exceeded. What is the maxium size for an array? How do allocate 256 byte? This PIC has more than 256 bytes of RAM. Is it not?
:=Thanks!
:=Thomas

Thomas the following code snippit will do what you want, and can actually address all available ram with a little tweaking of the #reserve's and an additional a bit of code to address bank 0 RAM

regards

Mike Broom

Code:
#include <16f876.h>

#reserve 0xa0xef
#reserve 0x110x16f
#reserve 0x190x1df

void WriteArray(int16 Index, int8 Value)
{
    int8 Bank;
    int8 Offset;

    Bank = 1;                       //Start in bank 1 no offset
    Offset = Index;
    if(Index >= 0x50)
    {
        Bank = 2;                   //Jump to bank 2 when we have filled bank 1
        Offset = (Index - 0x50);    //subtract size of bank 1
    }
    if(Index >= 0xB0)
    {
        Bank = 3;                   //Jump to bank 3 and subtract
        Offset = (Index - 0xB0);    //Size bank 1 & 2
    }
        switch(Bank)
        {
        case 1:
            write_bank(1,Offset,Value);
        break;
        case 2:
            write_bank(2,Offset,Value);
        break;
        case 3:
            write_bank(3,Offset,Value);
        break;
        default:
        break;
    }
}

int8 ReadArray(int16 Index)
{
    int8 Bank;
    int8 Offset;

    Bank = 1;                       //Start in bank 1 no offset
    if(Index >= 0x50)
    {
        Bank = 2;                   //Jump to bank 2 when we have filled bank 1
        Offset = (Index - 0x50);    //subtract size of bank 1
    }
    if(Index >= 0xB0)
    {
        Bank = 3;                   //Jump to bank 3 and subtract
        Offset = (Index - 0x60);    //Size bank 1 & 2
    }
    switch(Bank)
    {
        case 1:
            return(read_bank(1,Offset));
        break;
        case 2:
            return(read_bank(1,Offset));
        break;
        case 3:
            return(read_bank(1,Offset));
        break;
        default:
        break;
    }
}

void main(void)
{
    WriteArray(MyArray_Element,Value);   //This will write to any cell upto 256
    MyArray_Element_Value = ReadArray(MyArray_Element); //This will read fro the array
}

___________________________
This message was ported from CCS's old forum
Original Post ID: 144515289
thomas
Guest







Re: Maximum array size?
PostPosted: Mon Jun 16, 2003 1:25 pm     Reply with quote

Perfect! This is jus what I need. Thank you very much!
thomas
:=:=Hello,
:=:=
:=:=I am using PIC16F876 with CCS version 3.0. When I write "int array[256];" It flags an error, saying that the maximum subscription is exceeded. What is the maxium size for an array? How do allocate 256 byte? This PIC has more than 256 bytes of RAM. Is it not?
:=:=Thanks!
:=:=Thomas
:=
:=Thomas the following code snippit will do what you want, and can actually address all available ram with a little twaking of the #reserve's and an additional a bit of code to address bank 0 RAM
:=
:=regards
:=
:=Mike Broom
:=
:=#include <16f876.h>
:=
:=#reserve 0xa0:0xef
:=#reserve 0x110:0x16f
:=#reserve 0x190:0x1df
:=
:=void WriteArray(int16 Index, int8 Value)
:={
:= int8 Bank;
:= int8 Offset;
:=
:= Bank = 1; //Start in bank 1 no offset
:= Offset = Index;
:= if(Index >= 0x50)
:= {
:= Bank = 2; //Jump to bank 2 when we have filled bank 1
:= Offset = (Index - 0x50); //subtract size of bank 1
:= }
:= if(Index >= 0xB0)
:= {
:= Bank = 3; //Jump to bank 3 and subtract
:= Offset = (Index - 0xB0); //Size bank 1 & 2
:= }
:= switch(Bank)
:= {
:= case 1:
:= write_bank(1,Offset,Value);
:= break;
:= case 2:
:= write_bank(2,Offset,Value);
:= break;
:= case 3:
:= write_bank(3,Offset,Value);
:= break;
:= default:
:= break;
:= }
:=}
:=
:=int8 ReadArray(int16 Index)
:={
:= int8 Bank;
:= int8 Offset;
:=
:= Bank = 1; //Start in bank 1 no offset
:= if(Index >= 0x50)
:= {
:= Bank = 2; //Jump to bank 2 when we have filled bank 1
:= Offset = (Index - 0x50); //subtract size of bank 1
:= }
:= if(Index >= 0xB0)
:= {
:= Bank = 3; //Jump to bank 3 and subtract
:= Offset = (Index - 0x60); //Size bank 1 & 2
:= }
:= switch(Bank)
:= {
:= case 1:
:= return(read_bank(1,Offset));
:= break;
:= case 2:
:= return(read_bank(1,Offset));
:= break;
:= case 3:
:= return(read_bank(1,Offset));
:= break;
:= default:
:= break;
:= }
:=}
:=
:=void main(void)
:={
:= WriteArray(MyArray_Element,Value); //This will write to any cell upto 256
:= MyArray_Element_Value = ReadArray(MyArray_Element); //This will read fro the array
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515303
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group