start working on the speaker arduino code

This commit is contained in:
Vineet K 2024-04-15 21:55:51 -04:00 committed by kar
parent 8f3b27a652
commit fc85413fa9
2 changed files with 90 additions and 0 deletions

11
Makefile Normal file
View File

@ -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

79
main.c Normal file
View File

@ -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)
{
}