Newsgroup: it.hobby.elettronica.digitale
Titolo: Help Display HD44780

Salve a tutti, sono Ronnie ed ho un problema con il suddetto Display,
lo sto gestendo con un PIC16F84 ed uso il 4-bit mode.
Avrei alcuni dubbi:
-Le altre linee dati (D0-D3) vanno messe a 1 o a 0? (ho trovato schemi
contrastanti)
-Come diventa il processo di inizializzazione senza queste 4 linee dati?
-Come si comporta la linea Enable rispetto il dato?
-Quali sono le tempistiche fra un comando e l'altro(Enable compreso)?
N.B.:Metto una reply a questo messaggio con il codice che sto usando,
qualcuno può indicarmi dove sbaglio?
Grazie anticipatamente a tutti coloro che mi vogliano aiutare.
Ronnie

                PROCESSOR       16F84
                RADIX           DEC
                INCLUDE         "P16F84.INC"
;Suppress MPASM warning message 302:
;"Register in operand not in bank 0.  Ensure that bank bits are correct"
                ERRORLEVEL      -302
                __CONFIG         3FF1H
;LCD Control lines
LCD_RS          equ     2       ;Register Select
LCD_E           equ     3       ;Enable
;LCD data line bus
LCD_DB4         equ     4       ;LCD data line DB4
LCD_DB5         equ     5       ;LCD data line DB5
LCD_DB6         equ     6       ;LCD data line DB6
LCD_DB7         equ     7       ;LCD data line DB7
                ORG     0CH
tmpLcdRegister  res     2
msDelayCounter  res     2
                ;Reset Vector
                ORG     00H
Start
                bsf     STATUS,RP0      ;Swap to register bank 1
                movlw   00011111B       ;Set PORTA lines
                movwf   TRISA
                movlw   11111111B       ;Set PORTB lines
                movwf   TRISB
                bcf     PORTB,LCD_DB4   ;Set as output just the LCD's lines
                bcf     PORTB,LCD_DB5
                bcf     PORTB,LCD_DB6
                bcf     PORTB,LCD_DB7
                bcf     PORTB,LCD_E
                bcf     PORTB,LCD_RS
                bcf     STATUS,RP0      ;Swap to register bank 0
                ;LCD inizialization
                call    LcdInit
                ;Locate LCD cursor on row 0, col 0
                movlw   10H
                call    LcdLocate
                ;Shows "HELLO WORLD" string on LCD
                movlw   'H'
                call    LcdSendData
                movlw   'E'
                call    LcdSendData
                movlw   'L'
                call    LcdSendData
                movlw   'L'
                call    LcdSendData
                movlw   'O'
                call    LcdSendData
                movlw   ' '
                call    LcdSendData
                movlw   'W'
                call    LcdSendData
                movlw   'O'
                call    LcdSendData
                movlw   'R'
                call    LcdSendData
                movlw   'L'
                call    LcdSendData
                movlw   'D'
                call    LcdSendData
                movlw   ' '
                call    LcdSendData
                movlw   '!'
                call    LcdSendData
foreverLoop
                goto    foreverLoop
;**********************************************************************
; Delay subroutine
;
; W = Requested delay time in ms (clock = 4MHz)
;**********************************************************************
msDelay
                movwf   msDelayCounter+1
                clrf    msDelayCounter+0
                ; 1 ms (about) internal loop
msDelayLoop
                nop
                decfsz  msDelayCounter+0,F
                goto    msDelayLoop
                nop
                decfsz  msDelayCounter+1,F
                goto    msDelayLoop
                return
