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

Problem with Arrays

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



Joined: 12 Dec 2008
Posts: 7

View user's profile Send private message

Problem with Arrays
PostPosted: Thu Apr 02, 2009 11:01 am     Reply with quote

Hi All,

I have 2 loops in my code. One loop that fills an array, the other loop prints it out. See code below. If I take out the array and output the numbers as I get them, I get the data I expect; but with the array, I get a data stream that is shaped like "saw wave" out. Why is the data not consistent? What am I doing wrong?
Code:
#include <30F5011.h>
#device *=16
#device ICD=true
#fuses EC, NOWDT
#use delay(clock=40000000)
#use rs232 ( FORCE_sw, baud=460800, xmit=pin_F5, rcv=pin_F4, INVERT)


#use SPI(master, DI=pin_f2, clk=pin_f6, bits=16, mode=0, msb_first)

for(I3=0; I3<=1023; I3++)
      {   
          data[I3]=spi_xfer();     //Read 1024 16bit nubers and put in array
      }

for (I=0; I<=1023; I++)
      {
intMSB = make8(data[I],1);    //write 1024 16bit
intLSB = make8(data[I],0);
putc(intMSB);         
Putc(intLSB);
      }

Thanks for the help.
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Thu Apr 02, 2009 12:27 pm     Reply with quote

What is the type of I and I3? Are they both unsigned int16?
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
Guest








PostPosted: Thu Apr 02, 2009 1:05 pm     Reply with quote

yes
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Thu Apr 02, 2009 1:07 pm     Reply with quote

Can you post more of your code where you define the array?
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
SimpleGuy



Joined: 12 Dec 2008
Posts: 7

View user's profile Send private message

PostPosted: Thu Apr 02, 2009 1:19 pm     Reply with quote

refining my problem. I start going step by step. I run into the problem when i use a 16bit array. My input doesn't match my output.


#include <prototype.h>

void Main()
{
unsigned int16 data[6];
unsigned int16 i;
unsigned int8 temp1, temp2;

while(true)
{

for (i=0; i<=4; i++)
{
temp1=getc();
temp2=getc();
data[i]=(make16(temp1, temp2));
printf(" %u ",i);
}

printf("\n\r output from array\n\r");

for (i=0; i<=4; i++)
{
temp1=make8(data[i],0);
putc(temp1);
temp1=make8(data[i],1);
putc(temp1);
}
}
}


iF I input 444444
i get this out.

0 1 2 3 4
output from array
4\4^4`4b4d
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