Activate serial receive interrupt.

This commit is contained in:
Marco 2022-05-12 04:46:38 +02:00
parent ab91d5f50e
commit 43c3848d2a
3 changed files with 20 additions and 20 deletions

View File

@ -4,10 +4,7 @@
#include "include/uart.h" #include "include/uart.h"
#include "include/timer.h" #include "include/timer.h"
#include "include/commands.h"
uint8_t sec = 0;
uint16_t cnt = 0;
int main() int main()
{ {
@ -22,19 +19,10 @@ int main()
sei(); sei();
while (1) { while (1) {
if ((PORTB & (1<<PB2))>1) {
if ((PORTB & (1 << PB2)) > 1) _delay_us(10);
{ PORTB &= ~(1<<PB2);
_delay_ms(1);
PORTB &= ~(1 << PB2);
} }
if (cnt == 65500) {
printf("%u\n\r", TCNT0);
cnt = 0;
}
cnt++;
} }
return 0; return 0;
@ -44,3 +32,11 @@ ISR(TIMER0_COMPA_vect)
{ {
PORTB |= (1 << PB2); PORTB |= (1 << PB2);
} }
ISR(USART1_RX_vect)
{
char u;
u = UDR1;
cmd_collect(u);
}

View File

@ -6,7 +6,7 @@ static FILE stream = FDEV_SETUP_STREAM(uart_printf, NULL, _FDEV_SETUP_WRITE);
void uart_init(unsigned int baud) void uart_init(unsigned int baud)
{ {
stdout = &stream; stdout = &stream;
/* Set baud rate */ /* Set baud rate */
UBRR1H = (unsigned char)(baud>>8); UBRR1H = (unsigned char)(baud>>8);
@ -15,6 +15,9 @@ void uart_init(unsigned int baud)
/* Enable receiver and transmitter */ /* Enable receiver and transmitter */
UCSR1B = (1<<RXEN1)|(1<<TXEN1); UCSR1B = (1<<RXEN1)|(1<<TXEN1);
/*Enable the receive interrupt*/
UCSR1B |= (1 << RXCIE1);
/* Set frame format */ /* Set frame format */
UCSR1C |= (3<<UCSZ10); // 8 data bits UCSR1C |= (3<<UCSZ10); // 8 data bits
// UCSR1C &= ~(1<<USBS1); // 1 stop bit // UCSR1C &= ~(1<<USBS1); // 1 stop bit
@ -36,3 +39,4 @@ int uart_printf(char var, FILE *stream)
uart_sendByte(var); uart_sendByte(var);
return 0; return 0;
} }