|
|
View previous topic :: View next topic |
Author |
Message |
spark
Joined: 03 Jan 2012 Posts: 17
|
Creating an array |
Posted: Tue Jan 03, 2012 3:26 pm |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Jan 03, 2012 3:32 pm |
|
|
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
|
|
Posted: Tue Jan 03, 2012 4:45 pm |
|
|
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
|
|
Posted: Wed Jan 04, 2012 7:46 am |
|
|
I am now using a one-dimensional array of bytes. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Jan 04, 2012 10:58 am |
|
|
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
|
|
Posted: Fri Jan 06, 2012 10:45 am |
|
|
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
|
|
Posted: Fri Jan 06, 2012 11:10 am |
|
|
hey help95-
- what compiler version did you use that works OK as you state ?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 06, 2012 11:45 am |
|
|
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. |
|
|
|
|
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
|