johnjameson
Junior Member level 3
- Joined
- Jan 30, 2012
- Messages
- 31
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,516
I'll do that and then report back.Absolutely.
Just to check out your setup, leave aside the 8051. Just short the Tx and Rx on the HC-06, pair it with your PC, configure the hyperterminal with the right com port.
Now, whatever characters you hammer out on the hyperterminal should echo back.
Yip did the test,whatever I typed was echoed back.Absolutely.
Just to check out your setup, leave aside the 8051. Just short the Tx and Rx on the HC-06, pair it with your PC, configure the hyperterminal with the right com port.
Now, whatever characters you hammer out on the hyperterminal should echo back.
int Init_BT_With_feeback()
{
int State=0;
LCD_putcmd(LCD_LINE2,1);
LCD_Write_CText("INIT.BT HC06 BLEU ");
LCD_putcmd(LCD_LINE3,1);
LCD_Write_CText("Etape: 1 sur 4"); Delay_ms(500);
Delay_ms(500);
State=0;
// on nettoye avant..
Raz_Buffer();
UART1_Write_CText("AT"); // PAS de CR apres cde !
Delay_ms(500);
Flag_Timer1=0; TMR1IE_bit=1;
do
{
if(memcmp(buffer,"OK",2)==0)
{
State=1;
break;
}
}while(Flag_Timer1==0);
if(Flag_Timer1==1)return State;
buffer[19]=0; LCD_putcmd(LCD_LINE4,1); LCD_puts(buffer);
Delay_ms(500);
//-----------------------------
LCD_putcmd(LCD_LINE3,1);
LCD_Write_CText("Etape: 2 sur 4"); Delay_ms(500);
Raz_Buffer();
UART1_Write_CText("AT+PIN1234"); // PAS de CR apres cde !
Delay_ms(500);
Flag_Timer1=0; TMR1IE_bit=1;
do
{
if(memcmp(buffer,"OKsetPIN",8)==0)
{
State=2;
break;
}
}while(Flag_Timer1==0);
if(Flag_Timer1==1) return State;
buffer[19]=0; LCD_putcmd(LCD_LINE4,1); LCD_puts(buffer);
Delay_ms(500);
// -------------------------------
LCD_putcmd(LCD_LINE3,1);
LCD_Write_CText("Etape: 3 sur 4"); Delay_ms(500);
Raz_Buffer();
UART1_Write_CText("AT+NAMEHC06-7D69B"); // PAS de CR apres cde !
Delay_ms(500); buffer[19]=0; LCD_putcmd(LCD_LINE4,1); LCD_puts(buffer);
Flag_Timer1=0; TMR1IE_bit=1;
do
{
if(memcmp(buffer,"OKsetname",9)==0)
{
State=3;
break;
}
}while(Flag_Timer1==0);
if(Flag_Timer1==1) return State;
buffer[19]=0; LCD_putcmd(LCD_LINE4,1); LCD_puts(buffer);
Delay_ms(500);
// --------------------------------------
LCD_putcmd(LCD_LINE3,1);
LCD_Write_CText("Etape: 4 sur 4"); Delay_ms(500);
Raz_Buffer();
UART1_Write_CText("AT+VERSION");
Delay_ms(500); buffer[19]=0; LCD_putcmd(LCD_LINE4,1); LCD_puts(buffer);
Flag_Timer1=0; TMR1IE_bit=1;
do
{
if(memcmp(buffer,"OKlinvor",8)==0)State++;
{
State=4;
break;
}
}while(Flag_Timer1==0);
if(Flag_Timer1==1) return State;
Delay_ms(500); buffer[19]=0; LCD_putcmd(LCD_LINE4,1); LCD_puts(buffer);
CRLF();
State=5;
Delay_ms(500);
Raz_Buffer();
return(State);
}
BT_Reset=0;
UART1_Init(19200);
...
Init_Timer1();
BT_Reset=1;
.....
k=Init_BT_With_feeback() ;
Delay_ms(500);
LCD_putcmd(LCD_LINE4,1); Delay_ms(25);
if(k>4)
PrintOut(LCDHandler, "Init BT OK State=%02d ",k);
else
PrintOut(LCDHandler, "Init BT BAD State=%02d",k);
Delay_ms(500);
#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" */
}
}
Does the code have to be as long as that?
For example would this work for sending data to hyperterminal via bluetooth
example for uart
we suppose also, that the device pairing , PC side, is correct ..
and you allready have a driver to get the connexion with a virtual com port from your PC Bluetooth interface.
and software authorisation to do that...
#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" */
}
}
Delay_ms(500);
while (1)
{
printf ("Hello World!! \n\r"); /* Print "Hello World" */
Delay_ms(500);
}
But nothing came through on the hyperterminal,it was able to open a connection alright but then nothing but a blank screen.
I am using a 11.0592MHz with my 8051 too.
I'll try that.hello,
sorry, i don't know 8051
try to add some delay in your code ...
and maybe try also to reverse " \n\r" by "\r\n" or only "\r"
i allready encounter this kind of problem with external BT equipement..with RFOBasic and bluetooh application.
Code:Delay_ms(500); while (1) { printf ("Hello World!! \n\r"); /* Print "Hello World" */ Delay_ms(500); }
I didn't connect it directly as I dont have a cable.When you connect your 8051 project to hyperterminal directly using a cable, does it work as expected?
Right so I tried the loopback test and that worked.
I then loaded my 8051 with this code
Code:#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" */ } }
But nothing came through on the hyperterminal,it was able to open a connection alright but then nothing but a blank screen.
I am using a 11.0592MHz with my 8051 too.
#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++;
}
}
++#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]
++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()
{
++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);
++printf[/b]("Pulse. ");
r=bpm%100;
++printf[/b](" bpm ");
}
else {
++printf[/b]("out of range");} // otherwise bpm will be shown zero, if limit does not fit for your project you can change it.
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?