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

restart_cause

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



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

restart_cause
PostPosted: Sun Feb 05, 2006 9:17 pm     Reply with quote

I'm using a pic 16f877a and CCS PCM C Compiler, Version 3.223.
I have the WDT set up to reset the pic every 2.3 seconds unless it receives a serial packet. That part works fine, but the first time the pic boots I want some stuff to happen but if it is a WDT reset I want it to just jump into the main code. In the code below I have it blinking an led if it is a normal bootup, but that code seems to happen every time the wdt fires.
So what is happening is that every time the wdt fires the code in
case NORMAL_POWER_UP: happens and the leds blink.
What am I doing wrong?



void main()
{
init_PIC();
#use rs232(baud=BAUD_RATE,xmit=TX_PIN,rcv=RX_PIN,errors,bits=8,parity=N)
output_low(PIN_D4);//receive
setup_wdt(WDT_2304MS);

switch ( restart_cause() )
{
case WDT_TIMEOUT:
{
break;
}
case NORMAL_POWER_UP:
{
for(i=0;i<10;i++)
{
restart_wdt();
led1_on;
led2_on;
delay_ms(200);
led2_off;
led1_off;
delay_ms(200);
}

break;
}
}
_________________
Ringo Davis
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 10:20 pm     Reply with quote

Try to troubleshoot the problem. Use a printf() statement to display
the value returned by the restart_cause() function, in hexadecimal format.
Ttelmah
Guest







PostPosted: Mon Feb 06, 2006 9:07 am     Reply with quote

I'd suggest reading 'restart_cause', before doing anything. Quite few things do upset it's contents. So in your code:
Code:

#use rs232(baud=BAUD_RATE,xmit=TX_PIN,rcv=RX_PIN,errors,bits=8,parity=N)

void main() {
   int8 restart_reason;
   restart_reason=restart_cause();
   init_PIC();
   output_low(PIN_D4);//receive
   setup_wdt(WDT_2304MS);

   switch (restart_reason) {
   case .....



Best Wishes
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Wed Feb 08, 2006 8:55 am     Reply with quote

Ttelmah wrote:
I'd suggest reading 'restart_cause', before doing anything. Quite few things do upset it's contents. So in your code ...:

Best Wishes



That fixed it, Thanks
Ringo
_________________
Ringo Davis
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