copy UART to lcd

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
potzli
Posts: 36
Joined: 11 Jun 2010 14:39

copy UART to lcd

#1 Post by potzli » 07 Mar 2011 20:29

I would like to write on the lcd the ascii value (hex) comming from UART. My code didn't work fine. one time the code displayed is right and sometimes wrong...

Code: Select all

char  rs_in,
        rs_disp[3]

UART1_Init(2400);

while(1)
  {
    while (UART1_Data_Ready() == 1)

    {
      rsin = UART1_Read();
      timeout_counter=0; // on a reçu data
      bytetohex(rsin,rs_disp);

      if (ndatain==8)
      {
       ndatain=0;
       Lcd_Out (2,1,"");
      }
      Lcd_Out_cp(rs_disp);
      ndatain++;
    }

      if (++timeout_counter >=timeout)  
      {
        timeout_counter=0;
        Lcd_Out(2, 1, "                ");
        ndatain=0;
        Lcd_Out(2, 1, "");
      }

    Delay_ms(1);
  }
 }

What is wrong???
Thanks!

absalom
Posts: 69
Joined: 13 Feb 2009 09:03
Location: Germany

Re: copy UART to lcd

#2 Post by absalom » 07 Mar 2011 23:06

Please provide a code we can compile. Some variables are not declared and initialized, rs <> rs_in ..
Additionally it would help a lot to know the failure effect

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: copy UART to lcd

#3 Post by braus » 08 Mar 2011 01:25

Code: Select all

char  rs_in,
        rs_disp[3]   //it is missing you a semi colon

UART1_Init(2400);

while(1)
  {
    while (UART1_Data_Ready() == 1)

    {
      rsin = UART1_Read();   //is this variable the same you declared at the beginning? I mean rs_in
      timeout_counter=0;   //where did you declare this variable?
      bytetohex(rsin,rs_disp);   //MikroC has a complete conversion library, try it

      if (ndatain==8)   //where did you declare this variable?
      {
       ndatain=0;
       Lcd_Out (2,1,"");
      }
      Lcd_Out_cp(rs_disp);   //where did you declare this variable?
      ndatain++;
    }

      if (++timeout_counter >=timeout)  
      {
        timeout_counter=0;
        Lcd_Out(2, 1, "                ");
        ndatain=0;
        Lcd_Out(2, 1, "");
      }

    Delay_ms(1);
  }
}
Best Regards
Omar Galicia
Mexico City

Post Reply

Return to “mikroC PRO for PIC General”