How to Interface Bluetooth with 8051

Interfacing Bluetooth With 8051

Tags: Circuit diagram to interface Bluetooth with 8051,c source code to transmit data from 8051 using Bluetooth, Bluetooth c source code,Interfacing Bluetooth with 8051,8051 interfacing bluetooth,,
Overall rating
bluetooth-with-8051
8051 Primer Board

The 8051 Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.


NXP’s 8051 (89V51RD2), 8051 Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.


Bluetooth

Bluetooth is a proprietary open wireless technology standard for exchanging data over short distances from fixed and mobile devices, creating personal area networks (PANs) with high levels of security. Bluetooth technology allows electronic devices to communicate wirelessly.


Interfacing Bluetooth

Fig. 1 shows how to interface the Bluetooth with microcontroller. Bluetooth technology handles the wireless part of the communication channel; it transmits and receives data wirelessly between these devices. It delivers the received data and receives the data to be transmitted to and from a host system through a host controller interface (HCI). The most popular host controller interface today is either a UART or a USB. Here, I will only focus on the UART interface; it can be easily show how a Bluetooth module can be integrated on to a host system through a UART connection.


block-diagram-for-bluetooth-interfacing

Fig. 1 Interfacing Bluetooth to Microcontroller


Interfacing Bluetooth with 8051

Transmit & receive the data from host system to 8051 Primer Board by using Bluetooth module through UART0. The serial data is taken from or sent to the host system by using Bluetooth module through MAX232 into the SBUF register of 8051 microcontroller (refer serial interfacing with 8051). The serial data from the host device is taken by using the Serial Interrupt of the 8051 controller. The UART0 pin lines are used to transmit & receive operations in 8051 Primer Board.


Pin Assignment with 8051

 

UART DB-9 Connector

           8051

Lines

Serial Port Section

UART0(P1)

ISP PGM

TXD-0

P3.0

 

serial-port-section-8051

RXD-0

P3.1

UART1

(P2)

TXD-1

P1.2

RXD-1

P1.3


 
Circuit Diagram to Interface Bluetooth with 8051

circuit-diagram-to-interface-bluetooth-with-8051-accessory
 
Source Code

The Interfacing Bluetooth module with 8051 program is very simple and straight forward, which send a message to mobiles from 8051 Primer Board through Bluetooth module by using UART0. Some delay is occurring when a single data is sent to mobile through UART. C programs are written in Keil software. The baud rate of microcontroller is 9600.


C Program to transmit or receive data in 8051

 

#include<reg51.h>              //Define 8051 Registers

 

void serial(void);             //Serial Communication Register

void DelayMs(unsigned int);    //Delay Function

 

unsigned int i,j;

unsigned char b[25],d;

 

//---------------------------

//           Main Program

//---------------------------

void main()

{

    EA=1;                          //Enable All Interrupt

    ES=1;                          //Enable Serial Port Interrupt

    serial();                      //Serial Communication

         while(1);                 //Loop Forever

}

 

//-------------------------------------------

//       Serial Communication Register Initialisation

//-------------------------------------------

void serial(void)

{

    TMOD=0X20;                //Timer1, Mode2

    SCON=0X50;                //Serial Mode1, Receive Enable

    TH1=0XFD;                 //Baud Rate 9600bps

    TR1=1;                    //Timer1 ON

}

 

 

 

 

 

//-----------------------------------------

//       Serial Interrupt Function

//-----------------------------------------

void serin (void) interrupt 4      //Serial Port Interrupt

{

    if(RI==1)                      //Receive Interrupt Gets

    {                              //after Stop Bit get Received

         d=SBUF;                   //Serial Buffer value moved

         b[j]=d;                                                     

         SBUF=b[j];

         DelayMs(20);                   //Delay Function

         j++;

    }

    SCON=0X50;                     //Initialising Receive and

}

 

 

//---------------------------------

//               Delay Function

//---------------------------------

void DelayMs(unsigned int k)

{

    unsigned int i;

    for(i=0;i<=k;i++);

}        

 


To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.


In Keil, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without 8051 Primer Board.


The Flash Magic software is used to download the hex file into your microcontroller IC 8051 through UART0.


Testing the Bluetooth with 8051

Give +5V power supply to 8051 Primer Board; connect the 5V adapter with Bluetooth module which is connected with the 8051 Primer Board. There are two Bluetooth modules are required. One is connected with 8051 Primer Board; other one is connected with PC.


First connect the serial cable between 8051 Primer board & PC. Then open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show some text messages.


If the messages are correctly displayed in Hyper Terminal, then only connect the Bluetooth modules in 8051 Primer Board UART0 & PC.


If you are not reading any data from UART0, then you just check the jumper connections & just check the serial cable is working. Otherwise you just check the code with debugging mode in Keil. If you want to see more details about debugging just see the videos in below link.



General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,
       - User Manual of 8051 Primer Board.
       - Tutorial of how to create & Debug a project in KEIL.
       - Interfacing UART with 8051.

Join the World's Largest Technical Community

we respect your privacy.