#include <18F4550.h>
#include <string.h>
#include <stdio.h>
#fuses HS
#fuses NOLVP, NOWDT
#fuses NOPROTECT
#use delay (clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=SIM900)
//#use rs232(baud=9600,xmit=PIN_b6,rcv=PIN_b7,stream=PC)
#INT_EXT
void Initial_port()
{
set_tris_b(0x00);
}
void message()
{
char buffer[80];
char sms_index[4];
char sms [80];
char localt[9][5];
char sentent_1[]="CMGL:";
char sentent_2[]="gsm>";
int i,c,j,k,l,m;
int count;
for(i=0; i<80; i++)
buffer='0';
for(i=0; i<4; i++)
sms_index='0';
for(i=0; i<80; i++)
sms='0';
for(i=0; i<9; i++)
{
for(j=0; j<4; j++) localt[j] = '0';
}
fprintf(SIM900,"at+cmgl = rec unread \n\r");
delay_ms(100);
c=0;
do
{
while ( fgetc(SIM900) != '+')
{
c++;
if(c>20)
return;
}
for (i=0 ; i<40; i++)
buffer=fgetc(SIM900);
}
while (strncmp(buffer,sentent_1,5)!=0);
for (l=0; buffer[l] != ' '; l++);
for (m=0; buffer[m] !=',';m++);
l=l+1;
for(i=0; i<80; i++)
buffer='0';
fprintf(SIM900,"at+cmgr=%s\n\r",sms_index);
delay_ms(100);
do
{
while ( fgetc(SIM900) != '$');
for (i=0 ; i<60 ; i++)
{
buffer=fgetc(SIM900);
if(buffer == '<')
break;
}
}
while (strncmp(buffer,sentent_2,4)!=0);
for (l=0; buffer[l] != '>'; l++);
for (m=0; buffer[m] !='<'; m++);
l=l+1;
k=strlen(sms);
count = 0;
for(i=0; i<=k; i++)
{
if(sms == ',')
count++;
}
k=0;
for(i=0; i<9;i++)
{
for(j=0; j<4; j++)
{
localt[j] = sms[k];
k++;
}
}
}
void control_relay ()
{
char ch;
//ch=getc();
while(TRUE)
{
printf("\n\rSelect LED : ");
ch=getc();
putc(ch);
switch(ch)
{
case'a':
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
break;
case'b':
output_low(PIN_B0);
output_high(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
break;
case'c':
output_high(PIN_B2);
output_low(PIN_B1);
output_low(PIN_B0);
output_low(PIN_B3);
break;
case'd':
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_high(PIN_B3);
break;
}
}
}
void main (void)
{
Initial_port();
message();
control_relay ();
}
ใครรู้บ้างว่าทำไมส่ง sms เข้าไปแล้วมันไม่ทำงาน แต่คอมไพล์ผ่านแล้ว??? ใช้ ccs c
#include <string.h>
#include <stdio.h>
#fuses HS
#fuses NOLVP, NOWDT
#fuses NOPROTECT
#use delay (clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=SIM900)
//#use rs232(baud=9600,xmit=PIN_b6,rcv=PIN_b7,stream=PC)
#INT_EXT
void Initial_port()
{
set_tris_b(0x00);
}
void message()
{
char buffer[80];
char sms_index[4];
char sms [80];
char localt[9][5];
char sentent_1[]="CMGL:";
char sentent_2[]="gsm>";
int i,c,j,k,l,m;
int count;
for(i=0; i<80; i++)
buffer='0';
for(i=0; i<4; i++)
sms_index='0';
for(i=0; i<80; i++)
sms='0';
for(i=0; i<9; i++)
{
for(j=0; j<4; j++) localt[j] = '0';
}
fprintf(SIM900,"at+cmgl = rec unread \n\r");
delay_ms(100);
c=0;
do
{
while ( fgetc(SIM900) != '+')
{
c++;
if(c>20)
return;
}
for (i=0 ; i<40; i++)
buffer=fgetc(SIM900);
}
while (strncmp(buffer,sentent_1,5)!=0);
for (l=0; buffer[l] != ' '; l++);
for (m=0; buffer[m] !=',';m++);
l=l+1;
for(i=0; i<80; i++)
buffer='0';
fprintf(SIM900,"at+cmgr=%s\n\r",sms_index);
delay_ms(100);
do
{
while ( fgetc(SIM900) != '$');
for (i=0 ; i<60 ; i++)
{
buffer=fgetc(SIM900);
if(buffer == '<')
break;
}
}
while (strncmp(buffer,sentent_2,4)!=0);
for (l=0; buffer[l] != '>'; l++);
for (m=0; buffer[m] !='<'; m++);
l=l+1;
k=strlen(sms);
count = 0;
for(i=0; i<=k; i++)
{
if(sms == ',')
count++;
}
k=0;
for(i=0; i<9;i++)
{
for(j=0; j<4; j++)
{
localt[j] = sms[k];
k++;
}
}
}
void control_relay ()
{
char ch;
//ch=getc();
while(TRUE)
{
printf("\n\rSelect LED : ");
ch=getc();
putc(ch);
switch(ch)
{
case'a':
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
break;
case'b':
output_low(PIN_B0);
output_high(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
break;
case'c':
output_high(PIN_B2);
output_low(PIN_B1);
output_low(PIN_B0);
output_low(PIN_B3);
break;
case'd':
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_high(PIN_B3);
break;
}
}
}
void main (void)
{
Initial_port();
message();
control_relay ();
}