View previous topic :: View next topic |
Author |
Message |
tonydiablo
Joined: 21 Mar 2008 Posts: 2
|
sending sms with pic |
Posted: Sat May 10, 2008 3:27 am |
|
|
we're studying for a final project which is about smart home.
we have to send sms to a cell phone in emergencies with pic 16f877 and ericsson t10
Code: |
#int_EXT
void cep(void)
{
int num;
num="+90505xxxxxxx";
fprintf(GSM,”AT\r\n”)
delay_ms(1000)
fprintf(GSM,"AT+CMGS=\"%s\"\r\n",num); sms to number
delay_ms(1000);
fputc(0x1A,GSM); //to send sms ^Z
delay_ms(1000);
do{
output_high(pin_C4);
delay_ms(500);
output_low(pin_C4);
delay_ms(500);
}while(input(pin_B0));
|
we tried this program but it didn't work this is not whole program only an example but if we create a elementary program like this we can do other parts of the program
will anybody help us about programing especially ctrl-z and enter commands
thxs alot sorry my bad english |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat May 10, 2008 6:12 pm |
|
|
Code: | int num;
num="+90505xxxxxxx"; | The type 'int' is for storing an 8-bit integer. You can only use it for numbers 0 to 255. What you want to do is to store a series of characters, the correct name for this is string.
A string can be stored in an array like: Code: | char num[] = "+90505xxxxxxx"; |
It is good design to keep your interrupts as fast as possible. So don't use printf and delay commands in the interrupt routine, instead set a flag and in your main routine test for this flag.
Sensing SMS has been discussed many times before, use the search function of this forum to find example code. |
|
|
tonydiablo
Joined: 21 Mar 2008 Posts: 2
|
|
Posted: Tue May 13, 2008 4:26 am |
|
|
can anybody tell me what is wrong with this program .
i'm using 16f877 and t10 mobile phone via max232 but i cant send sms
#include <float.h>
#include <stdio.h>
#include <string.h>
#include <input.c>
#use rs232(baud=9600,parity=N,xmit=pin_c6,rcv=pin_C7,bits=8,stream=GSM)
byte num[12];
#int_RB
void RB_isr(void)
{
}
#int_EXT
void cep(void)
{
printf("AT") ;
putc(0x0d);
delay_ms(2000);
printf("AT+CMGF=0");
putc(0x0d);
delay_ms(2000);
printf("AT+CMGS=18");
putc(0x0d);
printf("079109558900080001000C91090535xxxxx00000570F95B5D06");
putc(0x1a);
delay_ms(20000);
do{
output_high(pin_C4);
delay_ms(500);
output_low(pin_C4);
delay_ms(500);
}while(input(pin_B0));
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(INT_RB);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
output_high(pin_c0);
delay_ms(500);
output_low(pin_c0);
delay_ms(500);
}
} |
|
|
bwhiten
Joined: 26 Nov 2003 Posts: 151 Location: Grayson, GA
|
fprintf with streams |
Posted: Tue May 13, 2008 7:21 am |
|
|
First thing I noticed is that since you used a STREAM name in your #use RS232 statement, you must use the stream versions of printf, etc. Look at the help documents for fprintf, fputc, etc.
Plus, your interrupt routines are waaaaaaaaaaay too long with these delays and print statements. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue May 13, 2008 8:04 am |
|
|
Code: | printf("AT+CMGS=18");
putc(0x0d);
printf("079109558900080001000C91090535xxxxx00000570F95B065D"); |
The way you are creating the text message here assumes the phone is in PDU mode instead of text mode. I don't see the command 'AT+CMGF=0'. Are you sure the phone always starts up in PDU mode?
'xxxxx' is not valid hex code. I assume you changed this when posting the code?
Your string is longer than the specified length of 18.
I don't know the T10 mobile phone but if it follows the GSM 03.40 standard then to me it looks like the message is composed in a wrong way. Why don't you use text mode? That would be a lot easier for a first application.
A delay of 20 seconds in an interrupt is considered bad programming. Interrupts are supposed to be as short as possible so the normal program flow can continue and you can detect other interrupts. Why didn't you implement my suggestion of setting a flag in the interrupt routine and testing this flag in your main?
Maybe there are more errors but you can test this yourself: connect the phone to your PC and use Hyperterm (or a similar program) to manually send the commands to the phone. This way you will also see the response from the phone, including error messages. I always test new phone commands like this, first try on the PC before you start programming. |
|
|
|