I am developing a project with a PIC18F45K22, and I want to use TIMER interrupts. A sensor will enable an interrupt at pin RB0, and then this interrupt will start the TIMER, when the timer is 1 min a LED should be turned ON.
I am using a internal osc at 16MHz.
Can you help me? how could I do it?
so far I was trying to use the code bellow
Code: Select all
void interrupt(void){
if(INT0F_bit == 1){
PORTD.B0 = 1;
text2 = (" INTERRUPT ");
T0CON.TMR0ON = 1; //Now start the timer!
INT0F_bit = 0;
Delay_ms(500);
PORTD.B0 = 0;
//text2 = (" Temperature: ");
}
else if(T0CON.TMR0IE && T0CON.TMR0IF){
//TMR0 Overflow ISR
counter++; //Increment Over Flow Counter
if(counter == 61)
{
//Toggle RB1 (LED)
if(PORTD.B5 = 0)
PORTD.B5 = 1;
else
PORTD.B5 = 0;
counter = 0; //Reset Counter
}
//Clear Flag
T0CON.TMR0IF = 0;
}
}
Code: Select all
INTCON.GIE = 1; // Enable GLOBAL interrupts
INTEDG0_bit = 1; // Set interrupt on rising edge
INT0IE_bit = 1; // Enable INT0 interrupts
INTCON.PEIE = 1; //peripharel interrupt enable
INTCON.TMR0IF = 0x0; //Clear timer0 overflow interrupt flag
INTCON.TMR0IE = 1; //Enable TIMER0 Interrupt
T0CON.T08BIT = 0; //8 BIT MODE
T0CON.T0CS = 0; //Prescaler gets clock from FCPU (5MHz)
T0CON.PSA = 0b111; //Timer Clock Source is from Prescaler