Why this code didn`t work?
I don't know what the problem is. Everything looks like it's in place. I want the LED to light up when I enter zero in the terminal. The terminal is a samsung phone and bluetooth HC-05. Everything about the hardware is fine.
#define F_CPU 8000000UL // 8 MHz
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
volatile char odb_dane;
volatile char odb_flaga = 0;
void USART_Init(unsigned int ubrr) {
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = (1<<URSEL)|(3<<UCSZ0);
}
void USART_RX_init(void) {
UCSRB |= (1 << RXCIE); // Włącz przerwania
sei(); // Włącz globalne przerwania
}
ISR(USART_RXC_vect) {
odb_dane = UDR;
if(odb_dane == '0') {
odb_flaga = 1;
}
else {
odb_flaga = 0;
}
}
void LED_init(void) {
DDRC |= (1 << PC4); // Ustaw pin PC4 jako wyjście
}
int main(void) {
USART_Init(MYUBRR);
USART_RX_init();
DDRC |= (1<<PC4); // Ustaw PB5 jako wyjście
// Inne inicjalizacje...
while(1) {
if(odb_flaga) {
PORTC |= (1 << PC4); // Włącz diodę LED
}
else {
PORTC &= ~(1 << PC4); // Wyłącz diodę LED
}
}
return 0;
}
I want the Led to light up when I send a 0 from the terminal.