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 support@ccsinfo.com

Need help with arrays

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



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

Need help with arrays
PostPosted: Tue Jul 03, 2012 9:37 am     Reply with quote

Hello,

I want to make a tetris game in ccs but I have a problem because SOME LEDS are permanent on.

I made an array and set everything to false:
Code:

int1 Pixel[16][8] = {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};

Then when I create the condition all Leds are on:
Code:

for(x = 0; x < 16; x++)
{
   for(y = 0; y < 8;y++)
   {       
      if(Row[x][y] == 1 || Pixel[x][y] == 1)
      {
         TurnLedOnByCoords(x+1,y+1);             
      }                   
   }
}

The function of TurnLedOnByCoords:
Code:

void TurnLedOnByCoords(int row, int col)
{
  if(row <= 7 || col <= 5)
  {
   if(row==1) output_high(PIN_A0);
   if(row==2) output_high(PIN_A1);
   if(row==3) output_high(PIN_A2);
   if(row==4) output_high(PIN_A3);
   if(row==5) output_high(PIN_A4);
   if(row==6) output_high(PIN_A5);
   if(row==7) output_high(PIN_B0);
   
   if(col==1)output_high(PIN_D4);
   if(col==2)output_high(PIN_C6);
   if(col==3)output_high(PIN_D5);
   if(col==4)output_high(PIN_B3);
   if(col==5)output_high(PIN_C5);

   
   delay_us(250);
   
   if(row==1) output_low(PIN_A0);
   if(row==2) output_low(PIN_A1);
   if(row==3) output_low(PIN_A2);
   if(row==4) output_low(PIN_A3);
   if(row==5) output_low(PIN_A4);
   if(row==6) output_low(PIN_A5);
   if(row==7) output_low(PIN_B0);
   
   if(col==1)output_low(PIN_D4);
   if(col==2)output_low(PIN_C6);
   if(col==3)output_low(PIN_D5);
   if(col==4)output_low(PIN_B3);
   if(col==5)output_low(PIN_C5);
  }
}


This function for turning on the leds is right because I use it in another project.

I hope that someone can help me.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 10:47 am     Reply with quote

The obvious question would be:

What is in
Code:
Row[x][y]
???

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 11:17 am     Reply with quote

a 0 or a 1

for example:

Code:
    Pixel[0][3]=true;
          Pixel[0][4]=true;
          Pixel[1][3]=true;
          Pixel[1][4]=true;


When i use BYTE instead of Boolean it works but thats not the way its only true and false that i need.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 12:05 pm     Reply with quote

Thanks for the explanation of "Pixel[][]".... which is _not_ "Row[][]".....

... sigh.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 12:18 pm     Reply with quote

Row[][] is a bool array just ignore Row because when for example Pixel[0][5] is set to true the led in Row 1 and Col 5 Should normally be on but the problem is that everything is on then. When I use byte instead of Boolean it works so how can i do it with boolean because otherwise the array is to big and i get an error that there is no space for all variables.

I hope you understand it.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 2:03 pm     Reply with quote

Hi,

Please repeat after me; always post your compiler version. Some compiler features have known issues with some versions, so this is critical information. See this post for more information on this issue: http://ccsinfo.com/forum/viewtopic.php?t=48363&highlight=int1+array

John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 2:08 pm     Reply with quote

Two-dimensional arrays of bits (int1) probably don't work in your version:
http://www.ccsinfo.com/forum/viewtopic.php?t=47101
They may not work in any version.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 3:14 pm     Reply with quote

I'm totally lost. I can't even start to understand what you are doing.

Please supply schematic for LEDs, shortest possible complete compilable code which CLEARLY illustrates problem, a lucid account of what does/doesn't should/shouldn't happen, and compiler version etc.

Mike
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jul 03, 2012 4:08 pm     Reply with quote

from the looks of it he is trying to drive a LED matrix ("screen")
and set each "pixel" individually...



...
its easier if you set each column or row a full byte and write entire columns or rows at the same time... you can address "pixels" individually as well with this byte aproach...
_________________
CCS PCM 5.078 & CCS PCH 5.093
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