PDA

View Full Version : How to MCLR by code for 16F877



fbestepe
- 17th November 2004, 08:29
Hi everybody,

I would like to learn how could I make MCLR reset by picbasic code. I mean, during MCLR reset some processes occur like PC turns back to start address and some others, what are the process occured during MCLR reset exactly, and could I realize all these processes by code? That is because the device is away from me and it requires MCLR reset sometimes, so I thought that I could do it by code periodically, once in a specified period.

Thanks for all,
Firat

Melanie
- 17th November 2004, 11:32
There is no vector you can jump to or instruction to effect an MCLR Reset.

You can cause the Watchdog Timer to time-out (if you've set it), but a watchDog Reset isn't the same.

The easiest way is to cross-connect a spare PIC pin (the one adjacent to the MCLR pin is a good choice!)... since they all power up as INPUT by default, all you have to do is OUTPUT your chosen pin LOW. Don't forget to TRIS your chosen pin as INPUT (until it's needed) and if you choose RA0 (as the adjacent pin), don't forget to set it to Digital Mode.

See the RESET sub-section of the "Special Features of the CPU" section in your PIC's Datasheet for details of the state of the internal registers of your PIC following any given Reset.

Dave
- 18th November 2004, 13:12
Firat, Yes it is possible to effect an MCLR function from within your code. Paste these lines into your code where you want to effect the reset function. I use this code on an 16F876 and it works great. I use it after waking from sleep mode.

Asm
bcf PCLATH, 3
bcf PCLATH, 4
goto 0
EndAsm

Try it and let me know....

Dave Purola,
N8NTA

fbestepe
- 18th November 2004, 15:31
Thanks for the replies Melanie and Dave,
I thought the solution that you explained, Melanie, but my hardware is completed and operating now. I do not want to touch the hardware so I have to solve this problem by code.
I will try your recommendation, Dave, and will inform you about the result.
Thanks again....
Firat.

Ingvar
- 18th November 2004, 16:34
Dave,

The trick you posted will "restart" the program but it will NOT affect the internal registers like a true reset would. As long as you 're aware of this there is no problems doing so.

/Ingvar

Dave
- 18th November 2004, 18:00
Ingvar, I never rely on the default settings of the processor comming out of an MCLR of soft reset as I have seen some strange default conditions in the past. I always set the registers initially that I will use and those that can effect the outcome. I usually reset the states of variables during program execution on a time or number of loops basis as I have seen some funny results from ram storage in the past. I assume that others are doing the same.

Dave Purola,

Vett58
- 20th November 2014, 20:52
Firat, Yes it is possible to effect an MCLR function from within your code. Paste these lines into your code where you want to effect the reset function. I use this code on an 16F876 and it works great. I use it after waking from sleep mode.

Asm
bcf PCLATH, 3
bcf PCLATH, 4
goto 0
EndAsm

Try it and let me know....

Dave Purola,
N8NTA



Thank you for sharing . Your post did help me. Thanks

Archangel
- 20th November 2014, 23:45
This thread predates my membership here by a year or two, and I had never seen it. Thanks Dave for this delicious tidbit and thanks to Vett58 for resurfacing it. BTW, it works a treat!

Vett58
- 21st November 2014, 01:08
This thread predates my membership here by a year or two, and I had never seen it. Thanks Dave for this delicious tidbit and thanks to Vett58 for resurfacing it. BTW, it works a treat!
I am grateful to you and all moderators and members to have shared the vast knowledge by this remarkably useful and accurate forum. Thanks for all you do.

Ioannis
- 24th November 2014, 14:28
The software reset is not a complete hardware reset. Keep that in mind, since some registers are not really reset as in a power cycle.

Ioannis

Acetronics2
- 24th November 2014, 16:46
also can use an output driving a Mosfet ( w/ a little cap between gate and ground ) that clamps the reset pin to gnd ...

not very smart, but damn efficient !

Alain

Demon
- 26th November 2014, 00:51
I'd do like Alain. Simple, few extra parts and reliable.

Robert