Comments for Notes.c

This commit is contained in:
Joseph Bryant 2024-04-17 15:26:01 -04:00
parent d4d4114b31
commit 9f6c350015

11
notes.c
View File

@ -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)
*/ */
@ -44,10 +43,12 @@ 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);