-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled2.c
31 lines (23 loc) · 796 Bytes
/
led2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define F_CPU 16000000UL // Defining clock
#include <avr/io.h> // Including library avr
#include <avr/interrupt.h> // Including library interrupt
// Extern interrupt function
ISR( INT0_vect ){
PORTC ^= (1 << 2); // Toggle Pin C2
}
int main( void ){
cli(); // Disable global interrupt
// Set pin c2 registers as output ( DDRxn --> DDRx )
// 7654_3210
DDRC |= (1 << 2); // binary xxxx_x1xx
// Set pin d2 register as input ( DDRxn --> DDRx )
DDRD &= ~(1 << 2); // binary xxxx_x0xx
PORTD |= (1 << 2); // Pull-up on Pin D2
// Set interrupt
EICRA |= (1 << 1); // external interrupt int0 - falling edge
EIMSK |= (1 << 0); // Enable external interrupt INT0
sei(); // Enable global interrupt
// Infinity loop
while ( 1 ){;;}
return 0;
}