Coding Style - PIC 18F4620 config fuses


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Coding Style - PIC 18F4620 config fuses

    Can anyone provide a style guide on how they handle the configuration fuses for the PIC 18F4620? I realise they will be different for every application.

    I use the MeLabs serial programmer (USB version) to load the MCSP bootloader and it is here I can set or clear a host of registers. This does not require me to do anything in the code like @ __CONFIG etc so I have not been bothering to set any explicit commands in my PBP code.

    By doing nothing in the code, the PIC resorts to the defaults which work OK but which do NOT result in lowest power operation.

    How do others handle this?

    Cheers
    BrianT

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do not use a boot-loader and the programmers I use are the PICSTART PLUS or PICKIT2 and mostly MPLAB, so this may not be of use to you.

    I set the fuses in the *.inc file. I have found that once the fuses are set for the chip I do not change them often. But that is me. I will make a note in the code of how the fuses are set.

    I know...why not set the fuses in the code if I make a note of how the *.inc is set in the code. For me it just seems to work better.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Always in my code using the ol' __CONFIG syntax (for PBP), new syntax when using ASM or C18 pragma.

    See USBDemo code.

    If i use a bootloader, i'll paste the config fuses in my code.. but comment them. So if i decide to remove the bootloader, i'll have my fuses ready.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Brian,

    I don't use bootloaders very often, so this isn't the way I normally do things.
    But I thought I'd give some food for thought on setting configs with either a bootloader or ICSP on 18F's.

    Code:
    ASM
    ;--[CONFIG1H]-------------------------------------------------- 
    CFG_1H =          _OSC_HSPLL_1H    ; Oscillator
    CFG_1H = CFG_1H & _FCMEN_OFF_1H    ; Fail-safe Clock Monitor
    CFG_1H = CFG_1H & _IESO_OFF_1H     ; Int/Ext Osc Switchover 
    ;--[CONFIG2L]-------------------------------------------------- 
    CFG_2L =          _PWRT_ON_2L      ; Power-ON Timer
    CFG_2L = CFG_2L & _BOREN_ON_2L     ; Brown Out
    CFG_2L = CFG_2L & _BORV_2_2L       ; Brown Out voltage
    ;--[CONFIG2H]-------------------------------------------------- 
    CFG_2H =          _WDT_ON_2H       ; Watch Dog Timer
    CFG_2H = CFG_2H & _WDTPS_512_2H    ; WDT Prescaler
    ;--[CONFIG3H]--------------------------------------------------
    CFG_3H =          _MCLRE_ON_3H     ; Master Clear Reset
    CFG_3H = CFG_3H & _LPT1OSC_OFF_3H  ; Low Power TMR1 Osc
    CFG_3H = CFG_3H & _PBADEN_OFF_3H   ; PORTB Analog
    CFG_3H = CFG_3H & _CCP2MX_PORTC_3H ; CCP Multiplexer
    ;--[CONFIG4L]-------------------------------------------------- 
    CFG_4L =          _STVREN_ON_4L    ; Stack Over/Under Reset
    CFG_4L = CFG_4L & _LVP_OFF_4L      ; Low Voltage Programming
    CFG_4L = CFG_4L & _XINST_OFF_4L    ; Extended Instructions
    CFG_4L = CFG_4L & _DEBUG_OFF_4L    ; Hardware Debugger
    
    ;--------------------------------------------------------------
        ifdef  LOADER_USED             ; If bootloader is used
            #include "RTconfig.inc"    ; change Configs at runtime
            WriteConfig?CC  _CONFIG1H, CFG_1H
            WriteConfig?CC  _CONFIG2L, CFG_2L
            WriteConfig?CC  _CONFIG2H, CFG_2H
            WriteConfig?CC  _CONFIG3H, CFG_3H
            WriteConfig?CC  _CONFIG4L, CFG_4L
        else                            ; If bootloader NOT used
            __CONFIG  _CONFIG1H, CFG_1H ; set __configs in program
            __CONFIG  _CONFIG2L, CFG_2L 
            __CONFIG  _CONFIG2H, CFG_2H 
            __CONFIG  _CONFIG3H, CFG_3H 
            __CONFIG  _CONFIG4L, CFG_4L 
        endif
    ENDASM
    ;----------------------------------------------[ END Configs]--
    If the bootloader is being used. It includes the Run-Time Config module from ...
    http://www.picbasic.co.uk/forum/showthread.php?t=4093

    Then sets the configuration manually at run-time.
    The module checks the configs on every reset, but only writes them if they are different.

    If the bootloader is Not being used, it saves space by not including the Run Time Config module and puts the __CONFIG's in the program like normal.

    Be carefull when changing Oscillator settings!
    If you set a mode that does not provide a system clock, or gives a clock at a frequency that the bootloader does not expect, ...
    You will have to re-Flash the bootloader to make it work again.
    You may even want to comment out the WriteConfig?CC _CONFIG1H line, just to make sure it doesn't get changed.

    HTH,
    DT

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. 18F4550 Bootloader enter via eeprom setting
    By bradb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd November 2008, 23:51
  3. Error 0X0000008E when connecting a 18F2550 USB HID
    By FranciscoMartin in forum USB
    Replies: 8
    Last Post: - 16th October 2008, 17:20
  4. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 15:26
  5. Installation sequence
    By Demon in forum General
    Replies: 23
    Last Post: - 11th July 2006, 03:56

Members who have read this thread : 0

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