HC-06 Bluetooth with PIC16F88 need help

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
edhnaw
Posts: 1
Joined: Fri Jan 06, 2017 8:21 am

HC-06 Bluetooth with PIC16F88 need help

Post by edhnaw »

Using:
-HC-06 as bluetooth module
-PIC16F88
-XC8 as compiler
-Android Application "Bluetooth Terminal" ( installed it to my Android Smartphone)

Hello people, I bought a HC-06 module and have been working on it for three days.
I have done quite a lot of research ( I really did) and managed to operate it by reading the Datasheet for PIC16F877A.
However, I am experiencing problems with PIC16F88 and I really, really need some help. I will be grateful if anyone could help.

I have written explanations for all of the functions that I have used to make it easier for you.

I am sending the code that I have written below. It does not work. Can someone please tell me what is wrong..?

Thank you in advance..


#include <xc.h>
// CONFIG1
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB0 // CCP1 Pin Selection bit (CCP1 function on RB0)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// CONFIG2
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode disabled)

#define _XTAL_FREQ 4000000

void generateLight(unsigned short counter); // indication for my led function

void main ()
{
unsigned short SerialResult; // this will contain the serial result

OSCCON=0b01101110; // 4mhz

TRISB= 0b00100100; // Rx and Tx are inputs

TXSTAbits.BRGH = 1; // high speed baud rate generator will be used

SPBRG = 25; // Setting the baud rate to approximately 9600

TXSTAbits.SYNC = 0; // asynchronous mode selected

RCSTAbits.SPEN = 1; //serial port enabled

RCSTAbits.CREN = 1; //continious receive enabled

while(1)
{
__delay_us(5); // waiting for pic to settle
while (PIR1bits.RCIF == 0) // waiting for serial to be completed
{
__delay_us(1);
}
SerialResult = RCREG; // reading the RCREG
generateLight(SerialResult); // lighting LEDs accordingly
}
}

void generatelight(unsigned short bluetooth)
{
if(bluetooth == 0x01) // set RB0 when read 1
{
RB0=1;
RB1=0;
}
else if (bluetooth == 0x00) // turn off all LEDs when read 0
{
RB0=0;
RB1=0;
}
else if (bluetooth == 0x02) // turn on all LEDs when read 2
{
RB1=1;
RB0=1;
}
}

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: HC-06 Bluetooth with PIC16F88 need help

Post by Benj »

Hello,

Have you tried doing some basic tests on the 16F88. For example a 1 second LED flash test and an output BAUD rate test to check the device is running and at the right frequency?

http://www.matrixtsl.com/wikiv7/index.p ... ED_flasher

Post Reply