View previous topic :: View next topic |
Author |
Message |
Ringo42
Joined: 07 May 2004 Posts: 263
|
restart_cause |
Posted: Sun Feb 05, 2006 9:17 pm |
|
|
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
|
|
Posted: Sun Feb 05, 2006 10:20 pm |
|
|
Try to troubleshoot the problem. Use a printf() statement to display
the value returned by the restart_cause() function, in hexadecimal format. |
|
|
Ttelmah Guest
|
|
Posted: Mon Feb 06, 2006 9:07 am |
|
|
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
|
|
Posted: Wed Feb 08, 2006 8:55 am |
|
|
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 |
|
|
|