CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

TC35I Receive question---use the txt message control LED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

TC35I Receive question---use the txt message control LED
PostPosted: Thu Oct 27, 2011 7:11 pm     Reply with quote

hello guys
I use the TC35I receive a txt message to control LED.
But when my code use the printf "AT", the buffer can't receive the "OK". Please help me check it, and where am I wrong in my code?

My code as follow:
Code:

#include <18f452.h>       
#include <string.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay (clock = 20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8)
#zero_ram 
 
#define  PORTA 0xF80
#define  PORTB 0xF81
#define  PORTC 0xF82                           
#define  PORTD 0XF83
 
#bit col8=PORTC.0 //Matrix LED common
#bit LED1=PORTD.0 //
#bit LED2=PORTD.1 //
#bit LED3=PORTD.2 //
#bit LED4=PORTD.3 //
#bit IGT =PORTD.4  //
#bit LED5=PORTD.5 //
#bit LED6=PORTD.6 //
#bit LED7=PORTD.7 //
 
#define Buf_Max 200 //buffer length200
#define NOT_FOUND (NULL)
 
unsigned char num[]="OK";
unsigned char i = 0;               //
unsigned char Rec_Buf[Buf_Max];    //
unsigned char N_MS[]="+CMTI";
unsigned char Command1[]="led3";
unsigned char Command2[]="unled3";
unsigned char Command3[]="led4";
unsigned char Command4[]="unled4";
 
