PIC header files

t06afre

Joined May 11, 2009
5,934
A thing then using MPLAB or MPLABX. You should ALWAYS work with a project. This video will show how to create a assembler project in MPLABX https://www.youtube.com/watch?v=IQcpr9h5MN4 If you program in assembler I will also highly recommend using a template file those are found in folder ......\Microchip\MPLABX\mpasmx\templates\Code your file will be the "18F8722TEMP.ASM" Copy the content of this file into your assembler file. You can use drag and drop into MPlabx. Then copy the conntent and close it. As you will not change the template file. The template file look this
Rich (BB code):
;******************************************************************************
;   This file is a basic template for assembly code for a PIC18F8722. Copy    *
;   this file into your project directory and modify or add to it as needed.  *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on the         *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the PIC18FX627/X722 Data Sheet for additional                    *
;   information on the architecture and instruction set.                      *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:                                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P18F8722.INC                                             *
;                                                                             *
;******************************************************************************
 LIST P=18F8722  ;directive to define processor
 #include <P18F8722.INC> ;processor specific variable definitions
;******************************************************************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please
;see the .inc file for futher details on notation.  Below are a few examples.
 
;   Oscillator Selection:
    CONFIG OSC = LP             ;LP
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used.
; More variables may be needed to store other special function registers used
; in the interrupt routines.
  CBLOCK 0x080
  WREG_TEMP ;variable used for context saving
  STATUS_TEMP ;variable used for context saving
  BSR_TEMP ;variable used for context saving
  ENDC
  CBLOCK 0x000
  EXAMPLE  ;example of a variable in access RAM
  ENDC
;******************************************************************************
;EEPROM data
; Data to be programmed into the Data EEPROM is defined here
  ORG 0xf00000
  DE "Test Data",0,1,2,3,4,5
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.
  ORG 0x0000
  goto Main  ;go to start of main code
;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.
  ORG 0x0008
  bra HighInt  ;go to high priority interrupt routine
;******************************************************************************
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.
  ORG 0x0018
  movff STATUS,STATUS_TEMP ;save STATUS register
  movff WREG,WREG_TEMP  ;save working register
  movff BSR,BSR_TEMP  ;save BSR register
; *** low priority interrupt code goes here ***

  movff BSR_TEMP,BSR  ;restore BSR register
  movff WREG_TEMP,WREG  ;restore working register
  movff STATUS_TEMP,STATUS ;restore STATUS register
  retfie
;******************************************************************************
;High priority interrupt routine
; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.
HighInt:
; *** high priority interrupt code goes here ***

  retfie FAST
;******************************************************************************
;Start of main program
; The main program code is placed here.
Main:
; *** main code goes here ***

;******************************************************************************
;End of program
  END
Setting the config bits is very important. MPLABX can do it for you. Take a look here section 4 to 7 http://microchip.wikidot.com/tls0101:config-bits-lab Then you are done you delete the old ones and use copy and paste of the new ones into your code
Hope this get you started
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Hi t06.

Yer, I should have put in the template, but I didn't want to waste time making the program look fancy. It was never meant to be used more than once...

I followed that video, but still the same problems persist. I included a screenshot of my attempts and the errors it generated below.

Microchip tech support was no help at all. Simply said that they couldn't replicate it, I should use MPLABX.

:(

Sparky
 

Attachments

t06afre

Joined May 11, 2009
5,934
Could you try to put your project(build from scratch) in a folder located on the root on your disk. Use also only lower case in any file/folder name and use short names
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Annoyingly, it builds fine when I'm on a uni computer...

Could having other IDE's like Codewarrior and Code Composer Studio affect MPLAB/X?

Sparky
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Well, I'm just about giving up.

I hate computers and computers hate me.

Even after removing all the previous IDE's and reinstalling MPLAB again, it still comes up with the same error messages.

All I want to do is program a PIC.

Thank you guys for all your help.

Sparky
 

tshuck

Joined Oct 18, 2012
3,534
I found this thread in looking up the problem. It paints a pretty dismal picture...:(

Apparently Office 365 will break the assembler... At least according to the folks here...

It looks like some people have had luck running it in a virtual machine...

Edit: the last post in this thread suggests that you
For Fix Error 154,333 problem on WIN7 x64 you need ;
select MPASMWIN.exe in installed folder and make it compatible mode Windows 7 or XP Service Pack 3 ,mine worked on windows 7 compatible.
This might work on windows 8.1... Worth a shot...
 
Last edited:

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Thanks guys, unfortunately those methods didn't work. Interestingly, I got a different build error message when MPASM was on XP v3.

I'm going back home for Easter today, I think I might have an old laptop (win 98!) under my bed... So I'll give it a try on that.

Just a bit frustrating that it couldn't work on one machine, but that's life sometimes, hehehe. :)

Thanks again to everyone who offered help over the course of six pages. :)

