commit fc85413fa9891c32b4d82cd7d0e27fd04220be91
parent 8f3b27a6527cd267c450a3b8018f1ffcc11aeb54
Author: Vineet K <git@vineetk.net>
Date: Mon, 15 Apr 2024 21:55:51 -0400
start working on the speaker arduino code
Diffstat:
| A | Makefile | | | 11 | +++++++++++ |
| A | main.c | | | 79 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,11 @@
+CC = avr-gcc
+CFLAGS = -O2 -Wall -Wextra -Werror -mmcu=atmega328p
+OBJCOPY = avr-objcopy
+
+all:
+ ${CC} ${CFLAGS} main.c
+ ${OBJCOPY} -j .text -j .data -O ihex a.out main.hex
+ rm -f a.out
+
+flash: all
+ avrdude -p atmega328p -c arduino -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex:i
diff --git a/main.c b/main.c
@@ -0,0 +1,79 @@
+/*
+ * EEL4746C - AVR Piano - Speaker Section
+ * speaker is connected to PD2 and ground
+ * buttons are connected to PB0-5, PC0-5, PD3-7
+ * the LCD Arduino UNO is connected to TX/RX (PD0/1)
+ */
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#define F_CPU 16000000UL
+#include <util/delay.h>
+
+#define P_RX 0
+#define P_TX 1
+#define P_SPKR 2
+
+unsigned short freqs[] = {
+ 100,
+ 200,
+ 250,
+ 300,
+ 350,
+ 400,
+ 500,
+ 600,
+ 700,
+ 750,
+ 1000,
+ 1250,
+ 1500,
+ 1750,
+ 2000,
+ 3000,
+ 4000,
+ 5000,
+ 6000,
+ 7000,
+ 8000
+};
+unsigned char note = 0;
+unsigned char buttonpressed = 1;
+
+int
+main(void)
+{
+ DDRB = 0x00;
+ DDRC = 0x00;
+ DDRD = (1 << P_TX) | (1 << P_SPKR);
+
+ PCMSK0 = 0xFF;
+ PCMSK1 = 0xFF;
+ PCMSK2 = ~(1 | (1 << 1) | (1 << 2));
+ PCICR = (1 << PCIE0) | (1 << PCIE1) | (1 << PCIE2);
+
+ sei();
+
+ //for (;;);
+ for (unsigned char n = 0;; n = (n + 1) % 2) {
+ if (!buttonpressed) continue;
+ _delay_us(71.43);
+ PORTD ^= 1 << P_SPKR;
+ }
+}
+
+ISR (PCINT0_vect)
+{
+
+}
+
+ISR (PCINT1_vect)
+{
+
+}
+
+ISR (PCINT2_vect)
+{
+
+}