Searching \ for '[PIC]: LCD Problems' 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: 'LCD Problems'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: LCD Problems'
2001\02\05@020610 by dr. Imre Bartfai

flavicon
face
Hi,
without studying your code in-depth, I see some typical problem in your
ISR. Critical places are marked below. I hope this helps.

Regards,
Imre


On Mon, 5 Feb 2001, Ian Hynes wrote:

{Quote hidden}

*** Statement below is bad as itself changes the status register

>          bcf       STATUS,0       ;Put registers into known page
>          movwf     STATUS_
>          movf      PCLATH,0       ;Save PCLATH
*** sorry - PCLATH can not be read as spec gives.
*** it is better not to change pages and set up save registers for
*** every bank at the same location.

{Quote hidden}

*** if you do not use IT's, there is no point to write an ISR

{Quote hidden}

*** RB2..4 will be low, RB4..7 will be high...

>          movwf   PORTB
>
>          clrf    PORTA
>          BANK_1
>          movlw   0x01F
>          movwf   TRISA
>          BANK_0
>          movlw   0x01F          ;PORTA to be all INPUTs
>          movwf   PORTA          ;Bits 0,1,2,3,4 set to "1"
*** to write to inputs does not make any sense

{Quote hidden}

Sorry, I did not follow the whole part of code. However, as I recall,
74164 has a clear pin which should be considered.

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2001\02\05@022513 by Bob Ammerman

picon face
----- Original Message -----
From: dr. Imre Bartfai <rootspamKILLspamPROF.PMMF.HU>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Monday, February 05, 2001 2:03 AM
Subject: Re: [PIC]: LCD Problems


> Hi,
> without studying your code in-depth, I see some typical problem in your
> ISR. Critical places are marked below. I hope this helps.
>
> Regards,
> Imre

Yikes! At least some of your corrections are incorrect!

I've marked my opinion with "!!!" below.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Quote hidden}

!!! I assume you meant to say 'statement above', but the original
!!! value of STATUS will be properlyy copied to W

> >          bcf       STATUS,0       ;Put registers into known page
> >          movwf     STATUS_
> >          movf      PCLATH,0       ;Save PCLATH
> *** sorry - PCLATH can not be read as spec gives.

!!! Why not??

> *** it is better not to change pages and set up save registers for
> *** every bank at the same location.

!!! In the F84 all GPR is mapped in both banks 0 and 1 anyway

>
> >          movwf     PCLATH_
> >          movf      FSR,0
> >          movwf     FSR_
> > b1       nop                      ;Do nothing for now
> >          nop
> >
> > int_ret  movlw     b'00011000'    ;Reset the INTCON bits BUT ...
> >          movwf     INTCON         ;.. let the PIC set GIE upon retfie

!!! Normally you'd test bits in INTCON,
!!! handle the interrupt and then clear them

> >          movf      FSR,0
> >          movwf     FSR
> >          movf      PCLATH_
> >          movwf     PCLATH
> >          movf      STATUS_,0      ;Return from interrupt

!!! You are missing a MOVWF STATUS here
!!! to restore the status register

> >          swapf     w_             ;Flip & laod the w register
> >          swapf     w_,w           ;without affecting the STATUS reg.
> >          retfie
>
> *** if you do not use IT's, there is no point to write an ISR

!!! This is certainly true!

{Quote hidden}

!!! Yep, after 'glitching' to all lows becuase of the
!!! clrf PORTB, above

{Quote hidden}

!!! Yep, plus RA4 is defined as an  "INPUT NC (no connection)"
!!! This is a bad idea (floating input).

!!! I stopped looking at the code, here (Bob A)

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\02\05@191409 by Ian Hynes

flavicon
face
Hey Bob & Imre,

Thanks, I've been thru the corrections and made changes to the ISR.
Imre's way of configuring the outpt is good - the LEDs go high right
at the start ; can't see any low-going little glitches on a CRO.

