aidantmurphy
New Member
The following is my code for creating interrupts. My problem is that the delay is 20ms, i want the user to be able to change the delay as they wish. Does anyone know how to do this? Have been looking at it how a couple of days now and im basically confusing myself.
#include <io16f877.h>
#pragma vector = 0x1
__interrupt void externISR()
{
if(INTF) //loop controllling software design of interrupts on PIC
{
RA0 = 0; // ensuring RA0 set low
// TMR1H and TMR1L = TMR1
TMR1H = 0xF6; // Pre - load timer with this value = 63035
TMR1L = 0x3B; // We want an overflow after 2500 ticks (interval of 20ms)
// As (2^16 -1)-2500 = 63035
TMR1IF = 0; // no interrupt flag
while(!TMR1IF); // interrupt flag ocuuring
RA0 = 1; // RA0 set high when interrupt occurs
INTF = 0; //related with INTCON register in void main, set to 0 here to clear interrupt.
}
}
void main()
{
TRISA = 0x0; //Set as an output on PortA
TRISB = 0x1; //Set as an input on PortB
RA0 = 0; // RA0 always set low
INTEDG = 0x1; // Set to trigger off the rising clock edge.
INTCON = 0x90; //this is our control and status of our interrupts.
T1CON = 0x3d; // sets the prescaler value of clock 1:8, oscillator enabled,internal clock selected
TMR1IE = 1;
TMR1IF = 0; // set at zero, flags are seen when = 1
while(1);
}
#include <io16f877.h>
#pragma vector = 0x1
__interrupt void externISR()
{
if(INTF) //loop controllling software design of interrupts on PIC
{
RA0 = 0; // ensuring RA0 set low
// TMR1H and TMR1L = TMR1
TMR1H = 0xF6; // Pre - load timer with this value = 63035
TMR1L = 0x3B; // We want an overflow after 2500 ticks (interval of 20ms)
// As (2^16 -1)-2500 = 63035
TMR1IF = 0; // no interrupt flag
while(!TMR1IF); // interrupt flag ocuuring
RA0 = 1; // RA0 set high when interrupt occurs
INTF = 0; //related with INTCON register in void main, set to 0 here to clear interrupt.
}
}
void main()
{
TRISA = 0x0; //Set as an output on PortA
TRISB = 0x1; //Set as an input on PortB
RA0 = 0; // RA0 always set low
INTEDG = 0x1; // Set to trigger off the rising clock edge.
INTCON = 0x90; //this is our control and status of our interrupts.
T1CON = 0x3d; // sets the prescaler value of clock 1:8, oscillator enabled,internal clock selected
TMR1IE = 1;
TMR1IF = 0; // set at zero, flags are seen when = 1
while(1);
}