Author Topic: 16 X 2 LCD showing wrong data  (Read 6618 times)

0 Members and 1 Guest are viewing this topic.

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
16 X 2 LCD showing wrong data
« on: February 23, 2015, 11:02:50 pm »
Hello Guys,
               I was using a PIC16F877A for driving 16*2 lcd but it is not showing the right data, I am print "Hello World"  but its showing like "HelloWo&l" (similar type of error) or like a black boxes on first row or something else and it changes every time I switch it off and on.
               I am using it in 4 bit mode, programmed it using Micro C library and programmed it using pic kit 2 (clone).
               I simulate it in proteus and it worked. Connections I made are same as shown in proteus image attachment. (the RV2 pot has no role in it nor have connected it to circuit)

program:

// LCD module connections
sbit LCD_RS at RC1_bit;        //c
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC1_bit;        //c
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main()
{
 Lcd_Init(); // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR); // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
 Lcd_Out(1,1,"Hello World");//Write text in 1st row

}
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: 16 X 2 LCD showing wrong data
« Reply #1 on: February 24, 2015, 12:28:38 am »
I am no expert, but your problem is familiar to me.

When I have a messed-up connection between LCD & MCU, that happens to me.  Bad wire, loose connection, etc.   You may be having similar problem.  For I2C ones, it also happens when I am slightly below voltage, which may not apply to you since you are not using I2C.  But it may not be an I2C thing and I just happen to notice it more as I use I2C more.

Try printing something short, see if it consistently happens more at certain length or happens with certain character(s).  This may give you some clues on which bit is the bit with problem.
 

Offline qno

  • Frequent Contributor
  • **
  • Posts: 422
  • Country: nl
Re: 16 X 2 LCD showing wrong data
« Reply #2 on: February 24, 2015, 07:20:30 am »
Check out your timing.

You cannot write data to fast to an LCD.
Usually an LCD can handle a 270 kHz clocked signal.
Why spend money I don't have on things I don't need to impress people I don't like?
 

Offline george graves

  • Super Contributor
  • ***
  • Posts: 1257
  • Country: us
Re: 16 X 2 LCD showing wrong data
« Reply #3 on: February 24, 2015, 08:21:23 am »
IIRC you can listen to a return from the LCD to know when it's know for you to send another command.

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #4 on: February 24, 2015, 08:47:52 am »
I am going to ones again wire each pin,
Which pin of lcd will give me the 'ready for next command' status ? And how could i set frequency at which i communicate to lcd ?
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline Moshly

  • Regular Contributor
  • *
  • Posts: 139
  • Country: au
  • What's wrong with this thing
Re: 16 X 2 LCD showing wrong data
« Reply #5 on: February 24, 2015, 09:45:10 am »
If the schematic uses the R/W line then you need to poll the status register to see if it is ready.

If it is set to write only, then the only option is to wait the maximum time.

see page 9 & 24 ->
https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #6 on: February 24, 2015, 10:24:55 am »
ohk I will try that @moshly
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: 16 X 2 LCD showing wrong data
« Reply #7 on: February 24, 2015, 01:05:58 pm »
If the display shows nearly the characters sent , your certainly hitting timing issues , either between nibbles , or between writes, polling the ready bit is tedious, just experiment with some delays.
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #8 on: February 25, 2015, 03:56:26 pm »
I tried everything at this point but still it not working I changed the pins and also experiment with delays

after changing the pins now its just showing black line in 1st row  :palm:

Donno what to do now  :-//
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: 16 X 2 LCD showing wrong data
« Reply #9 on: February 25, 2015, 04:04:49 pm »
The datasheet for the LCD controller should tell you how long each command takes to execute.  Just wait that long and you'll be fine.  Different commands take different amounts of time.

For example, here's an HD44780 datasheet:
http://www.adafruit.com/datasheets/HD44780.pdf

Pages 24-25 have the delays associated with each command.  Init, which probably includes clear and return home and a few others will take over 1.5ms to finish, data dumps are 37uS.  Since you're in 4-bit mode, you need to make sure you delay >37uS per 4-bit nibble.
« Last Edit: February 25, 2015, 04:08:55 pm by suicidaleggroll »
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #10 on: February 25, 2015, 05:55:15 pm »
Well here is the code with adding all the delay I can give and also the output

Program:-

          // 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

void main(){

  Lcd_Init();                        // Initialize LCD
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Delay_ms(2000);
 
  Lcd_Out(1,1,"Hello World");                 // Write text in first row
 
}

Still I get the wrong output I have attached the image.

At first the lcd show a black block in first row, I have to restart it then it show the output.
Please have a look, Really frustrated now  |O

