Joe G
Member
I have been learning to use the uart to bluetooth to turn an led on/ off for now, I had it working on a 44pin p18f45k20 demo brd. I have tranferd the code to a Pic18f46k80 but I am missing or incorrectly adjusted it?? It's not recieving anything, I just can't figure out what I'm missing? any help or guidance would be appreciated. I can still connect to the RN42 module with teraterm and configure it but can't seem to get the pic to hear it?
Code:
void setupuart() // ==========================================================================
{
LATEbits.LATE1=1;
// OSCCON = 0b01010010; //4meg
// PIC18F46K80
SPBRGH1 = 1;
SPBRG1 = 25; // 4mhz@9600bps
BAUDCON1bits.BRG16 = 1;
TRISC = 0b11000000; // RC6/TX/CK, RC7/RX/DT
TXSTA1=0b00100100;
ZeroRegs();
RCSTA1=0b10010000; // bit7 spen enables the EUSART1
// bit2 = set = Framing error (can be cleared by reading the RCREGx register and receiving next valid byte)
// bit1 = set = Overrun error (can be cleared by clearing bit, CREN)
RCSTA1bits.CREN = 1; // rec on
//TXSTA1bits.TXEN = 0; // tx off
if(PIR1bits.RC1IF==1) // set if full
{READ=RCREG1; //reading the RCREG
READ=RCREG1; //read the RCREG twice to make sure it's empty.
}
LATEbits.LATE1=0;
} // end of setupuart
// ++++++++++++++++++ uart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void bluetooth()
{
while(1)
{
while(PIR1bits.RC1IF==0)
{ } //RCIF interrupt flag bit will be set when a character is transferred
// clears when its read.
if(RCSTA1bits.FERR==1) // Read the RCSTA register to get the error flags
{
READ=RCREG1; //reading the RCREG
if(RCSTA1bits.FERR==1) // is it still set
RCSTA1bits.SPEN=0;
}
if(RCSTA1bits.OERR==1)
{RCSTA1bits.SPEN=0;
RCSTA1bits.CREN = 0; // rec back off
}
Delay10TCYx(1);
RCSTA1bits.SPEN=1;
RCSTA1bits.CREN = 1; // rec back on
READ=RCREG1; //reading the RCREG ASCII
LATCbits.LATC0=0;
if(READ==0x31) // 1
{
LATEbits.LATE1=1;
LATCbits.LATC0=1;
/* LATD = 0xff;
n = 0x59; // y FOR YES
write ();
n = 0x45; // e FOR YES
write ();
n = 0x53; // s FOR YES
write ();
n = 0x3A;
write ();
n = 0x29;
write ();
n = 0x20; // space
write ();
*/
}
else if(READ==0x30) // 0
{
/*LATD = 0b01001000;
n= 0x4F; // off
write ();
n= 0x46;
write ();
write ();
n = 0x20; // space
write ();
*/
LATEbits.LATE1=0;
LATCbits.LATC0=0;
}
else
{
LATCbits.LATC0=1;
/*
LATD=0b00000001;
n = 0x45; // ? FOR ERROR
write ();
n = 0x52; // ? FOR ERROR
write ();
write ();
n = 0x4F; // ? FOR ERROR
write ();
n = 0x52; // ? FOR ERROR
write ();
n = 0x3f; // ? FOR ERROR
write ();
n = 0x20; // space
write ();
*/
}
}
}
Last edited by a moderator: