Shop OBEX P1 Docs P2 Docs Learn Events
Problems with BS2sx and LCD — Parallax Forums

Problems with BS2sx and LCD

mhcmhc Posts: 6
edited 2005-07-23 12:47 in BASIC Stamp
Hello,

i tried to use a LCD Display with my Basic Stamp. For this i used a manual from a book. But it doesn't work. The light of the LCD is on an the contrast works also. But there was no text. I've attached the code. It would be nice if someone could help me.

thanks,

Marco

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-20 14:18
    This looks like an update of a program that I wrote for the BS1 about 10 years ago... recognize some of my own notes.

    The problem seems to be that you're using DIR1 (DIR ONE) instead of DIRL (DIR EL) -- so you're only making P1 an output instead of P0 - P7. Also, you don't need to modify the DIR register in your WrLCD routine as you are not reading from the LCD. I recently rewrote some LCD -- you can find useful routines for the BS2 family (not BS2p or·pe which have built-in commands)·below:
    LCD_Init:
      LcdBusOut = %0011                             ' 8-bit mode
      PULSOUT E, 3 : PAUSE 5
      PULSOUT E, 3 : PAUSE 0
      PULSOUT E, 3 : PAUSE 0
      LcdBusOut = %0010                             ' 4-bit mode
      PULSOUT E, 3
      char = %00101000                              ' multi-line mode
      GOSUB LCD_Command
      char = %00001100                              ' on, no crsr, no blink
      GOSUB LCD_Command
      char = %00000110                              ' inc crsr, no disp shift
      GOSUB LCD_Command
    
    

    ' Send command to LCD
    ' -- put command byte in 'char'
     
    LCD_Command:                                    ' write command to LCD
      LOW RS
    
    
    ' Write character to current cursor position
    ' -- but byte to write in 'char'
     
    LCD_Write_Char:                                 ' write character to LCD
      LcdBusOut = char.HIGHNIB                      ' output high nibble
      PULSOUT E, 3                                  ' strobe the Enable line
      LcdBusOut = char.LOWNIB                       ' output low nibble
      PULSOUT E, 3
      HIGH RS                                       ' return to character mode
      RETURN
    

    ' Writes stored (in DATA statement) zero-terminated string to LCD
    ' -- position LCD cursor
    ' -- point to 0-terminated string (first location in 'addr')
     
    LCD_Put_String:
      DO
        READ addr, char
        IF (char = 0) THEN EXIT
        GOSUB LCD_Write_Char
        addr = addr + 1
      LOOP
      RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 11/20/2004 2:29:11 PM GMT
  • mhcmhc Posts: 6
    edited 2004-11-20 14:47
    Thanks for your fast reply. i tried this and changed my code like the file in the attachment. Now there apears some charackters like { or } on the display but the rest doesn't work.·Is there another mistake in my code???
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-20 15:16
    Well, I was just showing some fragments -- and you didn't add all the other things necessary to make them work.· Let me make your life a bit easier: I've taken your display requirments and dumped them into my standard 4-bit LCD code (which is cleaner and more efficient than the older code).· You'll have to change your connections a bit (documented in the code).· The connections we use are compatible with the BS2p and BS2pe LCD commands; that way you can upgrade your BASIC Stamp later without having to change your circuit.

    I have actually tested this with a 4x20 LCD and it works perfectly.· The code has extra goodies that you'll ultimately be able to take advantage of.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 11/20/2004 3:20:40 PM GMT
  • mhcmhc Posts: 6
    edited 2004-11-21 10:59
    Thank you very much for your help I'm very glad about, because I'm just learning PBasic. now it works nearly perfekt. There is just one problem. The first and the third line is ok, but in the second and fourth line are also the last 8 characters from the first respectively from the third line. then it looks like this:

    THE BASIC STAMP!
    AMP!··· P B A S I C
    A PIC16C57 knows
    nows Parallax

    Whats the reason for this???

    thanks,

    Marco
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-21 18:44
    The addressing of your display does not match mine. You'll have to change the LcdLine2, LcdLine3, and LcdLine4 constants to match your display.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • mhcmhc Posts: 6
    edited 2004-11-21 20:51
    Were do I·get these values??? I've looked in the display data sheet (attached)·but the values there didn't work.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-21 21:36
    Sometimes we have to determine things imperically.

    Write a program that clears the display, then writes a '*' to a character location; use DEBUG to show you what the location is. Make sure there's enough PAUSE time in the loop to allow you to check the display and write down the column 0 addresses for each line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • mhcmhc Posts: 6
    edited 2004-11-21 22:31
    what do i have exactly to change in the code for doing this???
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-22 03:58
    Make a copy of the program and change the main section like this:

    Main:
      FOR addr = $00 TO $73
        char = LcdCls
        GOSUB LCD_Command
        PAUSE 1
        char = LcdLine1 + addr
        DEBUG HOME, "Position = ", IHEX2 char
        GOSUB LCD_Command
        char = "*"
        GOSUB LCD_Write_Char
        PAUSE 3000
      NEXT
    
      END
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 11/22/2004 7:13:36 PM GMT
  • mhcmhc Posts: 6
    edited 2004-11-22 18:32
    i found another mistake. the display must be initialised in 4 line mode. I've changed the code but it doesn't work. did I change the wrong thing???
    LCD_Init:
      LcdBusOut = %0011                             ' 8-bit mode
      PULSOUT E, 3 : PAUSE 5
      PULSOUT E, 3 : PAUSE 0
      PULSOUT E, 3 : PAUSE 0
      LcdBusOut = %0010                             ' 4-bit mode
      PULSOUT E, 3
      char = %00001001                              ' 4-line mode
      GOSUB LCD_Command
      char = %00001100                              ' on, no crsr, no blink
      GOSUB LCD_Command
      char = %00000110                              ' inc crsr, no disp shift
      GOSUB LCD_Command
    

    thanks,

    Marco
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-22 19:13
    When all else fails, go right to the source.· Your product doc says that it uses the KS0073 LCD driver.· A quick search of Google located the KS0073 docs (attached), and based on that document I have modified the initialization sequence as shown below.· Unfortunately, I don't have any displays that use this driver, so I can't test -- I will leave that up to you.

    Reset:
      PAUSE 20
      DIRL = %11111110
     
    LCD_Init_KS0073: 
      char = %00100000                   ' 4-bit mode
      GOSUB LCD_Command
      char = %00101000                   ' mult-line mode
      GOSUB LCD_Command
      char = %00001100                   ' display on, cursor off, blink off
      GOSUB LCD_Command
      char = %00000110                   ' inc crsr, no disp shift 
      GOSUB LCD_Command
      char = %00000001                   ' clear display
      GOSUB LCD_Command 
    
    


    According to your LCD docs, the line addresses should be:

    L1 = LcdDDRam + $00
    L2 = LcdDDRam + $20
    L3 = LcdDDRam + $40
    L4 = LcdDDRam + $60

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 11/22/2004 7:18:26 PM GMT
  • ScarecrowScarecrow Posts: 38
    edited 2005-07-21 11:11
    i have the same problem and i fear that its not because of the addresing, it writes ok untill 13 character then it continues to write but the same is appearing at line 2 char 1 at the same time



    Theres something in the ks0073 datasheet about the extension function set that talks about 4 line modes but i dont understand how to control it on the initialization, im sure that could be the problem =S

    Post Edited (Scarecrow) : 7/23/2005 12:12:52 PM GMT
  • ScarecrowScarecrow Posts: 38
    edited 2005-07-23 12:47
    do this as the init procedure then its all good

    btw addresses are:

    line1: $00
    line2: $14
    line3: $40
    line4: $54

    char = %00101100 'enter extended function set
    GOSUB LCDcmd
    char = %00001001 '4 lines
    GOSUB LCDcmd
    char = %00101000 'exit extended function set
    GOSUB LCDcmd
    char = %00001100 ' display on, cursor off, blink off
    GOSUB LCDcmd
    char = %00000110 ' inc crsr, no disp shift
    GOSUB LCDcmd
Sign In or Register to comment.