How to MCLR by code for 16F877


Closed Thread
Results 1 to 12 of 12
  1. #1
    fbestepe's Avatar
    fbestepe Guest

    Default How to MCLR by code for 16F877

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    fbestepe's Avatar
    fbestepe Guest


    Did you find this post helpful? Yes | No

    Default to the repliers

    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.

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    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

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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,

  7. #7
    Join Date
    Apr 2010
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: How to MCLR by code for 16F877

    Quote Originally Posted by Dave View Post
    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

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: How to MCLR by code for 16F877

    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!
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Apr 2010
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: How to MCLR by code for 16F877

    Quote Originally Posted by Archangel View Post
    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.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: How to MCLR by code for 16F877

    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

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: How to MCLR by code for 16F877

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: How to MCLR by code for 16F877

    I'd do like Alain. Simple, few extra parts and reliable.

    Robert

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 22:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 18:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts