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);
PORTB &= ~(1 << PB2);
}
if (cnt == 65500) {
printf("%u\n\r", TCNT0);
cnt = 0;
if ((PORTB & (1<<PB2))>1) {
_delay_us(10);
PORTB &= ~(1<<PB2);
}
cnt++;
}
return 0;
@ -43,4 +31,12 @@ int main()
ISR(TIMER0_COMPA_vect)
{
PORTB |= (1 << PB2);
}
}
ISR(USART1_RX_vect)
{
char u;
u = UDR1;
cmd_collect(u);
}

View File

@ -34,4 +34,4 @@ void initOverflowTimer1(void)
{
TCCR1B |= (1<<CS11);
TIMSK1 |= (1<<TOIE1);
}
}

View File

@ -6,8 +6,8 @@ static FILE stream = FDEV_SETUP_STREAM(uart_printf, NULL, _FDEV_SETUP_WRITE);
void uart_init(unsigned int baud)
{
stdout = &stream;
stdout = &stream;
/* Set baud rate */
UBRR1H = (unsigned char)(baud>>8);
UBRR1L = (unsigned char)baud;
@ -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;
}