Pic16f88 config problem

Discussion in 'Programmer's Corner' started by Dodgydave, Jun 27, 2012.

  1. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,965
    743
    I am trying to set the config register up by putting the following line in>>

    __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO


    but when i build it i get error message "illegal character ," presumably the comma in the line after config1.

    so i take the comma out and get another message "missing operator"

    yet if i put this line in >> __CONFIG b'10111110010100'
    it builds ok but with a nag warning.

    so what am i doing wrong????:confused::confused:
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Try replacing the comma with an ampersand.
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,338
    1,019
    Tried your line with a sample build and it works. The comma is OK but all of the ANDed values must be on one source line. I copy/pasted your code into MPLAB and it was on one line so maybe that's not what's going on but breaking the values into two lines got me to your reported problem. Also, if the __CONFIG is in column 1 you'll get scolded. I used MPLAB 8.63 (MPASM 5.39) to test it.

    Consider using the CONFIG directive instead of __CONFIG. You can specify each item on a separate line of code. Settings and values are in the processor header file (P18F88.inc). I find it better than __CONFIG which is an old construct.

    config setting=value [, setting=value]

    Grasping at straws dept:
    If you continue to have problems check the P18F88.inc file to be sure everything in the source is actually defined, on rare occasions, things get left out or are incorrect.

    The directive should appear before any code is generated (according to MPASM but not sure why this would be an issue).

    Also, be sure the the PIC is identified by MPLAB processor selection or by a 'list' directive.

    Make sure that no non-printing characters have crept into the source (been there).

    As a last resort, comment those lines out and re-type them from scratch (done that).

    Good luck!
     
    Last edited: Jun 27, 2012
  4. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,965
    743
    Tried the '&' symbol now i get this
    Error[126] C:\TEMP\16F88.ASM 6 : Argument out of range (not a valid config register address)


    this is my programme, all iwant to do is get started and make an led on porta flash a t 1hz

    so if you can spot my mistakes and correct me i would be grateful>>>

    LIST p=16F88 ;tell assembler what chip we are using
    #include "P16F88.inc" ;include the defaults for the chip
    ;set up config register
    __CONFIG _CONFIG1 & _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO

    org 0x0000 ;org sets the origin, 0x0000 for the 16F88,
    ;this is where the program starts running
    cblock 0x20
    d1
    d2
    d3
    endc

    bsf STATUS, RP0 ;select bank 1
    movlw b'11000110' ;set up prescaler to 128 on Tmr0
    movwf OPTION_REG

    movlw b'00000000' ;set PortA all outputs
    movwf TRISA
    movlw b'11111111'
    movwf TRISB ;set PortB all inputs
    bcf STATUS, RP0 ;select bank 0

    Loop
    bsf PORTA,0
    ;set bit 0 on
    call Delay
    ;
    bcf PORTA,0
    call Delay ;set bit0 off
    goto Loop ;go back and do it again
    Delay

    ;delay of 500msec at 8mhz clock
    ;999997 cycles
    movlw 0x08
    movwf d1
    movlw 0x2F
    movwf d2
    movlw 0x03
    movwf d3
    Delay_0
    decfsz d1, f
    goto $+2
    decfsz d2, f
    goto $+2
    decfsz d3, f
    goto Delay_0
    ;3 cycles
    goto $+1
    nop

    return
    end
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You should do like this
    Code ( (Unknown Language)):
    1.  
    2.      __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
    3.      __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    This is the config options
    Code ( (Unknown Language)):
    1.  
    2. ;----- CONFIG1 Options --------------------------------------------------
    3. _FOSC_LP EQU H'3FEC' ; LP oscillator
    4. _LP_OSC EQU H'3FEC' ; LP oscillator
    5. _FOSC_XT EQU H'3FED' ; XT oscillator
    6. _XT_OSC EQU H'3FED' ; XT oscillator
    7. _FOSC_HS EQU H'3FEE' ; HS oscillator
    8. _HS_OSC EQU H'3FEE' ; HS oscillator
    9. _FOSC_EC EQU H'3FEF' ; ECIO; port I/O function on RA6/OSC2/CLKO
    10. _EXTCLK EQU H'3FEF' ; ECIO; port I/O function on RA6/OSC2/CLKO
    11. _FOSC_INTOSCIO EQU H'3FFC' ; INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin
    12. _INTRC_IO EQU H'3FFC' ; INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin
    13. _FOSC_INTOSCCLK EQU H'3FFD' ; INTRC oscillator; CLKO function on RA6/OSC2/CLKO pin and port I/O function on RA7/OSC1/CLKI pin
    14. _INTRC_CLKOUT EQU H'3FFD' ; INTRC oscillator; CLKO function on RA6/OSC2/CLKO pin and port I/O function on RA7/OSC1/CLKI pin
    15. _FOSC_EXTRCIO EQU H'3FFE' ; EXTRC oscillator; port I/O function on RA6/OSC2/CLKO
    16. _EXTRC_IO EQU H'3FFE' ; EXTRC oscillator; port I/O function on RA6/OSC2/CLKO
    17. _FOSC_EXTRCCLK EQU H'3FFF' ; EXTRC oscillator; CLKO function on RA6/OSC2/CLKO
    18. _EXTRC_CLKOUT EQU H'3FFF' ; EXTRC oscillator; CLKO function on RA6/OSC2/CLKO
    19. _WDTE_OFF EQU H'3FFB' ; WDT disabled
    20. _WDT_OFF EQU H'3FFB' ; WDT disabled
    21. _WDTE_ON EQU H'3FFF' ; WDT enabled
    22. _WDT_ON EQU H'3FFF' ; WDT enabled
    23. _PWRTE_ON EQU H'3FF7' ; PWRT enabled
    24. _PWRTE_OFF EQU H'3FFF' ; PWRT disabled
    25. _MCLRE_OFF EQU H'3FDF' ; RA5/MCLR/VPP pin function is digital I/O, MCLR internally tied to VDD
    26. _MCLR_OFF EQU H'3FDF' ; RA5/MCLR/VPP pin function is digital I/O, MCLR internally tied to VDD
    27. _MCLRE_ON EQU H'3FFF' ; RA5/MCLR/VPP pin function is MCLR
    28. _MCLR_ON EQU H'3FFF' ; RA5/MCLR/VPP pin function is MCLR
    29. _BOREN_OFF EQU H'3FBF' ; BOR disabled
    30. _BODEN_OFF EQU H'3FBF' ; BOR disabled
    31. _BOREN_ON EQU H'3FFF' ; BOR enabled
    32. _BODEN_ON EQU H'3FFF' ; BOR enabled
    33. _LVP_OFF EQU H'3F7F' ; RB3 is digital I/O, HV on MCLR must be used for programming
    34. _LVP_ON EQU H'3FFF' ; RB3/PGM pin has PGM function, Low-Voltage Programming enabled
    35. _CPD_ON EQU H'3EFF' ; Data EE memory code-protected
    36. _CPD_OFF EQU H'3FFF' ; Code protection off
    37. _WRT_ALL EQU H'39FF' ; 0000h to 0FFFh write-protected
    38. _WRT_PROTECT_ALL EQU H'39FF' ; 0000h to 0FFFh write-protected
    39. _WRT_2048 EQU H'3BFF' ; 0000h to 07FFh write-protected, 0800h to 0FFFh may be modified by EECON control
    40. _WRT_PROTECT_2048 EQU H'3BFF' ; 0000h to 07FFh write-protected, 0800h to 0FFFh may be modified by EECON control
    41. _WRT_256 EQU H'3DFF' ; 0000h to 00FFh write-protected, 0100h to 0FFFh may be modified by EECON control
    42. _WRT_PROTECT_256 EQU H'3DFF' ; 0000h to 00FFh write-protected, 0100h to 0FFFh may be modified by EECON control
    43. _WRT_OFF EQU H'3FFF' ; Write protection off
    44. _WRT_PROTECT_OFF EQU H'3FFF' ; Write protection off
    45. _DEBUG_ON EQU H'37FF' ; In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
    46. _DEBUG_OFF EQU H'3FFF' ; In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
    47. _CCPMX_RB3 EQU H'2FFF' ; CCP1 function on RB3
    48. _CCP1_RB3 EQU H'2FFF' ; CCP1 function on RB3
    49. _CCPMX_RB0 EQU H'3FFF' ; CCP1 function on RB0
    50. _CCP1_RB0 EQU H'3FFF' ; CCP1 function on RB0
    51. _CP_ON EQU H'1FFF' ; 0000h to 0FFFh code-protected (all protected)
    52. _CP_ALL EQU H'1FFF' ; 0000h to 0FFFh code-protected (all protected)
    53. _CP_OFF EQU H'3FFF' ; Code protection off
    54. ;----- CONFIG2 Options --------------------------------------------------
    55. _FCMEN_OFF EQU H'3FFE' ; Fail-Safe Clock Monitor disabled
    56. _FCMEN_ON EQU H'3FFF' ; Fail-Safe Clock Monitor enabled
    57. _IESO_OFF EQU H'3FFD' ; Internal External Switchover mode disabled
    58. _IESO_ON EQU H'3FFF' ; Internal External Switchover mode enabled
    59.  
    I have used information in your PIC include file "C:\Program Files\Microchip\MPASM Suite\p16f88.inc" and the template file "C:\Program Files\Microchip\MPASM Suite\Template\Code\16F88TEMP.ASM"
     
    Last edited: Jun 28, 2012
  6. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,965
    743
    thanks have copied your line in and now it builds, looks like i left the config2 line off.

    Cheers your a STAR!!


    P.S. is that the only way to write to the config or can you do a "MOVWF CONFIG"
     
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Sorry, I got confused, I've only used PICs with one configuration line. Glad it works now.
    As far as I know that is the only way to set the configuration. It can't be changed without reprogramming, at least in the midrange PICs I use, so movwf wouldn't work.
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Its a good idea to always take a look into the template file and the include file. Then programming new PICs ;)
     
    Eric007 likes this.
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    QFT. It makes lots of sense (and is my standard way of starting a new project) to use the Microchip template file as a starting point. In this case the file is "16F88TEMP.ASM" and lives at ...\Program Files\Microchip\MPASM Suite\Template\Code.

    As it turns out, the configuration you were attempting to use exactly matches the template. Had you started there you would have saved yourself a few days of grief, and had a good example of some of the tricky syntax you need to use.
     
    Eric007 likes this.
Loading...