summaryrefslogtreecommitdiff
path: root/notes.c
diff options
context:
space:
mode:
authorVineet K <git@vineetk.net>2024-04-17 14:07:35 -0400
committerShokara Kou <kou@13f0.net>2024-04-17 14:07:35 -0400
commit0167a8d66544705eb256a59ea98e8b23f339da60 (patch)
treef166b896b9ff58c048f4dbf09826625a34cdbcee /notes.c
parent661b58dfd04e84b38d2202387a9f67ff1515e03a (diff)
add skeleton lcd.c
Diffstat (limited to 'notes.c')
-rw-r--r--notes.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/notes.c b/notes.c
new file mode 100644
index 0000000..448d7f7
--- /dev/null
+++ b/notes.c
@@ -0,0 +1,90 @@
1/*
2 * EEL4746C - AVR Piano - Speaker Section
3 * speaker is connected to PD2 and ground
4, PD3-7
5 * the LCD Arduino UNO is connected to TX/RX (PD0/1)
6 */
7
8#include <avr/io.h>
9#include <avr/interrupt.h>
10
11#define T1_PRESCALAR 8
12#define FREQ(f) (16e6 / f / T1_PRESCALAR / 2)
13
14#define P_RX 0
15#define P_TX 1
16#define P_SPKR 2
17
18unsigned short freqs[] = {
19 FREQ(100),
20 FREQ(200),
21 FREQ(250),
22 FREQ(300),
23 FREQ(350),
24 FREQ(400),
25 FREQ(500),
26 FREQ(600),
27 FREQ(700),
28 FREQ(750),
29 FREQ(1000),
30 FREQ(1250),
31 FREQ(1500),
32 FREQ(1750),
33 FREQ(2000),
34 FREQ(3000),
35 FREQ(4000),
36 FREQ(5000),
37 FREQ(6000),
38 FREQ(7000),
39 FREQ(8000),
40};
41unsigned char note = 8;
42unsigned char buttonpressed = 1;
43
44int
45main(void)
46{
47 DDRB = 0x00;
48 DDRC = 0x00;
49 DDRD = (1 << P_TX) | (1 << P_SPKR);
50
51 PCMSK0 = 0xFF;
52 PCMSK1 = 0xFF;
53 PCMSK2 = ~(1 | (1 << 1) | (1 << 2));
54 PCICR = (1 << PCIE0) | (1 << PCIE1) | (1 << PCIE2);
55
56 TCCR1A = 0x00; // use timer1 CTC mode
57 TCCR1B = 1 << WGM12; // already prescaled by 8 in table
58
59 sei();
60
61 //for (;;);
62 for (unsigned char n = 0;; n = (n + 1) % 2) {
63 if (!buttonpressed && n == 0) continue;
64
65 TCNT1 = 1;
66 OCR1A = freqs[note];
67 TCCR1B |= 1 << CS11;
68
69 while ((TIFR1 & (1 << OCF1A)) == 0);
70
71 PORTD ^= 1 << P_SPKR;
72 TIFR1 |= 1 << OCF1A;
73 TCCR1B &= ~(1 << CS11);
74 }
75}
76
77ISR (PCINT0_vect)
78{
79
80}
81
82ISR (PCINT1_vect)
83{
84
85}
86
87ISR (PCINT2_vect)
88{
89
90}