Skip to content

Instantly share code, notes, and snippets.

@pqlaz
Last active March 10, 2023 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pqlaz/1892594 to your computer and use it in GitHub Desktop.
Save pqlaz/1892594 to your computer and use it in GitHub Desktop.
Пример использования прерывания по изменению состояния входа
// Пример использования прерывания по изменению состояния входа
// avr-gcc, arduino nano AtMega168
#include <avr/interrupt.h>
#include <avr/io.h>
#define IN_PIN _BV(3) // button pin B3 (arduino nano - D11)
#define LED _BV(5) // arduino LED
ISR(PCINT0_vect) // pin change interrupt vector
{
if ( PINB & IN_PIN ) // pin B3 - button
PORTB |= LED;
else
PORTB &= ~LED;
}
int main()
{
DDRB = LED; // led pin - output mode
PORTB |= LED;
PCICR = _BV(PCIE0); // pin change interrupt enable
PCMSK0 = _BV(PCINT3); // pin change interrupt mask (pin B3/PCINT3)
sei(); // enable interrupts
for (;;);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment