mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 09:10:30 -05:00
Comments for Notes.c
This commit is contained in:
parent
d4d4114b31
commit
9f6c350015
17
notes.c
17
notes.c
@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* EEL4746C - AVR Piano - Speaker Section
|
* EEL4746C - AVR Piano - Speaker Section
|
||||||
* speaker is connected to PD2 and ground
|
* speaker is connected to PD2 and ground, PD3-7
|
||||||
, PD3-7
|
|
||||||
* the LCD Arduino UNO is connected to TX/RX (PD0/1)
|
* the LCD Arduino UNO is connected to TX/RX (PD0/1)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -42,12 +41,14 @@ unsigned char note = 8;
|
|||||||
unsigned char buttonpressed = 1;
|
unsigned char buttonpressed = 1;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
|
// Data Direction for Buttons, UART, Speaker
|
||||||
DDRB = 0x00;
|
DDRB = 0x00;
|
||||||
DDRC = 0x00;
|
DDRC = 0x00;
|
||||||
DDRD = (1 << P_TX) | (1 << P_SPKR);
|
DDRD = (1 << P_TX) | (1 << P_SPKR);
|
||||||
|
|
||||||
|
// Enabling Pin Change Interrupt for All Buttons
|
||||||
PCMSK0 = 0xFF;
|
PCMSK0 = 0xFF;
|
||||||
PCMSK1 = 0xFF;
|
PCMSK1 = 0xFF;
|
||||||
PCMSK2 = ~(1 | (1 << 1) | (1 << 2));
|
PCMSK2 = ~(1 | (1 << 1) | (1 << 2));
|
||||||
@ -58,16 +59,18 @@ main(void)
|
|||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
//for (;;);
|
// Sends Square wave to the Speaker When a Button is Pressed
|
||||||
for (unsigned char n = 0;; n = (n + 1) % 2) {
|
for (unsigned char n = 0;; n = (n + 1) % 2) {
|
||||||
if (!buttonpressed && n == 0) continue;
|
if (!buttonpressed && n == 0) continue;
|
||||||
|
|
||||||
|
// Prepare Timer/Counter
|
||||||
TCNT1 = 1;
|
TCNT1 = 1;
|
||||||
OCR1A = freqs[note];
|
OCR1A = freqs[note];
|
||||||
TCCR1B |= 1 << CS11;
|
TCCR1B |= 1 << CS11;
|
||||||
|
|
||||||
while ((TIFR1 & (1 << OCF1A)) == 0);
|
while ((TIFR1 & (1 << OCF1A)) == 0); // Monitor OutPut Compare Flag
|
||||||
|
|
||||||
|
// Toggles port For Speaker
|
||||||
PORTD ^= 1 << P_SPKR;
|
PORTD ^= 1 << P_SPKR;
|
||||||
TIFR1 |= 1 << OCF1A;
|
TIFR1 |= 1 << OCF1A;
|
||||||
TCCR1B &= ~(1 << CS11);
|
TCCR1B &= ~(1 << CS11);
|
||||||
|
Loading…
Reference in New Issue
Block a user