Interrupt Program

Discussion in 'Programmer's Corner' started by sathishbabug, Mar 10, 2009.

  1. sathishbabug

    Thread Starter New Member

    Mar 10, 2009
    9
    0
    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
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Greetings sathishbabug,

    Are you referring to the ATMEGA8515 AVR from Atmel?

    hgmjr
     
  3. hgmjr

    Moderator

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

    hgmjr
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Code ( (Unknown Language)):
    1.  
    2. #include <avr\io.h>
    3. #include <avr\interrupt.h>
    4.  
    5. #define ALARM_CONTROL PB2
    6.  
    7. unsigned char event_detected_flag;
    8.  
    9. /***********************************************
    10.  
    11.  This function is the repository for instructions
    12.  used for setting up the various IO ports...
    13.  
    14. ************************************************/
    15.  
    16. void INIT_DIO(void)
    17. {
    18.  DDRB |= (1<<ALARM_CONTROL);    /*  Set ALARM_CONTROL pin to output... */
    19. }
    20.  
    21. /**************************************
    22.  
    23.  This function contains all of the
    24.  instructions used to set up the
    25.  interrupt registers for INT0...
    26.  
    27. **************************************/
    28.  
    29. void INIT_INT0(void)
    30. {
    31.  GICR |= (1<<INT0);           /*  Enable INT0 interrupt... */  
    32.  GICR |= (1<<ISC01) | (1<<ISC00);     /* Set up to trigger on   */
    33.                                   /*   rising edge of INT0...  */
    34.  GIFR |= GIFR;   /*  Good practice to clear any */
    35.                   /*    interrupt flags that */
    36.                   /*    may have been set during */
    37.                   /*    the interrupt setup...   */  
    38. }
    39.  
    40. /**************************************
    41.  
    42.  This function contains all of the
    43.  instructions used to set up the
    44.  interrupt registers for INT1...
    45.  
    46. **************************************/
    47.  
    48. void INIT_INT1(void)
    49. {
    50.  GICR |= (1<<INT1);                          /*  Enable INT1 interrupt... */  
    51.  GICR |= (1<<ISC11) | (0<<ISC10);  /* Set up to trigger on   */
    52.                                        /*   rising edge of INT1...  */
    53.  GIFR |= GIFR;   /*  Good practice to clear any */
    54.                          /*    interrupt flags that   */
    55.                          /*    may have been set during */
    56.                          /*    the interrupt setup... */  
    57. }
    58.  
    59. /***********************************************
    60.  Interrupt Service Routine...
    61.  The digital signal used to trigger
    62.  the ALARM is connected to PORTD PD2...
    63. ************************************************/
    64.  
    65. ISR(INT0_vect)
    66. {
    67.  
    68.  event_detected_flag = 1;           /* Clear a flag used to indicate state of alarm... */
    69.  PORTB |= (1<<ALARM_CONTROL);      /* Set the alarm control bit high...  */
    70. }
    71.  
    72. /**************************************
    73.  
    74.  Interrupt Service Routine...
    75.  
    76.  The digital signal used to disable
    77.  the ALARM is connected to PORTD PD3...
    78.  
    79. **************************************/
    80.  
    81. ISR(INT1_vect)
    82. {
    83.   event_detected_flag = 0;         /* Clear a flag used to indicate state of alarm... */
    84.  PORTB &= ~(1<<ALARM_CONTROL);   /* Set the alarm control bit low...  */
    85. }
    86.  
    87. /**************************************
    88.  
    89.  Function Main handles all of the heavy
    90.  lifting...
    91.  
    92. **************************************/
    93.  
    94. int main(void)
    95. {
    96.  
    97.  INIT_DIO();
    98.  INIT_INT0();
    99.  INIT_INT1();
    100.  
    101.  sei();   /* Enable Global Interrupts...  */
    102.  
    103. for(;;) /* Set up an infinite loop...  */
    104.  {
    105.   /* This is the place for all of the  */
    106.   /*   stuff that needs to be done...    */
    107.  }
    108.  
    109.  return(0);
    110.  
    111. }
    112.  
    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
     
Loading...