OK, the new init & ISR segments look like so :-

init     movlw   b'11111111'
        movwf   PORTB          ;Make PORTB all HIGH, avoid turn-on
glitch??
        BANK_1
        movlw   b'00000001'    ;All except RB0 to be OUTPTs
        movwf   TRISB
        BANK_0
        movlw   b'00011111'
        movwf   PORTA
        BANK_1
        movlw   0x01F
        movwf   TRISA
        BANK_0
        retlw   0x00
;<...................>
       org       0x04
int      movwf     w_             ;Start interrupt routine
        movf      STATUS,0
        movwf     STATUS_
        movf      PCLATH,0       ;Save PCLATH
        movwf     PCLATH_
        movf      FSR,0
        movwf     FSR_
b1       nop            ;Do the interrupt routine
              ;There are KPD & LED routines in here let's not confuse
things ...
b2       nop            ;Send the result to RS232

int_ret  movlw     b'00011000'    ;Reset the INTCON bits BUT ...
        movwf     INTCON         ;.. let the PIC set GIE upon retfie
        movf      FSR,0
        movwf     FSR
        movf      PCLATH_
        movwf     PCLATH
        movf      STATUS_,0      ;Return from interrupt
        movwf     STATUS
        swapf     w_             ;Flip & laod the w register
        swapf     w_,w           ;without affecting the STATUS reg.
        retfie

The ISR works OK, as shown above. The cct grabs a nibble from a KPD
via a 74C922 and lights up 4 LEDs with it.

***The only thing that's NOT working is the LCD. ***

I made sure MPLAB is set to 2MHz, same as the cct, as Dave vanH
suggested. And i can change LCD, 74164 etc over into the 16C57 cct and
they work so it's not that ...

Wait'll i fiddle some more with it guys ... I'd better repost anyway
cuz I didn't put in the [PIC]: prefix originally. NEWTON's LAW
applies!<GR>


Bob Ammerman wrote:
>
> {Original Message removed}

2001\02\05@204604 by Bob Ammerman

picon face
----- Original Message -----
From: Ian Hynes <KILLspamelekKILLspamspamNETSTRA.COM.AU>
To: <RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU>
Sent: Monday, February 05, 2001 7:10 PM
Subject: Re: [PIC]: LCD Problems


{Quote hidden}

   ^^^^^^^^^^^^^^^ Should be movf FSR_,0

