robin171
Joined: 12 Sep 2008 Posts: 4
|
Very strange behaviour of a function! please help |
Posted: Wed May 06, 2009 5:15 am |
|
|
Hello,
I use PCWH v. 4.079 and PIC18F6720. I have the following code:
Code: | bool perilex2,perilex3;
perilex2 = PERILEX_POS2;
perilex3 = PERILEX_POS3;
if(perilex2) fputc('C',COM1);
else fputc('c',COM1);
if(perilex3) fputc('D',COM1);
else fputc('d',COM1);
read_perilex(&status,perilex2,perilex3); |
Code: | #define PERILEX_POS2 input(PIN_F7)
#define PERILEX_POS3 input(PIN_F6) |
The code must detect a square wave on pin F7 or F6. When I check the pins with a scope, no signal is present on both pins.
The code prints "cdABcdaB" to the serial port (see read_perilex function below). Somehow the variables perilex2 and perilex3 are changed when passing them into the function read_perilex. What is the problem here?
When I try this: read_perilex(&status,false,false) it works fine..
Code: | void read_perilex(status_t *status, bool step2, bool step3)
{
s_u8 p2_off_ctr,p2_on_ctr,p3_off_ctr,p3_on_ctr;
if(step3) fputc('A',COM1);
else fputc('a',COM1);
if(step2) fputc('B',COM1);
else fputc('b',COM1);
if(!step3 && (status->perilex_position == PERILEX_STEP3))
{
p3_on_ctr = 0;
if(p3_off_ctr > 100) status->perilex_position = PERILEX_STEP1;
else p3_off_ctr++;
}
else if(step3)
{
p3_off_ctr = 0;
if(p3_on_ctr > 100) status->perilex_position = PERILEX_STEP3;
else p3_on_ctr++;
}
else if(!step2 && (status->perilex_position == PERILEX_STEP2))
{
p2_on_ctr = 0;
if(p2_off_ctr > 100) status->perilex_position = PERILEX_STEP1;
else p2_off_ctr++;
}
else if(step2)
{
p2_off_ctr = 0;
if((p2_on_ctr > 100) && (status->perilex_position != PERILEX_STEP3)) status->perilex_position = PERILEX_STEP2;
else p2_on_ctr++;
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 06, 2009 11:36 am |
|
|
Quote: | bool perilex2,perilex3; |
You have created your own types. Please post the typedef or #define
statement for 'bool'.
What I would do, is to make a test program that checks if the variables
are passed properly. I would get rid of about 90% of your code,
to do this. |
|