mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 09:10:30 -05:00
80 lines
996 B
C
80 lines
996 B
C
/*
|
|
* 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)
|
|
{
|
|
|
|
}
|