Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic16f877a gsm remote controller error

Status
Not open for further replies.

artbellson

Newbie level 4
Joined
Mar 23, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
HI GUYS. the objective of the code is to decode the sms sent to gsm module and depending on the sms command it will switch relays connected to output pins of the ic.

please help me find the problem in the code. here is the code

Code:
#if defined(__PCB__)
#include <16f877a.h>*
#include <string.h>*
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT*
#use delay(clock=20000000) //must be 20 MHz*

#elif defined(__PCM__)
#include <16f877a.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=20000000) //must be 20 MHz*

#use rs 232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // serial*



void SerialInt();
int TEST_AT();
int SET_MEM();
int SET_PDU();
int SET_CNMI();
int SMSALERT();
int READ_SMS();
int DO_CMD();
int DEL_SMS();
void GET_CMD();
int GET_OK(int Stop_Search);

volatile int counter_search=0;
volatile int counter_read=0;

Volatile int HitCounter=0;// for string comparison*
Volatile int Next_CMD=0;


volatile Char Recieve_String[70];//buffer for incoming data*

void main()
{
SET_TRIS_A( 0x00 );// to avoid floating pins*
SET_TRIS_B( 0x00 );
OUTPUT_B(0X00);
SET_TRIS_C( 0x80 );
SET_TRIS_D( 0x00 );
SET_TRIS_E( 0x00 );

enable_interrupts(INT_RDA);// enable RDA interrupts*
enable_interrupts(GLOBAL);// enable global ints*


output_high(PIN_D1);// blink for circuit 'ON' confirmation*
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
Delay_ms(1000);

while(1)
{
if(TEST_AT())
{
if(SET_MEM())
{
if(SET_PDU())
{
if(SET_CNMI())
{
if(SMSALERT())
{
if(READ_SMS())
{
if(GET_CMD()) 
{
if(DEL_SMS())
{
DO_CMD();
}
}
else
{
DEL_SMS();
}
}
}
}
}
}
}
}

}