Find me and things I'm working on - https://www.yashkudale.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: 16 X 2 LCD showing wrong data
« Reply #11 on: February 25, 2015, 06:52:59 pm »
Well here is the code with adding all the delay I can give and also the output

Still I get the wrong output I have attached the image.

At first the lcd show a black block in first row, I have to restart it then it show the output.
Please have a look, Really frustrated now  |O
Where are you getting this "Lcd_Out" function (or for that matter, the Lcd_Iinit and Lcd_Cmd functions as well)?  Does it have the necessary delays built in?  Are you using some third party code or did you write them yourself?
 

Offline jc101

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: gb
Re: 16 X 2 LCD showing wrong data
« Reply #12 on: February 25, 2015, 07:11:08 pm »
The LCD library is from the MicroC compiler, assuming it's the MikroE compiler being used.

Within MicroC project have you got the right PIC and clock settings configured?
When compiling the project settings are used to calculate the right delays within the built in libraries etc.

It does look like timing and I suspect it could be related to the project settings.
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #13 on: February 25, 2015, 08:16:01 pm »
I am using Mikro C and ya I am using its lcd library and I got the code from its example codes.

I am sure I have got the micro controller right but the clock settings are on default and I haven't modified it what setting should I change ?
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline jc101

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: gb
Re: 16 X 2 LCD showing wrong data
« Reply #14 on: February 25, 2015, 08:25:40 pm »
I am using Mikro C and ya I am using its lcd library and I got the code from its example codes.

I am sure I have got the micro controller right but the clock settings are on default and I haven't modified it what setting should I change ?

The clock settings need to match the actual clock speed you are running the PIC at.  When I created a blank project for that PIC if defaulted to 8MHz are you using an 8MHz crystal for the PIC?
 

Offline jlmoon

  • Supporter
  • ****
  • Posts: 609
  • Country: us
  • If you fail the first time, keep trying!
Re: 16 X 2 LCD showing wrong data
« Reply #15 on: February 25, 2015, 09:32:29 pm »
If the display shows nearly the characters sent , your certainly hitting timing issues , either between nibbles , or between writes, polling the ready bit is tedious, just experiment with some delays.

Somehow 30 microsecond initialization loops come to mind  when dealing with the Hitachi 44XXX series 2x16 parts.  Is it when writing chars to the display you do 30uS delays to give enough time for LCD to be ready? 
Recharged Volt-Nut
 

Offline jlmoon

  • Supporter
  • ****
  • Posts: 609
  • Country: us
  • If you fail the first time, keep trying!
Re: 16 X 2 LCD showing wrong data
« Reply #16 on: February 25, 2015, 09:35:28 pm »
Can you include the LCD_Init , LCD_Cmd & LCD_Out functions in here.  Those might reveal your timing problem. 
Recharged Volt-Nut
 

Offline hamdi.tn

  • Frequent Contributor
  • **
  • Posts: 623
  • Country: tn
Re: 16 X 2 LCD showing wrong data
« Reply #17 on: February 25, 2015, 09:47:54 pm »
am not really sure but as far as i remember i had issue with lcd library with mikroC and solved when i wrote my own init functions , second you have to be careful cause again as far as i remember mikroC include lib for 8 bit interface and for 4 bit interface ,
third in the lcd datasheet you will find the appropriate delay after each operation. fourth check that you did input the right crystal value in mikroc interface
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #18 on: February 26, 2015, 11:38:34 am »
This is error given by Proteus (img)
Please help  |O

new code :-

          // 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

void main(){
  INTCON= 0;
  ADCON0= 0x06; // Configure all input and output in to digital
  ADCON1= 0x06; // Configure all input and output in to digital
  CMCON = 0x07;  //Set PORTA to Digital input
  TRISA = 0x00;  //PORTA as the input/output 0000 0111

  Lcd_Init();                        // Initialize LCD
  Delay_ms(500);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Delay_ms(500);
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Delay_ms(500);
 
  while(1){
  Delay_ms(500);
  Lcd_Out(1,1,"Hello World");                 // Write text in first row
  Delay_ms(500);
  }
}
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: 16 X 2 LCD showing wrong data
« Reply #19 on: February 26, 2015, 03:20:26 pm »
As you've been asked before, please verify the clock settings in your IDE match the actual clock speed on your board.
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #20 on: February 26, 2015, 03:56:31 pm »
I have cross checked it many times its set to 8MHz
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: 16 X 2 LCD showing wrong data
« Reply #21 on: February 26, 2015, 04:00:19 pm »
But is the MCU actually running at 8 MHz?
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: 16 X 2 LCD showing wrong data
« Reply #22 on: February 26, 2015, 05:05:47 pm »
Thank you guys it's working

It was faulty lcd
Find me and things I'm working on - https://www.yashkudale.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf