• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

GSM Based Temprature Monitoring system

Thread starter #1
as u see in the topic i am doing this project.. using AT89s52 MCU
i am doing the code segment of temperature sensing and gsm sms sending.. and they both works properly independently .. but i am having problem in combining those in a same code.. please help
i am using LM35 and gsm900A
i am attaching both independent working code and the combined code.. please tell me where i am wrong..
 

Attachments

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#2
You keep messing your self up in pointers..

your function..
C:
void gsm_send(unsigned int ch3) {......}
Your declaration specifies an int

C:
void gsm_send(unsigned int ch3)
{
   data_send(ch);
   //data_res();
   Delay_ms(100);
   data_send(ch1);
   Delay_ms(100);
   //data_res();
   data_send(ch2);
   Delay_ms(100);
   //data_res();
   data_send(a);
   data_send(ch9);
   data_send(a);
   data_send("\r\n");
   Delay_ms(100);
   num(ch3);
   Delay_ms(100);
   SBUF=0x1a;
   while(TI==0);
   TI=0;
}
Now data_send wants a pointer!!!! that means you need an array... You need to convert an int to an ascii array.

You have tried with a function " data_res"..

Un fortunately your compiler ( I'm assuming C51) doesn't have the atoi() function... Try this

C:
  data_send(itoa(gsm_val));

unsigned char* itoa( unsigned int numb)                           // My crass interpretation on itoa()..
   {
   char res[6];       // result
   char *tr = &res[5];     // traverse backwards
   *tr-- = 0;         // null
  
   do
       {
       *tr-- = numb%10+48;
       }while((numb/=10) >0);
   return ++tr;
   }
Now you don't need send_gsm()....
 
Last edited:
Thread starter #3
You keep messing your self up in pointers..

your function..
C:
void gsm_send(unsigned int ch3) {......}
Your declaration specifies an int

C:
void gsm_send(unsigned int ch3)
{
   data_send(ch);
   //data_res();
   Delay_ms(100);
   data_send(ch1);
   Delay_ms(100);
   //data_res();
   data_send(ch2);
   Delay_ms(100);
   //data_res();
   data_send(a);
   data_send(ch9);
   data_send(a);
   data_send("\r\n");
   Delay_ms(100);
   num(ch3);
   Delay_ms(100);
   SBUF=0x1a;
   while(TI==0);
   TI=0;
}
Now data_send wants a pointer!!!! that means you need an array... You need to convert an int to an ascii array.

You have tried with a function " data_res"..

Un fortunately your compiler ( I'm assuming C51) doesn't have the atoi() function... Try this

C:
  data_send(itoa(gsm_val));

unsigned char* itoa( unsigned int numb)                           // My crass interpretation on itoa()..
   {
   char res[6];       // result
   char *tr = &res[5];     // traverse backwards
   *tr-- = 0;         // null
   while((numb/=10) >0)
     {
     *tr-- = numb%10 + 48;
     }
   return ++tr;
   }
Now you don't need send_gsm()....
Thanks for your answer sir.

the data_send function is
void data_send(unsigned char *p)
having arguments of char type pointer
and i am sending data_send(ch); (i mean passing a variable of char type initialized globally)
and the gsm_send function

void gsm_send(unsigned int ch3)
ch3 is of int type because the temprature is in numerical form
and further this numerical value in ch3 variable is send to num() function which process it and convert the number into ASCII

as i said my independent gsm CODE is working find.. only problem is in combining
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#4
I am looking at your code....

In the ISR you call gsm_send(gsm_val); then that routine ( in gsm.h ) doesn't do any conversion at all

C:
void gsm_send(unsigned int ch3)
{
   data_send(ch);
   //data_res();
   Delay_ms(100);
   data_send(ch1);
   Delay_ms(100);
   //data_res();
   data_send(ch2);
   Delay_ms(100);
   //data_res();
   data_send(a);
   data_send(ch9);
   data_send(a);
   data_send("\r\n");
   Delay_ms(100);
   num(ch3);       //<----- This does nothing!!!!
   Delay_ms(100);
   SBUF=0x1a;
   while(TI==0);
   TI=0;
}
Also, depending on the compiler.... gsm_val needs to be volatile as its being used it two functions... the compiler may not include it!!!

The above routine isn't doing what you think it is....
 
Thread starter #6
Appologies.... I missed the dat routine in the numb routine....

Still using your code, try declaring gsm_val as volatile.... it might work...
to test that my ISR is working properly or not i just used
gsm_send (123);
a simple constant 123 to check if the control goes to ISR or not.. but it seems that its not.. because i didn't receive any text...
 

Latest threads

EE World Online Articles

Loading

 
Top