Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] LCD shows garbage value in PIC18F26K22

Status
Not open for further replies.

rishiraj

Junior Member level 1
Joined
Dec 25, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,393
My LCD interfacing code isn't working fine and it is showing garbage value. Here is the code

Code:
#include <stdio.h>
#include <stdlib.h>
#include <p18f26k22.h>
#include <delays.h>
#include <string.h>
#include "oscillator.h"
#define RS LATBbits.LATB0
#define RW LATBbits.LATB1
#define E LATBbits.LATB2
#define lcd PORTC


void data(char *value1);
void cmd(unsigned short);
void main()
{
    set_freq(f8Mhz);  // 8Mhz frequency Set.
    ANSELB=0;
    TRISB=0;
    ANSELC=0;
    TRISC=0;

    Delay100TCYx(100); //5ms delay
    
    cmd(0x38);
    
    cmd(0x0C);
    
    cmd(0x01);
    
    cmd(0x06);
   
    cmd(0x80);
    
    data("Hello");

    while(1);

}
 void cmd(unsigned short value)
 {
     lcd = value;
     RS=0;
     RW=0;
     E=1;
     Delay10TCYx(2); //10us delay
     E=0;
     Delay100TCYx(20); //1ms delay
 }

 void data(char *value1)
 {
     unsigned short i;
     for(i=0;i<strlen(value1);i++)
     {
     lcd = value1[i];
     RS=1;
     RW=0;    
     E=1;
     Delay10TCYx(2); //10us delay
     E=0;
     Delay100TCYx(20); //1ms delay
     }
     
 }

I am using a PIC18F26K22 microcontroller which has a bootloader.

PS: I did check other topics in this forum relating to this topic but none helped.
 

hi,
when u r writing a subroutine u must know tht the machine cycle for lcd execution is not faster than microcontroller.for eg if i give 100 pens in 10 sec to you and simulataneously u have a speed of recieving 30 pens in 10 sec ..will u be able t recieve all pen...there will be loss of pens..similarly if proper delay is not given between disable and enabling of EN pin then there wuld be garbage.u have give 1ms delay ......make it more than 100ms ..u will get output.....
 

try these commands before " Delay100TCYx(100); //5ms delay
cmd(0x38); "

cmd(0b00000011); // Sync LCD and Microcontroller step 1
cmd(0b00000011); // Sync LCD and Microcontroller step 2
cmd(0b00000011); // Sync LCD and Microcontroller step 3
cmd(0b00000010); // Sync LCD and Microcontroller verify.

long time ago i had the same problem and it got set, if i find the related material i will reply with attachments.
 

hi,
when u r writing a subroutine u must know tht the machine cycle for lcd execution is not faster than microcontroller.for eg if i give 100 pens in 10 sec to you and simulataneously u have a speed of recieving 30 pens in 10 sec ..will u be able t recieve all pen...there will be loss of pens..similarly if proper delay is not given between disable and enabling of EN pin then there wuld be garbage.u have give 1ms delay ......make it more than 100ms ..u will get output.....

This did not help after increasing the delay

- - - Updated - - -

try these commands before " Delay100TCYx(100); //5ms delay
cmd(0x38); "

cmd(0b00000011); // Sync LCD and Microcontroller step 1
cmd(0b00000011); // Sync LCD and Microcontroller step 2
cmd(0b00000011); // Sync LCD and Microcontroller step 3
cmd(0b00000010); // Sync LCD and Microcontroller verify.

long time ago i had the same problem and it got set, if i find the related material i will reply with attachments.

It did not help. The values in the LCD changed but they are still garbage
 

use near about delay of 5 ms in lcd initialization and after that use lcd_delay delay after sending data/command to lcd.
lcd_delay is delay that lcd need that time.
 

I used 5ms delay in initilization i.e. before sending the commands the the LCD. There is no delay between the commands.
Help me select the delay time between the E=1 and E=0 and after E=0. I have attached a snapshot from the data sheet. As far as I see, the delay should be about 350ms, isn't ? eda_forum_1.jpg
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top