summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--main.c79
2 files changed, 90 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9eba3af
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
1CC = avr-gcc
2CFLAGS = -O2 -Wall -Wextra -Werror -mmcu=atmega328p
3OBJCOPY = avr-objcopy
4
5all:
6 ${CC} ${CFLAGS} main.c
7 ${OBJCOPY} -j .text -j .data -O ihex a.out main.hex
8 rm -f a.out
9
10flash: all
11 avrdude -p atmega328p -c arduino -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex:i
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..9f99ce1
--- /dev/null
+++ b/main.c
@@ -0,0 +1,79 @@
1/*
2 * EEL4746C - AVR Piano - Speaker Section
3 * speaker is connected to PD2 and ground
4 * buttons are connected to PB0-5, PC0-5, PD3-7
5 * the LCD Arduino UNO is connected to TX/RX (PD0/1)
6 */
7
8#include <avr/io.h>
9#include <avr/interrupt.h>
10
11#define F_CPU 16000000UL
12#include <util/delay.h>
13
14#define P_RX 0
15#define P_TX 1
16#define P_SPKR 2
17
18unsigned short freqs[] = {
19 100,
20 200,
21 250,
22 300,
23 350,
24 400,
25 500,
26 600,
27 700,
28 750,
29 1000,
30 1250,
31 1500,
32 1750,
33 2000,
34 3000,
35 4000,
36 5000,
37 6000,
38 7000,
39 8000
40};
41unsigned char note = 0;
42unsigned char buttonpressed = 1;
43
44int
45main(void)
46{
47 DDRB = 0x00;
48 DDRC = 0x00;
49 DDRD = (1 << P_TX) | (1 << P_SPKR);
50
51 PCMSK0 = 0xFF;
52 PCMSK1 = 0xFF;
53 PCMSK2 = ~(1 | (1 << 1) | (1 << 2));
54 PCICR = (1 << PCIE0) | (1 << PCIE1) | (1 << PCIE2);
55
56 sei();
57
58 //for (;;);
59 for (unsigned char n = 0;; n = (n + 1) % 2) {
60 if (!buttonpressed) continue;
61 _delay_us(71.43);
62 PORTD ^= 1 << P_SPKR;
63 }
64}
65
66ISR (PCINT0_vect)
67{
68
69}
70
71ISR (PCINT1_vect)
72{
73
74}
75
76ISR (PCINT2_vect)
77{
78
79}