trying to use interrupt on port pin to toggle a led & when i run the code the led stays on , i increase the counter to 50 & the led stays off i can't seem to figure out whats wrong in the code or what i'm doing wrong
Mod edit: code tags
C:
// pic 18f2500
// pckit2 programmer
// MikrocPro compiler
int counter ;
void interrupt (){
INTCON.GIE = 0; // disable global interrupt
if (INTCON.TMR0IF == 1) // if TMR0IF overflow
{
count ++; // increment overflow counter
if (count ==20) { // after counting 20 TMR0IF overflow
PORTA.B0 = ~ PORTA.B0; // toggle PORTA.B0 pin
counter = 0; // reset counter to 0
{
INTCON.TMR0IF = 0; // reset TMR0IF
INTCON.GIE = 1; // enable global interrupt
TMR0L = 255 - 250; // reset TMR0 counter
}
}
}
}
void main (){
TRISA .B0 = 0; // PORTA.B0 configure as output
PORTA.B0 = 0;; // turn off PORTA.B0
T0CON = 0b11100010; // external oscillator 8Mhz 1:8 prescaler
INTCON.TMR0IE = 1; // enable TMR0 interrupt
INTCON.TMR0IP = 1; // enable TRM0 interrupt priority
INTCON.GIE = 1; // enable global interrupt
INTCON.GIEH = 1; // not sure if i need to enable this since GIE is enable
while (1){
}
}
Last edited by a moderator: