PDA

View Full Version : Software reset



leonel
- 21st February 2005, 11:13
There are any way to do a software reset, not an hardware reset?

mister_e
- 21st February 2005, 13:28
By software only ... no.... and yes.

If you connect one extra i/o to your MCLR pin... yes

leonel
- 21st February 2005, 14:59
What your saying is to connect, for example, porta.1 to MCLR pin and "write" porta.0 = 0 to make a software reset?!

mister_e
- 21st February 2005, 19:02
yep. just make sure your PORTA.1 is set to high or as input when you boot the pic and that's it.

EDIT: i don't know if it's working but i just read my 18F2320 datasheet about the STKPTR register. Probably you can set the stack register full and do few gosub to get a Stack Full Resets too. never tested it. i'll try this now and let you know.

mister_e
- 21st February 2005, 19:48
Mouhaha it's working


' program to perfom an software reset
' PIC18F2220
DEFINE LOADER_USED 1
DEFINE OSC 20

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600

loop var byte
begin:
STKPTR = 0 ' clear Stack resets bits
hserout ["software RESET",13,10]
start:
for loop = 10 to 0 step -1
hserout ["reset in ",dec loop,13,10]
pause 1000
next

STKPTR = $FF ' full stack pointer

gosub there

pause 1000
goto start
there:
hserout ["I'm supposed to be die now ;o("]
pause 1000
gosub there2
return
there2:
hserout ["I'm supposed to be die now for the 2nd time ;o("]
pause 1000
gosub there3
return

there3:
hserout ["I'm supposed to be die now for the 3rd time ;o("]
pause 1000
return


it never jump to 'there' or 'there2' and for sure 'there3'
cool stuff!

Darrel Taylor
- 21st February 2005, 19:56
if you're using an 18F type pic, you can just use the reset command.

@ reset

if using a 16F,

asm
  clrf PCLATH
  goto 0
endasm


Darrel

mister_e
- 21st February 2005, 20:31
@ reset

yup... always read the whole datasheet.

leonel
- 7th March 2005, 17:27
The code doesnīt make a software reset to all registers
@clrf PCLATH
@ goto 0

What i did wrong?

Regards
Leonel Monteiro

mister_e
- 7th March 2005, 17:32
well i'm not sure to agree 100% about that method. Are you still using the 18F series?

looks no 'cause you must use @ reset

did you try with the i/o reset method?

leonel
- 7th March 2005, 17:38
I'm using 16F so the @reset itīs not possible.
I didnīt try the I/O method because my PCB is done...

mister_e
- 7th March 2005, 17:44
my assumption is by using this method, it jumps only to the reset vector. So it doesn't produce any effects on the registers... so the i/o style should be considered.

leonel
- 7th March 2005, 18:00
Yes, I agree with you...
What do you think the ideia to do software reset putting all my registers to zero. Itīs easier and i havenīt to use the I/O method

mister_e
- 7th March 2005, 18:08
not sure of it... humm... what is the purpose of this software reset?

What do you expect?

Do you set all your registers at the begining?

Sure you can set all register to the default POR before the goto reset vector ... but those registers are not all to zero... see datasheet for POR setting of each registers.

leonel
- 7th March 2005, 18:24
The ideia in doing the software reset itīs that:
I have a "security command" and when this contact is closed the circuit workīs normally, but when the contact opens I donīt want that the circuit workīs, but when the contact closes again all my registers goes like it seems we remove the power, like it was the first time we were running the program...

What Iīm thinking to do is modify the value on the registers that I've modified and put them at zero or to the value that had at the beginning!

Bruce
- 7th March 2005, 18:37
If you just need to clear all RAM (variables) then use the CLEAR command.

If you want to start over from location 0 simulating a power-up condition, and clear RAM without a hardware reset, then use;

@ clrf PCLATH
@ goto 0

And place CLEAR as the first BASIC instruction.

If you have a security check routine that needs to clear RAM when a switch changes state, use the CLEAR command on entry to the routine.

Lots of options.

leonel
- 8th March 2005, 11:07
Thankīs, your solution works.
I was forgetting the clear command...
The code to do a software reset is:
clear
@ clrf PCLATH
@ goto 0

Best regards
Leonel

Worayoot
- 28th May 2008, 05:48
Thank you

@ clrf PCLATH
@ goto 0

I use with 12F work very well