Simple LCD code not working..


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2007
    Posts
    60

    Default Simple LCD code not working..

    Hi all,

    I have a couple of projects with 16F877a's and 4 line LCD panels working fine.

    I wanted to do something smaller scale, and have a 16F84a and a 2x16 LCD. I have used this LCD in the past and it was fine. I have written a very short program just to get the LCD going, but alas it doesn't show anything... Below is my code:

    Code:
    define osc 4
    
    ' Define LCD registers and bits
    DEFINE  LCD_DREG        PORTB            
    DEFINE  LCD_DBIT        4                    
    DEFINE  LCD_RSREG       PORTB            
    DEFINE  LCD_RSBIT       2                
    DEFINE  LCD_EREG        PORTB            
    DEFINE  LCD_EBIT        3
    
    TRISA = %11111
    
    butup           var porta.0
    butdn           var porta.1
    light             var portb.1
    
    light = 0
    
    pause 1000
    light = 1
    
    
    lcdout $fe,1
    
    Start:
    
    lcdout $fe,$80,"line one"
    lcdout $fe,$C0,"line two"
    
    pause 500
    toggle light
    
    goto Start
    On turn-on, the LCD enables (1st row black boxes, 2nd row blank) then waits the 1000 and clears the LCD. After that, I get nothing at all on the LCD, but the led blinks away happily.

    I've done this before on a 16F88 I think (albeit a while ago) which is why it is frustrating me so.

    Can anyone point out anything I've done wrong in the code? Do I need to declare anything else, etc? I have checked and rechecked the wiring many times, if no-one can point out anything I will have to source and test another LCD incase that is the problem.

    Thanks in advance.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    In theory it has to work, you may have one of those LCD timing problem OR LVP mode set to on. try

    for 16F877a
    Code:
    @   __CONFIG _XT_OSC & _LVP_OFF
    define OSC 4
    
    ' Define LCD registers and bits
    DEFINE  LCD_DREG        PORTB            
    DEFINE  LCD_DBIT        4                    
    DEFINE  LCD_RSREG       PORTB            
    DEFINE  LCD_RSBIT       2                
    DEFINE  LCD_EREG        PORTB            
    DEFINE  LCD_EBIT        3
    DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    Play with the contrast pot, make sure the R/W pin is tied to low. Not better, you may need to play with COMMANDUS and DATAUS values.

    For the 16F88 you may need to disable some Analog feature.


    HTH
    Last edited by mister_e; - 23rd April 2008 at 14:58.
    Steve

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

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    What about a line saying

    TRISB = 0
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Even if it's always a good practice, LCDOUT handle it for you.

    LCDOUT "a"

    .LST
    Code:
    0006   1683           02798         bsf     STATUS, RP0     ; Point to trises
    0007   1186           02799         bcf     LCD_EREG, LCD_EBIT      ; Set E to output
    0008   1205           02800         bcf     LCD_RSREG, LCD_RSBIT    ; Set RS to output
    0009   1205           02801         bcf     LCD_RWREG, LCD_RWBIT    ; Set RW to output
                          02802     if ((LCD_BITS) == 8)
                          02803         clrf    LCD_DREG        ; Set port to all output
                          02804     else
    MPASM  5.14                             A.ASM   4-23-2008  10:43:15         PAGE  3
    
    
    LOC  OBJECT CODE     LINE SOURCE TEXT
      VALUE
    
                          02805       if ((LCD_DBIT) == 0)
    000A   30F0           02806         movlw   0f0h
                          02807       else
                          02808         movlw   0fh
                          02809       endif
    000B   0585           02810         andwf   LCD_DREG, F     ; Set proper half of port to output
    Last edited by mister_e; - 23rd April 2008 at 15:49.
    Steve

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

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    As an apprentice, I , respect masters always.



    ---------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Still not working

    Thanks all for the replies.. I originally had the TRISB = 0, but removed it to simplify, added it back in, no difference. Added the cammandus & dataus lines, still no difference.

    I'm using the 16F84a for now, so no A/D, no LVP, I've made sure it has XT OSC.

    And have fiddled the contrast pot, I know it's right now tho, as the blocks come up on the first line, and then when I LCDOUT $fe,1.... The screen clears.

    I even measured continuity between the data pins on my pic, and the pins on the LCD incase I had a problem on my breadboard.

    I think I'm going to have to get another LCD panel to rule that out as being the problem...

    Any more suggestions I'd be happy to hear, but I now presume it's a hardware fault, seeings how it doesn't seem I stuffed up any of the code.

    Thanks again,

    Dave

    edit - R/W is also tied low... I know this as when I first connected it, I tied it high, and nothing happened, when I tied it low, it now clears...

  7. #7
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Fixed It

    Just a follow up...

    I got another LCD the same, connected it, it came up with crazy characters on the screen... In desperation I swapped the cable I was using (IDE HDD cable) and low and behold it works.

    On closer inspection, the cable I was using originally, has more conductors in it than pins on the plug. I pulled the plug apart, and there is a big copper bus-bar that connects certain pins to each other, and also I assume to ground. Must give some kind of shielding effect.

    Anyway all sorted.

    Thanks to everyone that helped...

    Cheers
    Dave

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by davewanna View Post
    On closer inspection, the cable I was using originally, has more conductors in it than pins on the plug. I pulled the plug apart, and there is a big copper bus-bar that connects certain pins to each other, and also I assume to ground. Must give some kind of shielding effect.
    Info you: Older IDE cables had 40 pins, newer ones have 80 pins, 40 normal + 40 grounds/shields, for use with the higher DMA speeds and transfer rates in the newer ATA spec's.

Similar Threads

  1. Simple LCD code not working!...WHY?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th November 2009, 19:48
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. My LCD code is not working...
    By kvrajasekar in forum mel PIC BASIC
    Replies: 2
    Last Post: - 7th December 2008, 05:41
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. LCD issue with EasyPIC5
    By manwolf in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th June 2008, 09:17

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