changeset 20:a24c832d292a tiny13

Fix the code for attiny9/10
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 24 Jun 2018 14:56:13 +0200
parents 393915e97bb1
children 23dc552f97bf
files main/Makefile main/main.c
diffstat 2 files changed, 29 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/main/Makefile	Thu Dec 01 15:51:42 2016 +0100
+++ b/main/Makefile	Sun Jun 24 14:56:13 2018 +0200
@@ -1,58 +1,29 @@
-DEVICE      = attiny85
-CLOCK      = 1000000
-PROGRAMMER = -c usbasp
-OBJECTS    = main.o
-
-# for ATTiny85
-# see http://www.engbedded.com/fusecalc/
-FUSES       = -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 
-
-# Tune the lines below only if you know what you are doing:
-AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
-COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
-
-# symbolic targets:
-all:	main.hex
-
-.c.o:
-	$(COMPILE) -c $< -o $@
+DEVICE = attiny9
+CLOCK = 1000000
+PROGRAMMER = usbasp
+OBJECTS = main.o
+PROGRAM = main.hex
+CFLAGS = -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
+CC = avr-gcc
+AVRDUDE = avrdude
 
-.S.o:
-	$(COMPILE) -x assembler-with-cpp -c $< -o $@
-
-.c.s:
-	$(COMPILE) -S $< -o $@
-
-flash:	all
-	$(AVRDUDE) -U flash:w:main.hex:i
+all: $(PROGRAM)
 
-fuse:
-	$(AVRDUDE) $(FUSES)
+%.o: %.c
+	$(CC) $(CFLAGS) -c $< -o $@
 
-# Xcode uses the Makefile targets "", "clean" and "install"
-install: flash fuse
-
-# if you use a bootloader, change the command below appropriately:
-load: all
-	bootloadHID main.hex
+flash: $(PROGRAM)
+	$(AVRDUDE) -c $(PROGRAMMER) -p $(DEVICE) -U flash:w:$<:i
 
 clean:
-	rm -f main.hex main.elf $(OBJECTS)
+	rm -f *.hex *.elf $(OBJECTS)
 
-# file targets:
-main.elf: $(OBJECTS)
-	$(COMPILE) -o main.elf $(OBJECTS)
+%.elf: $(OBJECTS)
+	$(CC) $(CFLAGS) -o $@ $(OBJECTS)
 
-main.hex: main.elf
-	rm -f main.hex
-	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
-	avr-size --format=avr --mcu=$(DEVICE) main.elf
-# If you have an EEPROM section, you must also create a hex file for the
-# EEPROM and add it to the "flash" target.
+%.hex: %.elf
+	rm -f $@
+	avr-objcopy -j .text -j .data -O ihex $< $@
+	avr-size --format=avr --mcu=$(DEVICE) $<
 
-# Targets for code debugging and analysis:
-disasm:	main.elf
-	avr-objdump -d main.elf
-
-cpp:
-	$(COMPILE) -E main.c`gg
+.PHONY: all clean flash
--- a/main/main.c	Thu Dec 01 15:51:42 2016 +0100
+++ b/main/main.c	Sun Jun 24 14:56:13 2018 +0200
@@ -41,26 +41,27 @@
     while (length --> 0) {
         note.raw = pgm_read_byte_near(notes++);
         if (note.note.octave) {
-            TCCR0B = 2;
+            TCCR0B = 1<<WGM02 | 1<<CS01;
             OCR0A = pgm_read_byte_near(FREQ + note.note.tone) >> (note.note.octave - 1);
         }
         if (note.note.length) {
             _delay_ms(220);
-            TCCR0B = 0;
+            TCCR0B = 1<<WGM02;
             _delay_ms(30);
         } else {
             _delay_ms(110);
-            TCCR0B = 0;
+            TCCR0B = 1<<WGM02;
             _delay_ms(15);
         }
-        PORTB ^= 1<<3 | 1<<4;
+        TCNT0 = 0;
+        PORTB ^= 1<<2;
     }
 }
 
 int main() {
-    DDRB = 1<<0 | 1<<3 | 1<<4;
-    TCCR0A |= 1<<COM0A0 | 1<<WGM01;
-    PORTB ^= 1<<4;
+    DDRB = 1<<1 | 1<<2;
+    TCCR0A |= 1<<COM0B0;
+    PORTB ^= 1<<2;
     play(INTRO_NOTES, 26);
     while(1) {
         play(MELODY_NOTES, 216);