Menu

Another LCD problem with 16f684

Help
2007-01-21
2013-05-30
1 2 > >> (Page 1 of 2)
  • Sterling Youngman

    I've wired a Hantronix 2x16 LCD to the PIC, following a diagram from MAKE: magazine. Vol. 07 Page 150

    I've tried several variations of code, but nothing works. when I use the routine outlined in the GCBasic docs, all the PIC pins are dead, so I have to think that it is the code that is not working.

    I also copied the code from another thread in this forum, where the guy used a 16f684, but still, I get nothing.

    I should point ount that there are no wires running to D0 - D3, only D4-D7 and RS, E, and of course power pins. R/W is running to ground as spec'd in the diagram, I also noticed this as an option in the Hantronix datasheet. I'm not reading from the LCD, so I don't think it matters. I did, however, wire it to a PIC pin, just to try it.

    I was thinking that I should try to control the LCD through my own code, instead of using the LCD functions, but I can't figure out how to do it.

    Any thought regard my ramblings?

    Cheers,

    Sterling

    P.S. Thanks for Great Cow BASIC. It has opened up a lot of possibilities. I look forward to further development.

     
    • Steve

      Steve - 2007-01-21

      Download the update from here:

      http://gcbasic.sourceforge.net/newfiles/

      Plus get the new lcd.h file too and throw it in your gcbasic/include directory

      I think the old lcd.h had an error in it.

       
    • Sterling Youngman

      I installed the new files, but nothing has changed. I did notice that in the lcd.h file, the LCD_IO is set to 4. In my program, I override that to 8, but I am actually only using 4 data bits, so when I change it back to 4, I get an error when compiling: SYSLCDTEMP.0 is not a valid I/O pin or port.

      below is code that compiles correctly. I have to point out that the R/W pin is not connected to the LCD, because that is not how it is spec'd in the diagram. If I take the line out, it won't compile.

      #chip 16F684, 8
      #mem 368
      #config _CP_OFF & _CPD_OFF & _MCLRE_OFF & _BOD_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT 

      #define LCD_IO 8
      #define LCD_DATA_PORT PORTC
      #define LCD_RS PORTC.4
      #define LCD_RW PORTA.1
      #define LCD_Enable PORTC.5
      '#define LCD_DB4 PORTC.0
      '#define LCD_DB5 PORTC.1
      '#define LCD_DB6 PORTC.2
      '#define LCD_DB7 PORTC.3

      main:

      Print "Hello World"
      wait 3 sec
      goto main

      -Sterling

       
    • Sterling Youngman

      Further strangeness:

      I examined the LCD.h code. Things look in order. I decide to add the following to my code, thinking I might see some voltage on the multimeter, from the data pins:

      DIR LCD_DB4 OUT
      DIR LCD_DB5 OUT
      DIR LCD_DB6 OUT
      DIR LCD_DB7 OUT

      The compiler crashes on the DB7 line. It is the same error as mentioned above.

       
    • Steve

      Steve - 2007-01-22

      Here is what I use, it works fine for me.  I notice your #config line has the & symbol.  Take that out.

      I have tried to use port A for LCD routines and haven't had any luck. Try just using port c and see if that works.

      'Chip model
      #chip 16F690, 8
      #config INTRC_OSC_NOCLKOUT, WDT_OFF

      'LCD connection settings
      #define LCD_IO 4
      #define LCD_DB4 PORTC.4
      #define LCD_DB5 PORTC.3
      #define LCD_DB6 PORTC.6
      #define LCD_DB7 PORTC.7
      #define LCD_RS PORTC.0
      #define LCD_RW PORTC.1
      #define LCD_Enable PORTC.2

      Start:
      ADOff
      CLS

      wait 250 us
      locate 1,0
      print("It works")
      end

      goto Start

       
    • Hugh Considine

      Hugh Considine - 2007-01-22

      If you are using the LCD with only 4 wires connected, you MUST set LCD_IO to 4. Using these lines of code:

      #define LCD_IO 8
      #define LCD_DATA_PORT PORTC
      #define LCD_RS PORTC.4 
      #define LCD_RW PORTA.1
      #define LCD_Enable PORTC.5

      GCBASIC expects this wiring configuration:

      PORTA.1 > RW
      PORTC.0 > DB0
      PORTC.1 > DB1
      PORTC.2 > DB2
      PORTC.3 > DB3
      PORTC.4 > DB4
      PORTC.4 > RS
      PORTC.5 > DB5
      PORTC.5 > Enable
      PORTC.6 > DB6
      PORTC.7 > DB7

      This program works for me:

      'General hardware configuration
      '#chip 18F4550, 20
      #chip 16F877A, 20

      'LCD connection settings
      #define LCD_IO 4
      #define LCD_DB4 PORTD.4
      #define LCD_DB5 PORTD.5
      #define LCD_DB6 PORTD.6
      #define LCD_DB7 PORTD.7
      #define LCD_RS PORTD.0
      #define LCD_RW PORTD.1
      #define LCD_Enable PORTD.2

      'Word variable declarations
      dim Counter as Word

      Print "Hello World!"
      Wait 1 sec

      do
      Counter += 1
      CLS
      LCDWord Counter
      wait 250 ms
      loop

      On my breadboard, I have connected the DB0-DB3 pins to ground. If they are not grounded, the LCD sometimes refuses to work.

      RW must be connected to the LCD, as GCBASIC uses this to check if the LCD is ready to receive instructions. The PIC stops running until the LCD indicates that it is ready, so if the RW line is disconnected the PIC will enter an infinite loop.

      One final thing: please download http://gcbasic.sourceforge.net/newfiles/update.zip and see if it helps. I've fixed quite a few bugs in the last few days - maybe one of them is the cause of the trouble.

       
    • Sterling Youngman

      Not for me. I get nothing but spaces and slashes and the occasional question mark on the LCD. The only thing I can think of id that bad data is being passed to the device.

      -Sterling

       
    • Steve

      Steve - 2007-01-22

      Sterling --

      I had the same spaces and slashes, until I updated to the newest version from http://gcbasic.sourceforge.net/newfiles/update.zip

      Maybe you could paste the .lst file after you compile?

       
    • Sterling Youngman

      I have already updated to the most recent files.

      Can you tell me where to find the .lst file? I've looked throughout the GCBasice folders, but I don't see anything with that extension.

      -Sterling

       
    • Sterling Youngman

      I've ordered an different PIC. It should be here in a few days. I'll post the outcome of it's insertion into my nightmare.

      -Sterling

       
    • Sterling Youngman

      I replaced the PIC with a 16F84A, and now everything works. I can't believe that it can't work with the 16F684.

      -Sterling

       
    • Nobody/Anonymous

      Well, Almost everything works.

      I can see the text, and it is correct, but the display if very faint. I have tried different POTs, but nothing makes it easily readable. I'm wondering if there is a timing issue with the LCD startup.

      Thoughts?

      Sterling

       
    • Nobody/Anonymous

      Glad you got it going.  Apologize for imperfect explanation before, your hookup includes +5V too?
           _____
          |10K  |-----5v
          |POT  |-----Pin 3
          |_____|-----Gnd

      Beyond that, don't know.

      Kent

       
    • Sterling Youngman

      Kent,

      I have the POT wired properly.

      Here is the odd thing: I was thinking that there may have been a problem with my soldering, so I ran a wire directly from the pot to the connector on the LCD board (skipping breadboard, ribbon cable and connectors).

      Suddenly, everything seemed fine, then removed the wire, and the LCD was still working as it should.

      Next I unplugged the power and then plugged it back in. From that point on, I've had nothing but a faint display. Of course I have tried to repeat my steps, but nothing works.

      -Sterling

       
    • Steve

      Steve - 2007-01-26

      Sterling,

      Just for something to try, my particular LCD display works best with about 3 - 4k of resistence on the contrast pin. 
      Maybe if you have some spare resistors laying around you could try that, just to get it visible.

      Steve

       
    • Sterling Youngman

      Kent,

      What are you using (if anything) as a clock oscillator, and how is it wired up?

      Also, Are you using pull-up resistors on unused pins?

      -Sterling

       
    • Steve

      Steve - 2007-01-26

      Tie unused pins on the LCD to ground.

       
    • Sterling Youngman

      unused pins on the PIC or D0-D3 on the LCD to LCD ground?

       
    • Nobody/Anonymous

      Sterling,

      I am using an Olimex pic18 development board that has a 20mhz crystal with caps already installed.  Not using portpin pullups, and not grounding unused LCD pins either.  Since you are getting the correct values/strings displayed then your timing is correct.

      I would be suspicious of your LCD voltage.  You absolutely need a solid 5v to the LCD.   If you are trying to run your LCD and backlight led off a laptop USB port thru your programmer, forget it.  Is your chip or LCD getting warm or hot? then you have a short or solder bridge.  If you are using a breadboard? then try using different pin holes, because the contacts may be sketchy, also try different wire/socket arrangement.  The list is endless.

      Kent 

       
    • Nobody/Anonymous

      Sterling,

      O.K. read your datasheet on your Hantronix 2x16, it may need a Negative contrast voltage.

      Kent

       
    • Sterling Youngman

      Kent,

      I'm new to electronics, so I'm not sure I follow about the negative contrast voltage.

      I a 10 Ohm resistor between ground and the contrast pin. I ahve also tried a 20K pot. They both give me the same result, and they both have proven to displace on the LCD at the correct contrast.

      I have noticed something very odd. If I disconnect the ground from the LCD, and then power up or off, the LCD flashes solid on/off as if the contrast is correct, then nothing comes up. Of course, the LCD is not GROUNDED, so if power isn't running through it, how can this happen?

      -Sterling

       
    • Sterling Youngman

      Kent,

      I forgot to mention that I am running a AC power adapter through a regulator, which provides clean 5V.

      Also, my LCD does not have a backlight.

       
    • Sterling Youngman

      Kent,

      What LCD are you using?

      -Sterling

       
    • Nobody/Anonymous

      Sterling,

      It's a 4X20 Orient Display AMC2004A-B-Y6NFDY.  It's a positive contrast voltage display as are most?  Got it for $10usd when ordered along with a serial backpack kit at http://www.phanderson.com/ordering_1.html.  Haven't got the serial part going yet with gcbasic, but works fine in 4 bit mode.

      If your display is indeed a negative voltage contrast display, you could also set up a dual supply voltage.  Either get a neg. 5v or neg. adj. regulator for less than a buck, or use 4-6 AA batterys.  Hook them up according to your Googled dual supply lcd diagram.

      Note: no  warranty tho, as I have already burnt a lcd controller port pin on a 2x16 display, on another project, makes for nice blank column spot on both lines.

      Kent

       
    • Sterling Youngman

      Kent,

      As far as I can tell, my LCD is a positive voltage contrast display, https://www.jameco.com/Jameco/Products/ProdDS/658890.pdf

      The wiring seems the same as for yours.

      For the heck of it, I set up a dual power setup. but that did not solve the problem.

      I wish I could find an electronic usergroup in the Los Angeles area. But Googling doesn't turn up anything.

      -Sterling

       
1 2 > >> (Page 1 of 2)

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.