Discussion in "8051 Discussion Forum" started by    Peter_Parker    Jul 26, 2014.
Sat Jul 26 2014, 07:59 pm
#1
Hey guys,
Tried using the search button to look for Bluetooth topics but the search function on the site doesn't seem to be working for me for some reason.
Anyway I have a HC-06 Bluetooth module,I put it on a breadboard,powered it up,paired it with my pc.Then I used Teraterm to open a connection to it,which it did(the red light stayed continuously on),entered in the command “AT” but I got no response back.
I presume this has something to do with the HC-06 being a slave only module and it has to be connected to a micro in order to view data on the hyperterminal.
So my query is can anyone direct to where I might view some example code which I could load onto a 8051 mirco(something that would send a word or number to the bluetooth) and then I could view the word/micro on the hyperterminal
thanks
Mon Jul 28 2014, 10:02 am
#2
HC-06 module is nothing but a serial connection over bluetooth. You do not need to send any command to this module. Once paired it will create a transparent channel between controller and other paired device (e.g. PC). So if you are sending something over bluetooth it will go directly to controller not module, same is the case if controller send something to module it will be sent to paired device directly.
Tue Jul 29 2014, 08:47 am
#3

Link the tx and rx pins on HC06, everything you send should be echoed back.
If it is not try all the possible baud rates.
Thu Jul 31 2014, 12:08 am
#4
@ Peter_Parker
HC06 by default baud rate is 9600
try the ExperimenterUK trick hope so it should be work
if not then use a max232 to get its output on another pc or laptop
Fri Aug 01 2014, 07:07 pm
#5
I linked the tx and rx pins,opened up the hyperterminal and whatever I typed appeared on the hyperterminal screen,so the echo test passed I think.

Would either of these work as testing codes to view output on hyperterminal?
https://www.pantechsolutions.net/microcontroller-boards/uart-interfacing-with-8051-primer
#include <REG51.H>
                /* special function register declarations   */ 
#include <stdio.h>
                /* prototype declarations for I/O functions */   
void serial_init(void); 
//------------------------------------------------- 
//Setup the serial port for 9600 baud at 11.0592MHz. 
//------------------------------------------------- 

void serial_init(void) 
{     
SCON  = 0x50;                         /* SCON: mode 1, 8-bit UART, enable rcvr         */     
TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload                    */     
TH1   = 0xFD;               /* TH1:  reload value for 9600 baud @ 11.0592MHz*/    
TR1   = 1;                  /* TR1:  timer 1 run                               */     
TI    = 1;                  /* TI:   set TI to send first char of UART           */ 
}  

 //-------------------------- 
//Main Program Starts Here
 //-------------------------- 

void main(void)
{             
serial_init();            
printf (" PS - PrimerC51 UART Demo\n\n\r");             
while (1)             
{             
printf ("Hello World!! \n\r");   /* Print "Hello World" */             
}         
}


https://www.pantechsolutions.net/project-kits/interfacing-bluetooth-with-8051-primer


[ Edited Sat Aug 02 2014, 07:23 am ]
Mon Aug 04 2014, 10:13 am
#6
Yes that would do or you can write even simpler code like this:

#include <REG51.H>
void main()
{
	TMOD = 0x20;
	SCON = 0x50;
	TH1 = 0xFD;
	TL1 = 0xFD;
	TR1 = 1;

	while (1) {
		SBUF = 'A';
		while (!TI);
		TI = 0;
	}
}
Thu Aug 07 2014, 07:31 pm
#7
Tried for ages to get either of the above codes working but was getting nothing back on the hyperterminal.Switched my 8051 chip for another one and then they both worked fine so I think my original chip might be fried.

Next step is to have a go with combining it with a sensor code(from another thread)
#include<reg51.h>

#include<string.h>
 

//heart beat monitor 8051 based
#define lcdport P1 // change for for hardware
sbit rw = P2^1; // LCD connection may be different
sbit rs=P2^0; // LCD interface with microcontroller
sbit en=P2^2; // Enable pin of LCD
unsigned char sec,sec100;
unsigned int bt,tick,r,bpm;
void lcdinit();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void send_string(unsigned char *s);
void msdelay(unsigned int);
void extrint (void) interrupt 0 // external Interrupt to detect the heart pulse
{
bt=tick; // number of ticks are picked
tick=0; // reset for next counting
}
void timer0 (void) interrupt 1 using 1 // Timer 0 for one second time
{
TH0 = 0xdc; //The value is taken for Ssc/100 at crystal 11.0592MHz
sec100++; // It is incremented every Ssc/100 at crystal 11.0592MHz
tick++; // This variable counts the time period of incoming pulse in Sec/100
if(tick>
=3500){tick=0;} // tick are limited to less trhan 255 for valid calculation
if(sec100 >
=100) // 1 sec = sec100 * 100
{
sec++;
sec100=0;
}
}
void main()
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
rw=0;
EA = 1;
TMOD = 0x21;
IT0 = 1;
EX0 = 1;
ET0 = 1;
TR0 = 1;
msdelay(1000);
lcdinit();
msdelay(1000);
send_string("Heart beat ");
msdelay(1500);
msdelay(500);
//delay(15000);
bpm=0;bt=0;
while(1)
{
if(sec >
=1)
{
sec=0;
/*
The sampling time is fixed 1 sec.
A variable "tick" is incremented with one tick per 100mSc in the timer 0 interrupt routine.
Each on occurring of external interrupt the value in the "tick" is picked up
and it is set to zero for recounting.
The process continues till next external interrupt.
Formula for calculating beats per minutes (microcontroller based heartbeat monitor ) is
as tick is the time period in Sec/100. so extract the frequency of pulses at external interrupt
Frequency = (1/tick)* 100 i.e pulses /sec
Then
bpm = frequency * 60 for one minutes i.e pulses per minute
in short we can do it as
bpm = 6000/ bt
*/
lcdcmd(0x02);
if(bt >
=7){
bpm = 6000/bt; // for valid output bt is limited so that it should be greater than 6
msdelay(500);
send_string("Pulse. ");
lcddata((bpm/100)+0x30);
r=bpm%100;
lcddata((r/10)+0x30);
lcddata((r%10)+0x30);
send_string(" bpm ");
}
else {
send_string("out of range");} // otherwise bpm will be shown zero, if limit does not fit for your project you can change it.
}
}
}
void lcdinit()
{
msdelay(100);
lcdcmd(0x01);
msdelay(500);
lcdcmd(0x38);
msdelay(500);
lcdcmd(0x38);
msdelay(500);
lcdcmd(0x38);
msdelay(500);
lcdcmd(0x06);
msdelay(500);
lcdcmd(0x0c);
msdelay(500);
lcdcmd(0x03);
msdelay(500);
msdelay(500);
}
void lcdcmd(unsigned char value)
{
rs=0;
lcdport=value;
msdelay(100);
en=1;
msdelay(100);
en=0;
msdelay(100);
rs=1;
}
void lcddata(unsigned char value)
//heart beat monitoring system using microcontroller
{
rs=1;
lcdport=value;
msdelay(10);
en=1;
msdelay(100);
en=0;
rs=0;
}
void msdelay(unsigned int i)
{
//unsigned int i;
while(i --);
}
void send_string(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i <=l;i++)
{
lcddata(*s); // write every char one by one
s++;
}
}


