mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 01:00:29 -05:00
add rudimentary interrupt-less UART
add interrupt support at least for reading the commands that come over UART
This commit is contained in:
parent
7eb9db0d82
commit
7ce6f869a0
33
notes.c
33
notes.c
@ -11,6 +11,9 @@
|
|||||||
#define T1_PRESCALAR 8
|
#define T1_PRESCALAR 8
|
||||||
#define FREQ(f) (16e6 / f / T1_PRESCALAR / 2)
|
#define FREQ(f) (16e6 / f / T1_PRESCALAR / 2)
|
||||||
|
|
||||||
|
#define HIGH(sn) ((sn >> 8) & 0xff)
|
||||||
|
#define LOW(sn) (sn & 0xff)
|
||||||
|
|
||||||
#define P_RX 0
|
#define P_RX 0
|
||||||
#define P_TX 1
|
#define P_TX 1
|
||||||
#define P_SPKR 2
|
#define P_SPKR 2
|
||||||
@ -74,6 +77,29 @@ ISR (PCINT2_vect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
usart_init(void)
|
||||||
|
{
|
||||||
|
// 115200 bps, RX/TX enabled
|
||||||
|
UBRR0 = 8;
|
||||||
|
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
|
||||||
|
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
usart_send(unsigned char c)
|
||||||
|
{
|
||||||
|
while (!(UCSR0A & (1 << UDRE0)));
|
||||||
|
UDR0 = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char
|
||||||
|
usart_read(void)
|
||||||
|
{
|
||||||
|
while (!(UCSR0A & (1 << RXC0)));
|
||||||
|
return UDR0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
@ -93,7 +119,10 @@ main(void)
|
|||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
|
usart_init();
|
||||||
|
|
||||||
// Sends Square wave to the Speaker When a Button is Pressed
|
// Sends Square wave to the Speaker When a Button is Pressed
|
||||||
|
unsigned short cycles = 0;
|
||||||
for (unsigned char n = 0;; n = (n + 1) % 2) {
|
for (unsigned char n = 0;; n = (n + 1) % 2) {
|
||||||
// check if any buttons are pressed, otherwise don't play a note
|
// check if any buttons are pressed, otherwise don't play a note
|
||||||
if (((PINB & PCMSK0) | (PINC & PCMSK1) | (PIND & PCMSK2)) == 0)
|
if (((PINB & PCMSK0) | (PINC & PCMSK1) | (PIND & PCMSK2)) == 0)
|
||||||
@ -110,5 +139,9 @@ main(void)
|
|||||||
PORTD ^= 1 << P_SPKR;
|
PORTD ^= 1 << P_SPKR;
|
||||||
TIFR1 |= 1 << OCF1A;
|
TIFR1 |= 1 << OCF1A;
|
||||||
TCCR1B &= ~(1 << CS11);
|
TCCR1B &= ~(1 << CS11);
|
||||||
|
cycles = (cycles + 1) % 0xffff;
|
||||||
|
|
||||||
|
usart_send(HIGH(cycles));
|
||||||
|
usart_send(LOW(cycles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user