DS3231 Alarm settings anybody


+ Reply to Thread
Results 1 to 15 of 15

Thread: DS3231 Alarm settings anybody23 days old

  1. #1
    Junior Member bravo's Avatar
    Join Date
    Apr 2019
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    167.37 MB

    0 Not allowed!

    Default DS3231 Alarm settings anybody

    Hi Folks,
    I need to use a DS3231 & have Alarm1 work once a day at 8 AM. I have the module running on a proton board & with the correct time set on it.
    Now I wish to enable Alarm 1 & set the alarm time. I have a 10K pull up resistor on pin 3 which is the alarm o/p pin.
    This is what I have tried which does not work:

    set_alarm:
    BIN_TO_BCD_VALUE = Almminutes
    GoSub BIN_TO_BCD
    BusOut $D0,$08,[BCD_OUTPUT] 'Save Almminutes

    BIN_TO_BCD_VALUE = AlmHours
    GoSub BIN_TO_BCD
    BusOut $D0,$09,[BCD_OUTPUT] 'Save AlmHours AlmHours

    BusOut $E0, $00, [00000101] 'enable Alrm 1, interupt o/p (not 1 hz sqr wave),
    'temperature oFF, Clock running.

    Any useful help would be appreciated.

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,288
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Did you solve it yet? It's not a device that I have used but looking at the data sheet I think that last line should be

    BusOut $D0, $0E, [00000101]
    My RAM is failing

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,426
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Once you have it operating you can change your subroutines for manipulating BCD to procedures using these:

    Code:
    '---------------------------------------------------------------
    ' Decimal to BCD converter
    ' Input     : pBytein
    ' Output    :
    ' Notes     : ByteOut = ((Bytein / 10) << 4) + (ByteIn // 10)
    '
    Proc BinToBCD(pDecIn As Byte), Byte
        Result = ((pDecIn / 10) << 4) + (pDecIn // 10)
    EndProc
    
    '---------------------------------------------------------------
    ' BCD to Decimal converter
    ' Input     : WREG
    ' Output    : WREG
    ' Notes     : Work with the two nibbles. Multiply the high nibble by 10, then add the low nibble to it
    '           : ByteOut = ((ByteIn >> 4) * 10) + (ByteIn & $0F)
    '
    Proc BCDToBin(pBCDin As Byte), Byte
        Result = ((pBCDin >> 4) * 10) + (pBCDin & $0F)
    EndProc
    Or you can include the "Maths.inc" library file into your program and the BCDToBin and BinToBCD procedures are inside there ready to use. This library file, as well as many others, are installed with the compilers. See the user's includes directory "C:\Users\Users Name\PDS\Includes"
    Last edited by top204; 19th November 2019 at 14:08.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Junior Member bravo's Avatar
    Join Date
    Apr 2019
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    167.37 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Hi See Mos & Les,
    Thanks for the interest.
    It is not solved yet. I tried your suggestion See Mos, which did not work. Les, the BCD conversions are in the code already, but good to know about the include. What is a bit confusing is that when setting the time, you write to one lot of addresses, which are then transferred to a buffer which starts at $D1. The data sheet does not mention if the alarm settings also go to a buffer one block along. I am guessing they do ???
    I could waste an extra pin on the chip & add some more code to check if the hour is 8 etc. etc., instead of just waiting for an alarm input. I have this project which includes the SIM800 module running on a 18F26K22 powered from a 1000mAH phone battery. The program does not include sleep so far. It has been running for 6 days so far, & the battery is still at 3.8604 volts. The current draw is just over 1mA without the SIM800 module turned on. The battery will be charged by a 1W solar panel & the chances of no sun for 6 days is pretty unlikely. So question is will the extra code & 10K pull up resistors increase the battery drain significantly ? I can check the time every 30 secs to if the hour & minute is correct.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Junior Member bravo's Avatar
    Join Date
    Apr 2019
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    167.37 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Hi All,
    I now have the opposite problem, the Alarm output is on & I can't turn it off yet.
    I added more alarm setting lines & changed the alarm time to the next minute which worked using this code:

    set_alarm:
    BIN_TO_BCD_VALUE = Almminutes '08h
    GoSub BIN_TO_BCD
    BusOut $D0,$08,[BCD_OUTPUT] 'Save Almminutes

    BIN_TO_BCD_VALUE = AlmHours '09h
    GoSub BIN_TO_BCD
    BusOut $D0,$09,[BCD_OUTPUT] 'Save AlmHours AlmHours

    BusOut $E0, $00, [$5] 'enable Alrm 1, interupt o/p (not 1 hz sqr wave),
    'temperature oFF, Clock running.
    BusOut $D0, $0E, [%00000101]
    BusOut $D0, $0A, [%10000000]
    Return

    So to try & turn it off, I assumed that the interrupt must be turned off, so I added what I think is the clear the interrupt flag code :

    MAIN_LOOP:
    If PORTA.1 = 0 Then High led1
    DelayMS 200
    BusOut $F0, $00, [0]
    Low led1

    GoSub read_time
    Cls
    Print At 1,1,Dec2 Hours,":",Dec2 minutes, ":",Dec2 Seconds

    DelayMS 1000

    GoTo MAIN_LOOP

    All this does is tun off the LED for 200 mS each cycle.
    Unfortunately nothing changed when the minute & the hour changed.
    Good test for the LED though !!!!

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,231
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    There's some nice looking code on the dark side (PBP) seems like you have to differenciate between day and date alarms (don't know if you're already doing that). So I guess you need to write 4 bytes to either reg 07 or reg 0B.
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,288
    Thumbs Up
    Received: 17
    Given: 0
    Total Downloaded
    872.27 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    There is a lot of code for the Arduino as well so it should not be too difficult to work things out.

    Just Google DS3231 Code
    My RAM is failing

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,135
    Thumbs Up
    Received: 66
    Given: 26
    Total Downloaded
    3.31 GB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    All your writes are to address $0D, except this one : BusOut $E0, $00, [$5] 'enable Alrm 1, interupt o/p (not 1 hz sqr wave),

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,426
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    If I had a bit of time, or a DS devies I would take a look at the library for it.

    But be very careful with the Arduno crap out there. :-) I looked at one article from a user and they actually had an alarm clock based upon the microcontroller running the time and comaparing it with the DS3231 time value, then triggering the alarm when they matched! Now how absolutely stupid is that? But these are the people who are writing code as experts and others copy and paste the text and the codes.

    I looked at the DS3231 C++ class library and it is dreadfully complex for such a simple task, which is the way of C++ and code is written that will fill a microcontroller's flash memory for the silliness of using classes and objects on an 8-bit microcontroller, so even a pin access uses 5 times more code and speed than a simple set or clear.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Junior Member bravo's Avatar
    Join Date
    Apr 2019
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    167.37 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Hi Les, I don't bother with Arduino because of all the includes & sign up to get this one etc., all for one line of code. I did do a small test on the DS3231 of not setting the alarm (not unsetting at this stage) & just doing the read the time, if hours = 8 and minutes = 0 then ...................which works fine. As I have moved to the 18F26K22 & have spare pins for the I2C, I designed the board to do this, & will have on Friday or Monday. I tried to move to an 18F26K40 which is cheaper & has an actual built in 31 Khz osc which does not require a crystal. I could not get Int0 or Int2 to work. Would you have a config example for this by any chance ?

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,135
    Thumbs Up
    Received: 66
    Given: 26
    Total Downloaded
    3.31 GB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Instead of using an internal osc you might find the 1herz output of the DS a very nice option. Or you can use the 32 kHz output. This is a perfect freq for any clock you want to build since you can use aTimer1 with some scaling to obtain a 1Hz freq. Both frequencies are probably more accurate than the Pic osc.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #12
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,426
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    The new 18FxxK40 devices are actually quite nice, and because they are new, they are quite a lot cheaper at the moment.

    The 18FxxK40 devices have PPS, and INT0, INT1 and INT2 need their chosen pins to be setup using PPS. It's a very simple process and made easier by the Proton compiler. :-)

    Here are some defines for INT0, INT1 and INT2 that I created for a recent program:

    Code:
    '------------------------------------------------------------------------------
    ' INT0 SFR macros
    '
    $define INT0_Flag() PIR0bits_INT0IF
    $define INT0_FlagClear() Clear PIR0bits_INT0IF          ' Clear the INT0 interrupt flag
    $define INT0_RisingEdgeSet()  Set INTCONbits_INT0EDG    ' Set INT0 for a rising edge
    $define INT0_FallingEdgeSet() Clear INTCONbits_INT0EDG  ' Set INT0 for a falling edge
    $define INT0_Enable() Set PIE0bits_INT0IE               ' Enable an INT0 Interrupt
    $define INT0_Disable() Clear PIE0bits_INT0IE            ' Disable an INT0 Interrupt
    
    '------------------------------------------------------------------------------
    ' INT1 SFR macros
    '
    $define INT1_Flag() PIR0bits_INT1IF
    $define INT1_FlagClear() Clear PIR0bits_INT1IF          ' Clear the INT1 interrupt flag
    $define INT1_RisingEdgeSet()  Set INTCONbits_INT1EDG    ' Set INT1 for a rising edge
    $define INT1_FallingEdgeSet() Clear INTCONbits_INT1EDG  ' Set INT1 for a falling edge
    $define INT2_Enable()  Set PIE0bits_INT1IE              ' Enable an INT1 Interrupt
    $define INT2_Disable() Clear PIE0bits_INT1IE            ' Disable an INT1 Interrupt
    
    '------------------------------------------------------------------------------
    ' INT2 SFR macros
    '
    $define INT2_Flag() PIR0bits_INT2IF
    $define INT2_FlagClear() Clear PIR0bits_INT2IF          ' Clear the INT2 interrupt flag
    $define INT2_RisingEdgeSet()  Set INTCONbits_INT2EDG    ' Set INT2 for a rising edge
    $define INT2_FallingEdgeSet() Clear INTCONbits_INT2EDG  ' Set INT2 for a falling edge
    $define INT2_Enable()  Set PIE0bits_INT2IE              ' Enable an INT2 Interrupt
    $define INT2_Disable() Clear PIE0bits_INT2IE            ' Disable an INT2 Interrupt
    To setup the PPS use this code:
    Code:
    '--------------------------------------------------------------------
    Main:
        INT0PPS = Pin_B0                            ' Set PPS so RB0 is INT0
        INT1PPS = Pin_B1                            ' Set PPS so RB1 is INT1
        INT2PPS = Pin_B2                            ' Set PPS so RB2 is INT2
    Setting the rising or falling trigger for INT0, INT1 and INT2 is in the above defines and setting an interrupt is standard for these devices and use the flag defines above. i.e.

    If INT1_Flag() = 1 Then
    '
    ' Do the code here for an INT1 interrupt
    '
    INT1_FlagClear() ' Clear the INT1 flag when complete
    EndIf


    The Pin_B0 and Pin_B1 etc, constants are at the end of each device's .def file and give each Port.Pin a number.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #13
    Junior Member bravo's Avatar
    Join Date
    Apr 2019
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    167.37 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Hi Les,
    Thanks for this I will give it another try. At this stage I am using the 18F26K22 with code to read the time. It is still drawing about half a milliamp. Hadv215, I did think about using the 32Khz from the DS3231 but have not done so yet. It took me about 5 hours to stop the chip repeatedly sending the daily report when getting to the correct time, which was caused by the program not having a chance to read the time again on its next loop, because it only reads the time every 45 loops, which started by an interrupt about every second. So immediately after sending the daily report, is a delay to make sure the time is on the next minute, & then do the gosub read_time. I have new issue to solve which I will do a separate post for, to examine one character in a string which won't compile.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #14
    Junior Member bravo's Avatar
    Join Date
    Apr 2019
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    167.37 MB

    0 Not allowed!

    Default Re: DS3231 Alarm settings anybody

    Hi Les again,
    Re the 26K40, can you post an example of the config file for this chip. I mean the config fuse list, which is not in the Help 18F config list.
    Thanks again for your help,
    Gary

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #15
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,426
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default 18F26K40 and 18F27K40 Config Fuse settings for internal and external oscillator

    For the fuses, take a lookin teh device's PPI file. They are at the end of it, and all the available fuese are also listed.

    The fuse setting can depend on how the device is being used, for example, the fuses below set for the internal oscillator:

    Code:
    Config_Start
    '
    ' Setup the fuses to use the internal oscillator on a PIC18F26K40 or PIC18F27K40.
    '
        RSTOSC   = HFINTOSC_1MHZ            ' With HFFRQ = 4MHz and CDIV = 4:1
        FEXTOSC  = Off                      ' External Oscillator not enabled
        MCLRE    = EXTMCLR                  ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RE3 pin function is MCLR
        WDTE     = Off                      ' WDT disabled
        CLKOUTEN = Off                      ' CLKOUT function is disabled
        CSWEN    = On                       ' Writing to NOSC and NDIV is allowed
        FCMEN    = Off                      ' Fail-Safe Clock Monitor disabled
        PWRTE    = On                       ' Power up timer enabled
        LPBOREN  = Off                      ' LPBOREN disabled
        BOREN    = Off                      ' Brown-out turned off
        BORV     = VBOR_245                 ' Brown-out Reset Voltage (VBOR) set to 2.45V
        ZCD      = Off                      ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
        PPS1WAY  = Off                      ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
        STVREN   = Off                      ' Stack full/underflow will not cause Reset
        Debug    = Off                      ' Background debugger disabled
        XINST    = Off                      ' Extended Instruction Set and Indexed Addressing Mode disabled
        SCANE    = Off                      ' Scanner module is Not available for use. SCANMD bit is ignored
        LVP      = Off                      ' HV On MCLR/VPP must be used for programming
        WDTCPS   = WDTCPS_15                ' Watchdog Divider ratio 1:1048576 (32 seconds)
        WDTCWS   = WDTCWS_7                 ' Window always open (100%). Software control. Keyed access not required
        WDTCCS   = LFINTOSC                 ' WDT input clock selector->WDT reference clock is the 31.2kHz HFINTOSC output
        WRT0     = Off                      ' Block 0 (000800-001FFFh) not write-protected
        WRT1     = Off                      ' Block 1 (002000-003FFFh) not write-protected
        WRTC     = On                       ' Configuration registers (300000-30000Bh) write-protected
        WRTB     = Off                      ' Boot Block (000000-0007FFh) not write-protected
        WRTD     = Off                      ' Data EEPROM not write-protected
        Cp       = Off                      ' UserNVM code protection disabled
        CPD      = Off                      ' DataNVM code protection disabled
        EBTR0    = Off                      ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        EBTR1    = Off                      ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        EBTRB    = Off                      ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    With the internal oscillator, several SFRs need to be manipuated to set the oscillator's frequency, and these are easily placed into procedures to make them extremely easy to use, and very easy to read in a program, and remember, unless a procedure is called in a program it will not be included in the program, so only the procedures that are called from the list below will be added to the final BASIC program, so they will not fill up the code memory space:
    Code:
    '--------------------------------------------------------------------
    ' Set the microcontroller to internal 4MHz operation with a HFINTOSC_1MHZ fuse
    ' Input     : None
    ' Output    : None
    ' Notes     : Waits for the oscillator to become stable
    '
    Proc Oscillator_4MHz()
        OSCCON1 = $60
        OSCCON3 = 0
        OSCEN   = 0
        OSCFRQ  = 2
        OSCTUNE = 0
        Repeat: Until OSCSTATbits_HFOR = 1
    EndProc
    
    '--------------------------------------------------------------------
    ' Set the microcontroller to internal 8MHz operation with an HFINTOSC_1MHZ fuse
    ' Input     : None
    ' Output    : None
    ' Notes     : Waits for the oscillator to become stable
    '
    Proc Oscillator_8MHz()
        OSCCON1 = $60
        OSCCON3 = 0
        OSCEN   = 0
        OSCFRQ  = 3
        OSCTUNE = 0
        Repeat: Until OSCSTATbits_HFOR = 1
    EndProc
    
    '--------------------------------------------------------------------
    ' Set the microcontroller to internal 16MHz operation with an HFINTOSC_1MHZ fuse
    ' Input     : None
    ' Output    : None
    ' Notes     : Waits for the oscillator to become stable
    '
    Proc Oscillator_16MHz()
        OSCCON1 = $60
        OSCCON3 = 0
        OSCEN   = 0
        OSCFRQ  = 5
        OSCTUNE = 0
        Repeat: Until OSCSTATbits_HFOR = 1
    EndProc
    
    '--------------------------------------------------------------------
    ' Set the microcontroller to internal 32MHz operation with an HFINTOSC_1MHZ fuse
    ' Input     : None
    ' Output    : None
    ' Notes     : Waits for the oscillator to become stable
    '
    Proc Oscillator_32MHz()
        OSCCON1 = $60
        OSCCON3 = 0
        OSCEN   = 0
        OSCFRQ  = 6
        OSCTUNE = 0
        Repeat: Until OSCSTATbits_HFOR = 1
    EndProc
    
    '--------------------------------------------------------------------
    ' Set the microcontroller to internal 64MHz operation with an HFINTOSC_1MHZ fuse
    ' Input     : None
    ' Output    : None
    ' Notes     : Waits for the oscillator to become stable
    '
    Proc Oscillator_64MHz()
        OSCCON1 = $60
        OSCCON3 = 0
        OSCEN   = 0
        OSCFRQ  = 8
        OSCTUNE = 0
        Repeat: Until OSCSTATbits_HFOR = 1
    EndProc
    The fuses below setup for an external oscillator, which does not need any FSR manipulation:
    Code:
    Config_Start
    '
    ' Setup the fuses to use the external oscillator on a PIC18F26K40 or PIC18F27K40.
    '
        RSTOSC   = EXTOSC                   ' EXTOSC operating per FEXTOSC Bits
        FEXTOSC  = HS                       ' HS (crystal oscillator) above 8 MHz. PFM set to high power
        MCLRE    = EXTMCLR                  ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RE3 pin function is MCLR
        WDTE     = Off                      ' WDT disabled
        CLKOUTEN = Off                      ' CLKOUT function is disabled
        CSWEN    = On                       ' Writing to NOSC and NDIV is allowed
        FCMEN    = Off                      ' Fail-Safe Clock Monitor disabled
        PWRTE    = On                       ' Power up timer enabled
        LPBOREN  = Off                      ' LPBOREN disabled
        BOREN    = Off                      ' Brown-out turned off
        BORV     = VBOR_245                 ' Brown-out Reset Voltage (VBOR) set to 2.45V
        ZCD      = Off                      ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
        PPS1WAY  = Off                      ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
        STVREN   = Off                      ' Stack full/underflow will not cause Reset
        Debug    = Off                      ' Background debugger disabled
        XINST    = Off                      ' Extended Instruction Set and Indexed Addressing Mode disabled
        SCANE    = Off                      ' Scanner module is Not available for use. SCANMD bit is ignored
        LVP      = Off                      ' HV On MCLR/VPP must be used for programming
        WDTCPS   = WDTCPS_15                ' Watchdog Divider ratio 1:1048576 (32 seconds)
        WDTCWS   = WDTCWS_7                 ' Window always open (100%). Software control. Keyed access not required
        WDTCCS   = LFINTOSC                 ' WDT input clock selector->WDT reference clock is the 31.2kHz HFINTOSC output
        WRT0     = Off                      ' Block 0 (000800-001FFFh) not write-protected
        WRT1     = Off                      ' Block 1 (002000-003FFFh) not write-protected
        WRTC     = On                       ' Configuration registers (300000-30000Bh) write-protected
        WRTB     = Off                      ' Boot Block (000000-0007FFh) not write-protected
        WRTD     = Off                      ' Data EEPROM not write-protected
        Cp       = Off                      ' UserNVM code protection disabled
        CPD      = Off                      ' DataNVM code protection disabled
        EBTR0    = Off                      ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        EBTR1    = Off                      ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        EBTRB    = Off                      ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    Last edited by top204; 1st December 2019 at 17:12.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Problem with DS3231
      By Mentcleer in forum Proton Plus Compiler v3
      Replies: 8
      Last Post: 26th August 2016, 12:58
    2. Oh dear. Strange things with a DS3231
      By Daniel in forum RTC Module
      Replies: 4
      Last Post: 11th February 2016, 23:49
    3. Fall Alarm
      By normnet in forum The Lounge
      Replies: 29
      Last Post: 16th November 2011, 23:07
    4. Hardware I2C and DS3231 RTC Problems
      By SimonJA in forum Proton Plus Compiler v3
      Replies: 3
      Last Post: 9th June 2010, 21:44
    5. DS3231 RTC to replace DS1307 - Can't get it working
      By SimonJA in forum Proton Plus Compiler v3
      Replies: 10
      Last Post: 20th January 2009, 11:25

    Members who have read this thread since 8th December 2019, 00:44 : 0

    Actions :  (Set Date)  (Clear Date)

    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