Retrieving UART data on LCD using PIC16F877A

Home Forums Microcontrollers PIC Microcontroller Retrieving UART data on LCD using PIC16F877A

Tagged: , ,

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #10670
    sandeep
    Participant

    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);
      }
    }
    
    #10671
    Ligo George
    Keymaster

    Just 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);
    
    #10703
    sandeep
    Participant

    First 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.

     

     

     

    #10704
    Ligo George
    Keymaster

    Just 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.

    #10710
    sandeep
    Participant

    I 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;
    }
    
    #10713
    sandeep
    Participant

    hi,

    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>

    #10715
    Ligo George
    Keymaster

    You may separate required data by doing some string operations in the received data.

    #10723
    sandeep
    Participant

    yes sir… i copied once received from rcreg… and printed only needed part on lcd…

    #10784
    sandeep
    Participant

    Hi 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));

    #10789
    Ligo George
    Keymaster

    Hello

    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.

    #10813
    sandeep
    Participant

    Hi 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???

    #10824
    Ligo George
    Keymaster

    Yes make sure that PIC baud rate matches with that of GSM module.

    #10827
    sandeep
    Participant

    sorry 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]);
    }
    
    #11040
    sandeep
    Participant

    Hi 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.

    #11046
    Ligo George
    Keymaster

    You 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().

Viewing 15 posts - 1 through 15 (of 29 total)
  • You must be logged in to reply to this topic.
>