New PBP version - Gold version - Is it really worth it?


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: New PBP version - Gold version - Is it really worth it?

    What exactly is a conditional config/compilation?
    You can write code that will easily compile for different PIC processors and not have to maintain and update separate program files for each processor... since different PIC's often name their registers differently, even though they do the same thing.

    Here are a couple(3) of examples... This code allows me to use either the 16F690 or the 16F1828.

    The first is an example of conditional config... meaning seting the configuration registers

    Code:
    #IF __PROCESSOR__ = "16F1828"
        #CONFIG
               __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
               __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
        #endconfig
        #else
           #IF __PROCESSOR__ = "16F690"
             #CONFIG
               __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
             #endconfig
               #ELSE 
               #ERROR "Program does not support " + __PROCESSOR__
           #ENDIF
    #endif
    
    #msg "compiling for target " + __PROCESSOR__

    an example of setting up registers...
    Code:
    #IF __PROCESSOR__ = "16F1828"
      AnselA  = 0              'and turn off analog
      AnselB  = 0             
      AnselC  = 0
      IOCAF = 0      'clear interrupt flag register
      WDTCON=010100 'SET WDT PRESCALER
    #ELSE
      Ansel  = 0               'and turn off analog
      AnselH = 0
      INTCON.0 = 0   'clear interrupt flag register
    #ENDIF
    An example of clearing the interrupt flag register for two different PICs...
    Code:
    #IF __PROCESSOR__ = "16F1828"
      IOCAF = 0
    #ELSE
        INTCON.0 = 0   'clear interrupt flag register
    #ENDIF
    At compile time, only the code that fits your selected processor is actually included in the final compiled code.
    Last edited by Heckler; - 8th October 2011 at 01:42.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Members who have read this thread : 2

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