int TEST_AT()
{
counter_read=0;

printf("AT");//send command*
putchar(0x0D);//send return ('enter' in hyperterminal)*

output_high(PIN_D1);
While(counter_read<=8)//"A T \R \R \N O K \R \N" characters returned by modem*
{
}
output_low(PIN_D1);

counter_read=0;
Delay_ms(500);// ignore all remaining characters received*

if(GET_OK(0X0A))
Return(1);
else return(0);

}
int SET_MEM()
{
counter_read=0;//reset all counters.*

printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");//text part of the command.*
putchar(0x0D);// enter*


While(counter_read<25)// stay here, ignore first 25 chars*
{
}

counter_read=0;// start filling up the array from cero...from here on, keep the incoming text for parsing*

while(counter_read<=28)// acquire all pertinent text, I'm only looking for an "OK" but for now I'm keeping all incoming txt.*
{// maybe for future use...*
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters received..if any.*

if(GET_OK(0X1C))
Return(1);
else return(0);
}


int SET_PDU()
{
counter_read=0;

printf("AT+CMGF=1");//send command*
putchar(0x0D);//send return*

While(counter_read<=15)// get all returned text*
{
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters recieved*

if(GET_OK(0X0E))
Return(1);
else return(0);
}


int SET_CNMI()
{
counter_read=0;//reset all counters.*

printf("AT+CNMI=2,1,2,0,0");//text part of the command.*
putchar(0x0D);//send return*

While(counter_read<24)// read all data*
{
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters recieved..if any.*

if(GET_OK(0X17))
Return(1);
else return(0);
}

int SMSALERT()
{
const char StrCMTI[]={"+CMTI"};

counter_read=0;

While(counter_read<=16)// read all data*
{
output_high(PIN_D1);// signal ready to receive sms*
}
counter_read=0;

Delay_ms(500);// ignore all remaining characters recieved..if any.*
output_low(PIN_D1);// off receive ready light.*
counter_search=2;

HitCounter=0;

while((HitCounter!=5)&&(counter_search<8))
{
if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
HitCounter++;

counter_search++;
}

if(HitCounter==0x05)
Return(1);
else return(0);
}


int READ_SMS()
{
counter_read=0;

printf("AT+CMGR=1");// send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROSCESING*
putchar(0x0D);

delay_ms(3000);// long [spam] message... so give time,* buffer will loop back one time...*
// text will be on second fill.*
counter_read=0;

if(GET_OK(0X45))
Return(1);
else return(0);

}

int GET_CMD()
{
const char CMD1[8][7]={"Led1 0","Led1 1","Led2 0","Led2 1","Led3 0","Led3 1","Led4 0","Led4 1"};

int offset=0;
int store_counter=0;
counter_search=0;


while((Recieve_String[counter_search]!='!')&&(counter_search<69))// wait till command indicator is found '!'*
{
counter_search++;
}

counter_search=counter_search+1;// increment one to actual first letter of command*
store_Counter=counter_search;// store current position for multiple searches*
NEXT_CMD=0;// NEXT_CMD keeps track of the command being read, thus used*
while((HitCounter!=6)&&(NEXT_CMD<8))// compare to all commands in list.*
{
counter_search=store_Counter;// initialize counter search with stored counter value.*
offset=0;// since value of counter is unknown use a separate counter for the const array*
HitCounter=0;// counts number of equal letters found.*

while((HitCounter!=6)&&(offset<=6))// keeps the counters in check...to not overshoot. and compares the strings*
{
if(Recieve_String[counter_search]==CMD1[NEXT_CMD][offset])// if letter is found*
HitCounter++;
offset++;
counter_search++;
}

if(HitCounter==6)// if 6 chars found...exit..*
{
Return(1);
}

NEXT_CMD++;// if increase to search next command.*


}

Return(0);
}


Void DO_CMD()
{
if(NEXT_CMD==0)output_low(PIN_B1);
if(NEXT_CMD==1)output_high(PIN_B1);

if(NEXT_CMD==2)output_low(PIN_B2);
if(NEXT_CMD==3)output_high(PIN_B2);

if(NEXT_CMD==4)output_low(PIN_B3);
if(NEXT_CMD==5)output_high(PIN_B3);

if(NEXT_CMD==6)output_low(PIN_B4);
if(NEXT_CMD==7)output_high(PIN_B4);

}

int DEL_SMS()
{
counter_read=0;

printf("AT+CMGD=1");//send command*
putchar(0x0D);//send return*

While(counter_read<=15)// get all returned text*
{
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters received*

if(GET_OK(0X0E))
Return(1);
else return(0);
}


int GET_OK(Stop_Search)
{
counter_search=0;

while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))//check buffer until an 'O' is found or 10 chars have been checked.*
{
counter_search++;//obvious*
}

if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))//check for a 'K' after the 'O'*
{
counter_search=0;
Return(1);//function returns true*
}
Return(0);
counter_search=0;
}



#INT_RDA
void SerialInt()
{
Recieve_String[counter_read]=getchar();
counter_read++;
if(counter_read==69)counter_read=0;
}



ERROR ENCOUNTERED:
Warning "line 62(1,1): Condition always TRUE
Error 51 "4relay.c" Line 76(1.2): A numeric expression must appear here
Error 51 "4relay.c" Line 82(1.5): A numeric expression must appear here

---------- Post added at 01:58 ---------- Previous post was at 01:57 ----------

by the way im using ccs compiler
 
Last edited:

ERROR ENCOUNTERED:
Warning "line 62(1,1): Condition always TRUE
Error 51 "4relay.c" Line 76(1.2): A numeric expression must appear here
Error 51 "4relay.c" Line 82(1.5): A numeric expression must appear here

how am i supposed to look for lines 62, 76 and 82
 

Code:
while(1)
{ [COLOR="#FF0000"]LIINE 62[/COLOR]
if(TEST_AT())
{
if(SET_MEM())
{
if(SET_PDU())
{
if(SET_CNMI())
{
if(SMSALERT())
{
if(READ_SMS())
{
if(GET_CMD())
{ [COLOR="#FF0000"]LINE 76[/COLOR]
if(DEL_SMS())
{
DO_CMD();
}
}
else [COLOR="#FF0000"]LINE 82[/COLOR]
{
DEL_SMS();
}
}
}
}
}
}
}
}

}
 
