• AVR Freaks

Hot!Single time execution intruction PIC18F87J60

Author
stoyanoff
Super Member
  • Total Posts : 252
  • Reward points : 0
  • Joined: 2011/01/10 03:37:28
  • Location: 0
  • Status: offline
2020/01/23 02:53:50 (permalink)
0

Single time execution intruction PIC18F87J60

Greetings! I have a PIC18F87J60 with an external RTC. So I need to setup this rtc and to not touch it anymore. If it is a regular procedure it will reset the RTC on every restart. 
Can I do this in code or I have to program the controller twise?
Thanks!
#1

6 Replies Related Threads

    ric
    Super Member
    • Total Posts : 25555
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Single time execution intruction PIC18F87J60 2020/01/23 02:55:40 (permalink)
    +1 (1)
    You left out the most important detail.
    What is the RTC chip?
    Does it have a register you can read that will indicate that it has been setup?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    pcbbc
    Super Member
    • Total Posts : 1501
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Single time execution intruction PIC18F87J60 2020/01/23 03:06:26 (permalink)
    +1 (1)
    stoyanoff
    I have a PIC18F87J60 with an external RTC. So I need to setup this rtc and to not touch it anymore. If it is a regular procedure it will reset the RTC on every restart. 
    Can I do this in code or I have to program the controller twise?

    Reading between the lines...
    You code is setting up a RTC every time the PIC18F87J60 resets/initializes.  You only want this to happen once.
    By "regular procedure" you mean function, and you are concerned that the function will get called every time the PIC resets.  You are correct in that assumption.
     
    Have I got that right?
     
    What external RTC are you using?
    What type of restarts do you want to set the RTC on?
    Only the first power up ever?  All power on resets, but not MCLR? What about BOR and other types of reset?
    From what source are you setting the RTC?
    #3
    stoyanoff
    Super Member
    • Total Posts : 252
    • Reward points : 0
    • Joined: 2011/01/10 03:37:28
    • Location: 0
    • Status: offline
    Re: Single time execution intruction PIC18F87J60 2020/01/23 11:26:07 (permalink)
    0
    I am using DS1338Z. I want just to set it just once! And the code to continue execute the main program.
    I don`t have other source -> the PIC18 is the only one.
    Thanks!
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18255
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Single time execution intruction PIC18F87J60 2020/01/23 11:40:02 (permalink)
    +1 (1)
    You already got you Answer.  Read the Clock on Bootup and see if you already initialized it.
    Register 7 Bit 5 looks good. or Register 0 bit 0. (remember you will need to set it again if the Battery is replaced)
    Or you can Write something to the RTCC RAM
    OR remember it in Other Permanent Memory.
    #5
    Mysil
    Super Member
    • Total Posts : 3634
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Single time execution intruction PIC18F87J60 2020/01/23 12:16:38 (permalink)
    0
    Hi,
    Make code to read control and status registers of the RTC device.
    If it is stopped, then start it, and set the time.
    If it is already running, then let it continue.
    If the time is wrong, then adjust it.
    If the time is reasonable, then let it continue as it is running.
     
    It is the same procedure as you do manually with any mechanical or electric clock.
     
    If you build the program, and program the MCU connected to the RTC device at the same time,
    then you may use __TIME__   and  __DATE__     macro text strings  from the compiler,
    to make initial time settings.
     
    Then there is no end to the possile complexitity to obtain time for adjustments.
     
        Mysil
     
    #6
    pcbbc
    Super Member
    • Total Posts : 1501
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Single time execution intruction PIC18F87J60 2020/01/24 01:52:58 (permalink)
    0
    I am not sure why you need to be concerned about this “set only once requirement” then.  Setting is always going to be a manual process since you do not have access to another time source.
     
    Almost all microprocessor based devices I am familiar with that have a RTC function start up with their times at midnight (or some other fixed time) and dates usually at their inception date.  They then have some user accessible mode that can be accessed to set/adjust the clock. They are going to need that anyway for when the RTC is wrong or the battery is changed. So I’m not sure I see the big deal.
     
    I suppose you might want to know if the clock has previously been set (for example a digital alarm clock flashes when the time is not set). But that is NOT the question the OP asked.
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5