SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By Ayaz123
#194294
Hi All,

i need a serious help here.

I am very new to programming and got this source code for a micro controller PIC18F26K80. The program code was written by my fellow work mate but he already left and has no one else with such competency. When I try to generate a hex file based on the source code It gave me error and even under project tree it gave me errors.

Below is the main source code:

void main(void)
{
Delay10KTCYx(2);----- got error here----unable to resolve identifier Delay10KTCYx
/* Configure the oscillator for the device */
ConfigureOscillator();

Delay10KTCYx(100);----- got error here----unable to resolve identifier Delay10KTCYx
/* Initialize I/O and Peripherals for application */
InitApp();

/* TODO <INSERT USER APPLICATION CODE HERE> */
unsigned char HL_ALLARM_CONT,x;
HL_ALLARM_CONT = 0;

//perform one complete cycle
while(adcstatus<8) AdcManager();

while(1)
{
//Delay1KTCYx(2);
AdcManager();


if (systemstatus == 0){
//WAITING FOR MIN TENSION ON PRE-CHARGE CAP
if (CG_SENS_V > 10.5){
systemstatus++;
}
}else if (systemstatus == 1){
//IGNITION OF ALTERNATOR AND WAIT
OUT_IGN = 1; OUT_LED = 1;
Delay10KTCYx(200); ----- got error here----unable to resolve identifier Delay10KTCYx
OUT_IGN = 0; OUT_LED = 0;
for (x = 0; x < 10; x++){
Delay10KTCYx(7);
AdcManager();
}
systemstatus++;
}else if (systemstatus == 2){
//CHECK FOR POWER GENERATION
if (MS_SENS_V > 10.0){
systemstatus++;
} else {
systemstatus=0;
}
}else if (systemstatus == 3){
//EARTH LEACKAGE CONTROL
//OUT_POS = 1; OUT_NEG = 1; OUT_LED = 1;
//OUT_POS = 1; OUT_NEG = 1; OUT_LED = 1;

if (HL_SENS_R < 800.0) {
if (HL_ALLARM < 1000) HL_ALLARM++;
} else {
if (HL_ALLARM > 0) HL_ALLARM--;
}
if (HL_ALLARM_CONT >= 5){
OUT_POS = 0; OUT_NEG = 0; OUT_LED = 0;
} else if (HL_ALLARM == 0){
OUT_POS = 1; OUT_NEG = 1; OUT_LED = 1;
} else if (HL_ALLARM == 1000){
if (OUT_POS == 1 && HL_ALLARM_CONT < 100) HL_ALLARM_CONT++;
OUT_POS = 0; OUT_NEG = 0; OUT_LED = 0;
}
}

/*
for (x = 0; x < adcstatus; x++){
Delay10KTCYx(10);
if (CG_SENS_V < 5.0) OUT_LED = 1;
Delay10KTCYx(10);
OUT_LED = 0;
}
Delay10KTCYx(250);*/
}

}

void SelChanConvADC(unsigned char chn){
ADCON0bits.ADON = 0;
ADCON0bits.CHS = chn;
ADCON0bits.ADON = 1;
Delay1KTCYx(2); ----- got error here----unable to resolve identifier Delay10KTCYx
ADCON0bits.GO = 1;
}

unsigned char BusyADC(void){
return ADCON0bits.DONE;
}

unsigned int ReadADC1(void){
unsigned int r;
r = ADRESH & 0b00001111;
r = r <<8;
r = r | ADRESL;
return r;
}

void AdcManager(void){
if (adcstatus == 0){
SelChanConvADC(MS_SENS);
adcstatus++;
} else if (adcstatus == 1){
if (!BusyADC()){
MS_SENS_VAL = ReadADC1();
MS_SENS_V = (MS_SENS_VAL*4.1/4096.0)*(MS_R22 + MS_R21)/MS_R21;
adcstatus++;
}
} else if (adcstatus == 2){
SelChanConvADC(CG_SENS);
adcstatus++;
}else if (adcstatus == 3){
if (!BusyADC()){
CG_SENS_VAL = ReadADC1();
CG_SENS_V = (CG_SENS_VAL*4.1/4096.0)*(CG_R14 + CG_R15)/CG_R15;
adcstatus++;
}
} else if (adcstatus == 4){
SelChanConvADC(HL_REF);
adcstatus++;
}else if (adcstatus == 5){
if (!BusyADC()){
HL_REF_VAL = ReadADC1();
HL_REF_V = (HL_REF_VAL*4.1/4096.0);//*(HL_R35 + HL_R6)/HL_R6;
adcstatus++;
}
} else if (adcstatus == 6){
SelChanConvADC(HL_SENS);
adcstatus++;

} else if (adcstatus == 7){
if (!BusyADC()){
HL_SENS_VAL = ReadADC1();
HL_SENS_V = (HL_SENS_VAL*4.1/4096.0);//*(HL_R12 + HL_R4)/HL_R4;
HL_VI = HL_REF_V*(HL_R35 + HL_R6)/HL_R6;
HL_VO = HL_SENS_V*(HL_R2 + HL_R4)/HL_R4;
if (HL_SENS_V < HL_REF_V){
//negative earth leakage
HL_SENS_R = -HL_VO*HL_R1*HL_R42/(HL_VO*HL_R42 + HL_VO*HL_R1 -HL_VI*HL_R42);
} else if (HL_SENS_V > HL_REF_V){
//positive earth leakage
HL_SENS_R = (-HL_VO*HL_R1*HL_R42+HL_VI*HL_R42*HL_R1)/(HL_VO*HL_R42 + HL_VO*HL_R1 -HL_VI*HL_R42);
} else {
//complete insulation
HL_SENS_R = 1000000;
}
adcstatus++;
}
} else if (adcstatus == 8){
adcstatus = 0;
}

}


Is any one can please help me in this regard.

Thanks,
Ayaz Amjad
By Valen
#194392
I don't know anything about programming PICs, but looking around Google for "Delay10KTCYx" suggests this is a delay routine part of the delay-library. And that seems to be not included into your program

Add #include <delays.h> to the top of your code and see if it compiles better.