PIC header files

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Hi all,

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

Rich (BB code):
LIST P=18F8722
#include <P18F8722.inc>

;--------------
;Configuration

CONFIG  OSC     = HS
CONFIG  MCLRE   = ON
CONFIG  DEBUG   = OFF
CONFIG  LVP     = OFF
CONFIG  WDT     = OFF

;---------------
;Main program

        ORG     0x0000
        GOTO    MAIN

MAIN    MOVLW   0x00
        MOVWF   TRISD

LOOP    MOVLW   0x55
        MOVWF   PORTD
        NOP
        GOTO    LOOP

        END
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
 

tshuck

Joined Oct 18, 2012
3,534
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...
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
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
 

Attachments

MaxHeadRoom

Joined Jul 18, 2013
28,617
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.
 

tshuck

Joined Oct 18, 2012
3,534
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...
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
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
 

Attachments

MaxHeadRoom

Joined Jul 18, 2013
28,617
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.
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
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.
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
The config should look like this.

Although the latest Include files show this:

Rich (BB code):
 IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
;              superseded by the CONFIG directive.  The following settings
;              are available for this device.
;
;   Oscillator Selection bits:
;     FOSC = LP            LP oscillator
;     FOSC = XT            XT oscillator
;     FOSC = HSHP          HS oscillator (high power > 16 MHz)
;     FOSC = HSMP          HS oscillator (medium power 4-16 MHz)
;     FOSC = ECHP          EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
;     FOSC = ECHPIO6       EC oscillator (high power, >16 MHz)
;     FOSC = RC            External RC oscillator, CLKOUT function on OSC2
;     FOSC = RCIO6         External RC oscillator
;     FOSC = INTIO67       Internal oscillator block
;     FOSC = INTIO7        Internal oscillator block, CLKOUT function on OSC2
;     FOSC = ECMP          EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
;     FOSC = ECMPIO6       EC oscillator (medium power, 500 kHz-16 MHz)
;     FOSC = ECLP          EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
;     FOSC = ECLPIO6       EC oscillator (low power, <500 kHz)
;
;   IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
;              superseded by the CONFIG directive.  The following settings
;              are available for this device.
;
;  
;
;   4X PLL Enable:
;     PLLCFG = OFF         Oscillator used directly
;     PLLCFG = ON          Oscillator multiplied by 4
;
;   Primary clock enable bit:
;     PRICLKEN = OFF       Primary clock can be disabled by software
;     PRICLKEN = ON        Primary clock enabled
;
;   Fail-Safe Clock Monitor Enable bit:
;     FCMEN = OFF          Fail-Safe Clock Monitor disabled
;     FCMEN = ON           Fail-Safe Clock Monitor enabled
;
;   Internal/External Oscillator Switchover bit:
;     IESO = OFF           Oscillator Switchover mode disabled
;     IESO = ON            Oscillator Switchover mode enabled
;
;   Power-up Timer Enable bit:
;     PWRTEN = ON          Power up timer enabled
;     PWRTEN = OFF         Power up timer disabled
;
;   Brown-out Reset Enable bits:
;     BOREN = OFF          Brown-out Reset disabled in hardware and software
;     BOREN = ON           Brown-out Reset enabled and controlled by software (SBOREN is enabled)
;     BOREN = NOSLP        Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
;     BOREN = SBORDIS      Brown-out Reset enabled in hardware only (SBOREN is disabled)
;
;   Brown Out Reset Voltage bits:
;     BORV = 285           VBOR set to 2.85 V nominal
;     BORV = 250           VBOR set to 2.50 V nominal
;     BORV = 220           VBOR set to 2.20 V nominal
;     BORV = 190           VBOR set to 1.90 V nominal
;
;   Watchdog Timer Enable bits:
;     WDTEN = OFF          Watch dog timer is always disabled. SWDTEN has no effect.
;     WDTEN = NOSLP        WDT is disabled in sleep, otherwise enabled. SWDTEN bit has no effect
;     WDTEN = SWON         WDT is controlled by SWDTEN bit of the WDTCON register
;     WDTEN = ON           WDT is always enabled. SWDTEN bit has no effect
;
;   Watchdog Timer Postscale Select bits:
;     WDTPS = 1            1:1
;     WDTPS = 2            1:2
;     WDTPS = 4            1:4
;     WDTPS = 8            1:8
;     WDTPS = 16           1:16
;     WDTPS = 32           1:32
;     WDTPS = 64           1:64
;     WDTPS = 128          1:128
;     WDTPS = 256          1:256
;     WDTPS = 512          1:512
;     WDTPS = 1024         1:1024
;     WDTPS = 2048         1:2048
;     WDTPS = 4096         1:4096
;     WDTPS = 8192         1:8192
;     WDTPS = 16384        1:16384
;     WDTPS = 32768        1:32768
;
;   CCP2 MUX bit:
;     CCP2MX = PORTB3      CCP2 input/output is multiplexed with RB3
;     CCP2MX = PORTC1      CCP2 input/output is multiplexed with RC1
;
;   PORTB A/D Enable bit:
;     PBADEN = OFF         PORTB<5:0> pins are configured as digital I/O on Reset
;     PBADEN = ON          PORTB<5:0> pins are configured as analog input channels on Reset
;
;   P3A/CCP3 Mux bit:
;     CCP3MX = PORTC6      P3A/CCP3 input/output is mulitplexed with RC6
;     CCP3MX = PORTB5      P3A/CCP3 input/output is multiplexed with RB5
;
;   HFINTOSC Fast Start-up:
;     HFOFST = OFF         HFINTOSC output and ready status are delayed by the oscillator stable status
;     HFOFST = ON          HFINTOSC output and ready status are not delayed by the oscillator stable status
;
;   Timer3 Clock input mux bit:
;     T3CMX = PORTB5       T3CKI is on RB5
;     T3CMX = PORTC0       T3CKI is on RC0
;
;   ECCP2 B output mux bit:
;     P2BMX = PORTC0       P2B is on RC0
;     P2BMX = PORTB5       P2B is on RB5
;
;   MCLR Pin Enable bit:
;     MCLRE = INTMCLR      RE3 input pin enabled; MCLR disabled
;     MCLRE = EXTMCLR      MCLR pin enabled, RE3 input pin disabled
;
;   Stack Full/Underflow Reset Enable bit:
;     STVREN = OFF         Stack full/underflow will not cause Reset
;     STVREN = ON          Stack full/underflow will cause Reset
;
;   Single-Supply ICSP Enable bit:
;     LVP = OFF            Single-Supply ICSP disabled
;     LVP = ON             Single-Supply ICSP enabled if MCLRE is also 1
;
;   Extended Instruction Set Enable bit:
;     XINST = OFF          Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
;     XINST = ON           Instruction set exte
;
Max.
 

