Bluetooth Interfacing with 8051
What is Bluetooth?
Bluetooth is a standardized protocol for sending and receiving data via a 2.4GHz wireless link.
It's a secure protocol, and it's perfect for short-range, Low-cost, Low-power, wireless transmission between electronic devices.
Image of Bluetooth(HC-05 module):-
Pin 1. Vcc:- It is connected to the 5v pin.
Pin 2. GND:- It is connected to the ground pin.
Pin 4. RX:- It is used to receive the serial data and is connected to the TX pin of the 8051 Microcontroller.
Task 1: To display a message on a Serial monitor using Bluetooth.
Code:-
#include<reg51.h>
void uart_begin();
void transfer(unsigned char a);
unsigned char receive();
void recstr(unsigned char d[]);
void str(unsigned char b[]);
void main()
{
uart_begin();
transfer(receive());
while(1);
}
void uart_begin()
{
SCON=0x50;//usingg mode1 and enable port to high to receive dataa
TMOD=0x20;//to turn on timer 1 and mode2
TH1=0xFD;//baud rate 9600
TR1=1;// turn on timer1
}
void transfer(unsigned char a)
{
SBUF=a;// store the character in empty registerr
while(TI==0);//wait till flag turns to 1
TI=0;// clear again
}
unsigned char receive()
{
while(RI==0);
RI=0;
return SBUF;
}
void str(unsigned char b[])
{
unsigned int i;
for (i=0;b[i]!='\0';i++)
{
transfer(b[i]);
}
}
0 Comments