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 support@ccsinfo.com

Very strange behaviour of a function! please help

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



Joined: 12 Sep 2008
Posts: 4

View user's profile Send private message

Very strange behaviour of a function! please help
PostPosted: Wed May 06, 2009 5:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 06, 2009 11:36 am     Reply with quote

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.
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