mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 01:00:29 -05:00
start working on the speaker arduino code
This commit is contained in:
parent
8f3b27a652
commit
fc85413fa9
11
Makefile
Normal file
11
Makefile
Normal 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
79
main.c
Normal 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)
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user