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

Help me about sensor and GSM module

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



Joined: 28 Jun 2008
Posts: 24

View user's profile Send private message

Help me about sensor and GSM module
PostPosted: Fri Oct 10, 2008 6:41 am     Reply with quote

#include <16F877.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock = 20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

#byte port_b=6

char phone_num[13]="+xxxxxxxxxxx" ;
char ctrl_z=0x1A ;
char CR = 0x0d ;
char LF = 0x0a ;


void send_sms(void)
{

if(!input(PIN_B4))
{
printf("at+cmgs=\"%s\"\n\r",phone_num);
printf("%c\n\r",CR);
printf("%c\n\r",LF);
printf("Products were sold out in Chatuchak area\n\r");
printf("%c\n\r",CR);
printf("%c\n\r",LF);
printf("%c\n\r",ctrl_z);
printf("%c\n\r",CR);
printf("%c\n\r",LF);

}
port_b=0x00;
}

void blink_led()
{
output_toggle(PIN_B7);
delay_ms(100);
}

void main()
{
set_tris_b(0xF0);
blink_led();
while(true)
{
send_sms();
}
}

i would like to send sms if my sensor can detect a light from led
but i have a problem. When sensor detect the sms were sent all time
but i would like to send it enought 1 time

Please help me
thank you
Guest








PostPosted: Fri Oct 10, 2008 9:18 am     Reply with quote

When you run the program, does the LED stay on, or does it flash once and stay off? I would try using output_toggle, output_high and output_low. You don't have to use set_trisb() then.

If you only want to send one message per light reception, you'd probably be better off connecting the sensor to an external interrupt. In the interrupt service routine, set a flag. in the while(true) loop in main(), poll that flag. If the flag is set, clear it, and send your SMS. Also, you don't need to use the set_trisb() if you use output_toggle and output_low.
Code:

#include <16F877.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock = 20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

#byte port_b=6

char phone_num[13]="+xxxxxxxxxxx" ;
char ctrl_z=0x1A ;
char CR = 0x0d ;
char LF = 0x0a ;
int1 sensor_flag=0;

#int_ext0
void ext0_isr()
{
  sensor_flag=1;
}

void send_sms(void)
{

if(!input(PIN_B4))
{
printf("at+cmgs=\"%s\"\n\r",phone_num);
printf("%c\n\r",CR);
printf("%c\n\r",LF);
printf("Products were sold out in Chatuchak area\n\r");
printf("%c\n\r",CR);
printf("%c\n\r",LF);
printf("%c\n\r",ctrl_z);
printf("%c\n\r",CR);
printf("%c\n\r",LF);

}
output_low(PIN_B7);
}

void blink_led()
{
output_toggle(PIN_B7);
delay_ms(100);
}

void main()
{
enable_interrupts(INT_GLOBAL);
enable_interrupts(INT_EXT0);
set_tris_b(0xF0);
blink_led();
while(true)
{
if(sensor_flag==1)
{
sensor_flag=0;
send_sms();
}
}
}



Just out of curiousity, what kind of hardware is sending the SMS?
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Fri Oct 10, 2008 11:22 am     Reply with quote

Just as a side note, your CR and LF after the printf containing the message is probably redundant as the \n\r does that for you...

Code:

printf("Products were sold out in Chatuchak area\n\r");
printf("%c\n\r",CR);            << dont't think this is needed
printf("%c\n\r",LF);             << dont't think this is needed
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