(btw: I don't much care for the ",0" syntax. I prefer ",W" and ",F")


{Quote hidden}

your
{Quote hidden}

nuts
{Quote hidden}

retfie
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2001\02\06@182532 by Ian Hynes
flavicon
face
PICers,

OK, I've made changes to the ISR as Bob A. and other guys suggested.
*MANY* thanks for the tips! The interrupt part of the programme works
fine - grabs a data nibble from a 4x4 keypad, via a 74C922 decoder and
dumps it to 4 LEDs on PORTB.

But the %&#! LCD still doesn't give a bleep. What's totally
infuriating is the routines work - at least they do on a 16C57. If
anyone's got any ideas, I'd be mighty interested to hear.

(I've got both the 16C84 & 16C57 ccts set up on protoboard, so it's
easy to make hardware changes. Both are stock standard ccts, though.)

Thnaks for *any* advice - Ian.

I'm conpletely stumped, so here's the full code :-

title lcdtst01
;
;DATE      : February 2, 2001
;PURPOSE   : A programme to control an HD44780 LCD via a PIC 16F84
;AUTHOR    : Ian H.
;SCHEMATIC : LCDTST01.sch
;
;COMMENTS  :
;
;PIC CONFIGURATION :
;
;                            ------   ------
; DAT_C, 74C922 =>       RA2 |1    ---   18| RA1         <= DAT_B,
74C922
; DAT_D, 74C922 =>       RA3 |2          17| RA0         <= DAT_A,
74C922
;     BATT TEST => T0CKI/RA4 |3          16| OSC1/CLKIN  <= 2MHz XTAL
;        +5 VDC ->     /MCLR |4          15| OSC2/CLKOUT <= 2MHz XTAL
;           GND ->       Vss |5   16F84  14| Vdd         <- +5 VDC
;    74C922, DA  <-  INT/RB0 |6          13| RB7        ->  LCD EN
(ENABLE)
;          LED1  <-      RB1 |7          12| RB6        ->  LCD CH
(CHARACTER BITS)
;          LED2  <-      RB2 |8          11| RB5        ->  LCD CK
(CLOCK)
;          LED3  <-      RB3 |9          10| RB4        ->  LED4
;                            ---------------
;REVISIONS :

LIST p=16F84, F=INHX8M, R=HEX
     errorlevel 0, -302, -305
           ;302="register in operand not in "
           ;305="Using Default Destination"

__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC

include "p16f84.inc"
include "asc2lcd.inc"    ;The LCD alpha-numeric assignments.
;
;CLOCK FREQ = 2.0 MHz

;*********************************************************
;VECTOR ASSIGNMENTS
;*********************************************************
pic84    equ   0x01FD      ;MAX memory address

;*********************************************************
;LCD pin assignments
;*********************************************************
EN       equ 7
CH       equ 6
CK       equ 5

RS       equ 3       ;Bit #4 in LCDFLAGS determines Command\Character
for
                    ;the LCD
;*********************************************************
;FLAG REGISTER assignments
;*********************************************************
VT        equ  2      ;VALID TRANSMISSION  ("VT") from 74C922 to RB0

;*********************************************************
;MACROS
;*********************************************************
BANK_0 MACRO
bcf  STATUS,RP0       ;RP0=STATUS.b5
bcf  STATUS,RP1       ;RP1=STATUS.b6
ENDM

BANK_1 MACRO
bsf STATUS,RP0
bcf STATUS,RP1
ENDM

;*********************************************************
;REGISTER ASSIGNMENTS
;BANK #0
;*********************************************************
CBLOCK 0x0C
w_                     ;Stores w during interrupts
STATUS_                ;A 'dummy' STATUS register
PCLATH_
FSR_
flags                  ;A 'decision' register
Keydata                ;Holds DATA NIBBLE from the 74C922
count_00               ;GP counters
count_01
count_02
count_03

;LCD registers.
temp                   ;Holds HEX data prior to conversion to ASCII
w2                     ;Dummy w register used by nib_tx
charac                 ;Data for the LCD
LCDflag                ;Flags R/W, cursor status etc
d10000                 ;ASCII digits to be loaded into the LCD
d1000
d100
d10
d01
count                  ;More counters .. used in the LCD routines
count_10               ;PAGE #1 count registers, available for
count_11               ;up to 3-loop counters
count_12
count_13
ENDC

;********************************************************
;Begin the MAIN PROGRAMME
;********************************************************
PAGE
        org       0x00
start    goto      main

        org       0x04
int      movwf     w_             ;Start interrupt routine
        movf      STATUS,0
        movwf     STATUS_
        movf      PCLATH,0       ;Save PCLATH
        movwf     PCLATH_
        movf      FSR,0
        movwf     FSR_
b1       call      kbdgrab        ;Do the interrupt routine
        movf      Keydata,0
        clrf      LCDflag
        bsf       LCDflag,RS     ;Set RS=1 for CHARACTER mode.
                                 ;Enable the 4 bit operating mode.
        movwf     temp           ;Now display the LCD readout
        call      hex2asc        ;Convert to ASCII
        movf      d01,0          ;And send to the LCD
        call      nib_tx
        movf      d10,0
        call      nib_tx
        movf      d100,0
        call      nib_tx

        rlf       Keydata,1
        bsf       Keydata,0
        movf      Keydata,0
        addlw     b'10100000'    ;Send 101 to the LCD INPUT (No new
data bits)
b2       movwf     PORTB          ;Send the result to RS232

int_ret  movlw     b'00011000'    ;Reset the INTCON bits BUT ...
        movwf     INTCON         ;.. let the PIC set GIE upon retfie
        movf      FSR_,0
        movwf     FSR
        movf      PCLATH_
        movwf     PCLATH
        movf      STATUS_,0      ;Return from interrupt
        movwf     STATUS
        swapf     w_             ;Flip & load the w register
        swapf     w_,w           ;without affecting the STATUS reg.
        retfie

;*************************************************************
;Initialise the PIC84's PORTS.
;
;PIN ASSIGNMENTS
;RB0  ..  INPUT. Reads DR  (Active High) from 74C922
;RB1  ..  LED1
;RB2  ..  LED2
;RB3  ..  LED3
;RB4  ..  LED4
;RB5  ..  OUTPT to 74164 (CK)
;RB6  ..  OUTPT to 74164 (Data B = 'CH')
;RB7  ..  OUTPT to LCD (EN)
;
;RA0  ..  INPUT. Reads DAT_A from 74C922
;RA1  ..  INPUT. Reads DAT_B from 74C922
;RA2  ..  INPUT. Reads DAT_C from 74C922
;RA3  ..  INPUT. Reads DAT_D from 74C922
;RA4  ..  INPUT. NC. Use for battery test?
;
;*************************************************************
init     movlw   b'11111111'
        movwf   PORTB          ;Make PORTB all HIGH, avoid turn-on
glitch??
        BANK_1
        movlw   b'00000001'    ;All except RB0 to be OUTPTs
        movwf   TRISB
        BANK_0
        movlw   b'00011111'
        movwf   PORTA
        BANK_1
        movlw   0x01F
        movwf   TRISA
        BANK_0
        retlw   0x00

;*********************************************************************
;KEYPAD GRAB - responds to an interrupt from the DA/VT pin on the
74C922,
;grabs the Data nibble and stores it in KeyData. It then sets b3 in
;flags before returning. VT, the pin, MUST be same as VT in the flags
register.
;*******************************************************************
kbdgrab movf     PORTA,0     ;Data are present.
       nop
       movwf    Keydata     ;Store the data
                            ;comf     Keydata,1   ;Invert the Active
Low input.
       movlw    b'00001111' ;Make SURE the upper nibble
       andwf    Keydata,1   ;really is b'0000'.
       bsf      flags,VT    ;Tell the main programme
       nop                  ;Jump to here if no input
       retlw    0x00

;********************************************************************
;hex2asc ... a HEX to BCD & ASCII conversion routine. The hex number
;to be converted must be in passed in 'temp'.
;Experimental - gives correct results on MPLAB simulator.
;********************************************************************
hex2asc  clrf    count
        bcf     STATUS,C
        movlw   0x064
        subwf   temp,1
        btfss   STATUS,C
         goto   $+3
        incf    count,1
         goto   $-5
        movf    count,0       ;Retrieve the MSD
        movwf   d100
        movlw   0x064
        addwf   temp,1
        clrf    count
        bcf     STATUS,C
        movlw   0x0A
        subwf   temp,1
        btfss   STATUS,C      ;-ve?
         goto   $+3
        incf    count,1
        goto    $-5
        movf    count,0       ;Retrieve the middle digit
        movwf   d10
        movlw   0x0A
        addwf   temp,1        ;???
        movf    temp,0        ;Retrieve LSD
        movwf   d01
        movlw   0x030         ;Convert to ASCII
        addwf   d100,1
        addwf   d10,1
        addwf   d01,1
        clrf    count
        clrf    temp
        retlw   0x00

;*********************************************************
; LCD ROUTINES .. protocols derived from HD44780 data sheet
; LCDtx4  .. a routine to drive the HC44780 LCD in 4-bit
;            mode via a 3-wire interface.
;
; Data byte must be passed in the 'charac' register
; Data format ... D7 D6 D5 D4 RS x x x
; Registers/PORTs needed :-
;                     w
;                     charac
;                     count
;                     PORTB.CH =     (character\instrucs)
;                     PORTB.CK =     (SIPO clock)
;                     PORTB.EN =     (LCD Enable)
;
;This routine shifts a NIBBLE of Data into the LCD but does so
;using a BYTE count. Data must be in the HIGH NIBBLE of the
;charac register. LOW nibble bits are all zeroes.
;************************************************************
lcdtx4   movlw    0x08
        IFDEF DEBUG          ;Bypass while trouble shooting.
          goto lcdout
        ENDIF

        movwf    count
        bcf      STATUS,C
        bcf      PORTB,CK
        nop                    ;Rest between bit ops.
        bsf      PORTB,CH      ;Initialise the Data port.
rotate   rlf      charac,1      ;Rotate the the Data thru CARRY, MSB
first.
        btfss    STATUS,C      ;Data bit = 1?
         bcf     PORTB,CH      ;No  - send a zero
        nop                    ;Rest between bit ops.
        bsf      PORTB,CK      ;Clock the bit thru
        nop
        nop                    ;Rest between bit ops.
        bcf      PORTB,CK
        decfsz   count,1       ;Stepped down thru 8 bits?
         goto    rotate-1      ;No  - keep clockin'
        nop                    ;Rest between bit-ops.
        bsf      PORTB,EN      ;Enable the LCD and
        nop
        nop
        nop
        nop                    ;transfer the Data.
        bcf      PORTB,EN
        nop
lcdout   bcf      PORTB,CH      ;Leave PORTB in a defined state. All
LOW.
        retlw    0x00          ;Return to calling routine in PAGE #1

;**************************************************************
;NIB_TX takes a Data byte and puts the LS nibble into the HIGH
;nibble of the charac register. High nibble is DATA, low nibble bits
;are all zero. Data byte is passed in the w register.
;NIB_TX checks RS of the LCDflags register to determine CHARACTER or
;COMMAND mode for the LCD
;*****************************************************************
nib_tx  movwf    w2           ;w2 a VIRTUAL w register.. NOT w_
       movlw    b'11110000'  ;Isolate the upper nibble and
       andwf    w2,0         ;retrieve it in w.
       movwf    charac       ;Stash the processed byte in charac
       btfsc    LCDflag,RS   ;RS=0? COMMAND mode?
        bsf     charac,3     ;No - set RS line for CHARACTER mode.
       call     lcdtx4       ;and send it to the LCD.
       IFNDEF DEBUG
        call     DLY160      ;Wait 160 us till the LCD settles
       ENDIF
       swapf    w2,1         ;Invert the H & L nibbles
       movlw    b'11110000'
       andwf    w2,0         ;Isolate the new upper 4 digits
       movwf    charac       ;and store in charac register.
       btfsc    LCDflag,RS   ;RS=0? COMMAND mode?
        bsf     charac,3     ;No  - set RS line for CHARACTER mode.
       call     lcdtx4       ;Send'em to the LCD
       IFNDEF DEBUG
        call     DLY160      ;Wait 160 uS till the LCD settles.
       ENDIF
       retlw    0x00         ;Go back to page #1 calling routine

;****************************************************************
;DLY160 ... a one-loop, 160 usec (2.0MHz xtal) delay routine
;Both LCD delay routines are called from PAGE #1 and return there.
;*****************************************************************
DLY160   movlw    0x0A5        ;0x050 Calculate C1= 4F (d79) for T=160
us)
        movwf    count_11
        decfsz   count_11,1
         goto    $-1
        retlw    0x00

