Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interrupt nesting in PIC18F4520

Status
Not open for further replies.

hez_91

Newbie level 5
Joined
May 21, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Singapore
Activity points
1,340
Hi

I am experiencing some difficulties in trying to get the TIMER1 to run in my interrupt routine.
In my interrupt routine, it has a password input module that waits for the input of the password in a for loop. During that time, I am suppose to set a time-limit for the input before sending off an alarm but timer1 interrupts are not active during my external interrupt routine. Is there anyway around this or am i doing anything wrong?
Code:
#include <p18f4520.h>		
#include <delays.h>
#include <stdio.h>
#include <string.h>
#include <usart.h>
#include <stdlib.h>

void checkInputs(void);	
void sendSMS(void);
void passwordPrompt(void);
//void receive_sms(void);

int pb, dip_sw, x, check, count, count2, systemArmed, y;
void high_isr(void);		// prototype of function high_isr

	
#pragma code high_vector = 0x08

void high_vector(void) 
{
   _asm    goto  high_isr  _endasm 	//jump to interrupt routine
}

#pragma code			//return to default code section

#pragma interrupt high_isr
void high_isr(void)
{
	if(INTCONbits.INT0IF) //Arm button
	{
	systemArmed = 2;
	Delay10KTCYx(200);
	}

  	if(INTCON3bits.INT2IF){ // Sound detected
	
	if(systemArmed==2)
	{
	
	Delay10KTCYx(200);
		if(PORTBbits.RB2 = !PORTBbits.RB2) // Glass break sensor triggered
		{
			T0CONbits.TMR0ON = 0;
			INTCONbits.TMR0IF = 0;
			INTCONbits.TMR0IE = 0;
			PORTBbits.RB5 = ~PORTBbits.RB5;
			passwordPrompt();
			T0CONbits.TMR0ON = 1;
			INTCONbits.TMR0IE = 1;
		//	sendSMS();
	
		}	

			INTCON3bits.INT2IF = 0;	
	}

 	}
	


	if (INTCONbits.TMR0IF) {				// Check for Timer0 overflow

	TMR0H = 0x0B;					// Clear Timer0 high byte register 
	TMR0L = 0xDC;					// Clear Timer0 low byte register

	if(systemArmed==2)
	{ 		
	count++;

	if(count==10) //After 10 seconds, read as idle and go into sleep mode
	{	
	PORTBbits.RB3 = ~PORTBbits.RB3;
	PORTBbits.RB5 = ~PORTBbits.RB5;
	count = 0;
	T0CONbits.TMR0ON = 0;	
//	Sleep();
	}			
	}

	INTCONbits.TMR0IF = 0;				// Clear Timer0 interrupt flag
	}

	if (PIR1bits.TMR1IF)
	{
	TMR1H = 0x0B;					// Clear Timer0 high byte register 
	TMR1L = 0xDC;					// Clear Timer0 low byte register
	count2++;
	if(y==1)
	{
	if(count2==10)
	{	
	count2=0;
	sendSMS();
//	
//		T1CONbits.TMR1ON = 0;
	}
		
	}
	PIR1bits.TMR1IF = 0;	
	} 	

}



void main()
{
count = 0;
count2 = 0;
systemArmed = 0;


TRISA = 0b11111111;
TRISB = 0b11010111;		
TRISC = 0b10111111;
TRISD = 0xff;


PORTA = 0x00;
PORTB = 0x00;
PORTD = 0;

SPBRG = 25;
TXSTA = 0b00100100;
RCSTA = 0b10010000;


RCONbits.IPEN = 0;

//INTCON2bits.INT2IP	= 1;            // IP2 high priority
INTCONbits.INT0IF	= 0;            // clear IF first
INTCONbits.INT0IE	= 1;            // Enable INT2

INTCON3bits.INT2IP	= 0;            // IP2 high priority
INTCON3bits.INT2IF	= 0;            // clear IF first
INTCON3bits.INT2IE	= 1;            // Enable INT2

INTCON2bits.INTEDG2 = 0; 



INTCON2bits.TMR0IP = 1;				// Set Timer0 interrupt to low priority
INTCONbits.TMR0IF = 0;				// clear IF first
INTCONbits.TMR0IE = 1;				// Enable Timer0 overflow interrupt

TMR0H = 0x0B;						// Clear Timer0 high byte register 
TMR0L = 0xDC;						// Clear Timer0 low byte register
T0CON = 0b10000011;					// On Timer0, set to 16-bit mode,
									// Use internal instruction clock,
									// Rising-edge trigger, set prescaler to 1:8

IPR1bits.TMR1IP = 1;
PIR1bits.TMR1IF = 0;
PIE1bits.TMR1IE = 1;

TMR1H = 0x0B;
TMR1L = 0xDC;
T1CON = 0b00110001;

INTCONbits.GIEL =1;
INTCONbits.GIE = 1;


Sleep();
PORTBbits.RB3 = 1;





}


void passwordPrompt()
{

count = 0; // reset time into idle status
count2 = 0;
y = 1;

for(x=0;x<10;x++) // loop
		{
dip_sw = PORTD & 0x0f; // read dip switches
Delay10KTCYx(150);
pb = PORTD & 0xf0; // read push buttons
pb >>=4; // shift the upper nibble to the lower nibble

	if(pb == dip_sw) //compare dip with push buttons
	{
		x = 0; // reset number of tries
		PORTBbits.RB5 = 1; // Light up RED LED
		Delay10KTCYx(100); 
		PORTBbits.RB5 = 0; // Off RED LED
		systemArmed = 0;
		break;
	}
	else if (pb != 0x0f)
	{
		PORTBbits.RB3 = 1; // Light up GREEN LED
		Delay10KTCYx(100);
		PORTBbits.RB3 = 0; // Off GREEN LED
		x++;		
	}		
			
			if(x==3) // number of tries allowed 
			{
	//			alarm(); //sound alarm
				PORTBbits.RB5 = 1; // Light up red LED
				sendSMS();
				break;
		//		PORTBbits.RB4 = 1; // Start recording
			}

			x--;		
		}	
}
 

timer1 interrupts are not active during my external interrupt routine.

the datasheet covered that quite extensively and clearly.

Is there anyway around this or am i doing anything wrong?

interrupts are supposed to be short and sweet. so keep them that way, as suggested by the datasheet.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top