Menu

LCD (16x2) IO mode 2, gibberish

Help
2017-02-14
2017-02-14
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-14

    I am using an 16F88 to control a LCD display (16x2 lines).
    I created a breadboard layout for the schematic used with a 74LS164 shift register.
    The sourde is simple:

    '''A demonstration program for GCGB and GCB.
    
    ; ----- Configuration
    
      #chip 16f88, 4
    
    
      '''Set up LCD
       #define LCD_IO 2_74XX164
    
    
    
      ; ----- Define Hardware settings
       #define LCD_DB PORTB.5
       #define LCD_CB PORTB.4
       #define LCD_NO_RW
    
    
    ; ----- Main body of program commences here.
    
    LCDBacklight on
    do forever
          CLS
          PRINT "Great Cow Basic"
          Locate 1,0
          PRINT "74LS164 LCD Driver"
          Wait 4 s
    
          CLS
          PRINT "Great Cow Basic"
          Locate 1,0
          PRINT "Minimal Setup"
          Wait 4 s
    
          cls
          Print "Demonstration"
          wait 3 s
    
     loop
    

    The source is compiled with 0.96 version of GCB and the HEX file is written with a PicKit2
    The display is responding but with al kind of gibberish
    Sometimes you can see parts of the printed messages. I checked the wiring about 10 times and can't find any error. Output is seen on the attachment

     

    Last edit: Ruud de Vreugd 2017-02-14
  • JANIS

    JANIS - 2017-02-14

    In my practice for some displays not like 2-wire and 4-bit system. Try an 8-bit system. The second - the data cable length should be as short as possible.

     
  • Theo

    Theo - 2017-02-14

    Ruud,

    looking at your picture, it seems to me that you are using a diode like 1N4007 or simular. That is not a small signal diode like 1N4148. If you are using the diagram from this link
    http://gcbasic.sourceforge.net/library/DIAGRAMS/2-Wire%20LCD/
    and you have checked the wiring more than twice, this diode is the only difference.
    If possible, change the diode with a smal signal one.

    Succes, Theo.

     

    Last edit: Theo 2017-02-14
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-14

    Theo,
    the diode is indeed a different one. It os a 1n4002. I don't have a signal diode at the moment. I have ordered one together with some other components. Should be here th eday after tomorrow (thursday)
    I'll be back :)

     
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-16

    Hi, rebuild the circuit and now I have a proper signaldiode. Looks like the switchfrequency of the diode makes all the difference. The display is now stable as a rock and works like it should be.

    Only one problem left. I created the backlightcontrol as in the documentation using a NPN transitor and two resistors (is not seen in the photo, I added that later). According to the documentation the backlight is controlled by pin 11 on the 74LS164. Pin 11 is however always high, LCDbacklight off won't switch the backlight off. The documentation stated the control is in lcd.h. In.96 there is no lcd.h only a mylcd.h and the glcd.h. Something changed?

    Ruud

     

    Last edit: Ruud de Vreugd 2017-02-16
  • Theo

    Theo - 2017-02-16

    Ruud,

    Go to the map where you have stored Syn0.96.000 and look into the map lowlevel

    GCB@Syn0.96.000\GreatCowBasic\Include\lowlevel

    there you will find lcd.h, which is automatic loaded during compiling.
    So it will be there.

    Question:
    are you sure pin 11 is always high?
    is the backlight off(or going off) if you simulate a zero on pin 11 or takeoff the power from the 74LS164 ?
    if possible, send a diagram how the transistor is connected.

     

    Last edit: Theo 2017-02-16
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-17

    Sorry about lcd.h I totaly overlooked the lowlevel folder. My mistake ;(
    In the attachments you find a diagram. Which is conform docs
    If I put the base at gnd or at vcc the backlight is going of and on so the circuit is functional.
    I hooked up my datalogger and it showed screenshot1. As you can see pin 11 is off on init and switching when there is something send to the display. But in the meantime stays on.
    I modified the code to display 2 simple lines and then toggle the backlight for 25 times with a 1 sec interval. See code:

    ****!!!!! EDIT --> NEW INFO !!!!!! *****
    Found what is the problem here. The new backlight setting will only be applied on a new outputcommand. If I put a CLS or LOCATE or a PRINT after a backlightsetting the LCD is responding correct.
    So just a backlight on or off on its own won't set the backlight until the first real print command
    * (removed asm from post)


    ; ----- Configuration
    
      #chip 16f88, 1 'tried 1, 2, 4 and 8 MHz with same result
    
    
      '''Set up LCD
       #define LCD_IO 2_74XX164
    
    
    
      ; ----- Define Hardware settings
       #define LCD_DB PORTB.5
       #define LCD_CB PORTB.4
       #define LCD_NO_RW
    
    
    ; ----- Main body of program commences here.
    
    
    
    
    do forever
          CLS
          PRINT "Great Cow Basic"
          Locate 1,0
          PRINT "74LS164 LCD Driver"
          Wait 1 s
    
          CLS
          PRINT "Great Cow Basic"
          Locate 1,0
          PRINT "Minimal Setup"
          Wait 1 s
    
          for bl=0 to 25
            LCDBacklight off
            wait 1 s
            LCDBacklight on
            wait 1 s
          next
     loop
    

    The output from the logger is seen in screenshot 2. The first time the backlight is of and stay off. Ending the inner loop the backlight status should be on starting te second iteration the backlight goes on and will remain on.

    Ruud

     

    Last edit: Ruud de Vreugd 2017-02-17
  • Theo

    Theo - 2017-02-17

    Ruud

    You are right about the backlight, the backlight only turns on(or off) in mode 1 and 2 after a write to the LCD-display.
    To resolved the issue with LCDBacklight you have to adapt the lcd.h;
    open lcd.h, search for:

    sub LCDBacklight(IN LCDTemp)

    #IFDEF LCD_IO 1, 2_74XX164      '1 and 2-wire mode with Backlight
       IF LCDTemp = ON then
          LCD_Backlight = LCD_Backlight_On_State
       Else
          LCD_Backlight = LCD_Backlight_Off_State
      END IF 
     #ENDIF
    

    insert between END IF and #ENDIF these 2 lines:

      Set LCD_RS OFF
      LCDWriteByte(0)
    

    save the lcd.h and compile your script again; observe result.

    Please report your result so that Anobium can adapt the lcd.h

    Dank je wel, Theo.

     
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-17

    Theo,
    Will do that when I get home tonight . I shall report back later on in this thread

    Wordt weer nachtwerk

     
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-18

    OK here it comes.
    First of all I made a backup copy of the orignal LCD.H. After that I made the modifications that Theo suggested. I was sure I made the correct changes but on compiling I got compiler errors on all lines using LCDWriteByte:

    Error 2: unbalanced Braces

    Examination of the errors showed me that the compiler had a problem with the binary notation in the form LCDWriteByte(b'xxxxxxxx'). The compiler choked on the apostrophe seeing it as a comment!!
    Through out the file I changed the syntax to LCDWrite(0bxxxxxxxx). Now the file compiled without any problem and more important the backlight is responding properly.
    Tried multiple scenario's with and without write commands in between. I couldn't find any further side effects.

    So 1. For some reason the compiler chokes on syntax b'some binary nummer'
    2. After making the changes it works as expected.
    3. I saw in LCD.h that this change is for the 1 and 2 wire solution. I tried the 2 wire solution using a 74LS164. I do have the parts for the one wire solution with 74LS595 shift register. Do you want me to put that to the test too?? No problem but that will take some time as I have to build the interface on the breadboard check it for errors and modify the script.

    Ruud

     
  • Anobium

    Anobium - 2017-02-18

    @Rudd. Thank you for the detailed report.

    The Error 2: unbalanced Braces is happening because you are editing system files that do not expect to be edited. You in the bowels of the system. When you edit these system file the archive bit (in the file system) is set - then, when you compile the compilation process checks for syntax errors hence the check and the error. The error itself is a formatting error that we are removing in the next build for binary number (so, you are one step ahead of us!). You can edit the binary as you did to resolve the issue - we should have done this a long time ago!!

    If you have time, please, please test on the 595 also - let us all make sure this works as expected for the next person! Please upload your lcd.h and I shall use in the next release - welcome to the community of developers!

    :-)

     
  • Theo

    Theo - 2017-02-18

    Ruud,

    Yesterday I haven't tested the changes I told you about; apparently there was an issue with LCDWriteByte(0)(as you noticed). But you managed to correct this issue; well done.

    The subroutine LCDBacklight(in LCDTemp) is changing in LCD_IO mode 1 and 2 only the the variable LCD_Backlight but does not perform an update of the shiftregister. By inserting those 2 line of code an extra update is forced.

    It would be great if you could test the backlight function in 1-wire mode with an 595. Be sure that you use as FET a BS170, otherwise you will be disappointed with the result.

    Thanks again.

    Theo.

     
  • Ruud de Vreugd

    Ruud de Vreugd - 2017-02-18

    Alright here I am back for an update.

    I build the 1 wire LCD driver mode on a breadboard as show in the documentation and the backlight control on pin 4 of the 74LS595 using a generic NPN transistor and some resistors. The result is show in the attached photo. On the top left you can see the BS170 FET and on the right the NPN transitor for the backlight. The PIC is a PIC16F88.

    For a start I tested with the original LCD.H. Result as expected the backlight is only responding on the next write action. Tested this with a loop where the backlight is toggling and after some delay I use a write action (locate, print ...)
    It was evident that the backlight was only changing on write.

    Second I tested whit a loop where only the backlight toggles with a small delay. The backlight remained in it entered state and only changed on the write action immediatly after the loop.

    Then I replaced the LCD.H and recompiled. Now the script is responding as it should be. The backlight is toggling as soon as the script requested and I could not find any side effects.

    So now I am able to switch off the backlight when there is no user interaction and switch it back on on a keypress. Saving batterylife!

    @Anobium, where and how do \i upload the modified LCD.H ?

    Ruud

     
  • Theo

    Theo - 2017-02-18

    Ruud

    thank you for testing the LCDBacklight function in 1-wire mode;
    with the input from the users, Great Cow Basic will become more and more GREATER.

    Tot de volgende keer.

    Theo.

     

    Last edit: Theo 2017-02-18
  • Anobium

    Anobium - 2017-02-19

    Ruud,

    Thank you. Send me a personal message and I will provide my personal email address.

     
  • Anobium

    Anobium - 2017-02-19

    @Ruud. I have updated the Help to clarify the config. Thank you for your draft Help page.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.