• AVR Freaks

lcd initialization problem

Author
dngdngdngdng
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2010/08/20 01:22:15
  • Location: 0
  • Status: offline
2010/08/20 01:30:54 (permalink)
0

lcd initialization problem

#include <P18F97J60.h>
#include <delays.h>   

#pragma config XINST = OFF
#pragma config FOSC = HS
#pragma config WDT = OFF

#define LCD_data PORTE
#define LCD_D7 PORTEbits.RE7
#define LCD_rs PORTHbits.RH2
#define LCD_rw PORTHbits.RH1
#define LCD_en PORTHbits.RH0

//void LCD8send(char c, char mode);        //mode=0 for communication
void LCD8init(void);




void LCD_command(unsigned char var)
{
    LCD_data = var;           
    LCD_rs = 0;                // Selected command register
    LCD_rw = 0;
    LCD_en = 1;                // Enable H->
    LCD_en =0;       
    Delay10TCYx(10);                // wait for LCD to process the command

}

void LCD_senddata(unsigned char c){         //our LCD write function

    LCD_data = c;
    LCD_rs = 1;                // set write to '1'
    LCD_rw = 0;                // read/write
    LCD_en = 1;                // Enable H->L
    LCD_en = 0;
    Delay10TCYx(1000);
}


void LCD_init(){
     LCD_data = 0x3F;     
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_en   = 0;
     Delay10TCYx(10);        //Wait for LCD to process the command
     LCD_data = 0x0F;     //Display on, Curson blinking command
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_en   = 0;
     Delay10TCYx(10);         //Wait for LCD to process the command
     LCD_data = 0x01;     //Clear LCD
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     LCD_en   = 0;
     Delay10TCYx(10);          //Wait for LCD to process the command
     LCD_data = 0x06;     //Entry mode, auto increment with no shift
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->L
     Delay10TCYx(10);
}


void LCD_sendstring(unsigned char *var)
{
    while(*var)                    //till string ends
        LCD_senddata(*var++);    //send characters one by one
}

void main(void){
    while(1){
      LATJ = 0xFF;            // Port J = 0101 0011
      TRISJ = 0x00;            // Port J all outputs
    LCD_init();
    LCD_command(0x80);


}   
      while(1){;}                // Trap CPU
}


Hi, i'm having problems initializing the LCD using the codes above..(found the code online)
i would like to get the characters shown on the LCD but currently it's not working.
also, to make it run in 8wire mode
using PICDEM 2 board....P18F97J60.h



thanks in advance for any help provided!
#1

