LCD Control


Closed Thread
Results 1 to 29 of 29

Thread: LCD Control

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Initialization of a 16x2 LCD.

    (4 bit Interface).

    The first picture is the initialization of a Hitachi HD44780.
    The second picture is the initialization of a Samsung KS0077.

    Best regards,

    Luciano




    Code:
    Hitachi HD44780 initialization
    (The above picture)
    
    E=1  D7=0  D6=0  D5=1  D4=1
    E=1  D7=0  D6=0  D5=1  D4=1
    E=1  D7=0  D6=0  D5=1  D4=1
    E=1  D7=0  D6=0  D5=1  D4=0
    
    E=1  D7=0  D6=0  D5=1  D4=0
    E=1  D7=1  D6=0  D5=0  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=1  D6=1  D5=1  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=0  D6=1  D5=1  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=1  D6=1  D5=0  D4=0
    Code:
    Samsung KS0077 initialization 
    (The above picture)
    
    E=1  D7=0  D6=0  D5=1  D4=1
    E=1  D7=0  D6=0  D5=1  D4=1
    E=1  D7=0  D6=0  D5=1  D4=1
    E=1  D7=0  D6=0  D5=1  D4=0
    
    E=1  D7=0  D6=0  D5=1  D4=0
    E=1  D7=0  D6=1  D5=0  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=1  D6=0  D5=0  D4=1
    
    E=1  D7=0  D6=0  D5=1  D4=0
    E=1  D7=0  D6=0  D5=0  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=0  D6=0  D5=0  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=1  D6=1  D5=1  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=0  D6=1  D5=1  D4=0
    
    E=1  D7=0  D6=0  D5=0  D4=0
    E=1  D7=1  D6=1  D5=0  D4=0
    Last edited by Luciano; - 18th January 2006 at 21:47.

  2. #2
    boboco's Avatar
    boboco Guest


    Did you find this post helpful? Yes | No

    Default LCD Control

    Hi all,

    thanks for the help.

    Curious is that the first line functions exactly as it should in every way, only the second line not. If I turn the contrast up to maximal all pixels turn black, though, so at least the line isn't dead.

    I've temporarily replaced the Displaytech with another type of unit. (all that work...., sob!) It worked at once so I take it that the Displaytech is bugged in some way. I've ordered a new one and hope that that will work, otherwise I'll have to change the whole construction to use some other. I'll report when I've got the results.

    Another short question on LCD control +PBP. If I want to control a 4 liner, which is essentially two complete LCDs in one, I've been doing it by switching both enable lines via resistors from one port and shorting each of the enable lines respectively with another two ports to disable it.

    It must be possible to program the PIC so that the selection of two enables is directly possible. (DEFINEs?) I've looked on the board but haven't found anything. Any ideas?

    Greetings

    Rob

  3. #3
    boboco's Avatar
    boboco Guest


    Did you find this post helpful? Yes | No

    Default LCD Control

    Hi all again,

    sorry Luciano, I didn't mention your post. As it would seem, the KS0077 isn't directly compatable to the HD44780. If that is the case, it would be interesting to write code for it as it is similar. If time allows, I'll try it.

    Greetings,
    Rob

  4. #4
    boboco's Avatar
    boboco Guest


    Did you find this post helpful? Yes | No

    Default LCD Control

    Hi all,

    thanks for the help.

    Curious is that the first line functions exactly as it should in every way, only the second line not. If I turn the contrast up to maximal all pixels turn black, though, so at least the line isn't dead.

    I've temporarily replaced the Displaytech with another type of unit. (all that work...., sob!) It worked at once so I take it that the Displaytech is bugged in some way. I've ordered a new one and hope that that will work, otherwise I'll have to change the whole construction to use some other. I'll report when I've got the results.

    Another short question on LCD control +PBP. If I want to control a 4 liner, which is essentially two complete LCDs in one, I've been doing it by switching both enable lines via resistors from one port and shorting each of the enable lines respectively with another two ports to disable it.

    It must be possible to program the PIC so that the selection of two enables is directly possible. (DEFINEs?) I've looked on the board but haven't found anything. Any ideas?

    Greetings

    Rob

  5. #5
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Your display is not correctly initialized.
    (This is why you get only one line).

    In order to use your LCD (KS0070b), you will have
    to manually initialize the KS0070b before you call the
    first PicBasic LCDOUT.

    Below you can find the pseudo code + a table.

    Best regards,

    Luciano


    See PDF page 32 for the initialization of the KS0070B in 4 bit mode
    http://www.ee.oulu.fi/research/tklab...river-3316.pdf


    Code:
    KS0070b Initialization
    
    2x16 LCD (KS0070b)
    4 bit mode
    2 lines
    Display=on
    Cursor=off
    Blink=off
    Increment mode
    Entire shif=off
    
    (Pseude-code, same as the table below).
    
    ==============================================
    Power on  
    (PIC and LCD module).
    ==============================================
    Wait 40 ms
    ==============================================
    
    (Function Set)
    
    ------------------
    Set the LCD pins: 
    DB7,DB6,DB5,DB4 = 0010
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs) 
    ------------------
    Set the LCD pins:
    DB7,DB6,DB5,DB4 = 0010
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs)
    ------------------
    Set the LCD pins:
    DB7,DB6,DB5,DB4 = 1000 (2 lines, 5x7 dots)
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs)
    ------------------
    ==============================================
    Wait 100 µs
    ==============================================
    
    (Display On/Off Control)
    
    Set the LCD pins: 
    DB7,DB6,DB5,DB4 = 0000 
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs)
     
    Set the LCD pins: 
    DB7,DB6,DB5,DB4 = 1100 (Display on, cursor off, blink off).
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs) 
    
    ==============================================
    Wait 100 µs
    ==============================================
    
    (Clear display)
    
    Set the LCD pins:
    DB7,DB6,DB5,DB4 = 0000 
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs) 
    
    Set the LCD pins:
    DB7,DB6,DB5,DB4 = 0001
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs) 
    
    ==============================================
    Wait 2 ms
    ==============================================
    
    (Entry Mode Set)
    
    Set the LCD pins:
    DB7,DB6,DB5,DB4 = 0000
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs) 
    
    Set the LCD pins:
    DB7,DB6,DB5,DB4 = 0110 (Incremet mode, entire shif off). 
    
    Toggle the Enable line:
    PULSOUT Enable_Pin,100 (min.100 µs) 
    
    ==============================================
    Wait 2 ms
    ==============================================
    
    
    End of the KS0070b Initialization.
    Last edited by Luciano; - 19th January 2006 at 21:36.

  6. #6
    boboco's Avatar
    boboco Guest


    Did you find this post helpful? Yes | No

    Thumbs up LCD Control

    Hello Luciano,

    Thanks, Pal. Now it works. And I've learnt something new.

    Best greetings,

    Rob
    Last edited by boboco; - 21st January 2006 at 13:15.

  7. #7
    Join Date
    Sep 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    i two have purchased an lcd that uses a k0007b criver chip i tried you example of initalising the display manualy not notheing hear is my code can some one check it for me please.

    '************************************************* ***************
    '* Name : LCD template.BAS *
    '* Author : John Hodgkiss *
    '* Notice : Copyright (c) 2007 John Hodgkiss *
    '* : All Rights Reserved *
    '* Date : 17/03/2007 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ****************


    'Template program for LCD useing a K0007b driver chip
    'KS0070b Initialization

    '2x16 LCD (KS0070b)
    '4 bit mode
    '2 lines
    'Display=on
    'Cursor=off
    'Blink=off
    'Increment mode
    'Entire shif=off

    start:
    'Power on


    'set variables

    output portA
    Db7 var byte
    Db6 var byte
    Db5 var byte
    Db4 var byte
    RS var byte
    E var byte
    PauseA var byte

    PauseC var byte
    'set constants

    PauseA = 10 ' 100us

    PauseC = 200 ' 2ms

    'define
    DEFINE LCD_DREG PORTA 'LCD data port

    DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4

    DEFINE LCD_RSREG PORTA 'LCD register select port
    DEFINE LCD_RSBIT 5 'LCD register select bit

    DEFINE LCD_EREG PORTA 'LCD enable port
    DEFINE LCD_EBIT 4 'LCD enable bit

    DEFINE LCD_BITS 4 'LCD bus size 4 or 8

    DEFINE LCD_LINES 2 'Number lines on LCD

    DEFINE LCD_COMMANDUS 2000 'Command delay time in us

    DEFINE LCD_DATAUS 50 'Data delay time in us


    pause 400 'pause for 40ms for lcd to start up




    'set pins

    Db7 = portA.3
    Db6 = portA.2
    Db5 = portA.1
    Db4 = portA.0

    RS = portA.4
    E = PortB.3

    output portA
    Output portB
    portA = low
    PortB = low
    setup:

    DB7 = 0
    DB6 = 0
    DB5 = 1
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    DB7 = 0
    DB6 = 0
    DB5 = 1
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    'set 2 lines 5x7 dots
    DB7 = 1
    DB6 = 0
    DB5 = 0
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    pause PauseA 'pause 100us

    'turn display On/Off control

    DB7 = 0
    DB6 = 0
    DB5 = 0
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    'Display cursor off, blink off
    DB7 = 1
    DB6 = 1
    DB5 = 1
    DB4 = 1
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    pause 10 ' wait 100us

    'clear display

    DB7 = 0
    DB6 = 0
    DB5 = 1
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    DB7 = 0
    DB6 = 0
    DB5 = 0
    DB4 = 1
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    pause PauseC 'pause 2ms

    'Entry mode

    DB7 = 0
    DB6 = 0
    DB5 = 0
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    DB7 = 0
    DB6 = 1
    DB5 = 1
    DB4 = 0
    'Toggle the Enable line:
    PULSOUT E, 100
    pause PauseA
    E = low

    pause pauseC


    loop:

    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout "Hello" ' Display Hello
    Pause 500 ' Wait .5 second

    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout "World"
    Pause 500 ' Wait .5 second

    Goto loop ' Do it forever




    is this correct??

    the dispaly does light up but thats it
    here is a link to the displays pdf file
    http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf

  8. #8
    Join Date
    Sep 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    hi there again i have been up all night trying to get this thing working no luck can some one please have a lok at my code or does anyone know where a example piece of code is. please iam desperate

  9. #9


    Did you find this post helpful? Yes | No

    Smile more info

    not a expert but my problems has always been with using a higher speed osc
    and not reseting lcd_dataus to match the crystal more delay for higher speeds just a thought

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Which compiler are you using? 'cause if that code above is PicBasicPro, you really, really need to get reading the PBP manual and learn it.

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You don't have any Black boxes????

    Or your contrast POT is crap, or you didn't installed it correctly.. or you forgot. ANY character LCD i know, once connected will produce those Black boxes.

    R/W pin is left floating in the air... must be tied to gnd

    Some LCD brand may need to tie unused DB<4:0> to Vss or Vdd... have a look to the datasheet
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  2. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  3. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. 4x40 LCD control problem
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th January 2005, 11:43

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts