int cnt=0,i=0,j=0;
void interrupt() //hardware interrupt ISR
{ //for high priority interrupt
INTCON.GIE=0;
TMR1ON_bit= 1; // start the timer1
for(i=0;i<10;i++) //this loop provides 5 cycles
{
LATC.B5= ~ LATC.B5; // toggle the output // Blink LED
for(j=0;j<5;j++) // Loop to provide 500ms delay;
{
while(TMR1IF_bit==0);
TMR1IF_bit=0;
}
}
TMR1ON_bit=0;
INTCON.GIE=1;
}
void main() {
ADCON0=0;
ADCON1=0x0F; // no analog inputs
PORTC.B7=0; //PortC.B7= input
TRISC.B7=1;
PORTC.B6=0; //PortC.B6= output
TRISC.B6=0;
PORTC.B5=0; //PortC.B5= output for continuous wave
TRISC.B5=0;
PORTB=0; //PortB= input for interrupt
TRISB=255;
INTCON.PEIE=1; //Enable global interrupt
INTCON.GIE=1;
// Settings For INT1
INT1IE_bit=1; // enable interrupt1
INT1IP_bit=1; //Enable priority high
INT1IF_bit=0; // clear flag bit
INTEDG1_bit=1; // interrupt on rising edge
// settings for Timer1
INTCON =0xC0; // since PEIE and GIE are already enabled.
TMR1H= 0x0B; // set timer values for 100ms
TMR1L= 0xDC;
TMR1IF_bit=0; // clear flag bit
TMR1IE_bit=0; // disable timer1 interrupt
TMR1IP_bit=0; //priority as low
T1CON= 0x30; // 16bit mode with pre-scalar of 1:8
// timer 1 not started
do
{
LATC.B6 = PORTC.B7;
} while(1) ;
}
void interrupt() //hardware interrupt ISR
{ //for high priority interrupt
if(INT1IF_bit==1) // not an obligation, but recommanded
{
TMR1ON_bit= 1; // start the timer1
for(i=0;i<10;i++) //this loop provides 5 cycles
{
LATC.B5= ~ LATC.B5; // toggle the output // Blink LED
for(j=0;j<5;j++) // Loop to provide 500ms delay;
{
while(TMR1IF_bit==0);
TMR1IF_bit=0;
}
}
TMR1ON_bit=0;
INT1IF_bit=0; // Raz the interrupt flag = obligation !
}
}
Note that you do not need to disable GIE yourself, it is automatically turned off when the interrupt is triggered and turned back on again at the end of the ISR.
Yaah I am doing the same.You must go into the interrupt when pressing the switch , isn't it ?
Note that you do not need to disable GIE yourself, it is automatically turned off when the interrupt is triggered and turned back on again at the end of the ISR.
suppose we are in an ISR and if a higher priority interrupt arrives, if GIE is automatically turned off then how would processor detect the higher interrupt.
As when higher priority arrives then processor must respond to it.
After this program, I want to test that how will the controller switches between higher and lower priority interrupts. Your answer will help me for the next program also
int cnt=0,cnt1=0,i=0,j=0;
void interrupt (void) //hardware interrupt ISR
{
if(INT1IF_bit==1)
{ //for high priority interrupt
TMR1ON_bit= 1; // start the timer1
INT1IF_bit=0;
for(i=0;i<10;i++) //this loop provides 5 cycles
{
LATC.B5= ~LATC.B5; // toggle the output
for(j=0;j<5;j++) // Loop to provide 500ms delay;
{
while(TMR1IF_bit==0);
TMR1IF_bit=0;
}
}
TMR1ON_bit= 0;
TMR1H= 0x0B; // set timer values for 100ms
TMR1L= 0xDC;
}
}
void interrupt_low () //timer interrupt ISR // for low priority interrupt
{
if(TMR0IF_bit==1)
{
cnt++;
if(cnt>=5)
{
cnt=0;
LATC.B4= ~LATC.B4; // toggle PORTC.B5
}
TMR0IF_bit=0;
TMR0H= 0x0B;
TMR0L=0xDC;
}
}
void main() {
ADCON0=0;
ADCON1=0x0F; // no analog inputs
PORTC.B7=0; //PortC.B7= input
TRISC.B7=1;
PORTC.B6=0; //PortC.B6= output
TRISC.B6=0;
PORTC.B5=0; //PortC.B5= output for continuous wave
TRISC.B5=0;
PORTC.B4=0; //PortC.B5= output for continuous wave
TRISC.B4=0;
PORTB=0; //PortB= input for interrupt
TRISB=255;
RCON =0x80;
INTCON.GIEH=1;
INTCON.GIEL=1;
// Settings For INT1
INT1IE_bit=1; // enable interrupt1
INT1IP_bit=1; //Enable priority high
INT1IF_bit=0; // clear flag bit
INTEDG1_bit=1; // interrupt on rising edge
// settings for Timer1
INTCON =0xC0; // since PEIE and GIE are already enabled.
TMR1H= 0x0B; // set timer values for 100ms
TMR1L= 0xDC;
TMR1IF_bit=0; // clear flag bit
TMR1IE_bit=0; // disable timer1 interrupt
TMR1IP_bit=0; //priority as low
T1CON= 0x30; // 16bit mode with pre-scalar of 1:8
// timer 1 not started*/*/
// settings for Timer3
INTCON =0xC0; // since PEIE and GIE are already enabled.
TMR0H= 0x0B; // set timer values for 100ms
TMR0L= 0xDC;
TMR0IF_bit=0; // clear flag bit
TMR0IE_bit=1; // enable timer3 interrupt
TMR0IP_bit=0; //priority as low
T0CON= 0x82; // 16bit mode with pre-scalar of 1:8
// timer 0 started
do
{
LATC.B6 = PORTC.B7;
} while(1) ;
}
do
{
LATC.B6 = PORTC.B7;
} while(1) ;
do
{
LATC.B6 = PORTC.B7;
}while(1);
if(cnt>=5)
{
cnt=0;
LATC.B4= ~LATC.B4; // toggle PORTC.B5
}
if(cnt>=5)
{
cnt=0;
OutputPin = ~OutputPin; // toggle output pin
}
.....
INTCON.GIEH=1;
INTCON.GIEL=1;
do
{
LATC.B6 = PORTC.B7;
}
while(1) *;
}
void interrupt (void) //hardware interrupt ISR
{
if(INT1IF_bit==1)
{ //for high priority interrupt
for(i=0;i<10;i++) //this loop provides 5 cycles
{
LATC.B5= ~LATC.B5; // toggle the output
for(j=0;j<5;j++) // Loop to provide 500ms delay;
{
TMR1ON_bit= 0;
TMR1H= 0x0B; // set timer values for 100ms
TMR1L= 0xDC;
TMR1ON_bit= 1; // start the timer1
while(TMR1IF_bit==0);
TMR1IF_bit=0;
}
}
INT1IF_bit=0;
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?