I am trying to connect my HC-05 bluetooth module with PIC16F877A. I know we have to use USART to talk with bluetooth module. So I started with USART of PIC by reading its datasheet.

I am using MPLABX IDE with XC8 compiler and i am not interested in using any libraries.

#pragma config FOSC = HS       // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#define _XTAL_FREQ 20000000

void main(void)

unsigned int i;

TXSTA=0X20; // TX RS232 settings
RCSTA=0X80; // RX RS232 Settings
SPBRG=31; // Baud rate is set based on Crystal clock

TXSTAbits.TXEN=1; // Enable RS232 transmission
RCSTAbits.SPEN=1; // Enable RS232 reception


TXREG= 65;


I used the above code to send a char 'A' from PIC to USART and was successful in reading it using my serial monitor on PC (with RS232).

Now form what I understood, if I replace the RS232 with my bluetooth module I should get the same char 'A' transmitted to my mobile phone.

I am using Bluetooth Terminal android app to check the reception of data. But the after the app connects to the module it just shows a blank screen. I dont receive anything.

What could be the reason please help me!!!!!!.

Things that I tried :

  1. There is no problem with the baud-rate, both my Rs232 and HC-05 works at 9600. I have ensured the same using my arduino and HC-05.

  2. there is no logic level problem I have used a potential divider to shift 5V to 3.3V.

I am quite new here so forgive me if my question is not that appropriate.


1 Answer 1


Hi guys I finally made a full working program for interfacing PIC with HC-05. The complete details can be found here: https://circuitdigest.com/microcontroller-projects/bluetooth-interfacing-with-pic-microcontroller

  • 1
    \$\begingroup\$ It's better to include code into your answer instead of referring to some external page. And include explanation what fixed your problem. \$\endgroup\$ Jul 26, 2017 at 4:47
  • \$\begingroup\$ Why is that? Why should I create a duplicate when I have already posted the details there? NO OFFENCE!! Just curious to know. \$\endgroup\$ Jul 27, 2017 at 5:04
  • \$\begingroup\$ electronics.stackexchange.com/help/how-to-answer \$\endgroup\$ Jul 27, 2017 at 7:10
  • \$\begingroup\$ Good answer = you explain solution to the problem in this answer. Bad answer = link to another site where is the answer. \$\endgroup\$ Jul 27, 2017 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.