View previous topic :: View next topic |
Author |
Message |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
pass struct into function |
Posted: Mon Sep 29, 2008 8:04 pm |
|
|
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);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
Thanks! |
Posted: Mon Sep 29, 2008 8:37 pm |
|
|
I figured it out. Thanks for pointing me to those! |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Sep 30, 2008 5:49 am |
|
|
Hi
I don't understand why passing the struct to a function, when the struct is declared as global?
Maybe just my poor understanding. |
|
![](templates/subSilver/images/spacer.gif) |
|