Skip to content

Commit

Permalink
Add example gaggia timer on attiny10
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Podkalicki committed Sep 18, 2023
1 parent fa82d89 commit 0076e39
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
32 changes: 32 additions & 0 deletions avr/attiny10/010_gaggia_example_timer/Makefile
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
56 changes: 56 additions & 0 deletions avr/attiny10/010_gaggia_example_timer/main.c
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);
}
}

0 comments on commit 0076e39

Please sign in to comment.