Hi
BT HC06 connected to my pic.
When i enable either RCIE or TXIE the program execution stops.
I think it has something to do with the "SYNC" Problem ??
Datasheet says SYNC, the 16f18877.h files also say SYNC is a valid word,
but Mplab X says Unable to resolve identifier SYNC
BT Modul is connected by a 3.3 to 5v inverter.
Can easy connect phone to BT modul
BT HC06 connected to my pic.
When i enable either RCIE or TXIE the program execution stops.
C:
//
#include "lcd.c"
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma config FEXTOSC = LP //XT // External Oscillator mode selection bits (XT (crystal oscillator) above 500kHz, below 4MHz; PFM set to medium power)
#pragma config RSTOSC = HFINT32 // Power-up default value for COSC bits (HFINTOSC with OSCFRQ= 32 MHz and CDIV = 1:1)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = OFF // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed by user software)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
#pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master Clear function)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF // WDT operating mode (WDT enabled regardless of sleep; SWDTEN ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC // WDT input clock selector (Software Control)
#pragma config WRT = OFF // UserNVM self-write protection bits (Write protection off)
#pragma config SCANE = available// Scanner Enable bit (Scanner module is available for use)
#pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)
#pragma config CP = OFF // UserNVM Program memory code protection bit (Program Memory code protection disabled)
#pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code protection disabled)
#define _XTAL_FREQ 8000000
#define FOSC 2000000L
#define back_light RB0
#define led1_on RE0
#define KN1 RC3
#define KN2 RC2
#define KN3 RA7
#define KN4 RA6
#define Skip_ROM 0xCC
#define Convert_T 0x44
#define Read_scratchpad 0xBE
#define Port_18B20 RB5
#define Tx_18B20 TRISB5 = 0
#define Rx_18B20 TRISB5 = 1
#define WAIT1 1000
#define WAIT2 500
#define DS18B20_CONV_TIME 750
#define DS18B20_RESET_PULSE 480
#define DS18B20_WAIT_TIME 60
#define DS18B20_PULLUP_TIME 2
#define ONEWIRE_PRESENT 0
#define ONEWIRE_ABSENT 1
bit modtaget,data_tick,sekund;
int get_value,data_inde;
static void interrupt isr(void) // Here is interrupt function - the name is unimportant.
{
if(TMR1IF) // Was this a timer overflow?
{
TMR1IF=0; // Clear interrupt flag, ready for next // timer run to 65k, gives 2 sec interrupt
//TMR1L=0x00; // overflow every 2 seconds. to prevent to much interrupt.
//TMR1H=0x80; // If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second
sekund=1;
}
}
void setup(void)
{
COSC0=0;
COSC1=0;
COSC2=1; // use second oss.
HFFRQ0=1;
HFFRQ1=1;
HFFRQ2=0; // 8 mhz
TRISA0=1; // NU
TRISA1=1; // NU
TRISA2=1; // NU
TRISA3=1; // NU
TRISA4=1; // input to timer
TRISA5=1; // NU
TRISA6=1; // Button 1
TRISA7=1; // Button 2
TRISB0=0; // Backlight on/off
TRISB1=0; // not used
TRISB2=0; // not used
TRISB3=0; // RS
TRISB4=0; // not used
TRISB5=1;// CHANGE temp reading DS18B20
TRISB6=1; // program
TRISB7=1; // program
TRISC0=1; // Xtal
TRISC1=1; // Xtal.
TRISC2=1; // button 3
TRISC3=1; // button 4
TRISC4=1; // not used
TRISC5=1; // not used
//TRISC6=0; //send data
//TRISC7=1; // recieve data
TRISD0=0; // DATA6
TRISD1=0; // DATA7
TRISD2=0; // DATA5
TRISD3=0; // DATA4
TRISD4=0; // NU
TRISD5=0; // NU
TRISD6=0; // NU
TRISD7=0; // ENABLE LCD
TRISE0=0; // LED Out
TRISE1=1;
TRISE2=1;
//TRISE3=1; // allways input RESET
/*IOCAN2=1; // negativ interrupt A2*/
//IOCAP3=1; // positiv interrupt A3 knap 4*/
//IOCAP4=1; // interrupt on pin RA4 positive = rain income
//IOCCP3=1; // interrupt on pin RC3 positive= knap 1
ANSELA=0b00000000; // set alle digital.
ANSELB=0b00000000;
ANSELC=0b00000000;
ANSELD=0b00000000;
ANSELE=0b0000;
//timer 1 setup
T1CS0=0; // 0110 = SOCS
T1CS1=1;
T1CS2=1;
T1CS3=0;
T1CKPS0=0; // no prescale
T1CKPS1=0;
nT1SYNC=1; // no sync
lcd_init(); //lcd's init
lcd_goto(0);
}
//Function to get a char from Rx.buffer of BT//
char BT_get_char(void)
{
if(OERR) // check for over run error
{
CREN = 0;
CREN = 1; //Reset CREN
}
if(RCIF==1) //if the user has sent a char return the char (ASCII value)
{
while(!RCIF);
return RCREG;
}
else //if user has sent no message return 0
return 0;
}
//End of function/
//Function to broadcast data from RX. buffer//
void broadcast_BT()
{
TXREG = 13;
__delay_ms(500);
}
//End of function//
//Function to load the Bluetooth Rx. buffer with one char.//
void BT_load_char(char byte)
{
TXREG = byte;
while(!TXIF);
while(!TRMT);
}
//End of function//
//Function to Load Bluetooth Rx. buffer with string//
void BT_load_string(char* string)
{
while(*string)
BT_load_char(*string++);
}
//End of function/
//******Initialize Bluetooth using USART********//
void Initialize_Bluetooth()
{
//Set the pins of RX and TX//
TRISC6=1;
TRISC7=1;
//Set the baud rate using the look up table in datasheet(pg114)//
BRGH=1; //Always use high speed baud rate with Bluetooth else it wont work
SPBRG=12;//129; // baudrate 9615
//Turn on Asyc. Serial Port//
CREN=1;
[B][SIZE=7]// SYNC=0; // not possible to use[/SIZE][/B]
SPEN=1;
//Set 8-bit reception and transmission
RX9=0;
TX9=0;
//Enable transmission and reception//
TXEN=1;
CREN=1;
//Enable global and ph. interrupts//
// GIE = 1;
/// PEIE= 1;
//Enable interrupts for Tx. and Rx.//
// RCIE=1;
//TXIE=1;
}
//___________BT initialized_____________//
void main (void)
{
setup();
Initialize_Bluetooth(); //lets get our bluetooth ready for action
// IOCAF4=0;
lcd_clear();
lcd_goto(0x00);
back_light=1; // turn on light in LCD
lcd_puts("Line 1 : Hello");
lcd_goto(0x40);
lcd_puts("Line 2 : Denmark!");
lcd_goto(0x14);
lcd_puts("Line 3 : World");
lcd_goto(0x54);
lcd_puts("Line 4 : Goodbye!");
RE0=1;
T1RD16=0; // turn on timer1 16 bit read write
TMR1ON=1; // turn on timer1
T1GE=0; // gate allways count
// IOCIE=1; // enable IOC
TMR1IE=1; // enable interrupr for timer1
GIE=1; // enable global interrupr
PEIE=1; // enable interrupr
__delay_ms(500); // delay
RCIF=0;
RCREG=0;
[B][SIZE=7] // RCIE=1; // interrupt for Recieving enabled , gives program stop[/SIZE][/B]
while (1)
{
if (sekund==1)
{ sekund=0;
(led1_on=!led1_on);
}
if (!KN1)
{
lcd_clear();
[B][SIZE=7]TXIE=1; // if enabled, program stops[/SIZE][/B]
BT_load_string("Bluetooth Initialized and Ready");
broadcast_BT();
BT_load_string("Press 1 to turn ON LED");
broadcast_BT();
BT_load_string("Press 0 to turn OFF LED");
broadcast_BT();
}
get_value=BT_get_char(); //Read the char. received via BT
//If we receive a '0'//
if (get_value=='0')
{
RE0=0;
BT_load_string("LED turned OFF");
broadcast_BT();
}
//If we receive a '1'//
if (get_value=='1')
{
RE0=1;
BT_load_string("LED turned ON");
broadcast_BT();
}
}
}
Datasheet says SYNC, the 16f18877.h files also say SYNC is a valid word,
but Mplab X says Unable to resolve identifier SYNC
BT Modul is connected by a 3.3 to 5v inverter.
Can easy connect phone to BT modul
