BLUETOOTH characteristics
- Bluetooth v2.1 + EDR Compatible
- 2.4GHz Class 2 Radio
- Range Exceeds 20m
- High Speed Data Rate Up To 3Mbps
- 12 Programmable Digital I/O Pins
- 2 Programmable Analog I/O Pins
- UART and USB Interfaces
- Onboard Antenna
- 8Mbit Flash Memory
- CSR BlueCore™ 4 Ext Chipset
The circuit is:
The 3D representation
The code:
Important points:#include <30F3012.h>#FUSES HS2_PLL8//The xtal freq is divided by 2 and multiplied by 8 (maximum using 20MHz xtal)
#FUSES NOWDT // NO Watch Dog Timer
#FUSES PR_PLL //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#use delay(clock=80000000)// 20MHz/2*8=80MHz=80000000#use rs232(baud=115200, UART1) //Set UART speed in 115.2kbps using the UART1
void wait() //Subroutine to wait for 2ms or until a character is received{int countdown; //Define a variable to coutndowncountdown=200; //Charge value to 200 times 10us
while((--countdown!=0)&&!kbhit()) //kbhit returns true when rs232 receives a characterdelay_us(10); //do a delay of 10us
}void main() //Main program{char pos; //Define the variable to receive the characterset_tris_b(0); //Define PORTB as output
pos='0'; //Charge an initial value to the variable
while(TRUE) //Do a loop{if((pos=='A'))//If the received character is an "A"output_high(PIN_B0); //Turn on the whole PORTB
else if ((pos=='X'))output_low(PIN_B0); //Turn on the whole PORTB
else //otherwiseoutput_high(PIN_B1); //Turn off the more significant bits
wait(); //Wait for visualization or another character
if(kbhit()) //If a character is received{pos=getc(); //Save the received character in the 'pos' variable
}}}
- Is important to use the PLL in order to achieve large clock frequency, otherwise, the compiler sends an error if you want baud rate higher than 38400 bps.
- The Bluetooth module is basically a serial port. The only difference is that you have to make the link to the PC before you can use it. After the connection, the module is view as any other port in the PC and can be accessed by a simple terminal.
The code is written in C for the CCS compiler (NOT the mikroC).
No comments:
Post a Comment