|
|
View previous topic :: View next topic |
Author |
Message |
bhas_r
Joined: 19 May 2009 Posts: 18
|
GSM Read sms error |
Posted: Wed May 23, 2012 6:16 am |
|
|
I am doing project on Device on/off and status through SMS. i able to send status but unable to read sms
here is my code on 2009 i succeeded with this code now not working Hardware is perfect bcz it works with PC
#include <16F877A.h>
#include <string.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use standard_io(A)
//#use standard_io(C)
//#use standard_io(D)
#byte porta = 0x05
#byte portc = 0x07
#byte portd = 0x08
void main()
{
int i;
char k[90];
set_tris_d(0x02);
set_tris_C(0x80);
set_tris_a(0x00);
output_d(0x00);
output_c(0x00);
output_a(0x00);
top:
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C4)
printf("AT\r");
delay_ms(1000);
printf("ATH\r");
delay_ms(1000);
printf("AT+IPR=9600\r");
delay_ms(1000);
printf("AT+ICF=3,3\r");
delay_ms(1000);
printf("AT+CMGF=1\r");
delay_ms(1000);
read:
i=0;
k[i]=getch();
if(k[i]!='+')
goto read;
if(k[i]=='+')
{
delay_ms(1000);
bit_set(porta,0x00);
delay_ms(2000);
printf("AT+CMGL=\x22REC UNREAD\x22\r");
for(i=0;i<=90;i++)
{
k[i]=getch();
bit_clear(porta,0x00);
if(k[i]=='(')
{
i++;
k[i]=getch();
if(k[i]=='A')
{
output_toggle(PIN_A0);
goto top;
}
if(k[i]=='B')
{
output_toggle(PIN_A1);
goto top;
}
if(k[i]=='C')
{
output_toggle(PIN_A2);
goto top;
}
goto top;
}
}
goto top;
}
goto top;
}
if there is any error in AT Commands plz help me to complete my project
THANKS in ADVANCE |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 23, 2012 7:20 am |
|
|
Hi,
A couple of things. Please use the 'Code' tags when posting your code so that proper formatting is preserved. As shown, your code is extremely difficult to read. Please tell us your compiler version, and please tell us which GSM module you are using, and how it's wired to the PIC.
There is at least one complete, working example of what you want to do in the archives written by user 'Gabriel'. You can find it here: http://www.ccsinfo.com/forum/viewtopic.php?t=42527
A couple of comments about your code. You should add 'Errors' to the #use rs232 statement to prevent the UART from hanging if the Rx buffer overflows. You should not be messing with 'Fast_io', and setting the 'Tris' registers yourself - that is not necessary for a project like this, the compiler will do it automatically. Some many disagree with this, but the use of 'Goto' statements in a 'C' program shows bad form. There are much better ways to program. Yes, it's legal 'C', but it's sloppy IMHO.
John |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed May 23, 2012 7:39 am |
|
|
Your program has so many problems that it makes me feel very sad.
I'm sorry to say so, but in the last few years this is one of the worst programs I've seen posted here and I'm not sure I want to (or can) help you.
Here are a few suggestions to at least make your program look like you have a clue as to what you are doing:
1) When posting code always use the 'code' buttons to preserve the layout of your program. This makes for easier reading and will get you more and better response.
2) NEVER use the goto command in C programs. It often leads to difficult to maintain code and is considered bad programming. Use while-loops and function calls instead.
3) The #use RS232 line is _not_ supposed to be inside a function. It should be at the start of your program next to the other #use lines.
4) Your RS232 is using PIN_C6 for transmit. Good. But the hardware receive is _not_ on PIN_C4. Check the datasheet again.
5) Always add the ERRORS keyword to the #use RS232 line. This will make the compiler add code for clearing UART receive buffer overflow errors. Without this the UART will stop working when you read the data too slow.
6) Get rid of all the code setting the TRIS registers and #use standard_io. By default the CCS compiler will handle the TRIS registers for you. Only in special situations where you need optimization you set these registers yourself. But first get your code working, optimization comes last.
7) Code: | bit_set(porta,0x00); | This is invalid code. The bit_set function expects an input like PIN_A1 defined in the CCS header files, not your defined port number.
This is just from starting to look at your code. I didn't even look at the AT commands. |
|
|
|
|
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
|