Except I wanna remove all the lcd code and replace it with the serial code to again view it on hyperterminal
I just having a guess here of removing the lcd code and adding the serial code in bold buts it probably all wrong.
[b]#include <REG51.H>
                /* special function register declarations   */ 
#include <stdio.h>
                /* prototype declarations for I/O functions */   
void serial_init(void); 
//------------------------------------------------- 
//Setup the serial port for 9600 baud at 11.0592MHz. 
//-------------------------------------------------[/b]
[b]void serial_init(void) 
{     
SCON  = 0x50;                         /* SCON: mode 1, 8-bit UART, enable rcvr         */     
TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload                    */     
TH1   = 0xFD;               /* TH1:  reload value for 9600 baud @ 11.0592MHz*/    
TR1   = 1;                  /* TR1:  timer 1 run                               */     
TI    = 1;                  /* TI:   set TI to send first char of UART           */ 
} [/b] 

unsigned char sec,sec100;
unsigned int bt,tick,r,bpm;
void msdelay(unsigned int);

void extrint (void) interrupt 0 // external Interrupt to detect the heart pulse
{
bt=tick; // number of ticks are picked
tick=0; // reset for next counting
}
void timer0 (void) interrupt 1 using 1 // Timer 0 for one second time
{
TH0 = 0xdc; //The value is taken for Ssc/100 at crystal 11.0592MHz
sec100++; // It is incremented every Ssc/100 at crystal 11.0592MHz
tick++; // This variable counts the time period of incoming pulse in Sec/100
if(tick>
=3500){tick=0;} // tick are limited to less trhan 255 for valid calculation
if(sec100 >
=100) // 1 sec = sec100 * 100
{
sec++;
sec100=0;
}
}
void main()
{
[b]serial_init(); [/b]
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;

EA = 1;
TMOD = 0x21;
IT0 = 1;
EX0 = 1;
ET0 = 1;
TR0 = 1;
msdelay(1000);

msdelay(1000);
printf("Heart beat ");
msdelay(1500);
msdelay(500);
//delay(15000);
bpm=0;bt=0;
while(1)
{
if(sec >
=1)
{
sec=0;
/*
The sampling time is fixed 1 sec.
A variable "tick" is incremented with one tick per 100mSc in the timer 0 interrupt routine.
Each on occurring of external interrupt the value in the "tick" is picked up
and it is set to zero for recounting.
The process continues till next external interrupt.
Formula for calculating beats per minutes (microcontroller based heartbeat monitor ) is
as tick is the time period in Sec/100. so extract the frequency of pulses at external interrupt
Frequency = (1/tick)* 100 i.e pulses /sec
Then
bpm = frequency * 60 for one minutes i.e pulses per minute
in short we can do it as
bpm = 6000/ bt
*/

if(bt >
=7){
bpm = 6000/bt; // for valid output bt is limited so that it should be greater than 6
msdelay(500);
[b]printf[/b]("Pulse. ");
r=bpm%100;
[b]printf[/b](" bpm ");
}
else {
[b]printf[/b]("out of range");} // otherwise bpm will be shown zero, if limit does not fit for your project you can change it.
}
}
}


[ Edited Thu Aug 07 2014, 07:34 pm ]
Fri Aug 08 2014, 04:44 pm
#8
Adding to it one more question if my device is paired say with my Android cellphone. Then how can i send and receive data(Say 'A') to the device and in the same way data received to the device. Should i need any app at cellphone side. if yes then which one.

Thanks
Sat Aug 09 2014, 08:58 pm
#9
@Peter_Parker, yes instead of lcd write function use printf there. thats the simplest change you can make to use serial instead of LCD.

@mohansaini, can you post in a different thread? its not reladted to this.
Sat Aug 09 2014, 09:55 pm
#10


@Peter_Parker, yes instead of lcd write function use printf there. thats the simplest change you can make to use serial instead of LCD.

@mohansaini, can you post in a different thread? its not reladted to this.

ajay_bhargav


Ok good,would the second code I posted there work then?
I tried to remove all the lcd related parts and all serial parts I added are wrapped in bold tags.
Replaced the send_string with printf

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm