-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBluetooth.c
More file actions
63 lines (50 loc) · 1.02 KB
/
Bluetooth.c
File metadata and controls
63 lines (50 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Bluetooth.c
*
* Created: 07-07-2022 21:48:50
* Author : hp
*/
#include <avr/io.h>
#define F_CPU 1000000UL /* Define frequency here its 1MHz */
void USART_Init( unsigned int baud )
{
/* Set baud rate */
UBRRH = (unsigned char)(baud>>8);
UBRRL = (unsigned char)baud;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
int main(void)
{
DDRB|=(1<<PB0);
USART_Init(25);
while (1)
{
if(USART_Receive()=='T')
{
PORTB|=(1<<PB0);
}
else if(USART_Receive()=='F')
{
PORTB&=~(1<<PB0);
}
}
}