17 Replies Related Threads

    frankcf1
    Super Member
    • Total Posts : 1105
    • Reward points : 0
    • Joined: 2009/01/09 08:20:10
    • Location: Northern New Jersey
    • Status: offline
    Re:lcd initialization problem 2010/08/20 05:42:11 (permalink)
    0
    Try repeating the first command three times with the added delays delays such as:
     
    delay 15 mS
     LCD_data = 0x3F;    
     LCD_rs   = 0;
     LCD_rw   = 0;
     LCD_en   = 1;
     LCD_en   = 0;
    delay 5 mS
     LCD_data = 0x3F;    
     LCD_rs   = 0;
     LCD_rw   = 0;
     LCD_en   = 1;
     LCD_en   = 0;
    delay 200uS
     LCD_data = 0x3F;    
     LCD_rs   = 0;
     LCD_rw   = 0;
     LCD_en   = 1;
     LCD_en   = 0;
    #2
    Brick
    Super Member
    • Total Posts : 1684
    • Reward points : 0
    • Joined: 2006/05/25 09:10:40
    • Status: offline
    Re:lcd initialization problem 2010/08/22 17:12:25 (permalink)
    #3
    SneaKSz
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2010/08/12 03:29:16
    • Location: The coast
    • Status: offline
    Re:lcd initialization problem 2010/08/25 16:48:43 (permalink)
    0
    Use a delay between a  enable and "dis"able + if you've set a port don't set it once again.
     
          ->LCD_rs   = 0;        //Selected command register
         -> LCD_rw   = 0;        //We are writing in data register
          LCD_en   = 1;        //Enable H->L
          LCD_en   = 0;
          Delay10TCYx(10);        //Wait for LCD to process the command
          LCD_data = 0x0F;     //Display on, Curson blinking command
        ->  LCD_rs   = 0;        //Selected command register
          ->LCD_rw   = 0;  

    The state doesn"t change
    #4
    dngdngdngdng
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2010/08/20 01:22:15
    • Location: 0
    • Status: offline
    Re:lcd initialization problem 2010/08/25 22:26:14 (permalink)
    0
    got it working...thanks for the fast replies! (:
    #5
    kg9fj
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2010/08/29 09:00:37
    • Location: 0
    • Status: offline
    Re:lcd initialization problem 2010/08/29 09:19:39 (permalink)
    0
    Hi, I am trying to drive the LCD used in the Explorer16 product (TSB1G7000-E by Truly Semi) with a PIC18F45K20.  I have read that, when first powered on, most LCDs initialize with all pixels on (black) until the unit is initialized.  However the unit I have has never shown any signs of any activity whatsoever; it always has a blank screen and after many hours of researching it and trying to drive it, I am about convinced the unit is fried. 

    I don't have much experience with driving LCDs, so can anyone confirm that I should see some activity on the screen when first powered on?  

    Does anyone have any experience with this part?

    Thank you in advance for your help!


    post edited by kg9fj - 2010/08/29 09:24:37
    #6
    Brick
    Super Member
    • Total Posts : 1684
    • Reward points : 0
    • Joined: 2006/05/25 09:10:40
    • Status: offline
    Re:lcd initialization problem 2010/08/29 16:45:48 (permalink)
    0
    Could be that the contrast is set really low... do you have access to the contrast pin? is there a dial for this?
    #7
    kg9fj
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2010/08/29 09:00:37
    • Location: 0
    • Status: offline
    Re:lcd initialization problem 2010/09/01 11:13:50 (permalink)
    0
    Brick, thank you for your question.  

    Actually, there is no contrast control on this module at all.   There 14 pins which are Vss, NC, Vdd, RW, RS, E and D<0:7>.  

    I am not aware of any abuse of the product, unless there was something I did to cause static damage.  I thought I had taken reasonable precautions to preclude that, however.  Also, I was careful not to reverse the supply leads..a favorite trick of mine.    

    Would you think there should have been some activity on the display with just power applied?
    post edited by kg9fj - 2010/09/01 11:15:00
    #8
    dha
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2010/09/15 22:23:22
    • Location: Slovenia
    • Status: offline
    Re:lcd initialization problem 2010/09/15 22:52:17 (permalink)
    0
    Im just borrowing this topic for my similar problem. This code below worked fine untill i changed Displaytech's 204A LCD with Winstar WH2004A-YYH-ET#. I can't find datasheet for that exact winstar. Ive found these 2: http://home.comet.bg/datasheets/LCD/WH2004A.pdfhttp://www.cpu.com.tw/kh/gon/lcd/doc/wh2004a-ygb-jp.pdf. They have different initialization routines. Ive tried both.


    My 1st init code:
    DelayMS(15)
    LCD_DATA = 0x03
    LCD_STROBE();
    DelayMs(5);
    LCD_DATA = 0x03;
    LCD_STROBE();
    DelayUs(200);
    LCD_DATA = 0x03;
    LCD_STROBE();
    DelayMs(5);
    LCD_DATA = 0x02;
    LCD_STROBE();
    DelayUs(200);
    lcd_write(0x28);
    lcd_write(0x0F);
    lcd_clear();
    lcd_write(0x06);


    2nd init code:
    DelayMs(40);
    LCD_DATA = 0x03;
    LCD_STROBE();
    DelayUs(40);
    lcd_write(0x28);
    DelayUs(40);
    lcd_write(0x28);
    DelayUs(40);
    lcd_write(0x0F);
    DelayUs(40);
    lcd_write(0x01);
    DelayMs(2);
    lcd_write(0x06);

    With 1st code after first initialization i get cursor, but as pa push pa button it just shows some symbols... if i reset uC and run program again, symbols stay on the screen.

    thanks ofr help...

    #9
    violin
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2005/05/09 04:59:48
    • Status: offline
    Re:lcd initialization problem 2010/09/16 02:06:14 (permalink)
    0
    Hi, I am trying to drive the LCD used in the Explorer16 product (TSB1G7000-E by Truly Semi) with a PIC18F45K20.  I have read that, when first powered on, most LCDs initialize with all pixels on (black) until the unit is initialized.  However the unit I have has never shown any signs of any activity whatsoever; it always has a blank screen and after many hours of researching it and trying to drive it, I am about convinced the unit is fried. 

    I don't have much experience with driving LCDs, so can anyone confirm that I should see some activity on the screen when first powered on?  

    Does anyone have any experience with this part?

    Thank you in advance for your help!

     
    Brick, thank you for your question.  

    Actually, there is no contrast control on this module at all.   There 14 pins which are Vss, NC, Vdd, RW, RS, E and D<0:7>.  

    I am not aware of any abuse of the product, unless there was something I did to cause static damage.  I thought I had taken reasonable precautions to preclude that, however.  Also, I was careful not to reverse the supply leads..a favorite trick of mine.    

    Would you think there should have been some activity on the display with just power applied?

    I suspect the contrast will be a fixed contrast via a resistor although I know nothing of this particular dev board to put my finger on your non-working LCD issue. – Did the board come with a preprogrammed MC as I feel it should have done so to check all its peripherals are working before starting in developing with it. If this is the case it did and nothing is seen on its LCD then I would advise to send it back as faulty, but you need to be clear that nothing would show on its LCD with the pre-programmed chip. Is there a power light incorporated with it and is it illuminated when powered?
    [size=3 font="times new roman"] 
     
    #10
    violin
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2005/05/09 04:59:48
    • Status: offline
    Re:lcd initialization problem 2010/09/16 02:18:58 (permalink)
    0
    Im just borrowing this topic for my similar problem. This code below worked fine untill i changed Displaytech's 204A LCD with Winstar WH2004A-YYH-ET#. I can't find datasheet for that exact winstar. Ive found these 2: http://home.comet.bg/datasheets/LCD/WH2004A.pdfhttp://www.cpu.com.tw/kh/gon/lcd/doc/wh2004a-ygb-jp.pdf. They have different initialization routines. Ive tried both.


    My 1st init code:
    DelayMS(15)
    LCD_DATA = 0x03
    LCD_STROBE();
    DelayMs(5);
    LCD_DATA = 0x03;
    LCD_STROBE();
    DelayUs(200);
    LCD_DATA = 0x03;
    LCD_STROBE();
    DelayMs(5);
    LCD_DATA = 0x02;
    LCD_STROBE();
    DelayUs(200);
    lcd_write(0x28);
    lcd_write(0x0F);
    lcd_clear();
    lcd_write(0x06);


    2nd init code:
    DelayMs(40);
    LCD_DATA = 0x03;
    LCD_STROBE();
    DelayUs(40);
    lcd_write(0x28);
    DelayUs(40);
    lcd_write(0x28);
    DelayUs(40);
    lcd_write(0x0F);
    DelayUs(40);
    lcd_write(0x01);
    DelayMs(2);
    lcd_write(0x06);

    With 1st code after first initialization i get cursor, but as pa push pa button it just shows some symbols... if i reset uC and run program again, symbols stay on the screen.

    thanks ofr help...


    Maybe the Displaytech's 204A LCD used a different controller than the Winstar WH2004A-YYH-ET# and looking at the posted link the Winstar seems use the HD44780 controller so I can't be sure about Displaytech's to know if it timing sequences differ or not.
     
    Can you find out anything of the Displaytechs controller. 

     
    Edit:
    OK I have just googled it and it is what I suspect it to be the Displaytech's 204A LCD uses a Samsung KS0066U controller - so the timings sequences will differ somewhat between the two different controllers and the code which ran OK with the Samsung controller will need to be adjusted to fit the Hitachi controller.
     
    post edited by violin - 2010/09/16 02:28:54
    #11
    dha
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2010/09/15 22:23:22
    • Location: Slovenia
    • Status: offline
    Re:lcd initialization problem 2010/09/16 02:51:14 (permalink)
    0
    Problem is that two datasheets for similar Winstar LCD (both with HD44780) describes different initialization routines (look at pdfs)... It tried both and non worked ... :( Maybe my code is wrong but i dont see it ...
    #12
    violin
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2005/05/09 04:59:48
    • Status: offline
    Re:lcd initialization problem 2010/09/16 04:50:48 (permalink)
    0
    Problem is that two datasheets for similar Winstar LCD (both with HD44780) describes different initialization routines (look at pdfs)... It tried both and non worked ... :( Maybe my code is wrong but i dont see it ...

     
    Sorry. I am too busy with my own projects than too spend much time reading up on with your issues. Maybe someone else has more time than me to do this reading. Search for my C18 44780 LCD for these timing routines. Regards
    #13
    dha
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2010/09/15 22:23:22
    • Location: Slovenia
    • Status: offline
    Re:lcd initialization problem 2010/09/17 04:19:57 (permalink)
    0
    violin

    Problem is that two datasheets for similar Winstar LCD (both with HD44780) describes different initialization routines (look at pdfs)... It tried both and non worked ... :( Maybe my code is wrong but i dont see it ...

     
    Sorry. I am too busy with my own projects than too spend much time reading up on with your issues. Maybe someone else has more time than me to do this reading. Search for my C18 44780 LCD for these timing routines. Regards



    ok, np. thanks
    #14
    dha
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2010/09/15 22:23:22
    • Location: Slovenia
    • Status: offline
    Re:lcd initialization problem 2010/09/27 23:19:26 (permalink)
    0
    I think problem was in that i called initialization in main function and writing to lcd happaned in subprogramm...
    #15
    newx2c
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2007/06/13 10:25:07
    • Location: 0
    • Status: offline
    Re:lcd initialization problem 2010/09/30 16:09:30 (permalink)
    0
    Sorry Guys but how to ask a question on this forum
     
    thanks,
    #16
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:lcd initialization problem 2010/10/01 03:27:16 (permalink)
    0
    Hmm, clicking "new post" into one of the subfourms... ? Smile

    GENOVA :D :D ! GODO
    #17
    dha
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2010/09/15 22:23:22
    • Location: Slovenia
    • Status: offline
    Re:lcd initialization problem 2010/10/18 22:40:09 (permalink)
    0
    Hello,

    Im still having problem with lcd initialization. I belive initialization routine is fine as lcd initialises if i call lcd_init() in subfunction. If i call lcd_init() in main() function it doesnt work...
    my code looks like this:

    main{
         (TRIS init)
         (AD init)
         (INT & TMR init)
         (SPI init)
         lcd_init(); <- it doesnt work (i also tried delaying it)

         while(1){
                  subfunction();
             }
    }

    subfunction{
         lcd_init(); <- it works here
    }

    #18
    Jump to:
    © 2019 APG vNext Commercial Version 4.5