mamush2013
Newbie level 4
- Joined
- Mar 10, 2013
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,339
i'm final year biomedical engineering student! i'm working my FYP!! my work is to design a multi- parameter human vital sign measuring device. the parameters are blood pressure,heart rate and body temperature! the project is embedded project. i use sensors micro-controller(pic18f452) and a display unit(LCD) to my design. i face a difficulty while writing the c program!! i can't convert the value i get from the light intensity from sensor(LDR) to a understandable heart rate!! i need the calculation or code that converts the voltage from the sensor to the readable heart rate value!!
let's make things clear i'm using the following materials for my design
1. proteus isis simulation software
2. mplab x current version for my c codding workbench
3 c18 c compiler
and lastly here is my code!
let's make things clear i'm using the following materials for my design
1. proteus isis simulation software
2. mplab x current version for my c codding workbench
3 c18 c compiler
and lastly here is my code!
Code:
* File: Temprature.c
* Author: TOSHIBA
*
* Created on May 5, 2013, 3:54 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include <adc.h>
#include<delays.h>
#include<string.h>
#include<p18f452.h>
#pragma config WDT=OFF,OSC=HS,OSCS=OFF,BORV=45,PWRT=ON,BOR=ON
#define rs PORTCbits.RC5
#define rw PORTCbits.RC6
#define en PORTCbits.RC7
#define sdata PORTD
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void adc_con(int);
void adc_con1(int);
void adc_init(void);
void Print_string(char *A);
void Delay_ms(int);
char HR[]="Heart Rate";
char NO[]="PRESS BUTTON";
float LDR[10],avg_output=0,temp;
unsigned int i=0;
/*
*
*
*/
void main(void)
{
TRISA=0x0f; // Configure RA3 as input pin
TRISB=0; // Configure Port B as output port
TRISC=0;
TRISD=0;
// Set cursor position to 1st line, 1st column
TRISBbits.RB4=1;
TRISBbits.RB5=1;
TRISBbits.RB6=1;
adc_init(); //ADC Initialization
while(PORTBbits.RB5==1)
{
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80);
Print_string(HR);
lcdcmd(0x87);
ADCON0=0xD1;
ADRES=0;
temp=0;
for(i=0;i<10;i++)
{
ADCON0bits.GO=1; // Start A/D
while(ADCON0bits.DONE==1); // Wait
LDR[i]=ADRES ; //Store data
Delay_ms(5);
temp=temp+LDR[i];
}
avg_output=temp/10;
avg_output=(1024-avg_output); // Take average
adc_con(avg_output);
}
while(PORTBbits.RB5==0){
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80);
Print_string(NO);
lcdcmd(0x87);
Delay_ms(1000);
}
}
void lcdcmd(unsigned char cmdout)
{
sdata=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
Delay_ms(20);
en=0;
}
void Delay_ms(int d)
{
int i,j;
for(i=0;i<d;i++)
{
for(j=0;j<d;j++)
{
}
}
}
void adc_init()
{
ADCON1=0xC0; // Make RA0/AN0 ,RA1,RA2,RA3,RA4,RA5,RA6 and RA7 ANALOG
// Select Channel0 & ADC off
// ADCON2=0x85; // Fosc/32 clock option
ADCON0=0xD1; // AN3... clock drived from internal RC Enable ADC
}
void adc_con( int adc_out)
{
int adc_out1;
int i=0;
char position=0xC3;
for(i=0;i<=3;i++)
{
adc_out1=adc_out%10; // To exract the unit position digit
adc_out=adc_out/10;
lcdcmd(position);
lcddata(48+adc_out1); // Convert into its corresponding ASCII
position--;
}
Delay_ms(100);
}
void adc_con1( int adc)
{
int adc_out2;
int i=0;
char position=0xCF;
for(i=0;i<=3;i++)
{
adc_out2=adc%10; // To exract the unit position digit
adc=adc/10;
lcdcmd(position);
lcddata(48+adc_out2); // Convert into its corresponding ASCII
position--;
}
}
void lcddata(unsigned char dataout)
{
sdata=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(30);
en=0;
}
void Print_string(char *a)
{
int i;
for(i=0;(*(a+i))!='\0';i++)
{
lcddata(*(a+i));
}
}