;****************************************************************
;DLY_5 ...  A two-loop, 5-m sec (2.0 MHz xtal) delay routine.
;Both LCD delay routines are called from PAGE #1 and return there.
;****************************************************************
DLY_5    movlw    0x01E         ;0x0F Calculate C2=$0A (d10) for T = 5
msec
        movwf    count_12
        movlw    0x0FF
        movwf    count_11
        decfsz   count_11,1
         goto    $-1
        decfsz   count_12,1
         goto    $-5
        retlw    0x00

;**********************************************************
;Main Programme  .. begin from upper half of Bank #0. Turn
;the interrupts OFF till we're configured.
;**********************************************************
main    bcf      INTCON,GIE   ;Switch off interrupts while we  ...
       BANK_0
       call     init         ;Initialise the ports

;***********************************************************
;Power up and configure the LCD
;***********************************************************
pwr_up   clrf     LCDflag
        bcf      LCDflag,RS  ;Clear RS.. COMMAND mode ENABLED
        IFNDEF DEBUG
         call    DLY_5       ;Wait 15 ms after switch-on
         call    DLY_5
         call    DLY_5
         call    DLY_5
        ENDIF

        movlw    b'00110000' ;Write 0x03 to the LCD three
        movwf    charac      ;times with suitable delays
        call     lcdtx4      ;RS=0 for COMMAND instructions
        IFNDEF DEBUG
         call    DLY_5
        ENDIF

        movlw    b'00110000'
        movwf    charac
        call     lcdtx4
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    b'00110000'
        movwf    charac
        call     lcdtx4
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    b'00100000'  ;4 bit interface
        movwf    charac
        call     lcdtx4
        IFNDEF DEBUG
         call    DLY160
        ENDIF

