-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example gaggia timer on attiny10
- Loading branch information
Łukasz Podkalicki
committed
Sep 18, 2023
1 parent
fa82d89
commit 0076e39
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -- | ||
# Copyright (c) 2023, Lukasz Marcin Podkalicki <lpodkalicki@gmail.com> | ||
# -- | ||
|
||
MCU=attiny10 | ||
BYTE0=0xFF | ||
LOCK=0xFF | ||
F_CPU=8000000 | ||
CC=avr-gcc | ||
LD=avr-ld | ||
OBJCOPY=avr-objcopy | ||
SIZE=avr-size | ||
AVRDUDE=avrdude | ||
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I. | ||
TARGET=main | ||
|
||
SRCS = main.c | ||
|
||
all: | ||
${CC} ${CFLAGS} -o ${TARGET}.o ${SRCS} | ||
${LD} -o ${TARGET}.elf ${TARGET}.o -g -mavrtiny | ||
${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.o ${TARGET}.hex | ||
${SIZE} -C --mcu=${MCU} ${TARGET}.elf | ||
|
||
flash: | ||
${AVRDUDE} -p ${MCU} -c usbasp -B10 -B10 -U flash:w:${TARGET}.hex:i -F -P usb | ||
|
||
fuse: | ||
$(AVRDUDE) -p ${MCU} -c usbasp -B10 -U fuse:w:${BYTE0}:m -U lock:w:${LOCK}:m | ||
|
||
clean: | ||
rm -f *.c~ *.h~ *.o *.elf *.hex |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2023, Łukasz Marcin Podkalicki <lpodkalicki@gmail.com> | ||
*/ | ||
|
||
#include <avr/io.h> | ||
#include <util/delay.h> | ||
|
||
#define IN_PIN PB0 | ||
#define OUT_PIN PB2 | ||
|
||
#define TIMER_SECONDS_MAX (1 * 60) | ||
|
||
int | ||
main(void) | ||
{ | ||
uint8_t timer_activated = 1; | ||
uint16_t timer_seconds = 0; | ||
uint8_t timer_counter = 0; | ||
|
||
/* setup */ | ||
CCP = 0xD8; // set register signature - 0xD8 | ||
CLKPSR = 0; // set the clock division factor | ||
DDRB |= _BV(OUT_PIN); // set OUT pin as OUTPUT | ||
PORTB |= _BV(OUT_PIN); // set OUT_PIN to HIGH at start | ||
|
||
|
||
/* loop */ | ||
while (1) | ||
{ | ||
if (PINB & _BV(IN_PIN)) | ||
{ | ||
timer_seconds = timer_counter = 0; // reset timer | ||
timer_activated = 1; // activate timer | ||
PORTB |= _BV(OUT_PIN); // set OUT pin as HIGH | ||
} | ||
|
||
if (timer_activated) | ||
{ | ||
if (timer_seconds == TIMER_SECONDS_MAX) | ||
{ | ||
timer_activated = 0; // deactivate timer | ||
PORTB &= ~_BV(OUT_PIN); // set OUT pin to LOW | ||
} | ||
else | ||
{ | ||
if (++timer_counter == 10) | ||
{ | ||
timer_counter = 0; | ||
timer_seconds++; | ||
} | ||
} | ||
} | ||
|
||
_delay_ms(100); | ||
} | ||
} |