diff options
| -rw-r--r-- | door_lock/Makefile (renamed from Makefile) | 2 | ||||
| -rw-r--r-- | door_lock/main.c | 28 | ||||
| -rw-r--r-- | main.c | 25 |
3 files changed, 29 insertions, 26 deletions
diff --git a/Makefile b/door_lock/Makefile index 27092b1..3214ccf 100644 --- a/Makefile +++ b/door_lock/Makefile @@ -1,6 +1,6 @@ CC = avr-gcc MCU = atmega328p -TARGET = blink +TARGET = app SRC = main.c OBJ = $(SRC:.c=.o) diff --git a/door_lock/main.c b/door_lock/main.c new file mode 100644 index 0000000..7308d35 --- /dev/null +++ b/door_lock/main.c @@ -0,0 +1,28 @@ +#include <avr/io.h> +#include <util/delay.h> + +int main(void) { + DDRB |= 1 << PINB1; // Set pin 9 on arduino to output + + /* 1. Set Fast PWM mode 14: set WGM11, WGM12, WGM13 to 1 */ + /* 3. Set pre-scaler of 8 */ + /* 4. Set Fast PWM non-inverting mode */ + TCCR1A |= (1 << WGM11) | (1 << COM1A1); + TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS11); + + /* 2. Set ICR1 register: PWM period */ + ICR1 = 39999; + + /* Offset for correction */ + int offset = 800; + + /* 5. Set duty cycle */ + while(1) { + OCR1A = 3999 + offset; + _delay_ms(5000); + OCR1A = 1999 - offset; + _delay_ms(5000); + } + + return 0; +} @@ -1,25 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> - -int main(void) -{ - DDRB |= (1 << DDB5); - - TCCR1A = 0; - TCNT1 = 65535 - (F_CPU / 1024); - TCCR1B = (1 << CS10) | (1 << CS12); - TIMSK1 = (1 << TOIE1); - - sei(); - - for (;;) - ; - - return 0; -} - -ISR(TIMER1_OVF_vect) -{ - PORTB ^= (1 << 5); - TCNT1 = 65535 - (F_CPU / 1024); -} |
