Created
September 23, 2021 22:38
-
-
Save walidamriou/93979913d142635202e4ea88672dea4d to your computer and use it in GitHub Desktop.
Signal input to output
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
/** | |
* | |
* @file main.h | |
* @brief main code for signal input to output | |
* | |
* @version 1.0.0 | |
* | |
* @author Walid Amriou | |
* @date 23/09/2021 | |
* | |
*/ | |
#include <avr/io.h> | |
#include <util/delay.h> | |
#include <avr/interrupt.h> | |
// handler of external Interrupt 4 of pin E4 | |
uint8_t pinstatus = 0; | |
ISR(INT4_vect) { | |
// change status of pin 7 (13 in arduino uno) | |
pinstatus=!pinstatus; | |
digitalWrite(9, pinstatus); | |
} | |
// config external interrupt 4 of pin 2 | |
void initInterrupt4(void) { | |
EIMSK |= (1 << INT4); // (External Interrupt Mask Register) controls whether the INT0 and INT1 interrupts are enabled, here control INT0 | |
EICRA |= (1 << ISC40); // External Interrupt Control Register A, Defines the type of signals that activates the external Interrupt, here set INT0 to trigger on any change | |
//EICRA |= (1 << ISC01); // set INT0 to trigger on falling edge | |
// EICRA |= (1 << ISC01 || 1 << ISC00); // set INT0 to trigger on rising edge | |
sei(); // a macro that executes an assembler instruction to enable interrupts. | |
} | |
void setup() { | |
// put your setup code here, to run once: | |
// make pin 2 output | |
DDRH |= (1<<6); // for PB1, and it means DDRB = DDRB | 0b00000010 | |
// | |
PORTE &= ~(1 << 4); // pullup | |
initInterrupt4(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//delay(200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment