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 7 years, 8 months ago by Guderz90.
-
AuthorPosts
-
February 4, 2015 at 9:31 am #10670sandeepParticipant
hi,
I just have a problem in copying the data from RCREG to an array and displaying it…
I tested RCIF and OERR flags using led which are working as expected like… RCIF and OERR sets while receiving data… and OERR is cleared by clearing and setting CREN… and RCIF is cleared after copying the data from RCREG to an array… but i couldnt display the received data…suggestions pls…
here is my code…if(RCIF) RD0=1;//led blinked { if(OERR) RD1=1;//led blinked { CREN = 0; CREN = 1; } for(i=0;i<=5;++i) { x[i]=RCREG; //rcif is cleared once the data is copied to an array... as expected. //but i couldnt display the copied data. Lcd4_Set_Cursor(1,1); lcd4_puts(x); Lcd4_Clear(); delay(500); } }
February 4, 2015 at 11:12 am #10671Ligo GeorgeKeymasterJust try like this :
for(i=0;i<=5;) { if(RCIF) { RD0=1;// RD0 LED ON if(OERR) { RD1=1;// RD1 LED ON CREN = 0; CREN = 1; } x[i]=RCREG; i++; } } x[i] = '\0'; Lcd4_Set_Cursor(1,1); lcd4_puts(x); Lcd4_Clear(); delay(500);
February 5, 2015 at 12:38 pm #10703sandeepParticipantFirst of all… thanks for your response sir.
As i tested the code with the hyperterminal…i could see the AT command printed on the terminal and as i press a key on the keyboard that gets printed on the lcd screan… so serial comm is of no problem.but when i interface pic with the gsm module. instead of getting OK i getback same command what i send(AT) on the lcd screan. suggestions pls.
February 5, 2015 at 12:55 pm #10704Ligo GeorgeKeymasterJust disable the ECHO feature of your GSM module. If it is enabled, the module will send back characters received during command mode.
AND you should send a Carriage Return (eg : “AT\r”) after the command to indicate the end of command.
February 7, 2015 at 11:17 am #10710sandeepParticipantI have disabled the echo feature using ATE0 command and have put the gsm module permanently on the text mode using AT+CMGF=1;&W , and now i get the garbage character on the lcd display, when i tried the code with the hyperterminal, i got the same garbage value but once i create an interrupt by pressing a key on keyboard that gets printed on lcd, but when i interface the controller with the gsm module, the same garbage value is printed repeatedly… i have done a code to receive a one character first… so here is the code…and i tried with the electrosome ‘s udf’s this time
do { UART_Write_Text("AT"); UART_Write(0x0D); //CR. UART_Write(0x0A); //NEW LINE. delay(2000); if(UART_Data_Ready()) { /*if(OERR) { CREN = 0; CREN = 1; }*/ x[0]=UART_Read(); RCREG=0; } Lcd4_Clear(); Lcd4_Set_Cursor(1,4); lcd4_putch(x[0]); delay(500); Lcd4_Clear(); }while(1); /*UDF*/ char UART_Data_Ready() { return RCIF; } char UART_Read() { while(!RCIF); return RCREG; }
February 8, 2015 at 8:26 pm #10713sandeepParticipanthi,
I must thank the forum for helpful suggestions posted. now the module has worked somewhat good, now by sending command AT i could see OK printed on the lcd screen. now to read the first msg using AT+CMGR=1; i receive data along with delivery OK and info s of the CMGR pattern, and my DOUBT is
1. how to disable the delivery message and
2. how to print only <data> out of RCREG format.
+CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs>,<sca>,
<tosca>,<length>]<CR><LF><data>February 9, 2015 at 11:31 am #10715Ligo GeorgeKeymasterYou may separate required data by doing some string operations in the received data.
February 10, 2015 at 10:21 am #10723sandeepParticipantyes sir… i copied once received from rcreg… and printed only needed part on lcd…
February 13, 2015 at 3:58 pm #10784sandeepParticipantHi sir,
As i copy data from RCREG to an array, i tried to convert the data to an ascii by adding 0x30 and 0x40 and print it on lcd. but i get
random alphabets and symbols which doesnt match with what i get it on hyperterminal.is that due to baud rate???
code used:
Lcd4_Clear();
Lcd4_Set_Cursor(1,0);
lcd4_putch((x[0]+0x30)); // if its giving unknown char ,add 0x40 to x[0] and try(HEX to ascii)
lcd4_putch((x[1]+0x30));
lcd4_putch((x[2]+0x30));
lcd4_putch((x[3]+0x30));February 15, 2015 at 12:00 pm #10789Ligo GeorgeKeymasterHello
I don’t understand what you are saying. If you are talking about GSM modem,, its data is already ASCII, no need to make any change.
February 18, 2015 at 10:26 am #10813sandeepParticipantHi sir,
i also have the same doubt sir but printing without converting gives me an undefined symbols…and i get alphabets only
once i convert using 0x30,but which are not the one i get on hyperterminal… should i check on baud rates???
February 19, 2015 at 2:27 pm #10824Ligo GeorgeKeymasterYes make sure that PIC baud rate matches with that of GSM module.
February 19, 2015 at 3:26 pm #10827sandeepParticipantsorry sir, my mistake… finally i got what required… no conversion was needed to display data from gsm on lcd. i got what exactly i got on hyperterminal now…
but as per the code below… loop is not getting repeated continuosly. i just mentioning last three bits for reference..while(1) { UART_Write_Text("AT+CMGR=1"); UART_Write(0x0D); UART_Write(0x0A); for(i=0;i<67;i++) { x[i]=UART_Read(); } Lcd4_Clear(); Lcd4_Set_Cursor(1,1); lcd4_putch(x[63]); // data corresponding bit lcd4_putch(x[64]); lcd4_putch(x[65]); }
March 16, 2015 at 10:09 am #11040sandeepParticipantHi sir,
I just want to read only the new messages, as i test the gsm module with the hyperterminal, we get the indication for the new message in
the form of +CMTI: “SM”,1, and my doubt is how to use this in c code, so that the loop must wait until this response is received from the gsm module,
where after that, comparing the required bit,mode of motor operation can be decided.
March 16, 2015 at 5:04 pm #11046Ligo GeorgeKeymasterYou may use interrupt for reading message indications from GSM module.
Use UART_Read() to read data only after receiving data. You can make sure that the data is received, by using UART_Data_Ready(). -
AuthorPosts
- You must be logged in to reply to this topic.