Added source code

This commit is contained in:
Gregor Riepl 2020-12-02 12:25:32 +01:00
parent 77504865c8
commit d1ccc84b8f
3 changed files with 139 additions and 0 deletions

98
Makefile Normal file
View file

@ -0,0 +1,98 @@
PRG = badge
OBJ = main.o
OPTIMIZE = -Os -std=gnu99
PROGRAMMER = usbtiny
MCU_TARGET = attiny13a
DEFS = -DF_CPU=1000000UL
INCLUDES = -I.
LIBS =
#LFUSE =
#HFUSE =
#EFUSE =
# You should not have to change anything below here.
CC = avr-gcc
DUDE = avrdude
HOST_CC = gcc
HOST_CFLAGS = -O0 -g
HOST_LDFLAGS =
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) $(INCLUDES)
override LDFLAGS = -Wl,-Map,$(PRG).map
DUDEFLAGS = -c $(PROGRAMMER) -p $(MCU_TARGET)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: $(PRG).elf lst text eeprom
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
rm -rf $(OBJ) $(PRG).elf $(PRG).lst $(PRG).map $(PRG).bin $(PRG).hex $(PRG).srec $(PRG)_eeprom.bin $(PRG)_eeprom.hex $(PRG)_eeprom.srec $(EXTRA_CLEAN_FILES)
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for flashing, EEPROM writing and fuse bit setting
flash: $(PRG).hex $(PRG)_eeprom.hex
$(DUDE) $(DUDEFLAGS) -U eeprom:w:$(PRG)_eeprom.hex:i -U flash:w:$(PRG).hex:i
flashprg: $(PRG).hex
$(DUDE) $(DUDEFLAGS) -U flash:w:$(PRG).hex:i
flasheep: $(PRG)_eeprom.hex
$(DUDE) $(DUDEFLAGS) -U eeprom:w:$(PRG)_eeprom.hex:i
fuse:
$(DUDE) $(DUDEFLAGS) -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m -U efuse:w:$(EFUSE):m
# Rules for building the .text rom images
text: hex bin srec
hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
# Rules for building the .eeprom rom images
eeprom: ehex ebin esrec
ehex: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_eeprom.srec
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ \
|| { echo empty $@ not generated; exit 0; }

41
main.c Normal file
View file

@ -0,0 +1,41 @@
/**
* Copyright CCC Basel 2020.
*
* This documentation describes Open Hardware and is licensed under the
* CERN OHL v. 1.2.
*
* You may redistribute and modify this documentation under the terms of the
* CERN OHL v.1.2. (http://ohwr.org/cernohl).
*
* This documentation is distributed
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING OF MERCHANTABILITY,
* SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Please see the CERN OHL v.1.2 for applicable conditions.
*/
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
void init() {
PORTB = 0;
DDRB = _BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB3) | _BV(PB4);
}
void loop() {
for (uint8_t i = 0; i < 5; i++) {
PORTB = _BV(i);
_delay_ms(500);
}
}
int main() {
init();
while (1) {
loop();
}
return 0;
}

BIN
main.o Normal file

Binary file not shown.