|
|
View previous topic :: View next topic |
Author |
Message |
shuhaida9337
Joined: 23 May 2016 Posts: 1
|
gsm coding |
Posted: Mon May 23, 2016 9:06 am |
|
|
hi i wanna ask
why my coding got error
the error is undefined identifier AT
AT is AT command that i used for sending msg to gsm.
Anyone please help me on this.
Code: |
#include <18f4550.h>
#device adc=10
#use delay (clock=4000000)
#fuses hs,nowdt,nolvp,nobrownout,noprotect
#byte porta=0xf80
#byte portc=0xF82
#byte portd=0xf83
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7,parity=N,stream=gsm)
unsigned int temp,sensor1,sensor2,vout1,vout2;
long count;
long tick=3000;
void send_sms()
{
putc("at+cmgs= \"+60134207507"");
putc(0x0d);
putc(0x0a);
delay_ms(1000);
}
void GSM_initialise()
{
putc("AT+CMGF=1\r");
putc(0x0d);
putc(0x0a);
delay_ms(1000);
}
void main_gsm()
{
GSM_initialise();
while(1)
send_sms();
printf("****Test****");
delay_ms(10);
printf("ALERT!!! Heatstroke risk is high!!!!");
delay_ms(10);
printf("*******");
putc(26);
delay_ms(1000);
}
void main()
{
count=tick;
set_TIMER2(0);
setup_TIMER_2(T2_DIV_BY_4,250,1);
setup_ccp1 (ccp_pwm);
set_pwm1_duty(921);
enable_interrupts(INT_TIMER2);
enable_interrupts (GLOBAL);
set_tris_a(1); // porta as input
set_tris_d(0); // portd as output (buzzer)
set_tris_c(0); // portc as ouput (GSM)
setup_adc_ports(all_analog);
setup_adc(adc_clock_internal);
while (1)
{
set_adc_channel(0); //select input from channel ANO
delay_ms(10);
sensor1= read_adc();
temp= (0.00488*sensor1)*1000;
vout1=(temp/10);
set_adc_channel(1);
delay_ms(10);
sensor2= read_adc();
vout2=(sensor2*0.00488)*1000;
if (vout1>=14 && vout2>=250)
{
output_high(pin_d0);
delay_ms(100);
}
else if (vout1>=14 && vout2<250)
{
output_low(pin_d0);
delay_ms(100);
}
else if (vout1<14 && vout2>=250)
{
output_high(pin_d0);
delay_ms(100);
}
else if (vout1<14 && vout2<250)
{
output_low(pin_d0);
delay_ms(100);
}
}
} |
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon May 23, 2016 9:21 am |
|
|
Hi,
Look for my post on GSM on the library.
Code: | putc("at+cmgs= \"+60134207507""); |
"Putc()" is for single characters, use "Printf()" instead.
g. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 23, 2016 9:25 am |
|
|
Quote: | void send_sms()
{
putc("at+cmgs= \"+60134207507"");
putc(0x0d);
putc(0x0a);
delay_ms(1000);
}
void GSM_initialise()
{
putc("AT+CMGF=1\r");
putc(0x0d);
putc(0x0a);
delay_ms(1000);
} |
On the first line, you are missing the 2nd escape sequence on the double-
quotes. Also, you should use printf() for these sequences. Do it like this
and it will compile without errors:
Code: | printf("at+cmgs= \"+60134207507\"");
printf("AT+CMGF=1\r"); |
Quote: | enable_interrupts(INT_TIMER2);
enable_interrupts (GLOBAL); |
You have no #int_timer2 interrupt function. If you enable interrupts
without a function and if you get an interrupt, your program will crash.
I think you mis-understand. Just because you enable Timer2 does not
mean you need to enable interrupts for it. Delete the two lines shown above. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon May 23, 2016 9:26 am |
|
|
Hi,
This line is wrong:
Code: |
putc("at+cmgs= \"+60134207507"");
|
Here is what the manual says about 'putc': putc (cdata) - cdata is a 8 bit character.
You need to be using 'puts', or better yet, 'printf' to be sending data to the GSM modem. Of course, you will actually want to use 'fprintf' with your stream identifier! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon May 23, 2016 10:16 am |
|
|
Lets just clarify here (or make it more confusing).
Putc, as standard accepts a single character.
CCS has an extension in that any function that accepts a single char, can be called with a constant 'string', and the function will be repeatedly called, once for each character in the string. This was an old extension to help people to be able to handle the limitations on the PIC architecture.
This extension has been retained in later versions of CCS.
So in fact putc will work with a constant string, but the escapes have to be right!. However it is not now the suggested way to work, and is a limited 'non standard on any other compiler' extension. |
|
|
|
|
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
|