You guys are awesome. :D

Sparky
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Hi guys.

I have MPLAB working now. :) It builds and programs fine. :)

I was wondering if you might be able to help with the C compiler? I promise this is all that is left to do. :)

I downloaded the Standard version of C18 from here:

http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=SW006011#dtDocumentation

(the bottom-most link).

However, when I run the program Wizard, and choose C18 as my compiler, the red crosses still appear next to it.

Any ideas?

Regards,

Sparky
 

t06afre

Joined May 11, 2009
5,934
Maybe the XC8 compiler is a better option. But if you plan to take some course and that course use the 18C, just stick with that compiler.
 

Thread Starter

Sparky49

Joined Jul 16, 2011
833
Hi guys.

In the end I got it working on Windows 7. Asm works just fine, I have already built several projects and programmed them successfully which is a real moral boost. :)

C is a different matter. I have both IDE's on my computer (I don't need to worry about switching drivers when I use each as PICkit 3 uses the same one), and they both recognise C8 and xc8 which is nice.

However, I have been curious about using pwm to make little tunes, so I copied the following program from this source:

Rich (BB code):
/*
Code written by Bobby By, Agatha Lee, Dan Niecestro 02-2009
This code uses a PWM signal from PIC 18F4520 to define the frequencies 
that produce the basic notes in one octave of the musical scale, 
and plays a simple song on a piezo speaker.
The volume of the speaker can be set by changing the duty cycle value (1~125)
*/

#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=40000000)

//define timer scaling value for each note
#define C 255 
#define D 227
#define E 204
#define F 191
#define G 170
#define A 153
#define B 136
#define C2 127
//

#define x 14 //total number of notes in song to be played - modify for specific song

//the song to be played in this demonstration is "Twinkle Twinkle Little Star" 
int song[x]={C, C, G, G, A, A, G, F, F, E, E, D, D, C}; //insert notes of song in array
int length[x]={1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2}; //relative length of each note
int i;

void main() {

      setup_ccp1(CCP_PWM); // PWM output on pin 17, RC2/CCP1 
      set_pwm1_duty(30);  // the number changes the volume of the piezo speaker

      for (i=0; i<x; i++) {     //play x notes inside song array
      
      setup_timer_2(T2_DIV_BY_16, song, 16); 
                               //set PWM frequency according to entries in song array
      delay_ms(400*length); //each note is played for 400ms*relative length
      setup_timer_2(T2_DIV_BY_16, 1, 16); //the PWM frequency set beyond audible range
                                          //in order to create a short silence between notes
      delay_ms(50);   //the silence is played for 50 ms                  
      }
}


I changed the header file to 18f8722.h, but it couldn't find it when it built. I then tried changing it to p18f8722.h and it seemed to have found it, but it then churned up errors saying #fuses and #use delay were invalid.

I'm nowhere near as good with C as I am with asm (which still isn't that good :p), any ideas as to what this could be? I know fuses are used to setup configuration of the PIC (much like CONFIG), but I'm unsure how to achieve this.

I will of course be changing the output pin to something which is appropriate to the 18f8722, but I'm assuming the rest of the code is C, so it shouldn't present itself as too great an obstacle?

Regards,

Sparky
 

t06afre

Joined May 11, 2009
5,934
Regarding the config bits. So are they discussed in the datasheet. You must read this section and set the config bits correct. If you see the last link in post #41 you can use MPLABX to do the hard work. I do not know how the C18 compiler works. But I know that then you have build a project and use the XC8 compiler. You do not have worry about the device specific header file. MPLAB(X) will take care of this for you. This one one of the reasons. Why YOU ALWAYS SHOULD WORK ON A PROJRCT BASIS USING MPLAB(X) (repeat after me ten times)
Also as long as you just are testing out things. You should go for using the internal oscillator. An external crystal may cause problems then using it on a breadboard.
 
Top