Hi everyone, literally my last resort after doing all the research I can, I'm not getting anywhere.
Basically I want to send a byte of data from my Android phone to a bluetooth module HC-05 and then mirror the image to PORTB of the PIC16F877A where I have connected a row of LED's for visual feedback. Now, I have written the code numerous times but with no luck. What I'm getting is completely wrong for what I'm sending to the HC-05 module.
I believe I'm going wrong with the Baud rate/Clock speed. I'm using an external xtal capable of 20MHz but coded for 4MHz.
The standard output of the HC-05 is 9600 Baud and to match this on the Microcontroller I've set BRGH to 0 and SPBRG to 6 but still not getting the correct output. Even switching BRGH to 1 and setting SPBRG to 25 still gives the incorrect output! Im getting the LED's to illuminate but not from the byte of for example say "11111111" it would show "00001111" even in debug mode it's showing on RCREG window it's receiving "00001111" and then sending this to PORTB.
Has anyone got a "generic" code for this set up that they know works? Or point me in the right direction of where I'm goign wrong? I have this example code pulled from the net which should work in theory, but doesnt.
Basically I want to send a byte of data from my Android phone to a bluetooth module HC-05 and then mirror the image to PORTB of the PIC16F877A where I have connected a row of LED's for visual feedback. Now, I have written the code numerous times but with no luck. What I'm getting is completely wrong for what I'm sending to the HC-05 module.
I believe I'm going wrong with the Baud rate/Clock speed. I'm using an external xtal capable of 20MHz but coded for 4MHz.
The standard output of the HC-05 is 9600 Baud and to match this on the Microcontroller I've set BRGH to 0 and SPBRG to 6 but still not getting the correct output. Even switching BRGH to 1 and setting SPBRG to 25 still gives the incorrect output! Im getting the LED's to illuminate but not from the byte of for example say "11111111" it would show "00001111" even in debug mode it's showing on RCREG window it's receiving "00001111" and then sending this to PORTB.
Has anyone got a "generic" code for this set up that they know works? Or point me in the right direction of where I'm goign wrong? I have this example code pulled from the net which should work in theory, but doesnt.
Code:
void main()
{
int i;
TRISB = 0x00;
PORTB = 0x00;
SPBRG = 6; //Baud rate formula gives 6 as BRGH is 0
TXSTA = 0b00100010;
RCSTA = 0b10010000;
RCIE = 1; //Receive Interrupt enable
do
{
TXREG++;
while (!TRMT);
while (!RCIF);
PORTB = RCREG;
for (i=0;i<300;i++); //delay in order to view
}
while(1);
}