8051 interfacing Bluetooth/Hyperterminal
Discussion in "8051 Discussion Forum" started by Peter_Parker Jul 26, 2014.
Sun Aug 10 2014, 04:41 pm
You forgot to print the values.
you need to print the bpm value.
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 ");
you need to print the bpm value.
printf("bpm: %d\r\n", bpm);
Sun Aug 10 2014, 08:08 pm
You forgot to print the values.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 ");
you need to print the bpm value.printf("bpm: %d\r\n", bpm);ajay_bhargav
Ah yes,thanks,I'll give that a go.
Tue Sep 02 2014, 03:49 am
Just to add to this,I've connected this now to a C# program that reads the serial data in and graphs it,only thing is its coming in too fast so its kinda hard for the graph to keep up.
Should I put in a delay between read counts to slow it down or maybe if it only reads from it when a finger is placed on the sensor instead of continuously reading
Here's the sensor code.
Should I put in a delay between read counts to slow it down or maybe if it only reads from it when a finger is placed on the sensor instead of continuously reading
Here's the sensor 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 */ } 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(); 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("Pulse. "); r=bpm%100; //printf("bpm: %d\r\n", bpm); printf(" %d\r\n", bpm); } else { printf("out of range");} // otherwise bpm will be shown zero } } } void msdelay(unsigned int i) { //unsigned int i; while(i --); }
[ Edited Tue Sep 02 2014, 03:50 am ]
Tue Sep 02 2014, 08:29 am
What is your graph displaying ?
I'm assuming it is "real time", so should be able to handle 1 second updates.
Really you want as much data as possible.
I'm assuming it is "real time", so should be able to handle 1 second updates.
Really you want as much data as possible.
Tue Sep 02 2014, 08:50 pm
What is your graph displaying ?
I'm assuming it is "real time", so should be able to handle 1 second updates.
Really you want as much data as possible.ExperimenterUK
No its displaying the data fine,Beats on the Y axis,Time on the x axis,just though the graph is small and tends to get very cluttered after a while.
The sensor isn't working right,LDR + LED combo,so the values only change when put your finger on the LDR then remove it and repeat as opposed to leaving your finger on the LDR and the values change that way.
Anyway thats something I need to fix myself
[ Edited Tue Sep 02 2014, 08:52 pm ]
Powered by e107 Forum System