#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++; } putc(0x0a); putc(0x0d); } */ 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; }
The tags are necessary, but not sufficient.
The OP did use the tags this time - but it takes more than just tags to make a readable, understandable post.
www.catb.org/.../smart-questions.html
It requires the poster to think about clearly presenting and describing the code and the observed problem(s) - which the OP has clearly not done.
Any programming exercise requires careful thought, analysis, and study to determine what, exactly, the requirement is - and how it can be solved.
I suspect that the fact that the OP has still not managed - after 2 attempts - to frame a clear and understandable post is symptomatic of underlying problems that need to be addressed before any success can be expected...
The OP did use the tags this time - but it takes more than just tags to make a readable, understandable post. the tags only help if as above AND evidently the poster has not heard of indenting. The "code" as is is totally unreadable. I have no idea if other issues may exist, but just seing the lack of indention (which led me to miss the greying since the "code" looks as if it was not "HTMLed"). I do not look at unindented code.
something else that should be mentioned is that when code is illegible to others it is also illegible to the "coder" this is a proven fact.
Erik
The code might have been indented. It's just that tab characters are normally not working so well outside the editor. Sometimes not even within the editor, depending on individual configuration settings.
maybe it has been changed, but (it used to be that) tabbing lead to some quite wild appearnces
just as a check
this is tabbed this is double tabbed this is spaced
well the preview show that Keil and notepad use the same tabbing
so, evidently the op has not heard of indenting
I am truly amazed seeing some of the scribbles posted here under the guise of "code"
For what it's worth ...
It seems far more likely to me that the OP simply cut/pasted from the original post and surrounded that with the <pre> tags. Any hint of indentation had already been lost by the first posting.
Yes, most people who get complaints about having forgotten the pre tags do not go back to the editor, but reposts from the previous post, including multiple source lines merged at random places.
Indeed.
And, again, didn't bother to pay attention to the preview!
Hardly surprising, then, that the code does not work.