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

pass struct into function

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



Joined: 19 Jul 2008
Posts: 16

View user's profile Send private message

pass struct into function
PostPosted: Mon Sep 29, 2008 8:04 pm     Reply with quote

I am trying to pass a struct into a function and it isn't working. There are no errors when I compile, but the led that should blink doesn't, so the counter isn't getting reset. I believe that I have tested everything else and there aren't other problems. Does anyone see the problem?

Thanks!
Richard

Code:
#include <18F2620.h>
#FUSES HS
#FUSES NOWDT
#FUSES NOPROTECT
#use delay(clock=20,000,000)
#use rs232 (baud = 9600, parity = N, xmit = PIN_C6, rcv = PIN_C7, bits = 8, ERRORS)
#define RAND_MAX 1000
#include <STDLIB.H>

struct servoStruct {
   int16 counter;
   int16 trigger;
};

struct servoStruct servo0;
struct servoStruct servo1;

void ledblink(struct servoStruct structIn);

#INT_RTCC
void servocounter()
{
   servo0.counter++;
   servo1.counter++;
   set_timer0(60535);
}
   
void main()
{
   setup_comparator (NC_NC_NC_NC);
   setup_timer_0 (RTCC_DIV_1|RTCC_INTERNAL);
   enable_interrupts (INT_RTCC);
   enable_interrupts (GLOBAL);
     
   servo0.counter = 0;
   servo0.trigger = 1000;
   servo1.counter = 0;
   servo1.trigger = 1000;
     
   delay_ms (500);
   output_high(PIN_C3);
   output_high(PIN_C4);

   WHILE (true)
   {
      if(servo0.counter == servo0.trigger)
      {
         ledblink(servo0);
      }
      if (servo1.counter == servo1.trigger)
      {
         output_toggle(PIN_C4);
         servo1.counter = 0;
      }
   }
}

void ledblink(struct servoStruct structIn)
{
   structIn.counter = 0;
   output_toggle (PIN_C3);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 8:17 pm     Reply with quote

Look at some examples of how to pass a structure as a function parameter:
http://www.ccsinfo.com/forum/viewtopic.php?t=31552
http://www.ccsinfo.com/forum/viewtopic.php?t=27988
rwjzownts



Joined: 19 Jul 2008
Posts: 16

View user's profile Send private message

Thanks!
PostPosted: Mon Sep 29, 2008 8:37 pm     Reply with quote

I figured it out. Thanks for pointing me to those!
Guest








PostPosted: Tue Sep 30, 2008 5:49 am     Reply with quote

Hi

I don't understand why passing the struct to a function, when the struct is declared as global?

Maybe just my poor understanding.
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