sulfur101
Newbie level 6
so i have found this code and i like it but when i plug it into MPLAB XC8 it does not work I've tried looking everywhere and no luck and i am stuck can some one please tell me what i am doing wrong. also can yall help me adding a analog pin to change the phase angle because i am stuck i dont code on a regular basis so i just need help.
this was coded on mikro C but i am useing a PICKIT 4 and it dosent read so i have been trying to convert it to MPLABS XC8 but still nothing i am useing the PIC16F877A In C code and i have no idea what i am doing please help
(here is my error message )
this was coded on mikro C but i am useing a PICKIT 4 and it dosent read so i have been trying to convert it to MPLABS XC8 but still nothing i am useing the PIC16F877A In C code and i have no idea what i am doing please help
Code:
unsigned char FlagReg;
sbit ZC at FlagReg.B0;
void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
INTCON.INTF = 0;
}
}
void main() {
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTA = 0;
ADCON1 = 7; //Disable ADC
TRISA = 0xFF; //Make all PORTA inputs
PORTD = 0;
TRISD = 0; //PORTD all output
OPTION_REG.INTEDG = 0; //interrupt on falling edge
INTCON.INTF = 0; //clear interrupt flag
INTCON.INTE = 1; //enable external interrupt
INTCON.GIE = 1; //enable global interrupt
while (1){
if (ZC){ //zero crossing occurred
delay_ms(2); // Change to get different angle = 360*delay/16.67
PORTD.B0 = 1; //Send a pulse
delay_us(250); //pulse width
PORTD.B0 = 0;
ZC = 0;
}
}
}
(here is my error message )
newfile.c:3:2: error: unknown type name 'sbit'
sbit ZC at FlagReg.B0;
^
newfile.c:3:9: error: expected ';' after top level declarator
sbit ZC at FlagReg.B0;
^
;
newfile.c:7:6: error: use of undeclared identifier 'INTCON'
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
^
newfile.c:9:2: error: use of undeclared identifier 'INTCON'
INTCON.INTF = 0;
^
newfile.c:14:2: error: use of undeclared identifier 'PORTB'
PORTB = 0;
^
newfile.c:15:2: error: use of undeclared identifier 'TRISB'
TRISB = 0x01; //RB0 input for interrupt
^
newfile.c:16:2: error: use of undeclared identifier 'PORTD'
PORTD = 0;
^
newfile.c:17:2: error: use of undeclared identifier 'TRISD'
TRISD = 0; //PORTD all output
^
newfile.c:18:2: error: use of undeclared identifier 'OPTION_REG'
OPTION_REG.INTEDG = 0; //interrupt on falling edge
^
newfile.c:19:2: error: use of undeclared identifier 'INTCON'
INTCON.INTF = 0; //clear interrupt flag
^
newfile.c:20:2: error: use of undeclared identifier 'INTCON'
INTCON.INTE = 1; //enable external interrupt
^
newfile.c:21:2: error: use of undeclared identifier 'INTCON'
INTCON.GIE = 1; //enable global interrupt
^
newfile.c:25:2: error: use of undeclared identifier 'PORTD'
PORTD.f0 = 1; //Send a 1ms pulse
^
newfile.c:26:2: warning: implicit declaration of function 'delay_ms' is invalid in C99 [-Wimplicit-function-declaration]
delay_ms(1);
^
newfile.c:27:2: error: use of undeclared identifier 'PORTD'
PORTD.f0 = 0;
^
1 warning and 14 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/newfile.p1' failed
make[2]: Leaving directory 'C:/Users/Omar/Documents/New Folder'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Omar/Documents/New Folder'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/newfile.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
Last edited by a moderator: