Microcontroller › 8051 › Bluetooth heart rate monitor? › Decided to scrap the previous
April 7, 2014 at 5:15 pm
#11496
John Jameson
Participant
Decided to scrap the previous code and try something different.Been trying to work this.
<code>
- #include reg51.h
- //#include
- void _nop_(void);
- #define delay_us _nop_(); //generates 1 microsecond
- #define LCD P3
- sbit RS=P2^0; //connect p0.0 to rs pin of lcd
- sbit EN=P2^2; //connect p0.1 to en pin of lcd
- sbit RW=P2^1;
- sbit PULSE=P0^0; //pulse input from heart beat sensor
- //sbit LED=P1^0; //led indicator for pulse indication
- void integer_lcd(int);
- void init_lcd(void);
- void cmd_lcd(unsigned char);
- void write_lcd(unsigned char);
- void delay_ms(unsigned int);
- unsigned int num=0;
- unsigned int num1=0;
- unsigned int dig_1,dig_2,dig_3,dig_4,test=0;
- unsigned int dig_11,dig_21,dig_31,dig_41,test1=0,test2=0;
- unsigned char k=0;
- void main(void)
- {
- init_lcd();
- //LED=0;
- write_lcd(‘H’);
- write_lcd(‘E’);
- write_lcd(‘A’);
- write_lcd(‘R’);
- write_lcd(‘T’);
- write_lcd(‘ ‘);
- write_lcd(‘B’);
- write_lcd(‘E’);
- write_lcd(‘A’);
- write_lcd(‘T’);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- cmd_lcd(0xc0);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘ ‘);
- write_lcd(‘C’);
- write_lcd(‘O’);
- write_lcd(‘U’);
- write_lcd(‘N’);
- write_lcd(‘T’);
- write_lcd(‘E’);
- write_lcd(‘R’);
- delay_ms(300);
- cmd_lcd(0x01);
- write_lcd(‘B’);
- write_lcd(‘e’);
- write_lcd(‘a’);
- write_lcd(‘t’);
- write_lcd(‘s’);
- write_lcd(‘:’);
- write_lcd(48);
- write_lcd(48);
- write_lcd(48);
- write_lcd(48);
- while(1)
- {
- if(PULSE==1) //check for input pulse from sensor
- {
- cmd_lcd(0x01);
- test++;
- num=test;
- dig_4=num%10;
- num=num/10;
- dig_3=num%10;
- num=num/10;
- dig_2=num%10;
- dig_1=num/10;
- if(test==9999)
- test=0;
- write_lcd(‘B’);
- write_lcd(‘e’);
- write_lcd(‘a’);
- write_lcd(‘t’);
- write_lcd(‘s’);
- write_lcd(‘:’);
- write_lcd(dig_1+48);
- write_lcd(dig_2+48);
- write_lcd(dig_3+48);
- write_lcd(dig_4+48);
- //LED=1;
- delay_ms(50);
- //LED=0;
- }
- }
- }
- ////////////////////////////////////////////////////////////////
- void init_lcd(void)
- {
- delay_ms(10); //delay 10 milliseconds
- cmd_lcd(0x38); //8 bit initialize, 5×7 character font, 16×2 display
- cmd_lcd(0x0e); //lcd on, cursor on
- cmd_lcd(0x06); //right shift cursor automatically after each character is displayed
- cmd_lcd(0x01); //clear lcd
- }
- //transmit command or instruction to lcd
- void cmd_lcd(unsigned char c)
- {
- EN=1;
- RW=0;//set enable pin
- RS=0; //clear register select pin
- LCD=c; //load 8 bit data
- EN=0; //clear enable pin
- delay_ms(2); //delay 2 milliseconds
- }
- //transmit a character to be displayed on lcd
- void write_lcd(unsigned char c)
- {
- EN=1; //set enable pin
- RW=0;
- RS=1; //set register select pin
- LCD=c; //load 8 bit data
- EN=0; //clear enable pin
- delay_ms(2); //delay 2 milliseconds
- }
- //generates delay in milli seconds
- void delay_ms(unsigned int i)
- {
- unsigned int j;
- while(i–>0)
- {
- for(j=0;j<500;j++)
- {
- ;
- }
- }
- }
- <code>
- I think this only works as a pulse counter so to calculate the beats per minute a time reference is needed I think.
When I load it onto my chip,the welcome message comes up on the lcd and then everytime I put my finger on the lrd the no of beats increment by 1 on the lcd screen.