diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2024-11-05 16:02:47 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2024-11-05 16:02:47 +0800 |
| commit | 364101428efe19ccfe0173b8d96831c08ad86865 (patch) | |
| tree | 4e8dadf75245595546f754fef93a202ecf6d311e /door_lock/main.c | |
| parent | 5ef1ec6262ca92417d253be8606890dd6cc34592 (diff) | |
| download | smart-home-364101428efe19ccfe0173b8d96831c08ad86865.tar.gz | |
wip: interrupt not working.
Diffstat (limited to 'door_lock/main.c')
| -rw-r--r-- | door_lock/main.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/door_lock/main.c b/door_lock/main.c index 9774bab..36c4a37 100644 --- a/door_lock/main.c +++ b/door_lock/main.c @@ -1,8 +1,6 @@ #include <stddef.h> #include <avr/io.h> -#include <util/delay.h> - -#include "serial.h" +#include <avr/interrupt.h> #define PWM_MIN 1200 #define PWM_MID 3000 @@ -17,28 +15,33 @@ static inline void servo_init(void) DDRB |= 1 << SERVO_PIN; TCCR1A |= (1 << WGM11) | (1 << COM1A1); TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS11); + ICR1 = 40000; DDRD &= ~((1 << LOCK_BTN) | (1 << UNLOCK_BTN)); PORTD |= (1 << LOCK_BTN) | (1 << UNLOCK_BTN); } -static inline uint8_t is_btn_pressed(uint8_t btn) -{ - return !((PIND >> btn) & 0x01); -} - int main(void) { servo_init(); - for(;;) { - if (is_btn_pressed(LOCK_BTN)) - OCR1A = PWM_MID; + EICRA |= (1 << ISC00); + EIMSK |= (1 << INT0); - if (is_btn_pressed(UNLOCK_BTN)) - OCR1A = PWM_MIN; - } + sei(); + + for(;;) + ; return 0; } + +ISR (INT0_vect) +{ + if ((PIND & (1 << LOCK_BTN))) + OCR1A = PWM_MID; + + if ((PIND & (1 << UNLOCK_BTN))) + OCR1A = PWM_MIN; +} |
