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

PCD: Problem calling functions inside infinite loop

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



Joined: 13 Jul 2005
Posts: 25
Location: Maryland

View user's profile Send private message

PCD: Problem calling functions inside infinite loop
PostPosted: Sun Mar 21, 2010 4:59 pm     Reply with quote

I'm hoping this is something silly, 'cause I'm stumped. I'm using 4.099, have the following test project:
Code:

#include <24F04KA200.h>

// Do some configuration
#fuses NOPROTECT, FRC, OSCIO, NOWDT, NOBROWNOUT, NOMCLR, NODSBOR, NODSWDT, NOWRT, NOWINDIS, NOPUT
#use delay(internal=8MHz)
#use fast_io(ALL)

// Function prototypes
void doDelay(void);

// Function does nothing
void doDelay(void)
{
   output_low(PIN_B9);
   output_low(PIN_B15);
   output_low(PIN_A6);
   delay_us(20);
   output_high(PIN_B9);
   output_high(PIN_B15);
   output_high(PIN_A6);
   delay_us(20);
   
   return;
}

void main() {   
   // Disable all analog pins as they are unneccessary for this application
   setup_adc_ports(NO_ANALOGS);
   
   // Set up the I/O lines
   set_tris_a(0x32);
   set_tris_b(0x4000);
   
   //output_high(PIN_B9);
   //output_high(PIN_B15);
   //output_high(PIN_A6);
   
   do {
      doDelay();
     
      output_low(PIN_B9);
      output_low(PIN_B15);
      output_low(PIN_A6);
      delay_us(20);
      output_high(PIN_B9);
      output_high(PIN_B15);
      output_high(PIN_A6);
      delay_us(20);
     
   } while (TRUE);
   
   return;
}

When the doDelay function is commented out of the do-while loop, things work fine, I see a square wave on the three output pins. When I leave it in, like above, nothing works - the lines stay low. What could be the problem?

Some more weirdness: if I uncomment the code that sets the three lines high BEFORE going into the infinite do-while, then what I see on the scope is almost a square wave with a very high duty cycle... It's as if the MCU reboots continuously, causing the lines to go low momentarily.
dima2882



Joined: 13 Jul 2005
Posts: 25
Location: Maryland

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 9:19 am     Reply with quote

Anybody? Bueller?

Plz, I really got to have this app working!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 12:56 pm     Reply with quote

There are only a couple people on this forum that normally answer PCD
questions. If they're not on here, you won't get a quick reply.

I don't have the PCD compiler, but the first thing I would do is to reduce
the program size.

1. Functions automatically return. You don't need a 'return' statement
at the end, unless the function is declared to return a value, and yours
don't. Remove the returns. Also, there is no Operating System for
main() to return to. Just put a continuous while(1) loop at the end of
main() or in your program. Delete the 'return'.

2. Get rid of #fast_io mode and the set_tris_x() statements, and let
the compiler set the TRIS.

3. Just toggle one pin, for example, Pin B9. See what happens.
dima2882



Joined: 13 Jul 2005
Posts: 25
Location: Maryland

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 1:06 pm     Reply with quote

Do I need a #use standard_io statement for the port I want to use? That's now the way I changed it. Going to go try it now...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 1:16 pm     Reply with quote

Quote:

Do I need a #use standard_io statement for the port I want to use?

The PCD manual says:
Quote:

Standard_io is the default I/O method for all ports.

So, you don't need one.
dima2882



Joined: 13 Jul 2005
Posts: 25
Location: Maryland

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 6:34 pm     Reply with quote

Reinstalled the compiler... Everything worked the way it is written in the listing of my original post. I guess something in Windows went to hell :(
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