Sending Data to Lcd using UART

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
fyp
Posts: 7
Joined: 24 Jun 2010 13:56

Sending Data to Lcd using UART

#1 Post by fyp » 29 Jun 2010 17:01

Hi, guys. I have problems regarding sending data to LCD through RS232. But I don't know whether my code is correct. I can't make it work with my code. I'm using a mikroC compiler. When I run it, the lcd did not successfully recevied the data.

My program:

Code: Select all

char *i = "NNNNN" ;


void main() {

    TRISB = 0x00;
    Lcd_Init(&PORTB);
    Lcd_Cmd(Lcd_CLEAR);
    Lcd_Cmd(Lcd_CURSOR_OFF);

  // Initialize USART module (8 bit, 2400 baud rate, no parity bit..)
  Usart_Init(2400);

  while(1) {
    if (Usart_Data_Ready()) {   // If data is received
    i = Usart_Read();         // Read the received data
    Usart_Write(i);            // Send data via USART
    Lcd_Out(1,1, i);


    }
  }
}//~!
somebody please help me..:(

Edited by administrator: Use Code tag!

User avatar
ranko.rankovic
Posts: 433
Joined: 11 Jun 2010 09:22

Re: Sending Data to Lcd using UART

#2 Post by ranko.rankovic » 30 Jun 2010 11:48

Hello fyp,

As seen in example, you are using our old mikroC compiler. This sub forum is for our newer mikroC PRO compiler.

Can you provide us with more info about your MCU and development system?
And if you can attach your whole project to this thread, so we could see where problem lies?

Best regards
Ranko Rankovic
mikroElektronika [Support Department]

fyp
Posts: 7
Joined: 24 Jun 2010 13:56

Re: Sending Data to Lcd using UART

#3 Post by fyp » 30 Jun 2010 13:21

ranko.rankovic wrote:Hello fyp,

As seen in example, you are using our old mikroC compiler. This sub forum is for our newer mikroC PRO compiler.

Can you provide us with more info about your MCU and development system?
And if you can attach your whole project to this thread, so we could see where problem lies?

Best regards
I'm sorry for posting at the wrong section. I'm using a PIC18F452 Microcontroller. The software i used for my project is mikroC and MPLAB IDE.

I can't get my rs232 to send data to lcd by using uart. Can you provide my some sample codes for it?

User avatar
ranko.rankovic
Posts: 433
Joined: 11 Jun 2010 09:22

Re: Sending Data to Lcd using UART

#4 Post by ranko.rankovic » 01 Jul 2010 15:42

Hello fyp,

Here is working example that sends data from RS232 to LCD using UART. I used EasyPIc6 with it's 2x16 LCD and 8MHz Crystal.

Best regards
Attachments
UART.rar
(60.95 KiB) Downloaded 1711 times
Ranko Rankovic
mikroElektronika [Support Department]

fyp
Posts: 7
Joined: 24 Jun 2010 13:56

Re: Sending Data to Lcd using UART

#5 Post by fyp » 03 Jul 2010 05:02

ranko.rankovic wrote:Hello fyp,

Here is working example that sends data from RS232 to LCD using UART. I used EasyPIc6 with it's 2x16 LCD and 8MHz Crystal.

Best regards
Thanks for the reply.I tried to run the program using MPLAB to my PIC18F452 MCU but it doesn't work.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: Sending Data to Lcd using UART

#6 Post by p.erasmus » 03 Jul 2010 12:18

Thanks for the reply.I tried to run the program using MPLAB to my PIC18F452 MCU but it doesn't work.
What are you trying to say here can you explain what you are doing as the example from mE is working
either you are doing something incorrect or you have a hardware problem, it is not the example code
that has a problem

:D
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

JPablo
Posts: 14
Joined: 05 May 2010 23:44

Re: Sending Data to Lcd using UART

#7 Post by JPablo » 31 Jan 2011 21:43

ranko.rankovic,

I have used your example and it has really helped me out but I have a small problem or may be its lack of understanding on my side. I have used your code slightly changed for the PIC16F887 and EasyPic6 see below but I keep getting the result in the picture (funny character) after I entre a single character on the terminal. I have to enter two characters to keep it displaying on the LCD.

The USART must be sending something else, Please help.

Thanks


Code: Select all

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned char uart_rd;
signed char temp;

void main(){
  ANSEL  = 0;                        // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                      // Disable comparators
  C2ON_bit = 0;

  temp = 0;

  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  Lcd_Out(1,1, "Input char:");
  Delay_ms(1000);

  UART1_Init(9600);              // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
  UART1_Write_Text("Start");
  UART1_Write(13);
  UART1_Write(10);



  do {
    if (UART1_Data_Ready() == 1) {
      uart_rd = UART1_Read();
      UART1_Write(uart_rd);
      temp = uart_rd;

    }
    Delay_ms(2000);
    Lcd_Chr(1,13, temp);

  }while(1);
}
Attachments
IMG.jpg
IMG.jpg (81.96 KiB) Viewed 9006 times

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: Sending Data to Lcd using UART

#8 Post by drdoug » 01 Feb 2011 01:18

I would suspect a couple things
1. Are you using a USB-UART box? Sometimes the buffering can get confused.
2. Put the LCD write inside the Uart_ready brackets. You may be getting caught in the 2 second delay. Also, try writing to the cursor position rather than a specific position and see the string of characters you send. Use unsigned char rather than signed char.

Code: Select all

  
LCD_Chr(1,12,":");

do {
    if (UART1_Data_Ready() == 1) {
      uart_rd = UART1_Read();
      UART1_Write(uart_rd);
      temp = uart_rd;   // why more variables?
      Lcd_Chr_Cp(uart_rd);  // keep the unsigned char, there is a difference
    }
  }while(1);

JPablo
Posts: 14
Joined: 05 May 2010 23:44

Re: Sending Data to Lcd using UART

#9 Post by JPablo » 02 Feb 2011 00:03

drdoug,

I am not using a USB-UART box; I am connecting directly to UART port. I have made the changes that you have suggested and I have had some better results particularly with this part

Code: Select all

Lcd_Chr_Cp(uart_rd);
After more playing I discovered that my terminal program was sending a carriage return when I was sending a single character!

Finally I found out where I was going wrong! I used another terminal program and all work well. I would have not been able to see it without youy help.

Thank you so much for the help.

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: Sending Data to Lcd using UART

#10 Post by drdoug » 02 Feb 2011 00:24

The mE terminal is a great tool for playing with uart. Give it a try. You can see exactly what is sent and received in any format (ASCII, Dec, hex etc)

Post Reply

Return to “mikroC PRO for PIC General”