/*******************/
#include<regx52.h> #include<lcddisplay.h> #include<UART_gsm.h> #include<string.h> #include<intrins.h> #include<stdlib.h>
sbit buz = P2^7;
sbit gsm = P3^2; sbit board = P3^3;
data unsigned char mobilenum[10]; data unsigned char msg[80]; unsigned char XX,newmsg=0,j=0;
void readmsg(void);
void serintr(void) interrupt 4 { if(RI==1) { XX=SBUF;
if(XX=='+') newmsg=1; j=j+1;
if(j>100) j=0;
RI=0; } }
void delay(unsigned int); void main() {
lcd_init(); UART_init(); lcdcmd(0x85);
board=1; gsm=0; RI=0;
lcdcmd(0x01); msgdisplay("searching for"); lcdcmd(0xc0); msgdisplay("GSM modem"); delay(300); send_to_modem("ate0"); //to avoid echo signals, enter(); again: send_to_modem("at"); // TO CHECKING GSM MODEM... enter(); delay(50); if(!RI) // Here we are waiting for data whitch is sending by GSM modem goto again;
RI=0; EA=1; ES=1; lcdcmd(0x01); msgdisplay("SYSTEM"); lcdcmd(0xc3); msgdisplay("CONNECTED"); delay(100); send_to_modem("at+creg=0"); // enter(); delay(300); newmsg=0;
xxx: lcdcmd(0x01); msgdisplay("CHEKING SIM"); send_to_modem("AT+CPIN?"); // enter(); delay(500); if(newmsg==0) goto xxx; buz=0; lcdcmd(0xC0); msgdisplay("SIM CONNECTED"); delay(500);
send_to_modem("at+cmgf=1"); // tr set message format astext mode enter();
send_to_modem("at+cmgd=1"); //delete the message1 enter(); delay(500); send_to_modem("at+cmgd=2"); //delete the message1 enter(); ES=1;
st: delay(1000); buz=1;
while(RI==1) { RI=0; delay(100); }
RI=0; lcdcmd(0x01); msgdisplay("GSM NOTICE BOARD"); lcdcmd(0xc0); msgdisplay("SYSTEM"); ES=1; delay(500); newmsg=0; while(newmsg==0); ES=0; //delay(500); readmsg();
ES=1; delay(500); ES=0; TR1=0; board=0; gsm=1; TR1=1; buz=0; msgdisplay(msg); delay(500);
ES=1; delay(500); enter(); delay(50); j=0; resend:
ch_send_to_modem(35); j=0; delay(500); if(j==0) { enter(); delay(50); goto resend; } while(j<50); lcdcmd(0x01); msgdisplay("Updating Message"); lcdcmd(0xc0); msgdisplay("1 "); delay(1000); ch_send_to_modem('3'); j=0; while(j<25); msgdisplay("2 "); delay(750); ch_send_to_modem('5'); delay(750); ch_send_to_modem(42); j=0; while(j<10); msgdisplay("3 "); delay(2000); ES=0; send_to_modem("<M "); send_to_modem(msg);
send_to_modem("><S 1><D L1><T 1>"); enter(); j=0; delay(1000); lcdcmd(1); buz=1; TR1=0; board=1; gsm=0; TR1=1; delay(500); send_to_modem("at+cmgs="); ch_send_to_modem('"'); send_to_modem(mobilenum); ch_send_to_modem('"'); enter(); delay(50); send_to_modem("MESSAGE UPDATED SUCCESSFULLY"); ch_send_to_modem(0x1a); ES=1; delay(500); lcdcmd(0x01); msgdisplay("MESSAGE SENT");
delay(3000); goto st; }
void readmsg(void) { unsigned char a,b,i,count,numcnt;
delay(100); ES=1; delay(300); ES=0;
lcdcmd(0x01); send_to_modem("at+cmgr=1"); enter();
count=0; i=0; a=0; numcnt=0;
while(count!=3) { while(RI==0); b=SBUF; if((b==',')||(a==1)) { if(numcnt<15) { if(numcnt>4) { mobilenum[numcnt-5]=b;
} a=1; numcnt++; } else a=0; } if(count==2) { msg[i++]=SBUF; }
RI=0; if(b==10) count+=1; }
msg[--i]='\0'; msg[--i]='\0'; mobilenum[10]='\0'; send_to_modem("at+cmgd=1"); enter();
}
No subject? No description? So just a display of excellence? Or how not to post source code?
Looking at the quality of code, it could be just a consultant touting for business.
Yes, real power-user of goto statements. Impressive - why give the language other instructions for loop control when goto can be used?
Loop constructs are slower than goto. I use the goto optimization in my code when I want it to run real fast.
Cool. Looks like I've attracted one of those pesky mimics. Now what could possibly be the trigger for that?
... and flies. Why is this always happening to me? So frustrating!
The fact that you are mimicking me suggests that you are one of them. That would certainly explain why you attract flies. Flies do like male cow manure.
The fact that you are mimicking me suggests that you are a simpleton. Simple is as simple does.
The goto statement is discouraged in C, because it alters the sequential flow of logic that is the characteristic of C language. This word encourages poor programming style. use of goto makes the program unreliable,unreadable,and hard to debug. they obscure the flow of control.
no, I do not like GoTo, but I see some luddites that have migrated to C from assembler liberally spreading them all over the code.
e.g. Loop constructs are slower than goto. I use the goto optimization in my code when I want it to run real fast is a typical statement from one such.
Erik
Yes GOTO causes fuzzy thinking but they have a place. Even MISRA C accepts the GOTO in forward references within a code block.
Bradford
We have break and continue that exits or restarts a loop.
What the language is missing is at a "break big" - some way to break out of multiple, nested, loop constructs. Some languages have constructs like break(2), break(3) and similar. But a named goto has the advantage that it doesn't require the break depth to be increased if an extra nested loop is added.
It isn't so fun with:
... if (check_if_finally_happy_with_solution()) { solution_found = true; break; } ... } if (solution_found) break; ... } if (solution_found) break; ... } if (!solution_found) { printf("Damn: don't send me on impossible quests.\n"); } else { ... }
Does it cause fuzzy thinking?
Or is its use (usually) a result of fuzzy thinking?
But can't the same be said of 'if', 'for', 'while' and function calls...?
"use of goto makes the program unreliable"
How so?
Use of 'goto' to jump into blocks makes leads to lots of issues. Hard to read code with potential to jump past important setup code.
Jumps are best when jumping out of blocks. Either to the start of a block (similar to a 'continue') or directly after end of block like a 'break'.
"use of goto makes the program unreliable,unreadable,and hard to debug."
Then you'll definitely want to stay away from the Linux kernel and device drivers.