;***************************************************************
;The following instrucs require 2 only NIBBLE WRITES to the LCD.
;Pass the parameters to the NIB_TX subroutine in w. NIB_TX will
;call the lcd_tx4 subroutine. BEWARE the nest level!!
;***************************************************************
        movlw    b'00101000'    ;Write FUNCTION SET
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    b'00001110'    ;Write ON/OFF
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    b'00000110'   ;write ENT MODE
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    b'00000011'   ;Return Cursor & LCD to home
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

;************************************************************
;Then display a "WAKE UP" message ...
;************************************************************
wakeup   movwf    charac
        IFNDEF DEBUG
         call    DLY_5
        ENDIF

        clrf     LCDflag
        bsf      LCDflag,RS    ;Set RS=1 for CHARACTER mode.
                               ;Enable the 4 bit operating mode.
        movlw    lcd_I         ;Load 'I'
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    lcd_A         ;Load 'A'
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

        movlw    lcd_N         ;Load 'N'
        call     nib_tx
        IFNDEF DEBUG
         call    DLY160
        ENDIF

setint  nop
       BANK_1
       movlw    0x0D
       movwf    OPTION_REG
       BANK_0
       clrf     TMR0
       movlw    b'10011000'      ;Enable the interrupts
       movwf    INTCON
       clrf     flags            ;Initialise the flags

       goto    $                 ;Hold it here
       end

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\02\06@191809 by Ian Hynes

flavicon
face
PICers,

Sorry to be a pain but ...

OK, the only lead I've got, maybe, is the following pin levels
measured on the LCD after startup and 1st, 2nd interrupts. (LOW = 0V,
HIGH = 5V)

LCD PIN    STARTUP     KPD inpt "1"    KPD inpt "D"

EN        LOW         HIGH            HIGH
RS        HIGH        LOW             LOW
D4        LOW         HIGH            HIGH
D5        HIGH        LOW             LOW
D6        HIGH        LOW             LOW
D7        HIGH        HIGH            HIGH

LEDs       ALL OFF     ALL ON          ALL OFF

Hmm ... seems to me EN & RS orta be the same after start up AND after
the ISR : they both call the same LCD routines. Do we have a lead
here? On it .......

Cheers - Ian

PS: Just to reiterate, the programme is LCDTST01, subject of my last
post, pin configs as shown nin that post, KPD is 4x4, decoder is
74C922.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


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