336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


bt2stick_examples.zip

PIC16F887 Based






Master Code

/*

 * Project name:

     Master;

 * Copyright:

     (c) MikroElektronika, 2005-2011.

  * Revision History:

     20110426:

       - initial release (SZ);

 * Description:

     This is a simple project which demonstrates the use of the BlueTooth Stick2 module.

     After establishing the connection Master repeatedly sends two strings ("mikroE" and "BlueTooth Stick2")

     to the Slave. The Slave receives them and displays them at the 2x16 COG LCD.

 * Test configuration:

     MCU:             PIC16F887

                      http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf#page=123

     Dev.Board:       EasyPIC6

                      http://www.mikroe.com/eng/products/view/297/easypic6-development-system/

     Oscillator:      HS, 8.00000 MHz

     Ext. Modules:    BlueTooth Stick2 at PORTC

                      ac:BlueTooth_Stick2_Board

                      http://www.mikroe.com/eng/products/view/680/bluetooth-2-stick/

     SW:              mikroC PRO for PIC

                      http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/

 * NOTES:

  - BlueTooth Stick2: Connect only Vcc, Gnd, Rx and Tx lines. You could use our Wire Jumpers:

    http://www.mikroe.com/eng/products/view/495/wire-jumpers/

    Also, 5V-3.3V Voltage Translator Board is required:

    http://www.mikroe.com/eng/products/view/182/5v-3-3v-voltage-translator-board/

  - Note that BlueGiga WT41 has default baudrate 115200bps and that you need to change the

    its firmware in order to run this example at 19200bps. Find out more here: http://www.bluegiga.com

  - Turn on both modules at the same time and wait for about one minute until the

    connection between the Master and the Slave establishes.

*/


void Wait()        //Wait 메소드

{

Delay_ms(1000);

}


void Wait2()    //Wait2 메소드

{

char i;

for(i = 0; i < 30; i++) Delay_ms(1000);

}


void main() 

{

     // All pins as digital I/Os

      ANSEL  = 0;

      ANSELH = 0;

      C1ON_bit = 0;                                 // Disable comparators

      C2ON_bit = 0;


      UART1_Init(19200);                            // Initialize UART1 module

      Wait(); Wait(); Wait();


      UART1_Write_Text("SET RESET");                // The SET RESET command returns the       factory settings of the module  

      UART1_Write(0x0D);                            // CR  

      Wait();

  

      UART1_Write_Text("SET BT PAIR *");            

// If command SET BT PAIR * is given, all pairings will be removed                  

      UART1_Write(0x0D);                            // CR  

      Wait();

  

  UART1_Write_Text("RESET");    // Command RESET is used to perform a software reset  

  UART1_Write(0x0D);                            // CR  

  Wait();

 

// The CALL command is used to initiate Bluetooth connections to the remote devices

// Instead of xx:xx:xx:xx:xx:xx enter real MAC address of the BT module you want to call                 

  UART1_Write_Text("CALL xx:xx:xx:xx:xx:xx 1 RFCOMM");  

  UART1_Write(0x0D);                            // CR  

  Wait2();



  while (1) {

    UART1_Write_Text("mikroE");                 // Sending Data to Slave module

    UART1_Write(13);                            // CR

    Wait();

    UART1_Write_Text("BlueTooth Stick2");       // Data

    UART1_Write(13);                            // CR

    Wait();

  }

}


/*

 * Project name:

     Slave;

 * Copyright:

     (c) MikroElektronika, 2005-2011.

  * Revision History:

     20110426:

       - initial release (SZ);

 * Description:

     This is a simple project which demonstrates the use of the BlueTooth Stick2 module.

     After establishing the connection Master repeatedly sends two strings ("mikroE" and "BlueTooth Stick2")

     to the Slave. The Slave receives them and displays them at the 2x16 LCD.

 * Test configuration:

     MCU:             PIC16F887

                      http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf#page=123

     Dev.Board:       EasyPIC6

                      http://www.mikroe.com/eng/products/view/297/easypic6-development-system/

     Oscillator:      HS, 8.00000 MHz

     Ext. Modules:    BlueTooth Stick2 at PORTC

                      ac:BlueTooth_Stick2_Board

                      http://www.mikroe.com/eng/products/view/680/bluetooth-2-stick/

     SW:              mikroC PRO for PIC

                      http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/

 * NOTES:

  - BlueTooth Stick2: Connect only Vcc, Gnd, Rx and Tx lines. You could use our Wire Jumpers:

    http://www.mikroe.com/eng/products/view/495/wire-jumpers/

    Also, 5V-3.3V Voltage Translator Board is required:

    http://www.mikroe.com/eng/products/view/182/5v-3-3v-voltage-translator-board/

  - Note that BlueGiga WT41 has default baudrate 115200bps and that you need to change the

    its firmware in order to run this example at 19200bps. Find out more here: http://www.bluegiga.com

  - Turn on both modules at the same time and wait for about one minute until the

    connection between the Master and the Slave establishes.

  - Turn ON the Lcd Backlight.

*/


