phrbob93
Member level 1
- Joined
- Mar 28, 2014
- Messages
- 38
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Location
- Jalandhar, punjab
- Activity points
- 343
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 #include<reg51.h> unsigned char *command = "AT"; unsigned char *echo = "ATE0"; unsigned char *msgConfig = "AT+CMGF=1"; unsigned char *number = "AT+CMGS=\"8283******\""; unsigned char *message = "hello"; unsigned char *CTRLZ = 0x1A; void serial_init(void); void serial(unsigned char); void puts(unsigned char *p ); void delay(void); void main() { serial_init(); puts(command); delay(); // delay of approx 1 sec puts(echo); delay(); puts(msgConfig); delay(); puts(number); delay(); puts(message); delay(); puts(CTRLZ); while(1); } void serial_init(void) { TMOD=0x20; //timer 1, mode 2(8-bit autoreload) to set baud rate TH1=0xFD; //-3 to TH1 for 9600 baud rate SCON=0x50; // 8 bit txion, 1 start 1 stop bit, REN enable for both txfr and rxve TR1=1; // start timer } void puts(char *p) { char *temp = p; /*temp pointer so that the actual pointer is not displaced */ while(*temp != 0x00) { serial(*temp); temp++; } } void serial(unsigned char x) { SBUF=x; while(TI==0); TI=0; } void delay(void) // delay for approx 1 sec { int i; TMOD=0x01; // timer 0 in mode 1 for(i=0;i<142;i++) { TL0=0x00; // starting value from 0 TH0=0x00; TR0=1; // sart timer while(TF0==0); // polling TF flag for high TR0=0; // stop timer TF0=0; // clear flag TF0 //} } }
I did the same AT commands on arduino and its working...Show the void main() code. Commands should end with \r or \r\n. Try sending "AT\r\n". Also applies for other commands.
Maybe UART baudrate problem. It will be good if you zip and post the complete project files.
We have to check the project settings in IDE. So, zip and post the complete Keil project files. We have to check if correct crystal frequency is used in the IDE.
https://www.edaboard.com/threads/277180/
working code in the above thread.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 #include"lcd.h" #include<reg51.h> #include<intrins.h> #include<string.h> void gsm_send(unsigned char *); unsigned char *ch="AT\r\n"; unsigned char *ch1="AT+CMGF=1\r\n"; unsigned char *ch2="AT+CMGS="; unsigned char *ch3="Hi world\r\n"; unsigned char *ch9="+918283046191"; unsigned char a[2],cha,ph[14],msg[10],count=0,count1=0; void main() { unsigned char j=0,cha; init(); P1=0x00; P2=0x00; SCON=0x50; TMOD=0x20; TH1=0xfd; TR1=1; a[0]='"'; // dont know what is this please explain a[1]='\0'; // and this also gsm_send(); while(1); } void data_send(unsigned char *p) { while(*p!='\0') { SBUF=*p; while(TI==0); TI=0; p++; } } void data_res() { unsigned char i=0; while(i<4) { unsigned char ch; RI=0; while(RI==0); ch=SBUF; i++; } } void gsm_send(unsigned char *ch3) { data_send(ch); data_res(); data_send(ch1); data_res(); data_send(ch2); data_res(); data_send(a); // dont know this 1 data_send(ch9); data_send(a); // and this 1 also data_send("\r\n"); data_send(ch3); data_res(); SBUF=0x1a; while(TI==0); TI=0; }
P3 = 0x03;
does your msg sending part is working?did you get success in sending sms with the code? a[2] is used for sending the null char probably used for the start and stop recognition for the mobile number while retrieving the msg from gsm.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 #include<reg51.h> #include<intrins.h> #include<string.h> void gsm_send(unsigned char *); void data_res(); unsigned char *ch="AT\r\n"; unsigned char *ch1="AT+CMGF=1\r\n"; unsigned char *ch2="AT+CMGS="; unsigned char *ch3="Hi world\r\n"; unsigned char *ch9="+918283046191"; unsigned char a[2]; void main() { SCON=0x50; TMOD=0x20; TH1=0xfd; TR1=1; a[0]='"'; a[1]='\0'; gsm_send(); while(1); } void data_send(unsigned char *p) { while(*p!='\0') { SBUF=*p; while(TI==0); TI=0; p++; } } void gsm_send(unsigned char *ch3) { data_send(ch); data_res(); data_send(ch1); data_res(); data_send(ch2); data_res(); data_send(a); data_send(ch9); data_send(a); // this may be problem for blank text, but when i removed it , there is no text msg data_send("\r\n"); data_send(ch3); data_res(); SBUF=0x1a; while(TI==0); TI=0; } void data_res() { unsigned char i=0; while(i<4) { unsigned char ch; RI=0; while(RI==0); ch=SBUF; i++; } }
Try adding this.
Code:P3 = 0x03;
#include <reg51.h>
#include <intrins.h>
#include <string.h>
char cmd1[] = "AT\r\n";
char cmd2[] = "AT+CMGF=1\r\n";
char cmd3[] = "AT+CMGS=\"8283046191\"\r\n";
char msg[] = "Hi from AT89S52";
void UART_Write(char);
void UART_Write_Text(char *);
void Delay_ms(unsigned long);
void main() {
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x03;
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xfd;
TR1 = 1;
while(1) {
UART_Write_Text(cmd1);
Delay_ms(1000);
UART_Write_Text(cmd2);
Delay_ms(1000);
UART_Write_Text(cmd3);
Delay_ms(1000);
UART_Write_Text(msg);
Delay_ms(500);
UART_Write(0x1A);
Delay_ms(8000);
}
}
void UART_Write(char s) {
SBUF = s;
while(TI == 0);
TI = 0;
}
void UART_Write_Text(char *s) {
while(*s)
UART_Write(*s++);
}
void Delay_ms(unsigned long value) {
unsigned long x, y;
for(x = 0; x < value; x++)
for(y = 0; y < 1275; y++);
}
Try this code. Compile for 11.0592 MHz. Test in Proteus before testing in hardware. Proteus doesn't have 89S52 so compile for AT89C52 for Proteus.
Code:#include <reg51.h> #include <intrins.h> #include <string.h> char cmd1[] = "AT\r\n"; char cmd2[] = "AT+CMGF=1\r\n"; char cmd3[] = "AT+CMGS=\"8283046191\"\r\n"; char msg[] = "Hi from AT89S52"; void UART_Write(char); void UART_Write_Text(char *); void Delay_ms(unsigned long); void main() { P0 = 0x00; P1 = 0x00; P2 = 0x00; P3 = 0x03; SCON = 0x50; TMOD = 0x20; TH1 = 0xfd; TR1 = 1; while(1) { UART_Write_Text(cmd1); Delay_ms(1000); UART_Write_Text(cmd2); Delay_ms(1000); UART_Write_Text(cmd3); Delay_ms(1000); UART_Write_Text(msg); Delay_ms(500); UART_Write(0x1A); Delay_ms(8000); } } void UART_Write(char s) { SBUF = s; while(TI == 0); TI = 0; } void UART_Write_Text(char *s) { while(*s) UART_Write(*s++); } void Delay_ms(unsigned long value) { unsigned long x, y; for(x = 0; x < value; x++) for(y = 0; y < 1275; y++); }
#include<reg51.h>
#include<intrins.h>
#include<string.h>
void gsm_send(unsigned char *);
void data_res();
unsigned char *ch="AT\r\n";
unsigned char *ch1="AT+CMGF=1\r\n";
unsigned char *ch2="AT+CMGS=";
unsigned char *ch3="Hi world\r\n";
unsigned char *ch9="+918283046191";
unsigned char a[2];
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
a[0]='"';
a[1]='\0';
gsm_send("MOTOR OFF");
while(1);
}
void data_send(unsigned char *p)
{
while(*p!='\0')
{
SBUF=*p;
while(TI==0);
TI=0;
p++;
}
}
void gsm_send(unsigned char *ch3)
{
data_send(ch);
data_res();
data_send(ch1);
data_res();
data_send(ch2);
data_res();
data_send(a);
data_send(ch9);
data_send(a);
data_send("\r\n");
data_send(ch3);
data_res();
SBUF=0x1a;
while(TI==0);
TI=0;
}
void data_res()
{
unsigned char i=0;
while(i<4)
{
unsigned char ch;
RI=0;
while(RI==0);
ch=SBUF;
i++;
}
}
Code:#include<reg51.h> #include<intrins.h> #include<string.h> void gsm_send(unsigned char *); void data_res(); unsigned char *ch="AT\r\n"; unsigned char *ch1="AT+CMGF=1\r\n"; unsigned char *ch2="AT+CMGS="; unsigned char *ch3="Hi world\r\n"; unsigned char *ch9="+918283046191"; unsigned char a[2]; void main() { SCON=0x50; TMOD=0x20; TH1=0xfd; TR1=1; a[0]='"'; a[1]='\0'; gsm_send("MOTOR OFF"); while(1); } void data_send(unsigned char *p) { while(*p!='\0') { SBUF=*p; while(TI==0); TI=0; p++; } } void gsm_send(unsigned char *ch3) { data_send(ch); data_res(); data_send(ch1); data_res(); data_send(ch2); data_res(); data_send(a); data_send(ch9); data_send(a); data_send("\r\n"); data_send(ch3); data_res(); SBUF=0x1a; while(TI==0); TI=0; } void data_res() { unsigned char i=0; while(i<4) { unsigned char ch; RI=0; while(RI==0); ch=SBUF; i++; } }
this is the difference in your code and reason for having blank msg because you sending blank msg.if speed is issue then try with higher baud rate and reduce the delay in milan code.
edited part or code see last line of main and check your gsm_send ();function. read the sample code again you can understand.your code at post#12Code:void main() { SCON=0x50; TMOD=0x20; TH1=0xfd; TR1=1; a[0]='"'; a[1]='\0'; gsm_send(); while(1);
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
a[0]='"';
a[1]='\0';
gsm_send("MOTOR OFF"); //edited line
while(1);
}
edited part or code see last line of main and check your gsm_send ();function. read the sample code again you can understand.
Code:void main() { SCON=0x50; TMOD=0x20; TH1=0xfd; TR1=1; a[0]='"'; a[1]='\0'; gsm_send("MOTOR OFF"); //edited line while(1); }
#include<reg51.h>
#include<intrins.h>
#include<string.h>
void gsm_send(unsigned char *);
void data_res();
unsigned char *ch="AT\r\n";
unsigned char *ch1="AT+CMGF=1\r\n";
unsigned char *ch2="AT+CMGS=";
//unsigned char *ch3="Hi world\r\n";
unsigned char *ch9="+918283046191";
unsigned char a[2];
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TR1=1;
a[0]='"';
a[1]='\0';
gsm_send("hello"); // edited
while(1);
}
void data_send(unsigned char *p)
{
while(*p!='\0')
{
SBUF=*p;
while(TI==0);
TI=0;
p++;
}
}
void gsm_send(unsigned char *ch3)
{
data_send(ch);
data_res();
data_send(ch1);
data_res();
data_send(ch2);
data_res();
data_send(a);
data_send(ch9);
data_send(a);
data_send("\r\n");
data_send(ch3);
data_res();
SBUF=0x1a;
while(TI==0);
TI=0;
}
void data_res()
{
unsigned char i=0;
while(i<4)
{
unsigned char ch;
RI=0;
while(RI==0);
ch=SBUF;
i++;
}
}
In my code the last line inside while(1) loop is an 8 second delay. Reduce it to 3 sec if you want to send messages faster. Also reduce the 1 sec delays to 500 ms delays and try.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 void gsm_send(unsigned char *ch3) { data_send(ch); //data_res(); delay(100); data_send(ch1); delay(100); //data_res(); data_send(ch2); delay(100); //data_res(); data_send(a); data_send(ch9); data_send(a); data_send("\r\n"); delay(100); data_send(ch3); delay(100); SBUF=0x1a; while(TI==0); TI=0; }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?