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
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
}
}