// LCD module connections

sbit LCD_RS at RB4_bit;

sbit LCD_EN at RB5_bit;

sbit LCD_D4 at RB0_bit;

sbit LCD_D5 at RB1_bit;

sbit LCD_D6 at RB2_bit;

sbit LCD_D7 at RB3_bit;


sbit LCD_RS_Direction at TRISB4_bit;

sbit LCD_EN_Direction at TRISB5_bit;

sbit LCD_D4_Direction at TRISB0_bit;

sbit LCD_D5_Direction at TRISB1_bit;

sbit LCD_D6_Direction at TRISB2_bit;

sbit LCD_D7_Direction at TRISB3_bit;

// End LCD module connections


char txt[17];

unsigned short i, tmp, DataReady;



// Uart Rx interrupt handler

void interrupt(){


  if (PIR1.RCIF == 1) {                         // Do we have uart rx interrupt request?

    tmp = UART1_Read();                         // Get received byte


       if (tmp == 13) {

         txt[i] = 0;                            // Puting 0 at the end of the string

         DataReady = 1;                         // Data is received

                   }

     else {

      txt[i] = tmp;                             // Moving the data received from UART to string txt[]

      i++;

     }

   PIR1.RCIF = 0;

   }


}


void Wait(){

Delay_ms(1000);

}


void main() {

  ANSEL  = 0;                                   // Configure AN pins as digital I/O

  ANSELH = 0;

  C1ON_bit = 0;                                 // Disable comparators

  C2ON_bit = 0;


  UART1_Init(19200);                            // Initialize UART1 module

  Wait();


  LCD_Init();                                   // LCD Init

  LCD_Cmd(_LCD_CLEAR);

  Lcd_Cmd(_LCD_CURSOR_OFF);


  Lcd_Out(1,1,"Connecting!");

  Lcd_Out(2,1,"Please, wait...");

  

  UART1_Write_Text("SET RESET");                // The SET RESET command returns the factory settings of the module    

  UART1_Write(0x0D);                            // CR  

  Wait();

  

  UART1_Write_Text("SET BT PAIR *");            // If command 밪ET BT PAIR *?is given, all pairings will be removed      

  UART1_Write(0x0D);                            // CR  

  Wait();

  

  UART1_Write_Text("RESET");                    // Command RESET is used to perform a software reset                  

  UART1_Write(0x0D);                            // CR  

  Wait();

 

  UART1_Write_Text("SET BT AUTH *");            // PIN code will be disabled and no encryption can be used during BT connections      

  UART1_Write(0x0D);                            // CR  

  Wait();

  Wait();

  Wait();  

  Wait(); 


  LCD_Cmd(_LCD_CLEAR);

  Lcd_Out(1,1,"Connected!");

  DataReady = 0;

  // setup interrupts

  PIE1.RCIE   = 1;

  INTCON.PEIE = 1;

  INTCON.GIE  = 0;

  Wait();


  LCD_Cmd(_LCD_CLEAR);                          // Clear display

  Lcd_Out(1,1,"Receiving...");

  Wait();

  

  while (1) {

    tmp = 0;                                    // Init variables

    i = 0;

    memset(txt, 0, 17);                         // Clear array of chars


    INTCON.GIE  = 1;                            // Interrupts allowed


    while (!DataReady) {                        // Wait while the data is received

        ;

    }


    INTCON.GIE  = 0;                            // Interrupts forbiden

    DataReady = 0;


    LCD_Cmd(_LCD_CLEAR);                        // Clear display

    Lcd_Out(1,1,"Received:");

    Lcd_Cmd(_LCD_SECOND_ROW);

    i = 0;

    while (txt[i] != 0){


       Lcd_Chr_CP(txt[i]);                      // Displaying the received text on the LCD

       i++;                                     

    }                                           


  }

}

Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백