Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to program a PIC

Status
Not open for further replies.

cardine

New Member
I have a big and frustrating problem, I have a PIC18F1320, a JDM programmer, MPLAB, and this code from Junebug

But I don't konow how to compile it into a hex file that I can write with icprog
Code:
#include <p18f1320.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO2
#define ServoPin LATBbits.LATB3
#define ServoTris TRISBbits.TRISB3

void main(void){
int ServoPos;
    OSCCON=0x70;                //Osc=8MHz
    ADCON0=0b00000101;          //A2D on and select AN1
    ADCON1=0x7d;                //A1 = analogue
    ADCON2=0b10110101;          //Right justify - Fosc/16
    ServoTris=0;                //make servo pin output
    ServoPin=0;                 //Servo output off
    CCP1CON=0b00001011;         //Special event trigger
    T1CON=0b10010001;           //Timer 1 on with Pre=2
    ServoPos=1500;              //set servo to mid position
    CCPR1=ServoPos;             //set CCP initial value   
    while(1){
        while(!PIR1bits.CCP1IF);    //wait for CCP interrupt bit
        ServoPin=0;                 //end pulse
        CCPR1=20000-ServoPos;       //Off time = 20mS - Servo Time
        PIR1bits.CCP1IF=0;          //clear int flag
        ADCON0bits.GO=1;            //start conversion
        while(ADCON0bits.GO);       //Wait for it to complete
        ServoPos=ADRES+1000;        //Pos will be 1mS to 2.023mS
        while(!PIR1bits.CCP1IF);    //wait for int flag
        ServoPin=1;                 //start pulse
        CCPR1=ServoPos;             //Servo time in uS
        PIR1bits.CCP1IF=0;          //clear int flag
    }
}
 
Looks like my Junebug servo code.

Start a project in MPLAB with the project wizard.
Select 18F1320 and C18.
Add a file called somert.c to the project and copy the above code into it.
Press F10.

Edit, you add the file after the project wizard has completed. Look under menu Project->Add new file.

HTH,

Mike.
 
Last edited:
I didn't find anywhere somert.c so i created a file with that name. When I pres F10 this error shows

Debug build of project `C:\Documents and Settings\bla\My Documents\sw.mcp' started.
Language tool versions: mpasmwin.exe v5.31, mplink.exe v4.31, mcc18.exe v3.31
Preprocessor symbol `__DEBUG' is defined.
Mon Jul 27 17:31:36 2009
----------------------------------------------------------------------
Make: The target "C:\Documents and Settings\bla\My Documents\somert.o" is out of date.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F1320 "C:\Program Files\Microchip\MPASM Suite\Template\Code\somert.c" -fo="somert.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\Program Files\Microchip\MPASM Suite\Template\Code\somert.c:1:Error [1027] unable to locate 'p18f1320.h'
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\bla\My Documents\sw.mcp' failed.
Language tool versions: mpasmwin.exe v5.31, mplink.exe v4.31, mcc18.exe v3.31
Preprocessor symbol `__DEBUG' is defined.
Mon Jul 27 17:31:37 2009
----------------------------------------------------------------------
BUILD FAILED
 
Last edited:
Try downloading and installing the latest version of C18. Your paths are not setup correctly and installing the latest version should fix that.

Mike.
 
I have installed MPLAB IDE 8.33 and C18 and now I get the same error

----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\bla\My Documents\4.mcp' started.
Language tool versions: mpasmwin.exe v5.31, mplink.exe v4.31, mcc18.exe v3.31
Preprocessor symbol `__DEBUG' is defined.
Mon Jul 27 18:40:26 2009
----------------------------------------------------------------------
Make: The target "C:\Documents and Settings\bla\My Documents\somert.o" is out of date.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F1320 "C:\Program Files\Microchip\MPASM Suite\somert.c" -fo="somert.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\Program Files\Microchip\MPASM Suite\somert.c:1:Error [1027] unable to locate 'p18f1320.h'
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\bla\My Documents\4.mcp' failed.
Language tool versions: mpasmwin.exe v5.31, mplink.exe v4.31, mcc18.exe v3.31
Preprocessor symbol `__DEBUG' is defined.
Mon Jul 27 18:40:28 2009
----------------------------------------------------------------------
BUILD FAILED
 
Last edited:
I installed all the programs three time and it is the same
What does it mean that

somert.o is out of date.
could not find file c018i.o


----------------------------------------------------------------------
Debug build of project `C:\777.mcp' started.
Language tool versions: mpasmwin.exe v5.31, mplink.exe v4.31, mcc18.exe v3.31
Preprocessor symbol `__DEBUG' is defined.
Mon Jul 27 21:05:14 2009
----------------------------------------------------------------------
Make: The target "C:\somert.o" is out of date.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F1320 "somert.c" -fo="somert.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Make: The target "C:\777.cof" is out of date.
Executing: "C:\MCC18\bin\mplink.exe" /p18F1320 "somert.o" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"777.cof" /M"777.map" /W
MPLINK 4.31, Linker
Copyright (c) 2009 Microchip Technology Inc.
Error - could not find file 'c018i.o'.
Errors : 1

Link step failed.
----------------------------------------------------------------------
Debug build of project `C:\777.mcp' failed.
Language tool versions: mpasmwin.exe v5.31, mplink.exe v4.31, mcc18.exe v3.31
Preprocessor symbol `__DEBUG' is defined.
Mon Jul 27 21:05:16 2009
----------------------------------------------------------------------
BUILD FAILED
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top