OK Morgan, Here is a working parser. it assumes WDT is on, but dont do anything to clear it till after the parser is finished. i get a lot of race loops if i forget. dont initialize anything either. just parse out the various flags and figure out why the reset occurred. This one traps WDT, MCLR, Cold boot, warm boot, deliberate timeouts, sleep, and other things. Reqires a flag register called mflag here. This router dumps all mystery states to the wmbt routine which initializes everything and puts selected registers on the rs232 output line for analysis. alice > Somebody have probably already written a routine to run after reset to d= ecode what coused th routine, like: > > If it was Watchdog reset goto WatchdogRecoveryHandler > If it was power on... > If it was brown out reset... > If it was.... > > Such routine might be time consuming to validate, so if somebody have te= sted working code i would appreciate that. > > It might be in an archive somewhere i have not found? > > And then there are those things to think about, i beliave, like not go a= head to load setup from EEPROM if it was a reset during EEPROM write and i= s still writing... > > Hmm... i should have checksum handling for EEPROM... > > /Morgan > Morgan Olsson morgans.rt@telia.com > Morgans Reglerteknik, H=E4llek=E5s, 277 35 KIVIK, SWEDEN > tel +46(0)414-446620, fax +46(0)414-672324 > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. ;; org 0 nop ; goto top ; org 0x004 top call init CLRF PORTA CLRF PORTC clrf PORTB ; clrf mflag ;for debugging purposes especially simulator ;parse the big guys btfsc status,TO ;status,4 GOTO TO1 ;to=3D1 wmbt or startup GOTO TO0 ;to=3D0 wdt in sleep or wdt TO0 btfss status,PD ;this actually is used goto wmbt ;to=3D0 pd=3D0 reset+clrwdt goto wozat ;to=3D0 pd=3D1 wdt TO1 btfss status,PD ;hello? hello? goto main ;to=3D1 pd=3D1 powerup goto wmbt ;to=3D1 pd=3D0 sleeeeeeeep ;parse out the flags next ;sort of a state machine i guess wotrst btfsc mflag,0 ;mclr+sleeping? not done, dump goto wmbt;zzz ;decrement lsb of sleep or continue t_6 btfsc mflag,6 ;err goes to dump goto wmbt ;dont clear this in wmbt t_7 btfsc mflag,7 ;decrement sleep loop goto woof t_0 btfsc mflag,0 ;main sleep goto zzzz t_2 btfsc mflag,2 ; during readout goto mopup ;restore old address and goto readlp t_1 btfsc mflag,1 ;flag for end of write loop goto disp t_4 btfsc mflag,4 ;setup area goto loopw t_5 btfsc mflag,5 goto loopw dunno goto wmbt ;dont know why were here ;))))))))main starts(((((((( -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.