PIC header files

Discussion in 'Embedded Systems and Microcontrollers' started by Sparky49, Apr 2, 2014.

  1. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    Hi all,

    I've written this simple program for a PIC18F8722, in MPLAB X:

    Code ( (Unknown Language)):
    1. LIST P=18F8722
    2. #include <P18F8722.inc>
    3.  
    4. ;--------------
    5. ;Configuration
    6.  
    7. CONFIG  OSC     = HS
    8. CONFIG  MCLRE   = ON
    9. CONFIG  DEBUG   = OFF
    10. CONFIG  LVP     = OFF
    11. CONFIG  WDT     = OFF
    12.  
    13. ;---------------
    14. ;Main program
    15.  
    16.         ORG     0x0000
    17.         GOTO    MAIN
    18.  
    19. MAIN    MOVLW   0x00
    20.         MOVWF   TRISD
    21.  
    22. LOOP    MOVLW   0x55
    23.         MOVWF   PORTD
    24.         NOP
    25.         GOTO    LOOP
    26.  
    27.         END
    28.  
    29.  
    However, when I debug it says it cannot find the P18F8722.inc file. I presume I'm doing something wrong here, but I'm unsure as what it could be. I tried loading a sample microchip program, but funnily enough, MPLAB flagged that section as having improper syntax (I believe this was due to a lack of < >'s either side of the file, as the file name was the same).

    Any help would be greatly appreciated. :)

    Sparky
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Do you have the correct assembler as the compiler tool to be used?

    Perhaps you could take a screenshot of the lower left portion of the IDE...
     
    Sparky49 likes this.
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
    Did you copy a version of the 8722.INC file from Program files/Microchip/MPASM suite to your working directory?
    Max.
     
    Sparky49 likes this.
  4. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    Hi guys.

    I'm not entirely sure I follow along 100%. I'm using a PICKIT 3, which I'm sure I've selected to debug with. I've attached a few screenshots below.

    Max, is this the correct location to put the file? I found this in my compiler (xc 8).

    However, when I click on the file, it comes up with the error messages as below.

    :/

    Thanks for your time guys. I really appreciate it.

    Sparky
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Ah... Looks like you are trying to compile an assembly program using a C compiler...;)
     
    Sparky49 likes this.
  6. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    :O :D

    Erm, okay. :) What compiler do I need then? :)

    EDIT: I've switched to MPASM. :)
     
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
    I don't use MPLAB X, I did not find it very user friendly for Assy programming, it appears to be geared for C, I find the MPLAB very usable.
    But the path for the INC file if you have installed the default MPLAB dir is
    C:\Program Files\Microchip\MPASM Suite\18f8722.inc.
    This should be copied to your project directory or somewhere where the project manager knows where, using the Project Wizard to form a project allows direction to the necessary files.
    Max.
     
    Sparky49 likes this.
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Well, I left assembly behind when I switched to MPLABX. :D

    However, I think it's just a project option to select the MPASM assembler, instead of the XC8 compiler...
     
    Sparky49 likes this.
  9. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    However... I now have these messages... -_-

    I'm perplexed as to what the Error is (points to END).

    I presume the red text isn't good either?

    p.s. apologies for my noob-ness - I hate computers. :p
     
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
    What you need to decide is whether you want to program in C or continue with assy.
    If Assembly I would recommend using MPLAB (not X) until you get the hang of formatting and a little more coding under your belt.
    Use project wizard at first.
    If you do follow this route, I would chose absolute rather than relative, when asked at compile time, at least at first.
    Also read through the MPLAB user guide, the first chapter is building a small pgm with showing the two options I mention.
    Max.
     
    Sparky49 likes this.
  11. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    Roger that Max.

    I'll uninstall MPLABX and get MPLAB just now. :)

    Thanks to both of you guys for your super quick replies and patience. :) If I could give you a hundred thumbs up I would.
     
  12. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    The config should look like
    Code ( (Unknown Language)):
    1. ;Specify Device Configuration Bits  
    2. __CONFIG    _XT_OSC & _PWRTE_ON & _BODEN_OFF & _CP_OFF & _WDT_ON
    Taken from this PDF.
     
    Sparky49 likes this.
  13. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367

    Although the latest Include files show this:

    Code ( (Unknown Language)):
    1.  
    2.  IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
    3. ;              superseded by the CONFIG directive.  The following settings
    4. ;              are available for this device.
    5. ;
    6. ;   Oscillator Selection bits:
    7. ;     FOSC = LP            LP oscillator
    8. ;     FOSC = XT            XT oscillator
    9. ;     FOSC = HSHP          HS oscillator (high power > 16 MHz)
    10. ;     FOSC = HSMP          HS oscillator (medium power 4-16 MHz)
    11. ;     FOSC = ECHP          EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
    12. ;     FOSC = ECHPIO6       EC oscillator (high power, >16 MHz)
    13. ;     FOSC = RC            External RC oscillator, CLKOUT function on OSC2
    14. ;     FOSC = RCIO6         External RC oscillator
    15. ;     FOSC = INTIO67       Internal oscillator block
    16. ;     FOSC = INTIO7        Internal oscillator block, CLKOUT function on OSC2
    17. ;     FOSC = ECMP          EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
    18. ;     FOSC = ECMPIO6       EC oscillator (medium power, 500 kHz-16 MHz)
    19. ;     FOSC = ECLP          EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
    20. ;     FOSC = ECLPIO6       EC oscillator (low power, <500 kHz)
    21. ;
    22. ;   IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
    23. ;              superseded by the CONFIG directive.  The following settings
    24. ;              are available for this device.
    25. ;
    26. ;  
    27. ;
    28. ;   4X PLL Enable:
    29. ;     PLLCFG = OFF         Oscillator used directly
    30. ;     PLLCFG = ON          Oscillator multiplied by 4
    31. ;
    32. ;   Primary clock enable bit:
    33. ;     PRICLKEN = OFF       Primary clock can be disabled by software
    34. ;     PRICLKEN = ON        Primary clock enabled
    35. ;
    36. ;   Fail-Safe Clock Monitor Enable bit:
    37. ;     FCMEN = OFF          Fail-Safe Clock Monitor disabled
    38. ;     FCMEN = ON           Fail-Safe Clock Monitor enabled
    39. ;
    40. ;   Internal/External Oscillator Switchover bit:
    41. ;     IESO = OFF           Oscillator Switchover mode disabled
    42. ;     IESO = ON            Oscillator Switchover mode enabled
    43. ;
    44. ;   Power-up Timer Enable bit:
    45. ;     PWRTEN = ON          Power up timer enabled
    46. ;     PWRTEN = OFF         Power up timer disabled
    47. ;
    48. ;   Brown-out Reset Enable bits:
    49. ;     BOREN = OFF          Brown-out Reset disabled in hardware and software
    50. ;     BOREN = ON           Brown-out Reset enabled and controlled by software (SBOREN is enabled)
    51. ;     BOREN = NOSLP        Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
    52. ;     BOREN = SBORDIS      Brown-out Reset enabled in hardware only (SBOREN is disabled)
    53. ;
    54. ;   Brown Out Reset Voltage bits:
    55. ;     BORV = 285           VBOR set to 2.85 V nominal
    56. ;     BORV = 250           VBOR set to 2.50 V nominal
    57. ;     BORV = 220           VBOR set to 2.20 V nominal
    58. ;     BORV = 190           VBOR set to 1.90 V nominal
    59. ;
    60. ;   Watchdog Timer Enable bits:
    61. ;     WDTEN = OFF          Watch dog timer is always disabled. SWDTEN has no effect.
    62. ;     WDTEN = NOSLP        WDT is disabled in sleep, otherwise enabled. SWDTEN bit has no effect
    63. ;     WDTEN = SWON         WDT is controlled by SWDTEN bit of the WDTCON register
    64. ;     WDTEN = ON           WDT is always enabled. SWDTEN bit has no effect
    65. ;
    66. ;   Watchdog Timer Postscale Select bits:
    67. ;     WDTPS = 1            1:1
    68. ;     WDTPS = 2            1:2
    69. ;     WDTPS = 4            1:4
    70. ;     WDTPS = 8            1:8
    71. ;     WDTPS = 16           1:16
    72. ;     WDTPS = 32           1:32
    73. ;     WDTPS = 64           1:64
    74. ;     WDTPS = 128          1:128
    75. ;     WDTPS = 256          1:256
    76. ;     WDTPS = 512          1:512
    77. ;     WDTPS = 1024         1:1024
    78. ;     WDTPS = 2048         1:2048
    79. ;     WDTPS = 4096         1:4096
    80. ;     WDTPS = 8192         1:8192
    81. ;     WDTPS = 16384        1:16384
    82. ;     WDTPS = 32768        1:32768
    83. ;
    84. ;   CCP2 MUX bit:
    85. ;     CCP2MX = PORTB3      CCP2 input/output is multiplexed with RB3
    86. ;     CCP2MX = PORTC1      CCP2 input/output is multiplexed with RC1
    87. ;
    88. ;   PORTB A/D Enable bit:
    89. ;     PBADEN = OFF         PORTB<5:0> pins are configured as digital I/O on Reset
    90. ;     PBADEN = ON          PORTB<5:0> pins are configured as analog input channels on Reset
    91. ;
    92. ;   P3A/CCP3 Mux bit:
    93. ;     CCP3MX = PORTC6      P3A/CCP3 input/output is mulitplexed with RC6
    94. ;     CCP3MX = PORTB5      P3A/CCP3 input/output is multiplexed with RB5
    95. ;
    96. ;   HFINTOSC Fast Start-up:
    97. ;     HFOFST = OFF         HFINTOSC output and ready status are delayed by the oscillator stable status
    98. ;     HFOFST = ON          HFINTOSC output and ready status are not delayed by the oscillator stable status
    99. ;
    100. ;   Timer3 Clock input mux bit:
    101. ;     T3CMX = PORTB5       T3CKI is on RB5
    102. ;     T3CMX = PORTC0       T3CKI is on RC0
    103. ;
    104. ;   ECCP2 B output mux bit:
    105. ;     P2BMX = PORTC0       P2B is on RC0
    106. ;     P2BMX = PORTB5       P2B is on RB5
    107. ;
    108. ;   MCLR Pin Enable bit:
    109. ;     MCLRE = INTMCLR      RE3 input pin enabled; MCLR disabled
    110. ;     MCLRE = EXTMCLR      MCLR pin enabled, RE3 input pin disabled
    111. ;
    112. ;   Stack Full/Underflow Reset Enable bit:
    113. ;     STVREN = OFF         Stack full/underflow will not cause Reset
    114. ;     STVREN = ON          Stack full/underflow will cause Reset
    115. ;
    116. ;   Single-Supply ICSP Enable bit:
    117. ;     LVP = OFF            Single-Supply ICSP disabled
    118. ;     LVP = ON             Single-Supply ICSP enabled if MCLRE is also 1
    119. ;
    120. ;   Extended Instruction Set Enable bit:
    121. ;     XINST = OFF          Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    122. ;     XINST = ON           Instruction set exte
    123. ;
    124.  
    Max.
     
    Sparky49 likes this.
  14. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I've never used the template files. Are you suggesting that one simply has to uncomment a line to set the functionality?

    I think it still needs to be a single line directive, no?
     
    Sparky49 likes this.
  15. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
    You can have both on the same computer, in fact there is a utility loaded with MPLAB X that has a driver swap that allows switching between them as the USB drivers are different.
    Max.
     
    Sparky49 likes this.
  16. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    Thanks, I'll give them a try.

    How I laid them out in my first attempt was how we were taught to do it at uni. Always good to get another perspective on things though.
     
  17. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
    Here is the one I am using at present with the comment point to the relevant register in the manual for the device.
    Code ( (Unknown Language)):
    1.  
    2.  
    3.      ;Setup CONFIG11H
    4.      CONFIG FOSC = HSHP, PLLCFG = OFF, PRICLKEN = OFF, FCMEN = OFF, IESO = OFF
    5.      ;Setup CONFIG2L
    6.      CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
    7.      ;Setup CONFIG2H
    8.      CONFIG WDTEN = OFF, WDTPS = 1
    9.      ;Setup CONFIG3H
    10.      CONFIG MCLRE = EXTMCLR, CCP2MX = PORTB3, CCP3MX = PORTC6, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTC0
    11.      ;Setup CONFIG4L
    12.      CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
    13.      ;Setup CONFIG5L
    14.      CONFIG CP0 = OFF, CP1 = OFF
    15.      ;Setup CONFIG5H
    16.      CONFIG CPB = OFF, CPD = OFF
    17.      ;Setup CONFIG6L
    18.      CONFIG WRT0 = OFF, WRT1 = OFF
    19.      ;Setup CONFIG6H
    20.      CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
    21.      ;Setup CONFIG7L
    22.      CONFIG EBTR0 = OFF, EBTR1 = OFF
    23.      ;Setup CONFIG7H
    24.      CONFIG EBTRB = OFF
    25.  
     
    Sparky49 and tshuck like this.
  18. Sparky49

    Thread Starter Active Member

    Jul 16, 2011
    834
    417
    Okay, so I've got MPLAB up and running, Ive entered my program and chosen the debugger. The new window pops up, detects the PICkit 3, but gets stuck on the connecting to PICkit 3. The green bar in the bottom left appears to get to 70% and then resets. What am I doing wrong now? :p

    Power and active LEDs are on, on the PICkit 3, but the status LED is off - I don't know if that is useful information.
     
  19. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Thanks Max.

    In that case, it may be throwing a fit because you are using the config directive to set bits in a configuration word that doesn't have it...

    So, MCLRE is part of CONFIG3H, bit your configuration is trying to set it to CONFIG1L...
     
    Sparky49 likes this.
  20. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
    What board do you have the Pikit 3 plugged into, do you have it powered? Or else you will have to set power from Pickit3 in the settings if it is not powered itself.
    Mine is for an 18F23k22.


    Max.
     
    Sparky49 likes this.
Loading...