Last active
March 10, 2023 22:19
-
-
Save pqlaz/1892594 to your computer and use it in GitHub Desktop.
Пример использования прерывания по изменению состояния входа
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Пример использования прерывания по изменению состояния входа | |
// 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