#include<softuart.h> #include<stdio.h> #include<reg51.h>
void uart_init(); sbit sw=P1^7;
unsigned char rx(); code unsigned char rd[] = "AT+CMGR=1"; code unsigned char ne[] = "AT+CNMI=2,2,0,0,0"; unsigned int r=0,m=0,s1=0,n1=0,f1=0,m2=0; unsigned char gs,mes_dat[]=0,mess[]=0; extern void lcd_init(); void lcd_cmd(unsigned char); void lcd_data(unsigned char); //void wait();
void gsm_delay(unsigned int); unsigned char txt[]="AT+CMGF=1"; unsigned char no[] ="AT+CMGS=\"9940151239\""; unsigned char del[]="AT+CMGDA=\"DEL ALL\"";
unsigned char sen[]="SENSOR";
void send_no(); void new_mess(); void gsm_read();
void delete(); void gsm_read(); void mode(); unsigned char rx(); unsigned char w, re,rx_data; void tx(unsigned char);
void serial(void) interrupt 4 {
if(TI==1) { TI=0; SBUF = '\0'; //ES=0; } else if(RI==1) { rx_data = SBUF;
if(rx_data=='+') { do { mess[m2] = rx_data;
m2++; RI=0; }while(rx_data=='T'); }
RI = 0; } }
void main() { uart_init(); lcd_init(); mode(); new_mess();
// delete();
while(1) { IE = 0x90; m = 0; r = 0; s1 = 0; m2 = 0;
re = rx_data;
if(re=='+') { RI = 0;
if(SBUF=='C') { lcd_data('1'); RI = 0; if(re=='M') { RI=0; lcd_data('2'); if(re=='T') { RI=0; do { gs = re; RI = 0; }while(gs!=0x0a);
do { gs = re; RI = 0; }while(gs!=0x0a);
m=-1; do { m = m+1;
mes_dat[m] = re; RI = 0;
}while(mes_dat[m]!=0x0d); mes_dat[m] = '\0'; m=0; lcd_cmd(0x01); lcd_cmd(0x80); while(mes_dat[m]!='\0') { lcd_data(mes_dat[m]); m++; } } } } } while(sw==1); m2=0; while(mess[m2]!='T') { //lcd_data(mess[m2]); tx(mess[m2]); m2++; }
send_no();
while(sen[s1]!='\0') { putc(sen[s1]); s1++; } putc(0x1a);
lcd_data('L');
gsm_delay(1000); gsm_delay(1000); gsm_delay(1000);
}
void new_mess() { n1=0; while(ne[n1]!='\0') { putc(ne[n1]); n1++; } putc(0x0a); putc(0x0d); gsm_delay(1000); }
void mode() { f1 = 0; while(txt[f1]!='\0') { putc(txt[f1]); f1++; }
putc(0x0a); putc(0x0d); gsm_delay(1000); }
void uart_init() { TMOD = 0x20; TH1 = -3; SCON = 0x50; TR1 = 1; //IE = 0x90; }
/*unsigned char rx() { unsigned char rec; while(RI==0); rec = SBUF; RI = 0; return rec; }
void delete() { unsigned int d ; d=0; while(del[d]!='\0') { putc(del[d]); d++; } putc(0x0a); putc(0x0d); gsm_delay(1000);
} */
void send_no() { unsigned int s=0; while(no[s]!='\0') { putc(no[s]);
s++;
putc(0x0a); putc(0x0d);
} /*void gsm_read() { m=0; r=0; lcd_data('R'); while(rd[r]!='\0') { putc(rd[r]); r++; }
void gsm_delay(unsigned int k) { unsigned int i,j; for(i=0;i<=k;i++) for(j=0;j<=1273;j++); } void tx(unsigned char tx_data) { SBUF = tx_data; while(TI==0); TI=0; }
This has nothing to do with GSM - it is purely a matter of serial comms!!
Here is a picture to help you: www.danlhenry.com/.../keil_code.png - in what way is that unclear?
Right over the message field it says:
NOTE: When posting messages, use the following HTML tags to make your message easier to read and understand. For more information, refer to
try reading it
Erik
View all questions in Keil forum