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

Creating an array

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



Joined: 03 Jan 2012
Posts: 17

View user's profile Send private message MSN Messenger

Creating an array
PostPosted: Tue Jan 03, 2012 3:26 pm     Reply with quote

Hello
Is there any possibility to set up an array?
I tried it with the following line, but I failed.
Code:
const bit j[][] = {{1,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,0,1,0,0,0,0,0},{0,0,0,1,0,0,0,0},
         {0,0,0,0,1,0,0,0},{0,0,0,0,0,1,0,0},{0,0,0,0,0,0,1,0},{0,0,0,0,0,0,0,1}};

How can it be achieved?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 03, 2012 3:32 pm     Reply with quote

You could press F11 while your project is open.
That will allow the onscreen help file to come up. Poke around and you'll find what you need.

or

look at some of the examples that CCS supplies in the 'examples' folder.
again, open,look,read.....easy as 1,2,3
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 03, 2012 4:45 pm     Reply with quote

I'm not sure that the compiler supports 2-dimensional bit arrays.
I tested it a little bit and I can't seem to make it work. It compiles
but it doesn't read back the correct data. It wouldn't surprise me
at all if the compiler only supports 1-dimensional bit arrays.

Also, you have it declared as 'const'. The manual says it can create
arrays of bits in RAM only.
spark



Joined: 03 Jan 2012
Posts: 17

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 04, 2012 7:46 am     Reply with quote

I am now using a one-dimensional array of bytes.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Jan 04, 2012 10:58 am     Reply with quote

int1 array [][] seem as shown below to work - though with inefficient code in 4.085!!
B U T ----heres what i got with 4.128 LST
Code:

.................... int1 Q[8][2]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
*
01C7:  CLRF   27
01C8:  CLRF   28


....................     if (1==Q[1][1]) Q[1][0]=0; 
01E1:  BTFSC  29.1
01E2:  BCF    29.0


so close but so bad.....
this points to a horrific "base 0" fault in the code generation
for var access ... OUCH !!!

It sure looks like a failed attempt in compiler-ville

YET with the compiler being taught to remember where it PUT the
array bytes ;-)) -- a fixed up approach could in future work.
neh ?
help95



Joined: 06 Jan 2012
Posts: 1

View user's profile Send private message

PostPosted: Fri Jan 06, 2012 10:45 am     Reply with quote

I've found the 2D arrays are implemented as such:
Code:

int h[12][4]={1,0,1,0,
              1,1,1,0,
              1,0,1,0,
              1,0,1,0,
              1,1,1,0,
              1,0,1,0,
              1,0,1,0,
              1,1,1,0,
              1,0,1,0,
              1,0,1,0,
              1,1,1,0,
              1,0,1,0,
};

This has 12 Rows and 4 Columns. A simple carriage return creates the next row in the array. I have used this for 4 rows and 12 columns and it has worked fine, and have seen examples with 97 rows. http://www.ccsinfo.com/forum/viewtopic.php?t=46854
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jan 06, 2012 11:10 am     Reply with quote

hey help95-
- what compiler version did you use that works OK as you state ??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 06, 2012 11:45 am     Reply with quote

He is using 'int', not 'int1', to declare his array. This thread is about
trying to make a 2-dimensional array of bits. We know a normal byte
array works.
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