Thanks for the C lesson, mea culpa. I've done the fix that you suggested but SLEEP(); still does not behave. I haven't checked if the compiler version is buggy. Some more testing is called for... Matt Bonner wrote: > > Antonio L Benci wrote: > > > > I am trying, so far in vain, to write some code for a 12C509 device > > which has to do the following (shown in pseudo C code): > > > > Power on Device Reset; > > > > main{ > > TRISB(0b11111100); > > CLEAR GPWU; CLEAR GPPU; > > > > switch (RESET_CAUSE()) { > > case NORMAL_POWER_UP: GP0=0, GP1-1; > > case MCLR_FROM_SLEEP: GP0=1, GP1-0; > > case default: error_handle(); > > } > > Your switch statement is always going to fall through to the default > error_handle function. > > You need a "break" statement in each of the case levels: > > switch (RESET_CAUSE()) > { > case NORMAL_POWER_UP: > GP0=0, GP1-1; > break; > case MCLR_FROM_SLEEP: > GP0=1, GP1-0; > break; > case default: > error_handle(); > break; > } > > The last break is not necessary but, unless you're really tight on code > space, it's good to put it in for clarity. > > --Matt Nino. -- ****************************************************** * Antonio (Nino) Benci * * Electronic Services Manager * * Monash University - Dept of Physics * * Wellington Rd, Clayton. 3168 * * Victoria, Australia. * * TEL - 61 3 9905 3649, FAX - 61 3 9905 3637 * * Mobile - 0414 764 763 (private and ah only) * * EMAIL - nino.benci@sci.monash.edu.au (work) * * - fleatech@excite.com (private) * * WWW - www.physics.monash.edu.au/ * ******************************************************