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

View File

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