Interrupt Program

Thread Starter

sathishbabug

Joined Mar 10, 2009
9
Help me

I want to generate an interrupt for micro controller(mc) 8515 from a transistor switch so that the mc activates the alarm..

I need a program for this ............in C language
 

hgmjr

Joined Jan 28, 2005
9,027
You have defined the means of triggering the alarm. What are the conditions that you plan on using to turn the alarm off?

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
Rich (BB code):
#include <avr\io.h>
#include <avr\interrupt.h>
 
#define ALARM_CONTROL PB2
 
unsigned char event_detected_flag;
 
/***********************************************
 
 This function is the repository for instructions 
 used for setting up the various IO ports...
 
************************************************/
 
void INIT_DIO(void)
{
 DDRB |= (1<<ALARM_CONTROL);    /*  Set ALARM_CONTROL pin to output... */
}
 
/**************************************
 
 This function contains all of the 
 instructions used to set up the 
 interrupt registers for INT0...
 
**************************************/
 
void INIT_INT0(void)
{
 GICR |= (1<<INT0);           /*  Enable INT0 interrupt... */   
 GICR |= (1<<ISC01) | (1<<ISC00);     /* Set up to trigger on   */
                                  /*   rising edge of INT0...  */
 GIFR |= GIFR;   /*  Good practice to clear any */
                  /*    interrupt flags that */
                  /*    may have been set during */
                  /*    the interrupt setup...   */  
}
 
/**************************************
 
 This function contains all of the 
 instructions used to set up the 
 interrupt registers for INT1... 
 
**************************************/
 
void INIT_INT1(void)
{
 GICR |= (1<<INT1);                          /*  Enable INT1 interrupt... */   
 GICR |= (1<<ISC11) | (0<<ISC10);  /* Set up to trigger on   */
                                       /*   rising edge of INT1...  */
 GIFR |= GIFR;   /*  Good practice to clear any */
                         /*    interrupt flags that   */
                         /*    may have been set during */
                         /*    the interrupt setup... */  
}
 
/***********************************************
 Interrupt Service Routine...
 The digital signal used to trigger
 the ALARM is connected to PORTD PD2...
************************************************/
 
ISR(INT0_vect)
{
 
 event_detected_flag = 1;           /* Clear a flag used to indicate state of alarm... */
 PORTB |= (1<<ALARM_CONTROL);      /* Set the alarm control bit high...  */
}
 
/**************************************
 
 Interrupt Service Routine...
 
 The digital signal used to disable
 the ALARM is connected to PORTD PD3...
 
**************************************/
 
ISR(INT1_vect)
{
  event_detected_flag = 0;         /* Clear a flag used to indicate state of alarm... */
 PORTB &= ~(1<<ALARM_CONTROL);   /* Set the alarm control bit low...  */
}
 
/**************************************
 
 Function Main handles all of the heavy
 lifting...
 
**************************************/
 
int main(void)
{
 
 INIT_DIO();
 INIT_INT0();
 INIT_INT1();
 
 sei();   /* Enable Global Interrupts...  */
 
for(;;) /* Set up an infinite loop...  */ 
 {
  /* This is the place for all of the  */ 
  /*   stuff that needs to be done...    */
 }
 
 return(0);
 
}
Here is a sample of code that uses an external signal to interrupt the
ATMEGA8515 on INT0 to turn assert a pin that if connected to an alarm
driver can be used to turn on an alarm.

hgmjr
 
Top