pls can anyone help me translate this code to gcb, its in c, most especially the interrupt part, thanks in advance...
//Target PIC: PIC16F877A
//Program for phase angle control
//---------------------------------------------------------------------------------------------------------
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);
PORTD.B0 = 1; //Send a pulse
delay_us(250);
PORTD.B0 = 0;
ZC = 0;
}
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Aaron. The JANIS code is very good. You should look to use his code.
I am posting this so that we do not shy away from the ask - this shows how simple Great Cow BASIC when migrating. This may help and it shows how Great Cow BASIC can simplify the programming experience. I have laid the code out in the same manner so you can compare and contrast.
But, the code of JANIS is a richer approach and you should review.
pls can anyone help me translate this code to gcb, its in c, most especially the interrupt part, thanks in advance...
//Target PIC: PIC16F877A
//Program for phase angle control
//---------------------------------------------------------------------------------------------------------
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
}
Hallo!
You can view my program code example, typing in the search box: Zero cross and firing angle ... My code works well
@Aaron. The JANIS code is very good. You should look to use his code.
I am posting this so that we do not shy away from the ask - this shows how simple Great Cow BASIC when migrating. This may help and it shows how Great Cow BASIC can simplify the programming experience. I have laid the code out in the same manner so you can compare and contrast.
But, the code of JANIS is a richer approach and you should review.
Anobium
Edited: I forgot to clear intf..
Last edit: Anobium 2017-01-21
thanks guys, GCB all the way