Ni yanfang
Member level 3
Help!! Does anyone can write concept of programming on sending sms on gprs modem connect with at89c51??? Kindly give me some ideas>
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 UART1_Write_Text("AT+CMGF=1"); UART1_Write(13); UART1_Write(10) ; Delay_ms(2000); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("97xxxxxxxx"); Delay_ms(100); UART1_Write(0x22); UART1_Write(13); UART1_Write(10) ; Delay_ms(1000); UART1_Write_Text("Hi! There"); UART1_Write(0x0D); UART1_Write(26); UART1_Write(0x0D);
#include<reg51f.h> // include at89x51 . h
#include<stdio.h>// include stdio . h
#include<stdlib.h>// include stdlib . h
#include<string.h>
unsigned char Command_AT[]="AT\r\n";
unsigned char Command_ATI[]="ATI\r\n";
unsigned char Command_ATCOPS[]="AT+COPS?\r\n";
unsigned char Command_ATCREG[]="AT+CREG?\r\n";
unsigned char Command_CMGF[]="AT+CMGF=1\r\n"; // AT+CMGF for selecting Text Mode
unsigned char Command_CMGS[]="AT+CMGS=\"+919619807404\"\r\n"; // recepient mobile number
unsigned char msg02[]="Hello!";
unsigned char okmsg[]="OK";
unsigned char errmsg[]="ERROR";
unsigned char recstr[10]=0,rec_str[10]=0;x=0,n,m;
void delay(void)
{int d;
for(d=0;d<600;d++);
}
void delay2(void)
{
unsigned int i;
for(i=0;i<65535;i++);
}
void initialize_serialcommunication(void)
{ IE = 0x90;
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
//RI=0;
//TI = 1;
}
void gsmcmdsend(unsigned char *cmd)
{
while(*cmd!='\0')
{
SBUF=*cmd;
while(TI==0);
TI=0;
cmd++;
}
}
void gsmreceive()
{
unsigned char i;
//memset(recstr,'0',sizeof(recstr));
for(i=0;i<2;i++)
{
if(RI==0);
{
delay();
}
if (RI==1)
{
recstr[i]=SBUF;
RI=0;
continue;
}
break;
}
//return i;
}
void serialrx(void) interrupt 4
{//x=n;
if(RI==0){;}
recstr[x]=SBUF;
gsmcmdsend(recstr);
RI=0;
//n=x;
}
void show_error()
{
gsmcmdsend(recstr);
}
void gsminit(void)
{ // AT COMMANDS
unsigned char j,ch=0;
//memset(recstr,0,sizeof(recstr));
//delay2();
gsmcmdsend(Command_AT);
delay2();
//x=n+1;
delay2();
//gsmreceive();
ch=strcmp(recstr,okmsg);
if(ch!=0);
{
show_error();
return;
}
delay2();
gsmcmdsend(Command_ATI);
delay2();
gsmcmdsend(Command_ATCOPS);
delay2();
gsmcmdsend(Command_ATCREG);
delay2();
gsmcmdsend(Command_CMGF);
delay2();
gsmcmdsend(Command_CMGS);
delay2();
gsmcmdsend(msg02);
delay2();
SBUF = 0x1A;
while(TI==0); TI = 0;
}
void main (void)
{
unsigned char ch;
P2=0xf0;
initialize_serialcommunication();
while (1)
{
while(P2==0xf0);
if(P2==0xb0)gsminit();
}
}
i m attaching code...
in this code if switch connected to port 2 is pressed then only sms will send...its working code...
i have used it time ago...so check it and let me know...
Code:#include<reg51f.h> // include at89x51 . h #include<stdio.h>// include stdio . h #include<stdlib.h>// include stdlib . h #include<string.h> unsigned char Command_AT[]="AT\r\n"; unsigned char Command_ATI[]="ATI\r\n"; unsigned char Command_ATCOPS[]="AT+COPS?\r\n"; unsigned char Command_ATCREG[]="AT+CREG?\r\n"; unsigned char Command_CMGF[]="AT+CMGF=1\r\n"; // AT+CMGF for selecting Text Mode unsigned char Command_CMGS[]="AT+CMGS=\"+919619807404\"\r\n"; // recepient mobile number unsigned char msg02[]="Hello!"; unsigned char okmsg[]="OK"; unsigned char errmsg[]="ERROR"; unsigned char recstr[10]=0,rec_str[10]=0;x=0,n,m; void delay(void) {int d; for(d=0;d<600;d++); } void delay2(void) { unsigned int i; for(i=0;i<65535;i++); } void initialize_serialcommunication(void) { IE = 0x90; SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TL1 = 0xFD; TR1 = 1; //RI=0; //TI = 1; } void gsmcmdsend(unsigned char *cmd) { while(*cmd!='\0') { SBUF=*cmd; while(TI==0); TI=0; cmd++; } } void gsmreceive() { unsigned char i; //memset(recstr,'0',sizeof(recstr)); for(i=0;i<2;i++) { if(RI==0); { delay(); } if (RI==1) { recstr[i]=SBUF; RI=0; continue; } break; } //return i; } void serialrx(void) interrupt 4 {//x=n; if(RI==0){;} recstr[x]=SBUF; gsmcmdsend(recstr); RI=0; //n=x; } void show_error() { gsmcmdsend(recstr); } void gsminit(void) { // AT COMMANDS unsigned char j,ch=0; //memset(recstr,0,sizeof(recstr)); //delay2(); gsmcmdsend(Command_AT); delay2(); //x=n+1; delay2(); //gsmreceive(); ch=strcmp(recstr,okmsg); if(ch!=0); { show_error(); return; } delay2(); gsmcmdsend(Command_ATI); delay2(); gsmcmdsend(Command_ATCOPS); delay2(); gsmcmdsend(Command_ATCREG); delay2(); gsmcmdsend(Command_CMGF); delay2(); gsmcmdsend(Command_CMGS); delay2(); gsmcmdsend(msg02); delay2(); SBUF = 0x1A; while(TI==0); TI = 0; } void main (void) { unsigned char ch; P2=0xf0; initialize_serialcommunication(); while (1) { while(P2==0xf0); if(P2==0xb0)gsminit(); } }
Or can I have your mindmap for this programming Please?hi. Thank you for your reply. By the way, I am not if my circuit have four switch button connect to at89c51 microcontroller.eg switch 1 connect with p3.3/int1, and rest of switch connect to p1.1 to p1.3. isnt't still working with my circuit? Thanks
This code is for sending SMS but it doesn't test for modem response. If you want the code which checks the response of modem then I need 1 week time to write the code.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 UART1_Write_Text("AT+CMGF=1"); UART1_Write(13); UART1_Write(10) ; Delay_ms(2000); UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("97xxxxxxxx"); Delay_ms(100); UART1_Write(0x22); UART1_Write(13); UART1_Write(10) ; Delay_ms(1000); UART1_Write_Text("Hi! There"); UART1_Write(0x0D); UART1_Write(26); UART1_Write(0x0D);
Zip and post your keil project files. I will modify it. Mention in detail how the buttons should work.