;**********************************************************************
; Init LCD
; This subroutine must be called before each other lcd subroutine
;**********************************************************************
LcdInit
                movlw   30             ;Wait 30 ms
                call    msDelay
                ;****************
                ; Reset sequence
                ;****************
                bcf     PORTB,LCD_RS    ;Set LCD command mode
                ;Send a reset sequence to LCD
                bsf     PORTB,LCD_DB4
                bsf     PORTB,LCD_DB5
                bcf     PORTB,LCD_DB6
                bcf     PORTB,LCD_DB7
                bsf     PORTB,LCD_E     ;Enables LCD
                movlw   5               ;Wait 5 ms
                call    msDelay
                bcf     PORTB,LCD_E     ;Disables LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                bsf     PORTB,LCD_E     ;Enables LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                bcf     PORTB,LCD_E     ;Disables LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                bsf     PORTB,LCD_E     ;Enables E
                movlw   1               ;Wait 1ms
                call    msDelay
                bcf     PORTB,LCD_E     ;Disables E
                movlw   1               ;Wait 1ms
                call    msDelay
                bcf     PORTB,LCD_DB4
                bsf     PORTB,LCD_DB5
                bcf     PORTB,LCD_DB6
                bcf     PORTB,LCD_DB7
                bsf     PORTB,LCD_E     ;Enables LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                bcf     PORTB,LCD_E     ;Disabled LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                ;Set 4 bit data bus length
                movlw   28H;
                call    LcdSendCommand
                ;Entry mode set, increment, no shift
                movlw   06H;
                call    LcdSendCommand
                ;Display ON, Curson ON, Blink OFF
                movlw   0EH
                call    LcdSendCommand
                ;Clear display
                call    LcdClear
                return
;**********************************************************************
; Clear LCD
;**********************************************************************
LcdClear
                ;Clear display
                movlw   01H
                call    LcdSendCommand
                movlw   2               ;Wait 2 ms
                call    msDelay
                ;DD RAM address set 1st digit
                movlw   80H;
                call    LcdSendCommand
                return
;**********************************************************************
; Locate cursor on LCD
; W = D7-D4 row, D3-D0 col
;**********************************************************************
LcdLocate
                movwf   tmpLcdRegister+0
                movlw   80H
                movwf   tmpLcdRegister+1
                movf    tmpLcdRegister+0,W
                andlw   0FH
                iorwf   tmpLcdRegister+1,F
                btfsc   tmpLcdRegister+0,4
                bsf     tmpLcdRegister+1,6
                movf    tmpLcdRegister+1,W
                call    LcdSendCommand
                return
;**********************************************************************
; Send a data to LCD
;**********************************************************************
LcdSendData
                bsf     PORTB,LCD_RS
                call    LcdSendByte
                return
;**********************************************************************
; Send a command to LCD
;**********************************************************************
LcdSendCommand
                bcf     PORTB,LCD_RS
                call    LcdSendByte
                return
;**********************************************************************
; Send a byte to LCD by 4 bit data bus
;**********************************************************************
LcdSendByte
                ;Save value to send
                movwf   tmpLcdRegister
                ;Send highter four bits
                bcf     PORTB,LCD_DB4
                bcf     PORTB,LCD_DB5
                bcf     PORTB,LCD_DB6
                bcf     PORTB,LCD_DB7
                btfsc   tmpLcdRegister,4
                bsf     PORTB,LCD_DB4
                btfsc   tmpLcdRegister,5
                bsf     PORTB,LCD_DB5
                btfsc   tmpLcdRegister,6
                bsf     PORTB,LCD_DB6
                btfsc   tmpLcdRegister,7
                bsf     PORTB,LCD_DB7
                bsf     PORTB,LCD_E     ;Enables LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                bcf     PORTB,LCD_E     ;Disabled LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                ;Send lower four bits
                bcf     PORTB,LCD_DB4
                bcf     PORTB,LCD_DB5
                bcf     PORTB,LCD_DB6
                bcf     PORTB,LCD_DB7
                btfsc   tmpLcdRegister,0
                bsf     PORTB,LCD_DB4
                btfsc   tmpLcdRegister,1
                bsf     PORTB,LCD_DB5
                btfsc   tmpLcdRegister,2
                bsf     PORTB,LCD_DB6
                btfsc   tmpLcdRegister,3
                bsf     PORTB,LCD_DB7
                bsf     PORTB,LCD_E     ;Enables LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                bcf     PORTB,LCD_E     ;Disabled LCD
                movlw   1               ;Wait 1ms
                call    msDelay
                return
                END
;;Grazie
Ronnie