sms based Lcd Display
Sat Feb 11 2012, 01:48 am
I am currently working on a project to display messages got from the modem to an lcd diaplay. but am still learning how to use the components.
-am using proteus for circuit design
-am using keil for code design
i dont know where to start please help with the code and design.
-am using proteus for circuit design
-am using keil for code design
i dont know where to start please help with the code and design.
Sat Feb 11 2012, 12:47 pm
write a simple code to display something on LCD first then we will help you move ahead. Which GSM device are you using now?
[Topic moved to Embedded GSM development Forum]
[Topic moved to Embedded GSM development Forum]
Sat Feb 11 2012, 04:17 pm
Hi Ajay, I have been reading through the different posts on this forum. and i realised my project is much similar to The on Mr Kirangowle posted a while ago. i am currently figuring out how it works but av realised it still has some problems. i dont want the OK to display onto the LCD display, i want only the sent sms to display. Need some help with this;
Below is the code;
I am using a Huawei MODEM
Below is the code;
#include <REGX52.H> #define LCD P1 #define LCD_EN 0x80 #define LCD_RS 0x20 //LCD Commands #define LCD_SETMODE 0x04 #define LCD_SETVISIBLE 0x08 #define LCD_SETFUNCTION 0x28 #define LCD_SETDDADDR 0x80 void delayms(unsigned char); void delayus(unsigned char); void lcd_init(); void lcd_reset(); void lcd_cmd (char); void lcd_data(unsigned char); void lcd_str (unsigned char *); void clear(void); void tx0(unsigned char); void delay_sms (unsigned int); void SMSString(char*text) ; void init(); void read_text(unsigned char * , unsigned char * , unsigned char *); unsigned char j,abc; unsigned char idata msg1[150]; unsigned char rec_no[20]; unsigned char time_date[20]; void serial () interrupt 4 { msg1[abc]=SBUF; abc++; RI=0; } void main (void) { /* if u do not want to check "OK" response after each AT command then enable interrupt IE=0X90 ; after last AT command of SMSString( "AT+CMGR=1\r"); // AT command to read sms so after that u recieve a no of bytes from modile if u disable it then u do not reieve it even data comes use a virtual terminal in Proteus run a Proteus and right click on virtual terminal and click on option echo character display. in Proteus there is no mobile model so u should enter text in hyper terminal to suppose gsm Modem is responding. use serial receive interrupt to receive data check here */ clear(); init(); lcd_init(); SMSString("AT\r"); // AT commands to initialize gsm modem delay_sms(1000); SMSString( "ATe0\r"); // turn off echo delay_sms(1000); SMSString( "AT&W\r"); // save settings delay_sms(1000); SMSString( "AT+CMGF=1\r"); // select text mode for sms delay_sms(1000); SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms delay_sms(1000); SMSString( "AT+CMGR= 901\r"); // AT command to read sms IE=0X90; // Enable serial interrupt delay_sms(2000); /* i get a response like this // +CMGR: "REC READ" ,"+2347060580383","10/10/23,14:29:33+04" // device1 off // Ok. */ // read sms and store in buffer msg1 read_text(msg1,rec_no,time_date); clear(); IE=0X00; // Disable all interrupt while(1); } void init(void) { j=0; abc=0; TL1=0XFD; //9600 @ 11.0592 TH1=0xFD; TMOD=0x20; SCON=0x50; TR1=1; } void SMSString(unsigned char* text) //function to send SMS using GSM modem { while (*text) { tx0(*text++); } } void tx0(unsigned char x) //send data to serial port 0 { EA=0; SBUF=x; while(TI==0); TI=0; EA=1; } void delay_sms (unsigned int count) { unsigned int i; // Keil v7.5a while(count) { i = 115; while(i> 0) i--; count--; } } void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time) { unsigned char *temp; temp=msg; do msg++; while(*msg!='+'); do msg++; while(*msg!='+'); // reaching at no do *no++=*msg++; while(*msg!='"'); // reaching at time *no++='\0'; msg++; msg++; msg++; do *time++=*msg++; while(*msg!='+'); // raching at message *time='\0'; do msg++; while(*msg!='\n'); msg++; do *temp++=*msg++; while(*msg!='\r'); // reaching at end of message *temp='\0'; lcd_cmd(0x80); // ist line address lcd_str(rec_no); // array having receipt no lcd_cmd(0xC0); // 2nd line address lcd_str(time_date); // array having date and time lcd_cmd(0x94); // 3rd line address lcd_str(msg1); // array having message } void lcd_reset() { LCD = 0xFF; delay_sms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(5); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(5); LCD = 0x02+LCD_EN; LCD = 0x02; delay_sms(5); } void lcd_init () { lcd_reset(); lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font. lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink. lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift. lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h. } void lcd_cmd (char cmd) { LCD = ((cmd > > 4) & 0x0F)|LCD_EN; LCD = ((cmd > > 4) & 0x0F); LCD = (cmd & 0x0F)|LCD_EN; LCD = (cmd & 0x0F); delay_sms(1); } void lcd_data (unsigned char dat) { LCD = (((dat > > 4) & 0x0F)|LCD_EN|LCD_RS); LCD = (((dat > > 4) & 0x0F)|LCD_RS); LCD = ((dat & 0x0F)|LCD_EN|LCD_RS); LCD = ((dat & 0x0F)|LCD_RS); delay_sms(1); } void clear(void) { unsigned char a; for(a=0;a<100;a++) msg1[a]=0x00; } void lcd_str (unsigned char *str) { while(*str){ lcd_data(*str++); } }
I am using a Huawei MODEM
Sun Feb 12 2012, 02:24 pm
@ Alvanbert
start it with pc and hyper terminal
do not come directly to controller
it would be difficult to come directly o controller without testing it with pc
connect he modem with pc using max232 chip
use hyper terminal to see the response of modem
start it with pc and hyper terminal
do not come directly to controller
it would be difficult to come directly o controller without testing it with pc
connect he modem with pc using max232 chip
use hyper terminal to see the response of modem
Sun Feb 12 2012, 04:56 pm
Hi majoka, i connected vterm and the modem via COMPIM and attached below are the results as seen from proteus.
The problem is that the receiving terminal replays some commands i enter on the transmitting terminal which i think it shouldnt though this doesnt happen when i use my phone instead, problem is the phone doesnt work with some at commands.
will this affect the final output on the lcd? how can i prevent it?
The problem is that the receiving terminal replays some commands i enter on the transmitting terminal which i think it shouldnt though this doesnt happen when i use my phone instead, problem is the phone doesnt work with some at commands.
will this affect the final output on the lcd? how can i prevent it?
Mon Feb 13 2012, 07:50 pm
problem is the phone doesnt work with some at commands.
will this affect the final output on the lcd? how can i prevent it?Alvanbert
Which phone u r using?
U need to use phone which supports AT commands?
Since u r in beginning i prefer u to purchase a GSM SIM300 modem. and try your logic in it.
Tue Feb 14 2012, 08:44 pm
Yes, I got it, now problem is still. How can i extract only message... dont want to want screen to display OK or ERROR... Just want it to display the messages as they come in. e.g if they are 3 messages..it will desplay message 1...then message 2..then message 3...then go back to message 1...the newest message is displayed first in the loop.... messages are deleted after 24 hours..i want to make this automatic in the code...pliz help i know am asking alot but this is what my supervisor asked of me...thanks
Wed Feb 15 2012, 04:12 pm
@ Alvanbert
which cell phone ur using ?
some cell phones gives error on reading
before reading u need to memory from which u want to read
phone memory or sim memory
firstly u has to go for 1 message
if u do at one 3 will be easy for u
which cell phone ur using ?
some cell phones gives error on reading
before reading u need to memory from which u want to read
phone memory or sim memory
firstly u has to go for 1 message
if u do at one 3 will be easy for u
Wed Feb 15 2012, 04:15 pm
Hi Kiran, i looked through Ajay's post and this is what i found;
The problem is i dont know where to insert it... i have been trying different ways but am always coming up with errors which give me alot of headache. pliz show me where in the code below i should insert the above code. THANX
Your help is highly appreciated.
//as you are using interrupts so its better //you keep a flag for tx, and instead of polling // TI, poll that flag bit TI_flag = 0; //usage SBUF = Data_to_send; while(!TI_flag); TI_flag = 0; //Now the ISR.. this what i was expecting... void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read RI = 0; //clear flag if((ch == Response[i]) || (i > 4)){ //if received character is there in Response or i is > 4 which means // you already have the right string... if(ch != 0x0D) { // 0x0D means data received.. //Store received data MyBuff[i++] = ch; } else { //seems like we have recieved our data //Now stop and indicate that new message has received MyBuff[i] = '\0'; NewMessage = 1; //do not forget to reset i :) i = 0; // no more errors.. } } else { //there is a miss match //reset counter i = 0; } } if(TI){ //if its a tx interrupt //clear TI TI = 0; //set a flag to indicate tx has completed TI_flag = 1; } }
The problem is i dont know where to insert it... i have been trying different ways but am always coming up with errors which give me alot of headache. pliz show me where in the code below i should insert the above code. THANX
#include <REGX52.H> #define LCD P1 #define LCD_EN 0x80 #define LCD_RS 0x20 //LCD Commands #define LCD_SETMODE 0x04 #define LCD_SETVISIBLE 0x08 #define LCD_SETFUNCTION 0x28 #define LCD_SETDDADDR 0x80 void delayms(unsigned char); void delayus(unsigned char); void lcd_init(); void lcd_reset(); void lcd_cmd (char); void lcd_data(unsigned char); void lcd_str (unsigned char *); void clear(void); void tx0(unsigned char); void delay_sms (unsigned int); void SMSString(char*text) ; void init(); void read_text(unsigned char * , unsigned char * , unsigned char *); read_notification(); unsigned char j,abc; unsigned char idata msg1[150]; unsigned char rec_no[20]; unsigned char time_date[20]; delay(int); int NewMessage; void main () { clear(); lcdinit(); init(); SMSString("AT\r"); // AT commands to initialize gsm modem delay(50); SMSString( "ATe0\r"); // turn off echo delay(50); SMSString( "AT&W\r"); // save settings delay(50); SMSString( "AT+CMGF=1\r"); // select text mode for sms delay(50); SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms IE=0x90; delay(10); while(!NewMessage); { NewMessage = 0; read_notification(); IE=0x90; } //New msg indication. // +CMTI: "SM",3 } void read_notification() { IE=0x00; clear(); SMSString("AT+CMGR="); tx0(MyBuff[12]); SMSString("\r"); IE=0x90; delay(100); read_text(msg1,rec_no,time_date); clear(); void SMSString(unsigned char* text) //function to send SMS using GSM modem { while (*text) { tx0(*text++); } } void tx0(unsigned char x) //send data to serial port 0 { EA=0; SBUF=x; while(!TI_flag); TI_flag = 0; EA=1; } void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read RI = 0; //clear flag if((ch == Response[k]) || (k > 4)) { //if received character is there in Response or i is > 4 which means // you already have the right string... if(ch != 0x0D) // 0x0D means data received.. { MyBuff[k++] = ch; } else { //seems like we have recieved our data //Now stop and indicate that new message has received MyBuff[k] = '\0'; NewMessage = 1; k = 0; } } else { msg1[abc]=ch;//received msg is stored. abc++; k = 0; } } if(TI) { //if its a tx interrupt //clear TI TI = 0; //set a flag to indicate tx has completed TI_flag = 1; } } } void init(void) { j=0; abc=0; TL1=0XFD; //9600 @ 11.0592 TH1=0xFD; TMOD=0x20; SCON=0x50; TR1=1; } void SMSString(unsigned char* text) //function to send SMS using GSM modem { while (*text) { tx0(*text++); } } void tx0(unsigned char x) //send data to serial port 0 { EA=0; SBUF=x; while(TI==0); TI=0; EA=1; } void delay_sms (unsigned int count) { unsigned int i; // Keil v7.5a while(count) { i = 115; while(i> 0) i--; count--; } } void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time) { unsigned char *temp; temp=msg; do msg++; while(*msg!='+'); do msg++; while(*msg!='+'); // reaching at no do *no++=*msg++; while(*msg!='"'); // reaching at time *no++='\0'; msg++; msg++; msg++; do *time++=*msg++; while(*msg!='+'); // raching at message *time='\0'; do msg++; while(*msg!='\n'); msg++; do *temp++=*msg++; while(*msg!='\r'); // reaching at end of message *temp='\0'; lcd_cmd(0x80); // ist line address lcd_str(rec_no); // array having receipt no lcd_cmd(0xC0); // 2nd line address lcd_str(time_date); // array having date and time lcd_cmd(0x94); // 3rd line address lcd_str(msg1); // array having message } void lcd_reset() { LCD = 0xFF; delay_sms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(5); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(5); LCD = 0x02+LCD_EN; LCD = 0x02; delay_sms(5); } void lcd_init () { lcd_reset(); lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font. lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink. lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift. lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h. } void lcd_cmd (char cmd) { LCD = ((cmd > > 4) & 0x0F)|LCD_EN; LCD = ((cmd > > 4) & 0x0F); LCD = (cmd & 0x0F)|LCD_EN; LCD = (cmd & 0x0F); delay_sms(1); } void lcd_data (unsigned char dat) { LCD = (((dat > > 4) & 0x0F)|LCD_EN|LCD_RS); LCD = (((dat > > 4) & 0x0F)|LCD_RS); LCD = ((dat & 0x0F)|LCD_EN|LCD_RS); LCD = ((dat & 0x0F)|LCD_RS); delay_sms(1); } void clear(void) { unsigned char a; for(a=0;a<100;a++) msg1[a]=0x00; } void lcd_str (unsigned char *str) { while(*str){ lcd_data(*str++); } }
Your help is highly appreciated.
Powered by e107 Forum System