18F2620 pbp3 example config please


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

    Default 18F2620 pbp3 example config please

    Having never used any 18F chips I'm after an example config section of code to have a look at before I try to migrate my code to the new pic.

    My current 16F886 config looks like this

    Code:
    #CONFIG
     __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT 
    
     __CONFIG _CONFIG2, _WRT_OFF & _BOR21V
    #ENDCONFIG
    My 16F886 defines look like the below any obvious issues with those and 18F2620 pic. It should be pin compatible I believe.

    Code:
    DEFINE OSC 8            'Set PicBasic Pro processor speed to 8 Mhz   
    OSCCON = %01110101         'Internal 8 mhz Osc and stable 
    
    CM1CON0 = 0             'Comparator Off
    CM2CON0 = 0             'Comparator Off
    
    T1CON  = %00110000        '$30 = Prescaler 1:8, TMR1 OFF
        
    TRISA = %00001011         'SET PORTA0, A1 & A3 AS INPUTS, REST AS OUTPUTS
    TRISB = %00000000         'SET PORTB AS OUTPUTS
    TRISC = %10010000         'SET PORTC AS OUTPUTS EXCEPT PORT C4 & C7
        
    ANSEL  = %00000001        'SET INPUT AN0 AS ANALOG INPUT
    ANSELH = %00000000              'Disable PortB AD
        
    ADCON0 = %10000001        'SETUP ADC CONVERTER MODULE FOSC/32 & ENABLE ADC MODULE on AD0
    ADCON1 = %00000000        'SETUP ADC LEFT JUSTIFY SET REFV to VDD & VSS  
    
    DEFINE LCD_DREG PORTB         'PORTB is LCD data port
    DEFINE LCD_DBIT 0         'PORTB.0 is the data LSB
    DEFINE LCD_RSREG PORTC         'RS is connected to PORTC.0
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC         'EN is connected to PORTC.1
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 8         '8 lines of data are used
    DEFINE LCD_LINES 4         'It is a 4-line display
    DEFINE LCD_COMMANDUS 2000     'Use 2000uS command delay
    DEFINE LCD_DATAUS 50         'Use 50uS data delay
    
    DEFINE ADC_BITS 8              'Set number of bits in result
    DEFINE ADC_CLOCK 3          'Set Clock source (3 = rc)
    DEFINE ADC_SAMPLEUS 50         'Set sampling time in uS
       
    DEFINE CCP1_REG PORTC         'HPWM channel 1 pin Port C Backlight PWM Driver
    DEFINE CCP1_BIT 2         'HPWM channel 1 pin Bit 2
    Thanks Peter

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Anyone with a config for a similiar 18F chip then? 2525, 4525, 4620?

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    I found this example so will keep trying.

    #CONFIG
    __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    __CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
    #ENDCONFIG

  4. #4
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    I did a migration of code from the 16F877 to the 18F452. They are *both* kind of older now...8^) If you thought it would be useful I can dig up the configurations for comparison. I never throw old code away, I just archive it. I've got versions of this particular ported code that go back to nearly the previous centrury.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    If you have something it would be useful thanks.

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    The configs aren't so much different. If you use a programmer like an ICD2/3 or a PICKIT3, MPLAB will show you the options.

    The easiest thing to do would be to set it up in a way that makes sense and simply try it.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    The sub directory, "DEVICE_REFERENCE" of the PBP3 directory has an example with and all of the options listed.
    Dave
    Always wear safety glasses while programming.

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    That's very useful thanks but how do you know which configs go on which line ? can you mix them up?

    CONFIG1H? xxxx & xxxx & xxxx etc etc
    CONFIG2H?
    CONFIG3H?
    etc

    Or do you just have as many config lines as reqd?

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


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Maybe I am not understanding the question, the 1H things go on the 1H line, 2H on the 2H line...
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Hi,
    Just look at the .INFO file, it has a "section" for each CONFIG you can possibly set for the device, choose one from each section if you don't know the default, like:
    Code:
    ; This is for the 18F26K20
    #CONFIG
      CONFIG FOSC = HSPLL
      CONFIG FCMEM = ON
      CONFIG IESO = OFF
      CONFIG PWRT = ON
      CONFIG BOREN = OFF
      ; And so on
    #ENDCONFIG
    That way you don't have to know which bit belongs to which register.

    Otherwise you have to resort to the datasheet and/or the .inc file for the device located in the MPASM directory, at the bottom of that file you'll find which bit goes where, like:
    Code:
    ;----- CONFIG1H Options --------------------------------------------------
    _FOSC_LP_1H          EQU  H'F0'    ; LP oscillator
    _FOSC_XT_1H          EQU  H'F1'    ; XT oscillator
    _FOSC_HS_1H          EQU  H'F2'    ; HS oscillator
    _FOSC_RC_1H          EQU  H'F3'    ; External RC oscillator, CLKOUT function on RA6
    _FOSC_EC_1H          EQU  H'F4'    ; EC oscillator, CLKOUT function on RA6
    _FOSC_ECIO6_1H       EQU  H'F5'    ; EC oscillator, port function on RA6
    _FOSC_HSPLL_1H       EQU  H'F6'    ; HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)
    _FOSC_RCIO6_1H       EQU  H'F7'    ; External RC oscillator, port function on RA6
    _FOSC_INTIO67_1H     EQU  H'F8'    ; Internal oscillator block, port function on RA6 and RA7
    _FOSC_INTIO7_1H      EQU  H'F9'    ; Internal oscillator block, CLKOUT function on RA6, port function on RA7
    _FCMEN_OFF_1H        EQU  H'BF'    ; Fail-Safe Clock Monitor disabled
    _FCMEN_ON_1H         EQU  H'FF'    ; Fail-Safe Clock Monitor enabled
    _IESO_OFF_1H         EQU  H'7F'    ; Oscillator Switchover mode disabled
    _IESO_ON_1H          EQU  H'FF'    ; Oscillator Switchover mode enabled
    
    
    ;----- CONFIG2L Options --------------------------------------------------
    _PWRT_ON_2L          EQU  H'FE'    ; PWRT enabled
    _PWRT_OFF_2L         EQU  H'FF'    ; PWRT disabled
    _BOREN_OFF_2L        EQU  H'F9'    ; Brown-out Reset disabled in hardware and software
    _BOREN_ON_2L         EQU  H'FB'    ; Brown-out Reset enabled and controlled by software (SBOREN is enabled)
    _BOREN_NOSLP_2L      EQU  H'FD'    ; Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
    _BOREN_SBORDIS_2L    EQU  H'FF'    ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
    _BORV_30_2L          EQU  H'E7'    ; VBOR set to 3.0 V nominal
    _BORV_27_2L          EQU  H'EF'    ; VBOR set to 2.7 V nominal
    _BORV_22_2L          EQU  H'F7'    ; VBOR set to 2.2 V nominal
    _BORV_18_2L          EQU  H'FF'    ; VBOR set to 1.8 V nominal
    And so on but again, I prefer the new way posted above.

    /Henrik.

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Thanks for the guidance here is my new 18F2620 config.

    Code:
    '------------------------------ New General 18F2620 configuration --------------------------
    '#CONFIG
    ' __CONFIG _CONFIG1H, _OSC_INTIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    ' __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L
    ' __CONFIG _CONFIG2H, _WDT_OFF_2H
    ' __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
    ' __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    '#ENDCONFIG
    'DEFINE OSC 8   'Set PicBasic Pro processor speed to 8 Mhz   
    'OSCCON = %01110110   'Internal 8 mhz Osc and stable 
    'CMCON  = %00000111  'Comparators Off
    'T1CON  = %00110000  '$30 = Prescaler 1:8, TMR1 OFF
     
    'TRISA = %00001011   'SET PORTA0, A1 & A3 AS INPUTS, REST AS OUTPUTS
    'TRISB = %00000000   'SET PORTB AS OUTPUTS
    'TRISC = %10010000   'SET PORTC AS OUTPUTS EXCEPT PORT C4 & C7
     
    'ADCON0 = %00000001  'SETUP ADC & ENABLE ADC MODULE on AD0
    'ADCON1 = %00001110  'SETUP ADC SET REFV to VDD & VSS AN0 
    'ADCON2 = %00100010  'SETUP ADC FOSC/32 LEFT JUSTIFY TAD 8
    Below is my working old 16F886 config. Any glaring errors in the above? I'm just swapping chips and I want all functions to remain the same.

    Code:
    '------------------------------ General 16F886 configuration --------------------------
    #CONFIG
     __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & 
    _INTRC_OSC_NOCLKOUT
     __CONFIG _CONFIG2, _WRT_OFF & _BOR21V
    #ENDCONFIG
    DEFINE OSC 8   'Set PicBasic Pro processor speed to 8 Mhz   
    OSCCON = %01110101   'Internal 8 mhz Osc and stable 
    CM1CON0 = 0    'Comparator Off
    CM2CON0 = 0    'Comparator Off
    T1CON  = %00110000  '$30 = Prescaler 1:8, TMR1 OFF
     
    TRISA = %00001011   'SET PORTA0, A1 & A3 AS INPUTS, REST AS OUTPUTS
    TRISB = %00000000   'SET PORTB AS OUTPUTS
    TRISC = %10010000   'SET PORTC AS OUTPUTS EXCEPT PORT C4 & C7
     
    ANSEL  = %00000001  'SET INPUT AN0 AS ANALOG INPUT
    ANSELH = %00000000              'Disable PortB AD
     
    ADCON0 = %10000001  'SETUP ADC CONVERTER MODULE FOSC/32 & ENABLE ADC MODULE on AD0
    ADCON1 = %00000000  'SETUP ADC LEFT JUSTIFY SET REFV to VDD & VSS

    Thanks Peter

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    I moved to a new pic to gain memory space but the same program compiled for the new pic is nearly twice the size as the 16F886 version :?
    Why is that and can I get some memory back. I don't need 18F longs for instance and that is already disabled in the compiler.

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Hi,
    My guess is that it's because on the 16 series (10 & 12 too I believe) the memory is "measured" in WORDS (14-bit words if I'm not mistaken) while on the 18 series it's measured in BYTES. So I don't think your program is actually getting twice as big, it's just displaying the size of it in BYTES instead of in WORDS.

    /Henrik.

  14. #14


    Did you find this post helpful? Yes | No

    Default Still get pickit2 config bits warning

    I still get the some config bits warning with pickit 2.
    I can't see why?

    Code:
    '------------------------------ General 18F2620 configuration --------------------------
    
    #CONFIG
     __CONFIG _CONFIG1H, _OSC_INTIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
     __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L
     __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
     __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
     __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    #ENDCONFIG
    
    
    DEFINE OSC 8			'Set PicBasic Pro processor speed to 8 Mhz 
    OSCCON = %01110000 		'Internal 8 mhz Osc  
    
    WDTCON = %00010101		'Set watchdog Timer for 1 second 
    
    CMCON  = %00000111		'Comparators Off
    CVRCON = %00000000		'CvRef Powered Down 
    
    CCP1CON= %00001100		'CCP1 Module PWM Mode
    CCP2CON= %00000000		'CCP2 Module Disabled 
    
    HLVDCON= %00000000		'HLVCON Disabled
    
    T1CON  = %00110000		'$30 = Prescaler 1:8, TMR1 OFF
    	
    TRISA = %00001011 		'SET PORTA0, A1 & A3 AS INPUTS, REST AS OUTPUTS
    TRISB = %00000000 		'SET PORTB AS OUTPUTS
    TRISC = %10010000 		'SET PORTC AS OUTPUTS EXCEPT PORT C4 & C7
    	
    ADCON0 = %00000001		'SETUP ADC & ENABLE ADC MODULE on AN0
    ADCON1 = %00001110		'SETUP ADC SET REFV to VDD & VSS AN0 
    ADCON2 = %00100010		'SETUP ADC FOSC/32 LEFT JUSTIFY TAD 8

  15. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Hi,
    What exactly does that mean, what warnings do you get and from where do you get them?

    Your code compiles and assembles fine with PBP 3.0.7.4 & MPASM 5.45. Are you using the standalone software for the PICKit2 and is it THAT software that gives you these misterious warnings?

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Make a "Complete" set of configs for any chip with ease.

    meCONFIG
    http://support.melabs.com/content/563-meCONFIG
    DT

  17. #17


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Yes the pickit 2 software states when programming that some configuration bits not in acceptable condition. It still programs and works fine but is disconcerting for users.

    That new meconfig software is interesting I see quite a few bits/parameters I have ignored/did not know about. :?
    Last edited by retepsnikrep; - 11th March 2014 at 17:00.

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


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    The PICkit software expects to see a value for EVERY configuration word.

    The latest versions of PBP3 do create default values for all of them.
    But when you use the #CONFIG block, it overrides all of the defaults, and you should include a "Complete" set for use with the PICkit programmers.

    Like you said, it will program and work ... but a complete set of configs will eliminate that warning.
    DT

  19. #19
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    melabs have a neat config editor meCONFIG ITS WORTH DOWNLOADING and free , or check out the DEVICE_REFERENCE folder in your pbp3 installed directory


    but for now try this
    Code:
    #CONFIG
      CONFIG  OSC = INTIO67
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRT = OFF
      CONFIG  BOREN = OFF
      CONFIG  BORV = 3
      CONFIG  WDT = ON
      CONFIG  WDTPS = 512
      CONFIG  CCP2MX = PORTC
      CONFIG  PBADEN = OFF
      CONFIG  LPT1OSC = OFF
      CONFIG  MCLRE = ON
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG

    ps not sure why your asking for PIC18F4520 config info in a 18F2620 thread why not start a new one ?
    Last edited by richard; - 25th November 2014 at 23:17.

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    the correct syntax and available config word (fuse) settings are available in the pbp3 device_reference folder

    File: PIC18F4520.INFO


    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Available configuration settings for PIC18F4520:
    ;
    ;
    ;  Oscillator Selection bits
    ;    CONFIG OSC = INTIO7     ;Internal oscillator block, CLKO function on RA6, port function on RA7
    ;    CONFIG OSC = INTIO67     ;Internal oscillator block, port function on RA6 and RA7
    ;    CONFIG OSC = RCIO6     ;External RC oscillator, port function on RA6
    ;    CONFIG OSC = HSPLL     ;HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)
    ;    CONFIG OSC = ECIO6     ;EC oscillator, port function on RA6
    ;    CONFIG OSC = EC     ;EC oscillator, CLKO function on RA6
    ;    CONFIG OSC = RC     ;External RC oscillator, CLKO function on RA6
    ;    CONFIG OSC = HS     ;HS oscillator
    ;    CONFIG OSC = XT     ;XT oscillator
    ;    CONFIG OSC = LP     ;LP oscillator

  21. #21
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Assembler uses columns, leave the same spacing as in the INC file.

    Robert

  22. #22
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    according to the book if I have the right code

    217 Attempt to Generate Code in Non-Code Segment

    Due to the Harvard Architecture (split code and data spaces) of the PICmicro
    MCUs, instructions may only be executed from CODE space (ROM). This error
    indicates that an attempt was made to generate opcodes in the data or
    EEPROM segments. In general, only the DS pseudo-op is legal in the data
    segment and DS, DB and DW are the only legal pseudo-ops in the EEPROM
    segment.
    if that doesn't help you might need to post your latest code

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


    Did you find this post helpful? Yes | No

    Default Re: 18F2620 pbp3 example config please

    Quote Originally Posted by richard View Post
    according to the book if I have the right code



    if that doesn't help you might need to post your latest code
    . . . and please use code tags as follows . . .

    [code] post code here[/code]




    Right click picture and click view to see full size . . .
    Name:  18f config.png
Views: 1630
Size:  138.3 KB
    Last edited by Archangel; - 17th December 2014 at 02:09.
    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.

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