Searching \ for '[PIC]: Getting 2-wire LCD interface to work (newbi' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/lcd/pic.htm?key=lcd
Search entire site for: 'Getting 2-wire LCD interface to work (newbi'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Getting 2-wire LCD interface to work (newbi'
2001\02\27@141121 by mmucker

flavicon
face
With no offers from anyone to run my LCD code, I'm posting it here for code
review.  I'd appreciate any help I can get.

My code is mostly a flat-out copy of Myke's demo code, with minor
modifications.  For instance, the code on Myke's page generates a huge
number of MPASM compiler warnings, so I tweaked (basically adding
destination operands) until the compiler warnings went away. Also, Myke's
code contained inline decimal math.  Rather than figuring out how to tell
the compiler to use decimal evaluation, I did the evaluation and replaced
the constant.  My code can be compared almost line for line with Myke's code
at http://www.myke.com/code/2wirepic.asm

My program is built on top of my first PIC program.  This program is
supposed to reset the LCD, display "Hi there" on the LCD, and then count
infinitely on the portB pins.

I can see that *something* is getting to the LCD, as it does change its
behavior/display when my project is powered up.

This is running on a 4MHz PIC16F84.  The LCD routines are marked with highly
visible comments if you want to scroll straight to them.  My initialization
code is also likely to have errors.

Many thanks in advance to anyone who looks at my code!

-Matt



My code looks like this:

       list    p=16f84
       __config _CP_OFF & _PWRTE_ON & _WDT_OFF ;add XT
       include <p16F84.inc>



;file register variables
inner   equ     0x0c    ;temp variable
outer   equ     0x0d    ;temp variable
output  equ     0x0e    ;the byte sent to the output pins of port b
Dlay    equ     0x0f    ;scratch byte for LCD delay routines
Temp    equ     0x10    ;temp byte for LCD routines
NOTemp  equ     0x11    ;temp byte for LCD routines

;constants
INNER_LOOP_DELAY        equ 0x8a
#DEFINE LCDData         PORTA,0
#DEFINE LCDClock        PORTA,1

;macros
ClockStrobe     MACRO
       bsf     LCDClock
       bcf     LCDClock
       ENDM

EStrobe         MACRO
       bsf     LCDData
       bcf     LCDData
       ENDM

;start of program
       org     0x00                    ;program memory base at 0x00
reset                                   ;reset vector
       goto    start                   ;Go to start of main program



       org     0x04                    ;Beginning of user code
start
;===========================================================================
=
;Setup stuff here.
;===========================================================================
=
       clrf    output                  ;clear the output shadow register
       clrf    outer                   ;initialize the outer loop counter
       clrf    PORTB                   ;clear the LED output pins
       clrf    PORTA                   ;clear the LCD output pins
       movlw   INNER_LOOP_DELAY
       movwf   inner                   ;initialize the inner loop counter

       bsf     STATUS,5                ;select bank 1
       clrf    TRISB                   ;set portb to outputs
       bcf     TRISA,0                 ;set LCDData to output
       bcf     TRISA,1                 ;set LCDClock to output
       bcf     STATUS,5                ;select bank 0



;===========================================================================
=
;Test things by writing to the LCD
;===========================================================================
=

       call    ResetLCD
       movlw   "H"
       call    SendLCDChar
       movlw   "i"
       call    SendLCDChar
       movlw   " "
       call    SendLCDChar
       movlw   "t"
       call    SendLCDChar
       movlw   "h"
       call    SendLCDChar
       movlw   "e"
       call    SendLCDChar
       movlw   "r"
       call    SendLCDChar
       movlw   "e"
       call    SendLCDChar

;===========================================================================
Main program code was here, stripped out for code review to save space.
;===========================================================================
test    goto    test


;===========================================================================
=
;LCD routines start here.
;===========================================================================
=
ResetLCD
       call    Dlay5                   ;Wait 20msec before resetting the LCD
       call    Dlay5
       call    Dlay5
       call    Dlay5

       bcf     STATUS,C                ;clear the carry flag (//WHY?)
       movlw   0x03                    ;reset command (//Is this right?  Should be 0x30?)
       call    NybbleOut               ;send the command
       call    Dlay5                   ;wait 5 usec before sending second time

       EStrobe
       call    Dlay160                 ;wait 160 usecs before sending third time

       EStrobe
       call    Dlay160                 ;wait 160 usecs before continuing

       ;LCD should now be reset.

       bcf     STATUS,C
       movlw   0x02                    ;LCS 4-bit mode command
       call    NybbleOut
       call    Dlay160

       movlw   0x28                    ;?? for two-line display
       call    SendLCDINST

       movlw   0x08                    ;turn off the display
       call    SendLCDINST

       movlw   0x01                    ;Clear display RAM
       call    SendLCDINST
       call    Dlay5

       movlw   0x06                    ;enable cursor move direction
       call    SendLCDINST

       movlw   0x0c                    ;turn LCD back on
       call    SendLCDINST

       return

SendLCDINST
       movwf   Temp
       swapf   Temp,w
       bcf     STATUS,C
       call    NybbleOut
       movf    Temp,w
       bcf     STATUS,C
       call    NybbleOut
       return

SendLCDChar
       movwf   Temp
       swapf   Temp,w
       bsf     STATUS,C
       call    NybbleOut
       movf    Temp,w
       bsf     STATUS,C
       call    NybbleOut
       return

NybbleOut
       movwf   NOTemp                  ;save the nybble to shift out
       swapf   NOTemp,F
       movlw   6                       ;clear the shift register
       movwf   Dlay
NOLoop1
       ClockStrobe
       decfsz  Dlay,F
       goto    NOLoop1

       bsf     LCDData                 ;Put out the Gate bit
       ClockStrobe

       bcf     LCDData                 ;Put out the RS bit
       rlf     PORTA,F
       ClockStrobe
       movlw   4
       movwf   Dlay
NOLoop2
       rlf     NOTemp,F
       bcf     LCDData
       rlf     PORTA,F
       ClockStrobe
       decfsz  Dlay,F
       goto    NOLoop2

       EStrobe
       return

Dlay160
       movlw   0xD8            ;256 - ( 160 / 4 )
       addlw   1
       btfss   STATUS,C
       goto    $-2
       return

Dlay5
       movlw   4
       movwf   Dlay
       movlw   0x18            ;256 - 0x0E8
       addlw   1
       btfsc   STATUS,Z
       decfsz  Dlay,F
       goto    $-3
       return

       end

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\02\27@152258 by Drew Vassallo

picon face
See comments where added:

>         call    ResetLCD

To be safe, you can send a cursor position command here.
i.e.,
         movlw   0x80   ; position line 1 column 0
         call  SendLCDINST

{Quote hidden}

These literals should all be 'X', not "X".  This is likely your biggest
problem.

>         bcf     STATUS,C                ;clear the carry flag (//WHY?)
>         movlw   0x03                    ;reset command (//Is this right?
>Should be 0x30?)

You clear the carry flag because it's an instruction, not data.  0x03 is
correct, not 0x30.

<SNIP>
>NybbleOut
>         movwf   NOTemp                  ;save the nybble to shift out
>         swapf   NOTemp,F

You can ensure that the shift register is REALLY cleared by making sure the
data bit is clear before sending all 6 bits to the shift register.
i.e.,
         bcf  LCDData

>         movlw   6                       ;clear the shift register
>         movwf   Dlay
>NOLoop1
>         ClockStrobe
>         decfsz  Dlay,F
>         goto    NOLoop1
>
<SNIP>

Try these changes.  They should help.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\02\27@153122 by Drew Vassallo

picon face
One more thing about your LCD code:

The way Myke has his program set up, you MUST use Clock as PORTA, 1 and Data
as PORTA, 0.  This is because he shifts the data bits left into Carry and
then shifts again left into PORTA.  Also, he clears the Data bit before the
shift in order to force the Clock line low.  If you define your port control
lines differently (I don't remember if you did or not), then his code won't
work out-of-the-box.

Myke should probably have noted that in his code, but he didn't.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics



'[PIC]: Getting 2-wire LCD interface to work (newbi'
2001\03\01@141423 by mmucker
flavicon
face
Drew,

Once again I wanted to thank you for taking the time to review my LCD code.

I finally found the source of the problem.  After many hours of frustrating
debugging work, I determined that the contacts on my breadboard were not
gripping pin RA.0, so the data was being properly output to the PIC pin, but
not making it to the shift register.  Holding the data line against the pin
instead of putting it in the breadboard caused my message to be properly
displayed on the LCD.

So, it wasn't the software, it wasn't the circuit, it was bad tools!

Thanks again,

-Matt

> {Original Message removed}

2001\03\01@191601 by miked

flavicon
face
>
> These literals should all be 'X', not "X".  This is likely your biggest
> problem.
>
Speaking of, how does one use the literal for ' ?
MPASM doesn't like movlw '''
I know I can just use the hex value.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...