Kod dla Atmega8A + HC-05 (Bluetooth)

Joined
Aug 22, 2023
Messages
2
Reaction score
0
#define F_CPU 1000000UL

#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>
#include <util/delay.h>
#define MYUBRR 11
#define BAUD 9600


volatile unsigned char odb_flaga = 0;


void USART_Init( unsigned int ubrr)
{




UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;

UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0)|(1<<USBS);

UCSRB = (1<<TXEN) | (1<<RXEN) | (1<<RXCIE);
odb_flaga = 1;

}



ISR(USART_RXC_vect){


}

ISR(USART_UDRE_vect){

UCSRB &= ~(1<<UDRIE);
}



void at_komenda_reakcja(unsigned char at_komenda_nr){


switch(at_komenda_nr){

case 0:

PORTC = 0x01;
_delay_ms(1000);
PORTC = 0x00;
_delay_ms(1000);
break;

case 1:

PORTC = 0x01;
_delay_ms(1000);
PORTC = 0x00;
_delay_ms(1000);
break;

}

}
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
void at_komenda_sprawdz(void){

USART_Receive();

at_komenda_reakcja(UDR);

}




int main(void)
{

DDRC = 0x01;
DDRD = 0x01;

USART_Init(MYUBRR);

sei();


while (1)
{


at_komenda_sprawdz();



}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top