From fc85413fa9891c32b4d82cd7d0e27fd04220be91 Mon Sep 17 00:00:00 2001 From: Vineet K Date: Mon, 15 Apr 2024 21:55:51 -0400 Subject: [PATCH] start working on the speaker arduino code --- Makefile | 11 ++++++++ main.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Makefile create mode 100644 main.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9eba3af --- /dev/null +++ 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 new file mode 100644 index 0000000..9f99ce1 --- /dev/null +++ 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 +#include + +#define F_CPU 16000000UL +#include + +#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) +{ + +}