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

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
mworks



Joined: 29 May 2007
Posts: 3

View user's profile Send private message

Need help with arrays
PostPosted: Tue May 29, 2007 7:57 pm     Reply with quote

I'm trying to write a program that will send out a stream of pulses based on values stored in an array. The lines at the very end are so I can distinguish the pulse start/end on a logic analyzer.

I tried to write it using the array values directly like if the array contained the value I[5] = 300, the I would use delay_ms(I[5]);

However that refused to work, the pic seemed to ignore it and use a value of 20us for the pulse.

so I wrote the code below.
It works except that if I change the line:
While(z!=14) to read While(z!=15) the program ceases to work.

It seems if I try to access anything above 14 in the array the program fails to run.

I'm using tiny bootloader , could this be the problem ?
I'm new at this so any pointers are very welcome.



Code:

#include <16F88.h>
#device adc=8
#build( reset=0x1, interrupt=0x5)
#ORG 0x0F00, 0x0FFF {}
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_A2,bits=8)

void main()
{

int y;
int z=0;
int dly[17] = {1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,3,3};

      while(TRUE)
      {
     
      While(z!=14)
         {
      y=dly[z];
      output_low(PIN_B0);
      If (y==1)
      {
      delay_us(585);
      }
      If (y==2)
      {
      delay_us(444);
      }
      If (y==3)
      {
      delay_ms(1.5);
      }
      z=z+1;
      y=dly[z];
      output_high(PIN_B0);
      If (y==1)
      {
      delay_us(585);
      }
      If (y==2)
      {
      delay_us(444);
      }
      If (y==3)
      {
      delay_ms(1.5);
      }
      z=z+1;
         }
      z=0;
      output_low(PIN_B0);
      delay_us(50);
      output_high(PIN_B0);
      delay_us(50);
     
      }
}


PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 29, 2007 11:18 pm     Reply with quote

Quote:
delay_ms(1.5);

Download the latest compiler manual.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Read the section on how to use the delay_ms() function. What does
it say about the parameter that may be passed to the function ?
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Wed May 30, 2007 1:37 am     Reply with quote

Hello,

int dly[17] create a 17 element array. subscript are from 0 to 16.

While(z!=14)
..
z=z+1 ( now z=15 )
..
z=z+1 ( now z=16)
..

If you start with 15 at the second z++, dly[z]; point to an unknown value probably not 1,2 or 3 then the last pulse is very short.

If the version CCS version 4 is not solving your problem, make a function
witch receive an argument and make the calculated number of delay_ necessary.

dro
_________________
in médio virtus
mworks



Joined: 29 May 2007
Posts: 3

View user's profile Send private message

PostPosted: Wed May 30, 2007 7:36 am     Reply with quote

PCM programmer wrote:
Quote:
delay_ms(1.5);

Download the latest compiler manual.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Read the section on how to use the delay_ms() function. What does
it say about the parameter that may be passed to the function ?


Thanks for pointing that out.
That was the problem.
I'm trying to learn C and Pics in general at the same time and while its fun , its also trying at times. Laughing
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