بنده یه پروژه دارم که توش ماژول های التراسونیک و رطوبت خاک وجی اس ام استفاده میشه .یه برنامه نوشتم که وقتی ارتفاع کم بشه پیام بده.و من با خبر شم.وبعد خودم رله رو روشن کنم.وخودم خاموشش کنم.ولی مشکل این جاست که روشن میتونم کنم ولی وقتی پیام میفرستم خاموش شه خاموش نمیشه .خیلی هم روش فک کردم ولی درست نمیشه .خواهشا اگه مقدوره کدم رو برسی کنید.
while (1)
{
halgheh:
r=read_adc(0);
r=1023-r;
PORTC.0=1;delay_us(20);PORTC.0=0;
while(PINC.1==0){};
timer=0;TCNT0=0;TCCR0=0x02;
while(PINC.1 == 1){};
TCCR0=0x00;
if(timer*256.0+TCNT0>30000.0){lcd_clear();lcd_goto xy(0,0);lcd_puts("chizi nist. o_O");}
else
{
d=0;d=(timer*256.0+TCNT0)*.17;
d=d/10;
if(d<10){ //if
check1:
for ( i=0 ; i<=2 ; i++)
{
putchar(at[i]);
}
delay_ms(3000);
pch=strstr(rx_buffer,"OK");
if(pch==0) goto check1;
PORTD.6=0;
delay_ms(1000);
//echo off
for ( i=0 ; i<=4 ; i++)
{
putchar(ATE0[i]);
}
delay_ms(2000);
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
// Global enable interrupts
#asm("sei")
pch=0;
rx_wr_index=0;
// text mode sms
for ( i=0 ; i<=9 ; i++)
{
putchar(text_mode[i]);
}
//checking ok
while(pch==0) {
pch=strstr(rx_buffer,"OK");
}
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
//send turning on sms
for ( i=0 ; i<=23 ; i++)
{
putchar(send_sms[i]);
}
delay_ms(1000);
for ( i=0 ; i<=20 ; i++)
{
putchar(sms_ok[i]);
}
putchar('\r');
putchar(ctrlz);
delay_ms(1000);
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
pch=0;
rx_wr_index=0;
a=0;
//delete all messege
for ( i=0 ; i<=18 ; i++)
{
putchar(cmgda[i]);
}
i=0;
while (1) {
rx_wr_index=0;
if(a>=56){ //if a>='8'
//delete all messege
for ( i=0 ; i<=18 ; i++)
{
putchar(cmgda[i]);
}
i=0;
delay_ms(10000);
}
pch=0;
rx_wr_index=0;
//waiting for +CMTI: from sim900
while(pch==0) {
pch=strstr(rx_buffer,"+CMTI:");
}
delay_ms(500);
//show messege request
for ( i=0 ; i<=7 ; i++)
{
putchar(cmgr[i]);
}
putchar(pch[12]);
putchar('\r');
a=pch[12];
pch=0;
rx_wr_index=0;
delay_ms(1500);
//checking ok
// while(pch==0) {
//pch=strstr(rx_buffer,"OK");
//}
//pch=0;
//checking on
pch=strstr(rx_buffer,"on");
if(pch != 0){
PORTD.7=1;
pch=0;
rx_wr_index=0;
}
//checking off
pch=strstr(rx_buffer,"off");
if(pch != 0) {
PORTD.7=0;
pch=0;
rx_wr_index=0;
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
goto halgheh;
}
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
pch=0;
}
} //if
lcd_clear();sprintf(st,"d=%3.0fcm r=%d",d,r);lcd_puts(st);delay_ms(150);
} //else
}//whille
{
halgheh:
r=read_adc(0);
r=1023-r;
PORTC.0=1;delay_us(20);PORTC.0=0;
while(PINC.1==0){};
timer=0;TCNT0=0;TCCR0=0x02;
while(PINC.1 == 1){};
TCCR0=0x00;
if(timer*256.0+TCNT0>30000.0){lcd_clear();lcd_goto xy(0,0);lcd_puts("chizi nist. o_O");}
else
{
d=0;d=(timer*256.0+TCNT0)*.17;
d=d/10;
if(d<10){ //if
check1:
for ( i=0 ; i<=2 ; i++)
{
putchar(at[i]);
}
delay_ms(3000);
pch=strstr(rx_buffer,"OK");
if(pch==0) goto check1;
PORTD.6=0;
delay_ms(1000);
//echo off
for ( i=0 ; i<=4 ; i++)
{
putchar(ATE0[i]);
}
delay_ms(2000);
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
// Global enable interrupts
#asm("sei")
pch=0;
rx_wr_index=0;
// text mode sms
for ( i=0 ; i<=9 ; i++)
{
putchar(text_mode[i]);
}
//checking ok
while(pch==0) {
pch=strstr(rx_buffer,"OK");
}
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
//send turning on sms
for ( i=0 ; i<=23 ; i++)
{
putchar(send_sms[i]);
}
delay_ms(1000);
for ( i=0 ; i<=20 ; i++)
{
putchar(sms_ok[i]);
}
putchar('\r');
putchar(ctrlz);
delay_ms(1000);
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
pch=0;
rx_wr_index=0;
a=0;
//delete all messege
for ( i=0 ; i<=18 ; i++)
{
putchar(cmgda[i]);
}
i=0;
while (1) {
rx_wr_index=0;
if(a>=56){ //if a>='8'
//delete all messege
for ( i=0 ; i<=18 ; i++)
{
putchar(cmgda[i]);
}
i=0;
delay_ms(10000);
}
pch=0;
rx_wr_index=0;
//waiting for +CMTI: from sim900
while(pch==0) {
pch=strstr(rx_buffer,"+CMTI:");
}
delay_ms(500);
//show messege request
for ( i=0 ; i<=7 ; i++)
{
putchar(cmgr[i]);
}
putchar(pch[12]);
putchar('\r');
a=pch[12];
pch=0;
rx_wr_index=0;
delay_ms(1500);
//checking ok
// while(pch==0) {
//pch=strstr(rx_buffer,"OK");
//}
//pch=0;
//checking on
pch=strstr(rx_buffer,"on");
if(pch != 0){
PORTD.7=1;
pch=0;
rx_wr_index=0;
}
//checking off
pch=strstr(rx_buffer,"off");
if(pch != 0) {
PORTD.7=0;
pch=0;
rx_wr_index=0;
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
goto halgheh;
}
// delete receive buffer
for(i=0;i<=128;i++) {
rx_buffer[i]=0;
}
pch=0;
}
} //if
lcd_clear();sprintf(st,"d=%3.0fcm r=%d",d,r);lcd_puts(st);delay_ms(150);
} //else
}//whille