Ni yanfang
Member level 3
- Joined
- Jul 30, 2013
- Messages
- 59
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 432
#include <reg51.h>
#include <stdio.h>
#define dataport P1;
sbit irout=P2^1;
sbit rs=P2^2;
sbit rw=P2^3;
sbit e=P2^4;
void serial_init(void);
void delay(int);
void lcdinit();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void convert(unsigned char *);
void serial_init(void)
{
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TR1 = 1;
TI = 1;
}
void serial(void) interrupt 4
{
unsigned int y[25];
if(RI==1)
{
y[25]=SBUF;
RI=0;
lcdinit();
convert(y[25]);
}
}
void lcdinit()
{
lcdcmd(0x38); //2 Line, 5X7 Matrix
lcdcmd(0x0c); //Display On, Cursor Blink
delay(1);
lcdcmd(0x01); // Clear Screen
delay(1);
lcdcmd(0x81); // Setting cursor to first position of first line
delay(1);
}
void convert(unsigned char *strs)
{
unsigned char m;
while(strs[m]!='\0')
{
lcddata(strs[m]);
m++;
}
}
void lcddata(unsigned char dat)
{
dataport = dat;
rs=1;
rw=0;
e=1;
delay(1);
e=0;
return;
}
void lcdcmd(unsigned char dat)
{
dataport = dat;
rs=0;
rw=0;
e=1;
delay(1) ;
e=0;
return;
}
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<1000;j++);
}
void main(void)
{
IE=0x90;
irout=1;
irout=0;
while(1)
{
if(irout==1)
{
delay(200);
serial_init();
printf("AT+CMGF=1%c",13);
delay(200);
printf("AT+CMGS=\"#######8520\"%c",13);
delay(200);
printf("Hi :-) GSM Modem Test");
delay(20);
printf("%c",0x1A);
delay(200);
while(irout==1);
}
}}
sorry I forgot to mention I just want to send sms . and I did not connect lcd.Code:#include <reg51.h> #include <stdio.h> #define dataport P1; sbit irout=P2^1; sbit rs=P2^2; sbit rw=P2^3; sbit e=P2^4; void serial_init(void); void delay(int); void lcdinit(); void lcdcmd(unsigned char); void lcddata(unsigned char); void convert(unsigned char *); void serial_init(void) { SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TR1 = 1; TI = 1; } void serial(void) interrupt 4 { unsigned int y[25]; if(RI==1) { y[25]=SBUF; RI=0; lcdinit(); convert(y[25]); } } void lcdinit() { lcdcmd(0x38); //2 Line, 5X7 Matrix lcdcmd(0x0c); //Display On, Cursor Blink delay(1); lcdcmd(0x01); // Clear Screen delay(1); lcdcmd(0x81); // Setting cursor to first position of first line delay(1); } void convert(unsigned char *strs) { unsigned char m; while(strs[m]!='\0') { lcddata(strs[m]); m++; } } void lcddata(unsigned char dat) { dataport = dat; rs=1; rw=0; e=1; delay(1); e=0; return; } void lcdcmd(unsigned char dat) { dataport = dat; rs=0; rw=0; e=1; delay(1) ; e=0; return; } void delay(int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<1000;j++); } void main(void) { IE=0x90; irout=1; irout=0; while(1) { if(irout==1) { delay(200); serial_init(); printf("AT+CMGF=1%c",13); delay(200); printf("AT+CMGS=\"#######8520\"%c",13); delay(200); printf("Hi :-) GSM Modem Test"); delay(20); printf("%c",0x1A); delay(200); while(irout==1); } }}
just take it as example then proceed with your code
#include <reg51.h>
#include <stdio.h>
sbit irout=P1^3;
sbit rs=P2^2;
sbit rw=P2^3;
sbit e=P2^4;
void serial_init(void);
void delay(int);
void serial_init(void)
{
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TR1 = 1;
TI = 1;
}
void serial(void) interrupt 4
{
unsigned int y[25];
if(RI==1)
{
y[25]=SBUF;
RI=0;
}
}
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<1000;j++);
}
void main(void)
{
IE=0x90;
irout=1;
irout=0;
while(1)
{ if(irout==1)
{
delay(200);
serial_init();
printf("AT+CMGF=1%c",13);
delay(200);
printf("AT+CMGS=\"9747358520\"%c",13);
delay(200);
printf("Hi :-) GSM Modem Test");
delay(20);
printf("%c",0x1A);
delay(200);
while(irout==1);
}
}}
Code:#include <reg51.h> #include <stdio.h> sbit irout=P1^3; sbit rs=P2^2; sbit rw=P2^3; sbit e=P2^4; void serial_init(void); void delay(int); void serial_init(void) { SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TR1 = 1; TI = 1; } void serial(void) interrupt 4 { unsigned int y[25]; if(RI==1) { y[25]=SBUF; RI=0; } } void delay(int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<1000;j++); } void main(void) { IE=0x90; irout=1; irout=0; while(1) { if(irout==1) { delay(200); serial_init(); printf("AT+CMGF=1%c",13); delay(200); printf("AT+CMGS=\"9747358520\"%c",13); delay(200); printf("Hi :-) GSM Modem Test"); delay(20); printf("%c",0x1A); delay(200); while(irout==1); } }}
i think this is the program that you want... try it and update me....
All d best....
sbit irout=P1^3; (irout???)
printf("AT+CMGS=\"9747358520\"%c",13);(13??)
printf("AT+CMGS=\"9747358520\"%c",13); // after enter the phone number we have to give ALT+ENTER to send message 13 is ASCII Value for ALT+ENTER
irout is the name assigned for pin P1^3
I read through AT command code already. But can you help me add in LED p3^6 in your code. led on when device is sending sms and led off when device is not sending sms or did nothing. Thank you so much.Code:printf("AT+CMGS=\"9747358520\"%c",13); // after enter the phone number we have to give ALT+ENTER to send message 13 is ASCII Value for ALT+ENTER irout is the name assigned for pin P1^3
it is the simple code for sending message when press P1^3 pin in microcontroller. for more u have to change as u required...
http://www.testech-elect.com/enfora/tutorial_send_receive_sms_using_gsm_modem.htm
for more detail about GSM refer this link... then u can understand... if anymore doubt post here...
sbit status P3^6; // name assigned for P3^6
void main(void)
{
IE=0x90;
irout=1;
status=0;
irout=0;
while(1)
{ if(irout==1)
{
status=1;
delay(200);
serial_init();
printf("AT+CMGF=1%c",13);
delay(200);
printf("AT+CMGS=\"9747358520\"%c",13);
delay(200);
printf("Hi :-) GSM Modem Test");
delay(20);
printf("%c",0x1A);
delay(200);
status=0;
while(irout==1);
}
Code:sbit status P3^6; // name assigned for P3^6 void main(void) { IE=0x90; irout=1; status=0; irout=0; while(1) { if(irout==1) { status=1; delay(200); serial_init(); printf("AT+CMGF=1%c",13); delay(200); printf("AT+CMGS=\"9747358520\"%c",13); delay(200); printf("Hi :-) GSM Modem Test"); delay(20); printf("%c",0x1A); delay(200); status=0; while(irout==1); }
Change the main function like this
The code is actually turning on the LED (status) before sending SMS and turning it OFF after sending SMS. There is no button code in it. I am assuming status as LED. Write a delay code which gives exactly 2 sec delay. I will give you a working code.
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 sbit status P3^6; // name assigned for P3^6 void main(void) { IE=0x90; irout=1; status=0; while(1) { if(irout==1) { delay(200); //should be a delay of 50 ms if(irout==1) { status=1; delay(2000); serial_init(); printf("AT+CMGF=1%c",13); delay(200); // delay od 2 sec printf("AT+CMGS=\"9747358520\"%c",13); delay(200); // delay od 2 sec printf("Hi :-) GSM Modem Test"); delay(20); printf("%c",0x1A); delay(200); status=0; } } } }
、Is your button attached to the irout pin?
Also, have you implemented some form of debouncing for your button?
BigDog
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 sbit status P3^6; // name assigned for P3^6 sbit irout P1^3; // name assigned for P1^3 void main(void) { IE=0x90; irout=1; status=0; while(1) { if(irout==1) { delay(200); //should be a delay of 50 ms if(irout==1) { status=1; delay(2000); serial_init(); printf("AT+CMGF=1%c",13); delay(200); // delay od 2 sec printf("AT+CMGS=\"9747358520\"%c",13); delay(200); // delay od 2 sec printf("Hi :-) GSM Modem Test"); delay(20); printf("%c",0x1A); delay(200); status=0; } } } }
hai
am sure am working with that Printf will print data in serial com work in keil
Ofcourse it will not work. printf will not print to uart ....
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?