2023-10-27 11:59:35 +02:00
|
|
|
/*
|
|
|
|
* Control PB5 with the two buttons. One button disables, the other enables.
|
|
|
|
* The board uses interrupts for this.
|
|
|
|
*/
|
2023-10-27 09:50:27 +02:00
|
|
|
#define F_CPU 16000000UL
|
|
|
|
#define __AVR_ATmega328P__
|
2023-10-27 11:59:35 +02:00
|
|
|
#include <avr/interrupt.h>
|
2023-10-27 09:50:27 +02:00
|
|
|
#include <avr/io.h>
|
|
|
|
|
2023-10-27 11:59:35 +02:00
|
|
|
// code for INT0
|
|
|
|
ISR(INT0_vect) { PORTB |= (1 << PORTB5); }
|
|
|
|
|
|
|
|
// code for INT1
|
|
|
|
ISR(INT1_vect) { PORTB &= ~(1 << PORTB5); }
|
|
|
|
|
2023-10-27 09:50:27 +02:00
|
|
|
int main(void) {
|
2023-10-27 11:59:35 +02:00
|
|
|
DDRB = 0xff; // write to B
|
|
|
|
DDRD = 0; // read from D
|
2023-10-27 09:50:27 +02:00
|
|
|
|
2023-10-27 11:59:35 +02:00
|
|
|
PORTD |= (1 << PORTD2) | (1 << PORTD3); // pull up D2 and D3
|
2023-10-27 09:50:27 +02:00
|
|
|
PORTB = 0;
|
|
|
|
|
2023-10-27 11:59:35 +02:00
|
|
|
// enable external interruprs
|
|
|
|
EIMSK |= (1 << INT0);
|
|
|
|
EIMSK |= (1 << INT1);
|
|
|
|
|
|
|
|
// trigger when anything changes
|
|
|
|
EICRA |= (1 << ISC00); // for INT0
|
|
|
|
EICRA |= (1 << ISC10); // for INT1
|
|
|
|
|
|
|
|
sei(); // interrupt magic macro
|
2023-10-27 09:50:27 +02:00
|
|
|
while (1) {
|
2023-10-27 11:59:35 +02:00
|
|
|
// do nothing
|
2023-10-27 09:50:27 +02:00
|
|
|
}
|
|
|
|
}
|