16 X 2 LCD showing wrong data  - Page 1
Forum section: electronics / beginners

author: yashrk
author_rank: Frequent Contributor
timestamp: February 23, 2015, 11:02:50 pm
content: 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 connectionssbit LCD_RS at RC1_bit; //csbit 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; //csbit 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 connectionsvoid main(){Lcd_Init(); // Initialize LCDLcd_Cmd(_LCD_CLEAR); // Clear displayLcd_Cmd(_LCD_CURSOR_OFF); // Cursor offLcd_Out(1,1,"Hello World");//Write text in 1st row}

author: Rick Law
author_rank: Super Contributor
timestamp: February 24, 2015, 12:28:38 am
content: 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.

author: qno
author_rank: Frequent Contributor
timestamp: February 24, 2015, 07:20:30 am
content: Check out your timing.You cannot write data to fast to an LCD.Usually an LCD can handle a 270 kHz clocked signal.

author: george graves
author_rank: Super Contributor
timestamp: February 24, 2015, 08:21:23 am
content: IIRC you can listen to a return from the LCD to know when it's know for you to send another command.

author: yashrk
author_rank: Frequent Contributor
timestamp: February 24, 2015, 08:47:52 am
content: 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 ?

author: Moshly
author_rank: Regular Contributor
timestamp: February 24, 2015, 09:45:10 am
content: 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

author: yashrk
author_rank: Frequent Contributor
timestamp: February 24, 2015, 10:24:55 am
content: ohk I will try that @moshly

author: 22swg
author_rank: Frequent Contributor
timestamp: February 24, 2015, 01:05:58 pm
content: 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.

author: yashrk
author_rank: Frequent Contributor
timestamp: February 25, 2015, 03:56:26 pm
content: I tried everything at this point but still it not working I changed the pins and also experiment with delaysafter changing the pins now its just showing black line in 1st rowDonno what to do now

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 25, 2015, 04:04:49 pm
content: 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.pdfPages 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.

author: yashrk
author_rank: Frequent Contributor
timestamp: February 25, 2015, 05:55:15 pm
content: Well here is the code with adding all the delay I can give and also the outputProgram:-// LCD module connectionssbit 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 connectionsvoid main(){Lcd_Init(); // Initialize LCDDelay_ms(2000);Lcd_Cmd(_LCD_CLEAR); // Clear displayDelay_ms(2000);Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor offDelay_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

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 25, 2015, 06:52:59 pm
content: Quote from: yashrk on February 25, 2015, 05:55:15 pmWhere 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?

author: jc101
author_rank: Frequent Contributor
timestamp: February 25, 2015, 07:11:08 pm
content: 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.

author: yashrk
author_rank: Frequent Contributor
timestamp: February 25, 2015, 08:16:01 pm
content: 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 ?

author: jc101
author_rank: Frequent Contributor
timestamp: February 25, 2015, 08:25:40 pm
content: Quote from: yashrk on February 25, 2015, 08:16:01 pmThe 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?

author: jlmoon
author_rank: Unknown
timestamp: February 25, 2015, 09:32:29 pm
content: Quote from: 22swg on February 24, 2015, 01:05:58 pmSomehow 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?

author: jlmoon
author_rank: Unknown
timestamp: February 25, 2015, 09:35:28 pm
content: Can you include the LCD_Init , LCD_Cmd & LCD_Out functions in here. Those might reveal your timing problem.

author: hamdi.tn
author_rank: Frequent Contributor
timestamp: February 25, 2015, 09:47:54 pm
content: 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

author: yashrk
author_rank: Frequent Contributor
timestamp: February 26, 2015, 11:38:34 am
content: This is error given by Proteus (img)Please helpnew code :-// LCD module connectionssbit 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 connectionsvoid main(){INTCON= 0;ADCON0= 0x06; // Configure all input and output in to digitalADCON1= 0x06; // Configure all input and output in to digitalCMCON = 0x07; //Set PORTA to Digital inputTRISA = 0x00; //PORTA as the input/output 0000 0111Lcd_Init(); // Initialize LCDDelay_ms(500);Lcd_Cmd(_LCD_CLEAR); // Clear displayDelay_ms(500);Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor offDelay_ms(500);while(1){Delay_ms(500);Lcd_Out(1,1,"Hello World"); // Write text in first rowDelay_ms(500);}}

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 26, 2015, 03:20:26 pm
content: As you've been asked before, please verify the clock settings in your IDE match the actual clock speed on your board.

author: yashrk
author_rank: Frequent Contributor
timestamp: February 26, 2015, 03:56:31 pm
content: I have cross checked it many times its set to 8MHz

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 26, 2015, 04:00:19 pm
content: But is the MCU actually running at 8 MHz?

author: yashrk
author_rank: Frequent Contributor
timestamp: February 26, 2015, 05:05:47 pm
content: Thank you guys it's workingIt was faulty lcd