void CLR_Buf(void);               //clear the buffer
int1  Hand(unsigned char *a);       
//*******************************************
#int_RDA
void RDA_isr()
{
  Rec_Buf[i]=getc();
  i++;               
  if(i>200)         
  {
    i = 0;
  }
 
}
/***************main******************************/
void main()
{
         set_tris_d(0x00);
         set_tris_c(0x80); [b]// it set the RC_PIN7 input mode[/b]
         output_d(0x00);
         col8=1;
         enable_interrupts(int_rda);     
         enable_interrupts(GLOBAL);   
         delay_ms(1000);        //
         CLR_Buf();             //
         delay_ms(6000);        //
          while(!Hand(num))     //           
{
               printf("AT\r\n");
               delay_ms(6000);   //
               LED7=1;
            }
         CLR_Buf();        //
         LED1 = 0;        //get "ok" ==my code can't carry out this step!
         delay_ms(3000);     
         printf("AT+CPMS=\"MT\",\"MT\",\"MT\"\r\n
                 delay_ms(3000);     //
         while(!Hand(num));       //
         CLR_Buf();                //
         LED2 = 0;                 //
         
         delay_ms(3000);     //
         printf("AT+CNMI=2,1\r\n");//new msm come in
         
         delay_ms(3000);     //
         while(!Hand(num));       //
         CLR_Buf();                //
         
         delay_ms(3000);     //
         printf("AT+CMGF=1\r\n");set TEXT mode
       
         delay_ms(3000);     //
         while(!Hand(num));         //
         CLR_Buf();                //
         
         delay_ms(3000);     /
         printf("AT+CMGD=1\r\n");//delete this msm       
         delay_ms(3000);     //
         while(!Hand(num));         //
         CLR_Buf();                //
         LED1 = 0;                 //successful
         
         while(true)
            {
                if(strstr(Rec_Buf,N_MS)!=NULL)    //
                    {
                     CLR_Buf();                   //
                     delay_ms(3000);        //
                     printf("AT+CMGR=1\r\n");//
                     
                     delay_ms(3000);        //
                      while(!Hand(num));          //
                     
                     if(strstr(Rec_Buf,Command1)!=NULL)  //if the msm is the"open1"
                           LED3 = 0;                           //the turn on the LED7
                       else if(strstr(Rec_Buf,Command2)!=NULL) //if the msm is the"close1"
                          LED3 = 1;                           /Turn off LED7
                       else if(strstr(Rec_Buf,Command3)!=NULL)  //if the msm is the"open2"
                             LED4 = 0;                           //the turn on the LED4
                       else if(strstr(Rec_Buf,Command4)!=NULL) //if the msm is the"close2"
                           LED4 = 1;                           //the turn off the LED4
                     CLR_Buf();                              //               
                     delay_ms(3000);                   //
                     printf("AT+CMGD=1\r\n");//delete the readed msm                     
                     delay_ms(3000);                   //
                     while(!Hand(num));                       //
                     CLR_Buf();                              //               
  }
               }
}
/*************************/
/************************/
void CLR_Buf(void)
{
   unsigned char k;
    for(k=0;k<Buf_Max;k++)    //
       {
         Rec_Buf[k] = 0;
      }
    i = 0;                   
}
/***********************************************/
int1 Hand(unsigned char *a)
{     
   
    if(strstr(Rec_Buf,a)!=NULL)
      return (1);
     
   else
      return (0);
     
}


Last edited by leevise on Sun Nov 06, 2011 10:54 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 27, 2011 10:23 pm     Reply with quote

I don't think this method of array initialization works in CCS:
Quote:

unsigned char *num="OK";
unsigned char i = 0; //
unsigned char Rec_Buf[Buf_Max]; //
unsigned char *N_MS="+CMTI";
unsigned char *Command1="led3";
unsigned char *Command2="unled3";
unsigned char *Command3="led4";
unsigned char *Command4="unled4";


Change all the array declarations to a more traditional K&R method, like this:
Code:

unsigned char num[]="OK";

CCS follows K&R (mostly), and that's how the K&R book says to initialize
an array. (Page 83 of K&R 1st Edition, 1978).
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Thu Oct 27, 2011 10:41 pm     Reply with quote

PCM programmer wrote:
I don't think this method of array initialization works in CCS:
Quote:

unsigned char *num="OK";
unsigned char i = 0; //
unsigned char Rec_Buf[Buf_Max]; //
unsigned char *N_MS="+CMTI";
unsigned char *Command1="led3";
unsigned char *Command2="unled3";
unsigned char *Command3="led4";
unsigned char *Command4="unled4";


Change all the array declarations to a more traditional K&R method, like this:
Code:

unsigned char num[]="OK";

CCS follows K&R (mostly), and that's how the K&R book says to initialize
an array. (Page 83 of K&R 1st Edition, 1978).



Thank you for your advice!

I modified my code
Code:

unsigned char num[]="OK";
unsigned char i = 0;               
unsigned char Rec_Buf[Buf_Max];   
unsigned char N_MS[]="+CMTI";
unsigned char Command1[]="led3";
unsigned char Command2[]="unled3";
unsigned char Command3[]="led4";
unsigned char Command4[]="unled4";


BUt it doesn't running normal, the buffer can't receive the"OK",and the LED1 light.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Oct 28, 2011 6:52 am     Reply with quote

hi,

check this out:
http://www.ccsinfo.com/forum/viewtopic.php?t=42527

it does what you want... for 4 LEDs.
used a different phone... you might need to modify it a bit to work with yours.

BUT, first things first... you must know 100% that your COM between pic and Cell is working...

i recommend you make a spliced cable where you can see the serial from the phone on your PC as well...

that way you know if your pic is actually making the phone respond.

next up, make a simple program that sends an AT command to the phone and checks for reception of "OK"...

once you got that.... its all down hill... its just a matter of reading the AT command list for your phone and sending the right commands from the PIC....



G
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 28, 2011 7:59 am     Reply with quote

from a quick look...

Add 'errors' to the rs232(....) options ! Otherwise the UART will stop after 2 bytes from the phone.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 28, 2011 3:55 pm     Reply with quote

Instead of acting helpless, learn how to trouble-shoot a program.
You have a problem. The program doesn't find "OK" in the modem
response. You are checking for "OK" with the strstr() function.
It requires two strings.

How do you know for a fact what is in those two strings ?
You don't.

So, put in some diagnostic printf statements at the start of your Hand()
function so you can see the contents of the two arrays. Add the lines
shown in bold below:
Quote:

int1 Hand(unsigned char *a)
{

printf("Num = %s \r\n", a);
printf("Rec_Buf = %s \r\n", Rec_Buf);
printf("\n\r");


if(strstr(Rec_Buf,a)!=NULL)
return (1);
else
return (0);
}

The Num array should contain "OK", and the Rec_Buf array should also
(you hope) contain "OK". If one or both of them do not have "OK", then
you need to investigate and do more trouble-shooting of the code for that
array, and look in other parts of the program for the problem.

What I want you to do is to stop acting helpless, and to start trouble-
shooting your own code.
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

Re: TC35I Receive question---use the txt message control LED
PostPosted: Sun Nov 06, 2011 9:17 am     Reply with quote

leevise wrote:
Code:

/***************main******************************/
void main()
{
         set_tris_d(0x00);
         [b]set_tris_c(0x00);[/b]       
         output_d(0x00);
 


I found the wrong that I forgot set the C7 input mode ,the code is setted as follow:

Code:
set_tris_c(0x80);


My code is OK,when I modified this code!
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

Re: TC35I Receive question---use the txt message control LED
PostPosted: Sun Nov 06, 2011 10:56 am     Reply with quote

hello guys
I am success, it works good . it is the code as follow :
leevise wrote:
hello guys
I use the TC35I receive a txt message to control LED.
But when my code use the printf "AT", the buffer can't receive the "OK". Please help me check it, and where am I wrong in my code?

My code as follow:
Code:

#include <18f452.h>       
#include <string.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay (clock = 20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8)
#zero_ram 
 
#define  PORTA 0xF80
#define  PORTB 0xF81
#define  PORTC 0xF82                           
#define  PORTD 0XF83
 
#bit col8=PORTC.0 //Matrix LED common
#bit LED1=PORTD.0 //
#bit LED2=PORTD.1 //
#bit LED3=PORTD.2 //
#bit LED4=PORTD.3 //
#bit IGT =PORTD.4  //
#bit LED5=PORTD.5 //
#bit LED6=PORTD.6 //
#bit LED7=PORTD.7 //
 
#define Buf_Max 200 //buffer length200
#define NOT_FOUND (NULL)
 
unsigned char num[]="OK";
unsigned char i = 0;               //
unsigned char Rec_Buf[Buf_Max];    //
unsigned char N_MS[]="+CMTI";
unsigned char Command1[]="led3";
unsigned char Command2[]="unled3";
unsigned char Command3[]="led4";
unsigned char Command4[]="unled4";
 
void CLR_Buf(void);               //clear the buffer
int1  Hand(unsigned char *a);       
//*******************************************
#int_RDA
void RDA_isr()
{
  Rec_Buf[i]=getc();
  i++;               
  if(i>200)         
  {
    i = 0;
  }
 
}
/***************main******************************/
void main()
{
         set_tris_d(0x00);
         set_tris_c(0x80); [b]// it set the RC_PIN7 input mode[/b]
         output_d(0x00);
         col8=1;
         enable_interrupts(int_rda);     
         enable_interrupts(GLOBAL);   
         delay_ms(1000);        //
         CLR_Buf();             //
         delay_ms(6000);        //
          while(!Hand(num))     //           
{
               printf("AT\r\n");
               delay_ms(6000);   //
               LED7=1;
            }
         CLR_Buf();        //
         LED1 = 0;        //get "ok" ==my code can't carry out this step!
         delay_ms(3000);     
         printf("AT+CPMS=\"MT\",\"MT\",\"MT\"\r\n
                 delay_ms(3000);     //
         while(!Hand(num));       //
         CLR_Buf();                //
         LED2 = 0;                 //
         
         delay_ms(3000);     //
         printf("AT+CNMI=2,1\r\n");//new msm come in
         
         delay_ms(3000);     //
         while(!Hand(num));       //
         CLR_Buf();                //
         
         delay_ms(3000);     //
         printf("AT+CMGF=1\r\n");set TEXT mode
       
         delay_ms(3000);     //
         while(!Hand(num));         //
         CLR_Buf();                //
         
         delay_ms(3000);     /
         printf("AT+CMGD=1\r\n");//delete this msm       
         delay_ms(3000);     //
         while(!Hand(num));         //
         CLR_Buf();                //
         LED1 = 0;                 //successful
         
         while(true)
            {
                if(strstr(Rec_Buf,N_MS)!=NULL)    //
                    {
                     CLR_Buf();                   //
                     delay_ms(3000);        //
                     printf("AT+CMGR=1\r\n");//
                     
                     delay_ms(3000);        //
                      while(!Hand(num));          //
                     
                     if(strstr(Rec_Buf,Command1)!=NULL)  //if the msm is the"open1"
                           LED3 = 0;                           //the turn on the LED7
                       else if(strstr(Rec_Buf,Command2)!=NULL) //if the msm is the"close1"
                          LED3 = 1;                           /Turn off LED7
                       else if(strstr(Rec_Buf,Command3)!=NULL)  //if the msm is the"open2"
                             LED4 = 0;                           //the turn on the LED4
                       else if(strstr(Rec_Buf,Command4)!=NULL) //if the msm is the"close2"
                           LED4 = 1;                           //the turn off the LED4
                     CLR_Buf();                              //               
                     delay_ms(3000);                   //
                     printf("AT+CMGD=1\r\n");//delete the readed msm                     
                     delay_ms(3000);                   //
                     while(!Hand(num));                       //
                     CLR_Buf();                              //               
  }
               }
}
/*************************/
/************************/
void CLR_Buf(void)
{
   unsigned char k;
    for(k=0;k<Buf_Max;k++)    //
       {
         Rec_Buf[k] = 0;
      }
    i = 0;                   
}
/***********************************************/
int1 Hand(unsigned char *a)
{     
   
    if(strstr(Rec_Buf,a)!=NULL)
      return (1);
     
   else
      return (0);
     
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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