Last edited by a moderator:

Code:
nt TEST_AT();
int SET_MEM();
int SET_PDU();
int SET_CNMI();
int SMSALERT();
int READ_SMS();
int DO_CMD();
int DEL_SMS();
void GET_CMD();
int GET_OK(int Stop_Search);

GET_CMD() has void return type....
Code:
if(READ_SMS())
{
if(GET_CMD())
{ LINE 76
if(DEL_SMS())
{
DO_CMD();
 
Code:
nt TEST_AT();
int SET_MEM();
int SET_PDU();
int SET_CNMI();
int SMSALERT();
int READ_SMS();
int DO_CMD();
int DEL_SMS();
void GET_CMD();
int GET_OK(int Stop_Search);

GET_CMD() has void return type....
Code:
if(READ_SMS())
{
if(GET_CMD())
{ LINE 76
if(DEL_SMS())
{
DO_CMD();

How to fix the code?
 

Code:
void GET_CMD();
change void to int

dont know why you are using int though
its better to use unsigned char...
 
i got new error on DO_CMD(); command. it says function used but not defined.

---------- Post added at 08:16 ---------- Previous post was at 08:12 ----------

thanks alot of helping me. i changed int to void in declaration and the only warning is the "Warning "line 62(1,1): Condition always TRUE"
 

hi guys. i need help compiling this code into .hex file. do any one has ccs compiler?

Code:
#if defined(__PCB__)
#include <16f877a.h>*
#include <string.h>*
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT*
#use delay(clock=8000000) //must be 8 MHz*

#elif defined(__PCM__)
#include <16f877a.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=8000000) //must be 8 MHz*

#use rs 232(baud=2400, xmit=PIN_C6, rcv=PIN_C7) // serial*



void SerialInt();
int TEST_AT();
int SET_MEM();
int SET_PDU();
int SET_CNMI();
int SMSALERT();
int READ_SMS();
int DO_CMD();
int DEL_SMS();
int GET_CMD();
int GET_OK(int Stop_Search);

volatile int counter_search=0;
volatile int counter_read=0;

Volatile int HitCounter=0;// for string comparison*
Volatile int Next_CMD=0;


volatile Char Recieve_String[70];//buffer for incoming data*

void main()
{
SET_TRIS_A( 0x00 );// to avoid floating pins*
SET_TRIS_B( 0x00 );
OUTPUT_B(0X00);
SET_TRIS_C( 0x80 );
SET_TRIS_D( 0x00 );
SET_TRIS_E( 0x00 );

enable_interrupts(INT_RDA);// enable RDA interrupts*
enable_interrupts(GLOBAL);// enable global ints*


output_high(PIN_D1);// blink for circuit 'ON' confirmation*
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
Delay_ms(1000);

while(1)
{
if(TEST_AT())
{
if(SET_MEM())
{
if(SET_PDU())
{
if(SET_CNMI())
{
if(SMSALERT())
{
if(READ_SMS())
{
if(GET_CMD()) 
{
if(DEL_SMS())
{
DO_CMD();
}
}
else
{
DEL_SMS();
}
}
}
}
}
}
}
}

}


int TEST_AT()
{
counter_read=0;

printf("AT");//send command*
putchar(0x0D);//send return ('enter' in hyperterminal)*

output_high(PIN_D1);
While(counter_read<=8)//"A T \R \R \N O K \R \N" characters returned by modem*
{
}
output_low(PIN_D1);

counter_read=0;
Delay_ms(500);// ignore all remaining characters received*

if(GET_OK(0X0A))
Return(1);
else return(0);

}
int SET_MEM()
{
counter_read=0;//reset all counters.*

printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");//text part of the command.*
putchar(0x0D);// enter*


While(counter_read<25)// stay here, ignore first 25 chars*
{
}

counter_read=0;// start filling up the array from cero...from here on, keep the incoming text for parsing*

while(counter_read<=28)// acquire all pertinent text, I'm only looking for an "OK" but for now I'm keeping all incoming txt.*
{// maybe for future use...*
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters received..if any.*

if(GET_OK(0X1C))
Return(1);
else return(0);
}


int SET_PDU()
{
counter_read=0;

printf("AT+CMGF=1");//send command*
putchar(0x0D);//send return*

While(counter_read<=15)// get all returned text*
{
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters recieved*

if(GET_OK(0X0E))
Return(1);
else return(0);
}


int SET_CNMI()
{
counter_read=0;//reset all counters.*

printf("AT+CNMI=2,1,2,0,0");//text part of the command.*
putchar(0x0D);//send return*

While(counter_read<24)// read all data*
{
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters recieved..if any.*

if(GET_OK(0X17))
Return(1);
else return(0);
}

int SMSALERT()
{
const char StrCMTI[]={"+CMTI"};

counter_read=0;

While(counter_read<=16)// read all data*
{
output_high(PIN_D1);// signal ready to receive sms*
}
counter_read=0;

Delay_ms(500);// ignore all remaining characters recieved..if any.*
output_low(PIN_D1);// off receive ready light.*
counter_search=2;

HitCounter=0;

while((HitCounter!=5)&&(counter_search<8))
{
if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
HitCounter++;

counter_search++;
}

if(HitCounter==0x05)
Return(1);
else return(0);
}


int READ_SMS()
{
counter_read=0;

printf("AT+CMGR=1");// send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROSCESING*
putchar(0x0D);

delay_ms(3000);// long [spam] message... so give time,* buffer will loop back one time...*
// text will be on second fill.*
counter_read=0;

if(GET_OK(0X45))
Return(1);
else return(0);

}

int GET_CMD()
{
const char CMD1[8][7]={"Led1 0","Led1 1","Led2 0","Led2 1","Led3 0","Led3 1","Led4 0","Led4 1"};

int offset=0;
int store_counter=0;
counter_search=0;


while((Recieve_String[counter_search]!='!')&&(counter_search<69))// wait till command indicator is found '!'*
{
counter_search++;
}

counter_search=counter_search+1;// increment one to actual first letter of command*
store_Counter=counter_search;// store current position for multiple searches*
NEXT_CMD=0;// NEXT_CMD keeps track of the command being read, thus used*
while((HitCounter!=6)&&(NEXT_CMD<8))// compare to all commands in list.*
{
counter_search=store_Counter;// initialize counter search with stored counter value.*
offset=0;// since value of counter is unknown use a separate counter for the const array*
HitCounter=0;// counts number of equal letters found.*

while((HitCounter!=6)&&(offset<=6))// keeps the counters in check...to not overshoot. and compares the strings*
{
if(Recieve_String[counter_search]==CMD1[NEXT_CMD][offset])// if letter is found*
HitCounter++;
offset++;
counter_search++;
}

if(HitCounter==6)// if 6 chars found...exit..*
{
Return(1);
}

NEXT_CMD++;// if increase to search next command.*


}

Return(0);
}


Void DO_CMD()
{
if(NEXT_CMD==0)output_low(PIN_B1);
if(NEXT_CMD==1)output_high(PIN_B1);

if(NEXT_CMD==2)output_low(PIN_B2);
if(NEXT_CMD==3)output_high(PIN_B2);

if(NEXT_CMD==4)output_low(PIN_B3);
if(NEXT_CMD==5)output_high(PIN_B3);

if(NEXT_CMD==6)output_low(PIN_B4);
if(NEXT_CMD==7)output_high(PIN_B4);

}

int DEL_SMS()
{
counter_read=0;

printf("AT+CMGD=1");//send command*
putchar(0x0D);//send return*

While(counter_read<=15)// get all returned text*
{
}

counter_read=0;

Delay_ms(500);// ignore all remaining characters received*

if(GET_OK(0X0E))
Return(1);
else return(0);
}


int GET_OK(Stop_Search)
{
counter_search=0;

while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))//check buffer until an 'O' is found or 10 chars have been checked.*
{
counter_search++;//obvious*
}

if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))//check for a 'K' after the 'O'*
{
counter_search=0;
Return(1);//function returns true*
}
Return(0);
counter_search=0;
}



#INT_RDA
void SerialInt()
{
Recieve_String[counter_read]=getchar();
counter_read++;
if(counter_read==69)counter_read=0;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top