tshuck

Joined Oct 18, 2012
3,534
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?
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
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.
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
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?
Here is the one I am using at present with the comment point to the relevant register in the manual for the device.
Rich (BB code):
     ;Setup CONFIG11H
     CONFIG FOSC = HSHP, PLLCFG = OFF, PRICLKEN = OFF, FCMEN = OFF, IESO = OFF
     ;Setup CONFIG2L
     CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
     ;Setup CONFIG2H
     CONFIG WDTEN = OFF, WDTPS = 1
     ;Setup CONFIG3H
     CONFIG MCLRE = EXTMCLR, CCP2MX = PORTB3, CCP3MX = PORTC6, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTC0
     ;Setup CONFIG4L
     CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
     ;Setup CONFIG5L
     CONFIG CP0 = OFF, CP1 = OFF
     ;Setup CONFIG5H
     CONFIG CPB = OFF, CPD = OFF
     ;Setup CONFIG6L
     CONFIG WRT0 = OFF, WRT1 = OFF
     ;Setup CONFIG6H
     CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
     ;Setup CONFIG7L
     CONFIG EBTR0 = OFF, EBTR1 = OFF
     ;Setup CONFIG7H
     CONFIG EBTRB = OFF
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
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.
 

tshuck

Joined Oct 18, 2012
3,534
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...
 

MaxHeadRoom

Joined Jul 18, 2013
28,617
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.
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.
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...
Mine is for an 18F23k22.


Max.
 
Top