/*******************/
#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();
}
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'.