initial
This commit is contained in:
BIN
code/Builds/main.elf
Executable file
BIN
code/Builds/main.elf
Executable file
Binary file not shown.
27
code/Builds/main.hex
Normal file
27
code/Builds/main.hex
Normal file
@@ -0,0 +1,27 @@
|
||||
:100000000C943E000C9450000C9450000C94500042
|
||||
:100010000C9450000C9450000C9450000C94500020
|
||||
:100020000C9450000C9450000C9450000C94500010
|
||||
:100030000C9450000C9450000C9450000C94500000
|
||||
:100040000C9450000C9450000C9450000C945000F0
|
||||
:100050000C9450000C9450000C9450000C945000E0
|
||||
:100060000C9450000C9450000C9450000C945000D0
|
||||
:100070000C9450000C9450000C94500011241FBE9E
|
||||
:10008000CFEFCDBFDFE3DEBF28E3A0E0B8E301C0E0
|
||||
:100090001D92A330B207E1F70E9452000C94CB00EE
|
||||
:1000A0000C94000082E08093210484E0809321047A
|
||||
:1000B00088E0809321048091140488608093140464
|
||||
:1000C00081E08093400680914206806180934206E1
|
||||
:1000D0008091420687608093420690910238E091B9
|
||||
:1000E0000038F091013820E030E052E064E048E070
|
||||
:1000F00076E08091080484FF17C050932604609333
|
||||
:1001000026042115310531F5409326048091080419
|
||||
:1001100084FF0AC05093260460932604409326046B
|
||||
:100120008091080484FDF6CF911509F150932504C0
|
||||
:10013000409326049F5FE917F10588F46093250436
|
||||
:100140008091080484FFF2CF509326046093260424
|
||||
:1001500020E137E22150310940932504CACF609352
|
||||
:1001600026048091080484FDEFCF9111DFCF7093B6
|
||||
:1001700046068091480681608093480680914B0630
|
||||
:1001800080FFFCCFE0915006F0915106F695E7957F
|
||||
:0A019000F695E795CBCFF894FFCF6A
|
||||
:00000001FF
|
||||
BIN
code/Builds/main.o
Normal file
BIN
code/Builds/main.o
Normal file
Binary file not shown.
12
code/compile_flags.txt
Normal file
12
code/compile_flags.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
--target=avr
|
||||
-D
|
||||
__AVR_ATtiny1616__
|
||||
-D
|
||||
F_CPU=3000000UL
|
||||
-I
|
||||
/usr/lib/avr/include
|
||||
-I
|
||||
./include
|
||||
-I
|
||||
../../dmm-libs/include
|
||||
|
||||
69
code/main.c
Normal file
69
code/main.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <avr/io.h>
|
||||
#include <stdint.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
void ADC_init(void) {
|
||||
// Enable ADC and set the reference voltage to AVDD
|
||||
ADC1.CTRLA = ADC_ENABLE_bm; // Enable ADC
|
||||
ADC1.CTRLC |= ADC_REFSEL_VDDREF_gc; // Reference voltage selection
|
||||
ADC1.CTRLC |= ADC_PRESC_DIV256_gc; // Prescaler
|
||||
}
|
||||
|
||||
uint16_t ADC_read(uint8_t channel) {
|
||||
// Select the ADC channel
|
||||
ADC1.MUXPOS = channel;
|
||||
|
||||
// Start the conversion
|
||||
ADC1.COMMAND |= ADC_STCONV_bm;
|
||||
|
||||
// Wait for conversion to complete
|
||||
while (!(ADC1.INTFLAGS & ADC_RESRDY_bm));
|
||||
|
||||
//// Clear the interrupt flag
|
||||
//ADC0.CH0.INTFLAGS = ADC_CH_CHIF_bm;
|
||||
|
||||
// Read the result
|
||||
return ADC1.RES; // Return the 12-bit result
|
||||
}
|
||||
|
||||
int main(void){
|
||||
PORTB.DIRSET = 1 << 1;
|
||||
PORTB.DIRSET = 1 << 2;
|
||||
PORTB.DIRSET = 1 << 3;
|
||||
|
||||
PORTA.PIN4CTRL |= PORT_PULLUPEN_bm;
|
||||
ADC_init();
|
||||
|
||||
uint8_t suck = 0;
|
||||
uint16_t cooldown = 0;
|
||||
while(1){
|
||||
suck = !(PORTA.IN & (1<<4));
|
||||
if(suck){
|
||||
static uint8_t timer = 0;
|
||||
static uint16_t duty = 0;
|
||||
|
||||
if(timer == 0)
|
||||
duty = (ADC_read(6)/4);
|
||||
|
||||
PORTB.OUTSET = 1 << 1;
|
||||
PORTB.OUTCLR = 1 << 3;
|
||||
if(++timer > duty){
|
||||
PORTB.OUTSET = 1 << 2;
|
||||
}
|
||||
else{
|
||||
PORTB.OUTCLR = 1 << 2;
|
||||
}
|
||||
cooldown=10000;
|
||||
}
|
||||
else {
|
||||
PORTB.OUTCLR = 1 << 1;
|
||||
PORTB.OUTCLR = 1 << 2;
|
||||
if(cooldown > 0){
|
||||
cooldown--;
|
||||
PORTB.OUTSET = 1 << 3;
|
||||
}
|
||||
else
|
||||
PORTB.OUTCLR = 1 << 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
59
code/makefile
Normal file
59
code/makefile
Normal file
@@ -0,0 +1,59 @@
|
||||
TARGET = main
|
||||
SRCS := $(shell find -name '*.c')
|
||||
FILES = $(SRCS:%.c=%) #main uart avrIOhelper/io-helper #uart#hier alle c-Datein reinschreiben, trennung durch " " und ohne .c-Endung
|
||||
MCU = attiny1616
|
||||
PROGC = t1616
|
||||
CC = avr-gcc
|
||||
TOOL = serialupdi -P /dev/ttyUSB0
|
||||
#TOOL = atmelice
|
||||
#TOOL = avrispmkii
|
||||
#TOOL = usbasp-clone
|
||||
|
||||
BUILDDIR = Builds
|
||||
|
||||
DEFINES = -DF_CPU=3000000UL
|
||||
|
||||
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
||||
LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections
|
||||
|
||||
LDFILES = $(foreach FILE,$(FILES),$(BUILDDIR)/$(FILE).o)
|
||||
|
||||
all: clean $(BUILDDIR)/$(TARGET).elf
|
||||
|
||||
$(BUILDDIR)/%.o: %.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) -c $< -o $(BUILDDIR)/$*.o
|
||||
|
||||
$(BUILDDIR)/$(TARGET).elf: $(LDFILES)
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(LDFLAGS) $(LDFILES) -o $(BUILDDIR)/$(TARGET).elf
|
||||
|
||||
$(BUILDDIR)/$(TARGET).hex : $(BUILDDIR)/$(TARGET).elf
|
||||
avr-objcopy -j .data -j .text -O ihex $< $@
|
||||
|
||||
fuse:
|
||||
avrdude -p $(PROGC) -c $(TOOL) -U lfuse:w:0xE8:m -U hfuse:w:0xD1:m
|
||||
|
||||
load: $(BUILDDIR)/$(TARGET).hex
|
||||
avrdude -p $(PROGC) -c $(TOOL) -U flash:w:$(BUILDDIR)/$(TARGET).hex -v -B 4MHz
|
||||
|
||||
program: clean load
|
||||
|
||||
reset:
|
||||
avrdude -p $(PROGC) -c $(TOOL)
|
||||
|
||||
size: $(BUILDDIR)/$(TARGET).elf
|
||||
avr-size -C --mcu=$(MCU) $(BUILDDIR)/$(TARGET).elf
|
||||
|
||||
.PHONY=clean
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
|
||||
#Fuse m1284p external Osz. Long startuptime
|
||||
# avrdude -c usbasp-clone -p m1284p -U lfuse:w:0xff:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
|
||||
|
||||
#Fuse m1284p internal Osz. Long startuptime
|
||||
# avrdude -c usbasp-clone -p m1284p -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
|
||||
|
||||
|
||||
Reference in New Issue
Block a user