i tried lately to make a program that uses timer0 to overflow from 255 to 0 and goto the isr code which will turn an led on if button on T0CKI pin was pressed for once as I was taught from microchip's timer0 datasheet tutorial but it is not working at all whatever I tried to change from code, written in MPLAB X IDE compiled with XC8, here is the code:
#include "config.h"
void interrupt ISR();
void INIT();
void main(){
INIT();
while(1){
if(PORTAbits.RA4 == 1){
TMR0--;
}
}
}
void interrupt ISR(){
if(INTCONbits.TMR0IF == 1 && INTCONbits.TMR0IE == 1){
TMR0 = 255;
INTCONbits.TMR0IF = 0;
PORTDbits.RD0 = 1;
}else{
PORTDbits.RD0 = 0;
}
}
void INIT(){
INTCON = 0b11100000;
OPTION_REG = 0b11100111;
TRISDbits.TRISD0 = 0;
PORTDbits.RD0 = 0;
TRISAbits.TRISA4 = 1;
TMR0 = 255;
}
this is main.c where I wrote all the code config.h is just where I set the configuration bits using Windows->Configuration bits in MPLAB
thanks in advance for all repliers much appreciated