Home › Forums › Microcontrollers › PIC Microcontroller › Retrieving UART data on LCD using PIC16F877A
Tagged: LCD, pic16f877a, UART
- This topic has 28 replies, 3 voices, and was last updated 9 years, 6 months ago by Guderz90.
-
AuthorPosts
-
March 17, 2015 at 5:12 pm #11060sandeepParticipant
Hi sir,
my doubt is, will the +cmti response comes under the gsm echo feature? becoz, as i could read the message and display it on lcd using the AT+CMGR=1, why cant we do it replacing the CMGR with CNMI and wait for the +CMTI response to be displayed on the lcd, as in both the cases, the RCIF plays the main role.
March 18, 2015 at 11:16 am #11064sandeepParticipantHi sir,
As i tried, code entering the loop only if the RCIF flag is raised,with below code, the code enters the loop, and the data from rcreg is transfered to an array(checked using led blinking),but as i tried to test the +CMTI format to check for the new messages,like in the second part of code.but as soon as it receives a message the +cmti response must be send to the controller, i.e RCREG, but it is not happening.suggestions pls.
I am not sure, whether the +CMTI response is sent to controller or not. and my other doubt is whether the +CMTI response comes under the ECHO feature, because i have disabled the echo feature, will it be a reason for this??
while(!RCIF) { RB2=1; //LED, which keeps blinking, loop working good. delay(2000); RB2=0; delay(2000); for(i=0;i<10;i++) { x[i]=RCREG; } if(x[0]=='+'|| x[1]=='+'||x[2]=='+'||x[3]=='+') //+CMTI: "SM",1 { RB1=1; // testing this like x[0]!='+', then it works, so array is working good. delay(2000); RB1=0; delay(2000); } else continue; }
March 18, 2015 at 2:55 pm #11069Ligo GeorgeKeymasterNot, ECHO mode..
You should turn on NEW Message Indications by using correct settings
- AT+CMGF=1 – Text Mode
- AT+CNMI=2,0,0,0,0
March 19, 2015 at 4:18 pm #11086sandeepParticipantHi sir,
code is concerned, i m trying to debug the code from the basics, the basic code is as shown below, I tried it with the led’s, like,
if the format is correct then RB1 to blink or else RB3 to blink, but it is not happening.suggestions pls.void main() { //unsigned char data; TRISC = 0xC0; TRISB = 0x00; TRISD = 0x00; PORTC = 0x00; PORTD = 0x00; PORTB = 0x00; UART_Init(); Lcd4_Init(); delay(500); GIE = 1; PEIE = 1; char i,c; int j,k,l; delay(6000); //delay provided for the gsm to get signal stable. RCREG = 0; UART_Write_Text("AT+CMGF=1"); UART_Write(0x0D); UART_Write(0x0A); UART_Write_Text("AT+CNMI=2,0,0,0,0"); // as suggested by u sir, but as per datasheet, it might be 2,1,0,0,0 UART_Write(0x0D); // it remains same even after changing to AT+CNMI=2,1,0,0,0 UART_Write(0x0A); while(RCIF) // checking data ready { for(i=0;i<=64;i++) { x[i]=UART_Read(); } if(x[2]=='+'&& x[3]=='C') { RB1 = 1; lcd4_delayms(1000); RB1 = 0; } else if(x[2]!='+'&&x[3]!='C') { RB3 = 1; lcd4_delayms(1000); RB3 = 0; RCREG=0; } continue; } i=0; x[i]=0; RCREG=0; delay(1000); }
March 20, 2015 at 9:10 pm #11095Ligo GeorgeKeymasterYou should check whether the data is ready or not… every time before calling UART_Read().
June 15, 2015 at 8:25 pm #11477Guderz90ParticipantHi, l am sending messages with a PIC but the AT commands are being included in the received text.
A screenshot of the message has been attached.
Thank you in advance.
June 16, 2015 at 8:11 am #11479Ligo GeorgeKeymasterPlease post the code or AT command used to send this sms.
June 18, 2015 at 8:19 pm #11497Guderz90Participantok, here is the code:
UART1_Write_Text("AT"); UART1_Write(0X0D); Delay_ms(1000); UART1_Write_Text("ATE0"); UART1_Write(0X0D); Delay_ms(1000); UART1_Write_Text("AT+CMGF=1"); UART1_Write(0X0D); Delay_ms(1000); UART1_Write_Text("AT+CMGS=\"0772166326\""); UART1_Write(0X0D); UART1_Write_Text("Patient has fallen, provide assistance"); UART1_Write(0X1A); UART1_Write(0X0D); Delay_ms(4000);
June 18, 2015 at 9:51 pm #11499Ligo GeorgeKeymasterI can’t find any problems in the above code.
What about the entire code ? Is it too lengthy ?
Make sure that free RAM is above 30% otherwise it may cause such issues.
June 19, 2015 at 11:02 pm #11506Guderz90ParticipantThanks
My RAM usage is 30% (70% is free). I used this copy2Ram method to reduce my RAM usage. Maybe it might be one of the causes.
Below is the method I used and how the code would look like:
const char UART_txt1[] = "AT"; const char UART_txt2[] = "AT+CMGF=1"; const char UART_txt3[] = "AT+CMGS=\"0772166326\""; const char UART_txt4[] = "Patient has fallen, provide assistance"; //.................................................................................................................. char * CopyConst2Ram(char * dest, const char * src) { char * d ; d = dest; for(;*dest++ = *src++;); return d; } //.................................................................................................................. UART1_Write_Text(CopyConst2Ram(msg, UART_txt1)); UART1_Write(0X0D); Delay_ms(1000); UART1_Write_Text(CopyConst2Ram(msg, UART_txt9)); UART1_Write(0X0D); Delay_ms(1000); UART1_Write_Text(CopyConst2Ram(msg, UART_txt2)); UART1_Write(0X0D); Delay_ms(1000); UART1_Write_Text(CopyConst2Ram(msg, UART_txt3)); UART1_Write(0X0D); UART1_Write_Text(CopyConst2Ram(msg, UART_txt5)); UART1_Write(0X1A); UART1_Write(0X0D); Delay_ms(4000);
June 21, 2015 at 2:18 pm #11512Ligo GeorgeKeymasterSorry I don’t understand your CopyConst2Ram(). You can use the following function for that.
char* CopyConst2RAM(const char* ctxt) { static char temp[20]; char i; for(i =0; temp[i] = ctxt[i]; i++); return txt; }
June 21, 2015 at 2:25 pm #11515Guderz90Participantok thanks. But would that be the cause for the problem?
June 24, 2015 at 7:55 am #11527Ligo GeorgeKeymasterSorry, I can’t find any other problems.
June 24, 2015 at 3:35 pm #11529Guderz90Participantok, thanks very much
-
AuthorPosts
- You must be logged in to reply to this topic.