Page 1 of 1

can any one give me c code for ext int0 for attiny2313

Posted: 09 Sep 2012 09:52
by sallo124
i m working with attiny2313.can any one give me c code to genrate ext int0... :shock:

Re: can any one give me c code for ext int0 for attiny2313

Posted: 14 Sep 2012 12:58
by filip
Hi,

Try this ::

Code: Select all

int cnt = 0;                               // Global variable cnt

void interrupt_ISR () org IVT_ADDR_INT1 {  // Interrupt rutine
  SREG_I_bit = 0;                          // Disable Interrupts
  cnt++;                                   // Increment variable cnt
  SREG_I_bit = 1;                          // Enable Interrupts
}

void main() {                    // Main program
  DDRD = 0xF7;                   // Set PORTD.3 as input
  DDRB = 0xFF;                   // Set PORTB as output

  // Clear PORTB and PORTD
  PORTD = 0;
  PORTB = 0;

  PCMSK = 0x08;                  // Set PORTD.3 as the interrupt pin in this example
  MCUCR = 0x08;                  // Set interrupt for falling edge on PORTD.3
  GIMSK = 0x80;                  // External interrupt for INT1 (PORTD.3) is enabled
  SREG_I_bit = 1;                // Enable Interrupts

  while(1){                      // Unending loop
    PORTB = cnt;                 // Write on PORTB value of varibale cnt
  }
}
This code will increment the value on PORTB on every falling edge on PORTD.3.

Regards,
Filip.

Re: can any one give me c code for ext int0 for attiny2313

Posted: 21 Sep 2012 13:39
by sallo124
thank u filip