mod04 ex02 done
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
// 13.2.6 : PCMSK2 – Pin Change Mask Register 2
|
// 13.2.6 : PCMSK2 – Pin Change Mask Register 2
|
||||||
// -> (1 << PCINT20) | (1 << PCINT18)
|
// -> (1 << PCINT20) | (1 << PCINT18)
|
||||||
|
|
||||||
volatile uint8_t prevPIND; // Store previous state of PIND
|
|
||||||
volatile uint8_t value = 0;
|
volatile uint8_t value = 0;
|
||||||
|
|
||||||
void print_binary(int value) {
|
void print_binary(int value) {
|
||||||
@@ -81,20 +80,10 @@ int main() {
|
|||||||
PCICR = (1 << PCIE2); // 13.2.4 : enable pin change interrupt, bit PCIE2 for PCINT[23:16], (Table 14-9 : alternates : PD2 - PCINT18, PD4 - PCINT20)
|
PCICR = (1 << PCIE2); // 13.2.4 : enable pin change interrupt, bit PCIE2 for PCINT[23:16], (Table 14-9 : alternates : PD2 - PCINT18, PD4 - PCINT20)
|
||||||
PCMSK2 = (1 << PCINT20) | (1 << PCINT18); // 13.2.6 : enable individual pin chang interrupt
|
PCMSK2 = (1 << PCINT20) | (1 << PCINT18); // 13.2.6 : enable individual pin chang interrupt
|
||||||
|
|
||||||
prevPIND = PIND;
|
|
||||||
|
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(PCINT2_vect) {
|
ISR(PCINT2_vect) {
|
||||||
uint8_t currentPIND = PIND; // Read the current state of Port D
|
on_press(SW1, increment_led);
|
||||||
uint8_t changedPins = currentPIND ^ prevPIND; // Find changed bits
|
on_press(SW2, decrement_led);
|
||||||
|
|
||||||
if (!TEST(changedPins, SW1)) {
|
|
||||||
on_press(SW1, increment_led);
|
|
||||||
}
|
|
||||||
if (!TEST(changedPins, SW1)) {
|
|
||||||
on_press(SW2, decrement_led);
|
|
||||||
}
|
|
||||||
prevPIND = currentPIND;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user