Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD letter 'a' problem

Status
Not open for further replies.

hhhsssmmm

New Member
Hello

Im using a PIC18F4220 @ 20Mhz ceramic with C18 compiler.

Im trying to do a simple test program where the PIC sends out the letter 'a' to an LCD connected to PORTD (8bit mode).....no nibbling!

However I can not get a consistent result each time the PIC is powered up. The behaviour is that sometimes the letter 'a' is displayed perfectly and sometimes it is not displayed at all. Sometimes the cursor simply blinks or sometimes the display remains completely blank.

Im using the following LCD module from Palm Technology Co., LTD

Display: LCD 20x2

Model: PMC2002D9-SBLW-1


Below is my test program. Please can some one help me to get the stable letter 'a' result each time the PIC is powered up.

Thank you

Haseeb

Code:
#include <p18f4220.h>
#include <delays.h>
     
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
  
void SendLCD(unsigned char Byte, unsigned char type);

#define LCD LATD //LCD Latch PORT
#define LCD_RS LATEbits.LATE0 //Register Select (0: Instruction/ 1: Data)
#define LCD_E LATEbits.LATE2 //Enable (Starts data read/write)

void main (void)
{   
   
    ADCON1 = 0x0F; //SET ALL PORTS as DIGITAL I/O
   
    PORTD = 0; //initiallize PORTD  
    TRISD = 0x00; //LCD output
   
    PORTE = 0; //initiallize PORTE
    TRISEbits.TRISE0 = 0;  //LCD Register Select (to LCD Pin 4)
    TRISEbits.TRISE2 = 0;  //LCD Enable (to LCD Pin 6)       





    //Initialize the LCD

    LCD = 0x00; //clear LCD PORTD pins

    Delay1KTCYx(100); //delay 20mS

    SendLCD(0x03,0); //Initialization command

    Delay1KTCYx(25); //delay 5mS

    SendLCD(0x03,0); //Initialization command

    Delay10TCYx(75); //delay 150uS

    SendLCD(0x03,0); //Initialization command

    Delay10TCYx(75); //delay 150uS

    SendLCD(0x3C,0); //Interface lenght is 8 bits long, 2-lines, 5x10 dots

    Delay10TCYx(25); //delay 50uS   

    SendLCD(0x10,0); //Turn off LCD

    Delay10TCYx(25); //delay 50uS

    SendLCD(0x01,0); //Clear LCD

    Delay10TCYx(25); //delay 50uS

    SendLCD(0x06,0); //Increment the cursor after each byte written

    Delay10TCYx(25); //delay 50uS

    SendLCD(0x0F,0); //Turn on LCD, cursor on, cursor blinking on

    Delay10TCYx(25); //delay 50uS
   
   




    SendLCD(0x80,0); //Send 0x80 to set line to 1

    Delay10TCYx(25); //delay 50uS   






    SendLCD('a',1); //print letter 'a' on LCD

    while(1); //loop forever



       

} //end of main()
                                                                                               




void SendLCD(unsigned char Byte, unsigned char type)
{
   
    LCD_RS = type; //Set whether it is a Command (0) or Data/Char (1)   

    LCD = 0x00; //Clear the LCD PORTD

    LCD = Byte; //assign the new data to the LCD PORTD

    //Toggle the E(enable)   
    LCD_E = 1; //Set Enable High
   
    //Delay 5uS
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();
    Nop();   
   
    LCD_E = 0; //Set Enable Low

}
 
i dont know if this is normal, but sometimes while using atmegas, the chip has to be reset a few times so that the LCD works, my guess is that its just a comunication problem caused by bad connections.
 
In my opinion i think there can be issue either with the delay routines or the connection in circuit. Its mostly connection issue for LCDs.

One more thing,

If i were you, i would make two separate functions

SendCommand(Command);
SendData(Data);

and all the necessary delays would be in those functions.

So the code would be like:
SendCommand(0x03);
SendCommand(0x3C);

Also having more delay in initialization is not a problem. I think your LCD is not initialing properly.
 
Wrong delays seem to make for the majority of the "it does not work" / "it does not work properly" problems with LCDs
 
Last edited:
Try this:

Code:
SendLCD((unsigned char)'a',1); //print letter 'a' on LCD

or
Code:
unsigned char temp = 'a';

SendLCD(temp,1); //print letter 'a' on LCD
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top