|
|
View previous topic :: View next topic |
Author |
Message |
comet_utob
Joined: 01 Jul 2013 Posts: 5
|
plz help me :-( |
Posted: Mon Jul 01, 2013 7:25 am |
|
|
hello friend
I have a problem with compiling my project.
The compiler opened a new tab with the name of my device pic16f877a and made error that "can not change device type this far into the code" and five other error that all are about that tab--> pic16f877a
I couldn't understand what should i do. Please help me
MORE:
This is my code:
Code: |
#include<16F877A.h> //EDIT:) TNX: dyeatman
#include <main.h>
#include<stdlib.h>
#include<string.h>
#include<lcd.c>
#use delay(clock=20000000)
#use rs232 (baud=9600,xmit=PIN_B0,rcv=PIN_B1,stream=GSM)
#use rs232(baud=4800,xmit=PIN_A1,rcv=PIN_A0,stream=GPS) //EDIT:) TNX JAY
char wru[] = {"wru"};
char about[] = {"about"};
char help[] = {"help"};
char get[] = {"get"};
char num[12];
char lat[12];
char lngtd[12];
char speed[12];
char tdata[12];
char ch = 0;
int count1 = 0;
char data[120]; // for sms storage---150//
int16 count = 0;
int16 hbeat = 70;
int16 prev = 70;
int16 prev1 = 70;
int16 result = 0;
void init_phone()
{
fprintf(GSM,"AT\r\n");
delay_ms(1500);
fprintf(GSM,"AT+CMGF=1\r\n");
delay_ms(1500);
}
void get_GPS_data()
{
while(1)
{
fgets(data,GPS);
if(strstr(*data,*"GPRMC"))//search for GRMC string Data variable//
{
break;
}
}
}
void get_gps_field(byte buf[],int field)
{
int i=0;
int j=0;
int count = 0;
while(buf[i])
{
if(buf[i] == ',')
count ++;
if(count == field)
break;
i++;
}
i++;
while(buf[i]!=',')
{
tdata[j]=buf[i];
i++;
j++;
}
tdata[j] = 0;
}
void heart_rate()
{
if ((hbeat < 60) || (hbeat > 90))
{
fprintf(GSM,"AT+CMGS=\%s\"\r\n",num);
delay_ms(1000);
if(hbeat<60)
{
fprintf(GSM,"***ALERT***LOW heart \r\n");
}
if(hbeat>90)
{
fprintf(GSM,"***ALERT***HIGH heart \r\n");
}
fprintf(GSM,"Heart rate:%lu\r\n",hbeat);
fprintf(GSM,"Person located at lat: %s lng:%s\r\n",lat,lngtd);
fprintf(GSM,"speed:%s kmph.\r\n",speed);
delay_ms(1000);
fputc(0x1A,GSM);
fgetc(GSM);
delay_ms(2000);
}
}
void main()
{
int i=0;
int j=0;
lcd_init();
lcd_putc('\f');//clear lcd//
lcd_gotoxy(1,1);//row-1,column-1//
printf(lcd_putc,"GPS&GSM based");
lcd_gotoxy(1,2);//row-1 column-1//
printf(lcd_putc,"Health monitoring");
fprintf(GSM,"AT\r\n");
delay_ms(1500);
init_phone();
lcd_putc('\f');//clear lCD//
lcd_gotoxy(1,1);//row-1,column-1//
printf(lcd_putc,"please insert");
lcd_gotoxy(1,2);//row-2,column-1//
printf(lcd_putc,"Your Finger");
while(1)
{
get_GPS_data();
get_gps_field(data,3);//get lat
strcpy(lat,tdata);
get_gps_field(data,5);//get lngtd
strcpy(lngtd,tdata);
get_gps_field(data,7);//speed
strcpy(speed,tdata);
count = 0;
delay_ms(250);//find heart rate
while(input(PIN_A1))//pulse high
{
delay_ms(1);
count = count+1;
}
while(!input(PIN_A1))//pulse low
{
delay_ms(1);
count = count+1;
}
count = count;
lcd_gotoxy(1,1);
hbeat = 60000/count;
result = (hbeat+prev+prev1)/3;
prev1 = prev;
prev = hbeat;
hbeat = result;
if((hbeat>0)&&(hbeat<250))
{
lcd_putc('\f');
printf(lcd_putc,"heart rate = %lu",hbeat);
lcd_gotoxy(1,2);
if(hbeat<60)
{
printf(lcd_putc,"Low HR");
}
else if(hbeat>90)
{
printf(lcd_putc,"High HR");
}
else
{
printf(lcd_putc,"NORMAL HR");
}
}
fprintf(GSM,"AT+CMGR = 1\r\n");
fgets(data,GSM);//capture sms data in to data variable//
if(strlen(data)<14)//if no sms continue//
{
continue;
}
//delete the message
fprintf(GSM,"AT+CMGD = 1\r\n");//if sms received then delete it//
delay_ms(1000);
//read the available message content//
i= 0;
//extract the number
while(data[i]!='9')
{
i++;
}
if((data[i] =='9')&&(data[i+1] =='1'))
{
i++;
// SHAK i++;
for(j=0;j<10;j++)
{
num[j] = data[i];
i++;
}
num[j] = 0;
}
lcd_putc('\f');
lcd_gotoxy(1,1);//row-1,column-1//
printf(lcd_putc,"ph:%s",num)
delay_ms(5000);
if(strstr(data,get))
{
fprintf(GSM,"AT+CMGS =\"%s\"\r\n",num);
fprintf(GSM,"Hello, I am located at");
fprintf(GSM,"lat: %s lng: %s",lat,lngtd);
fprintf(GSM,"speed:%s kmph,"speed);
fprintf(GSM,"Heart rate is:%Lu\r\n",hbeat);
delay_ms(1000);
fputc(0x1A,GSM);//^z
delay_ms(2000);
}
else if(strstr(data,about))
{
fprintf(GSM,"AT+CMGS =\"%s\"\r\n",num);
fprintf(GSM,"GPS&GSM Based Real Time Human Health Monitoring\r\n");
delay_ms(1000);
fputc(0x1A,GSM);//^z
delay_ms(2000);
}
else if(strstr(data,help))
{
fprintf(GSM,"AT+CMGS =\"%s\"\r\n",num);
fprintf(GSM,"send \"get\" to get heart beat and location \r\n");
fprintf(GSM,"Send \"about\"to know about me \r\n");
fputc(0x1A,GSM);//^z
delay_ms(2000);
}
}
} |
Last edited by comet_utob on Mon Jul 01, 2013 10:23 pm; edited 1 time in total |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Jul 01, 2013 7:29 am |
|
|
The device definition must always come first.
Quote: | #include <main.h>
#include<16F877A.h>
#include<stdlib.h> |
Move the second line to the first position. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Jul 01, 2013 5:33 pm |
|
|
Hi,
You aren't using the hardware UART with either the GPS or the SMS modem. Is that your intention?
As coded, I don't think there is much chance of your project working as you hope. You really need to implement an interrupt driven serial routine for the GPS data.
Which GPS and SMS modem are you using?
John |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jul 01, 2013 6:03 pm |
|
|
couple other points...
1)...
#use rs232 (baud=9600,xmit=PIN_B0,rcv=PIN_B1,stream=GSM)
#use rs232(baud=4800,xmit=PIN_B1,rcv=PIN_A0,stream=GPS)
...
you've got Pin B1 used for BOTH rcv and xmt depending on the stream. I don't think you really meant that to happen..
2) ...
if(hbeat>90)
{
fprintf(GSM,"***ALERT***low heart \r\n");
}
... probably mean HIGH heart, not low heart as hbeat>90
hth
jay |
|
|
comet_utob
Joined: 01 Jul 2013 Posts: 5
|
|
Posted: Mon Jul 01, 2013 9:20 pm |
|
|
thank you friends for your very good advices
as a matter of fact i want to program a pic16f877a for a project to measure heartbeat and send sms to the concern doctor (sms include heartrate and location of patient) i want to use sim900 module for sending sms, is it good ?
comet; |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|