LCD command -watch the numbers in red how do we choose them?

Discussion in 'Programmer's Corner' started by zeeba, Oct 6, 2010.

  1. zeeba

    Thread Starter New Member

    Sep 26, 2010
    22
    0
    Hi
    I want some help to anderstand this code specially Initialise the LCD [LCD commands] >>watch the numbers in red how do we choose them??

    I tried it on the board but nothing was displayed on the LCD what is the problem??



    ;LCD text demo - 4 bit mode
    ;Nigel Goodwin 2002

    LIST p=16F876A ;tell assembler what chip we are using
    include "P16F876A.inc" ;include the defaults for the chip
    ERRORLEVEL 0, -302 ;suppress bank selection messages
    __config 0x3F11 ;sets the configuration settings (oscillator type etc.)




    cblock 0x20 ;start of general purpose registers
    count ;used in looping routines
    count1 ;used in delay routine
    counta ;used in delay routine
    countb ;used in delay routine
    tmp1 ;temporary storage
    tmp2
    templcd ;temp store for 4 bit mode
    templcd2
    d1
    d2
    endc

    LCD_PORT Equ PORTB
    LCD_TRIS Equ TRISB
    LCD_RS Equ 0x04 ;LCD handshake lines
    LCD_RW Equ 0x06
    LCD_E Equ 0x07

    org 0x0000

    goto Initialise

    Text addwf PCL, f
    retlw 'H'
    retlw 'e'
    retlw 'l'
    retlw 'l'
    retlw 'o'
    retlw 0x00

    Text2 ADDWF PCL, f
    RETLW 'R'
    RETLW 'e'
    RETLW 'a'
    RETLW 'd'
    RETLW 'y'
    RETLW '.'
    RETLW '.'
    RETLW '.'
    RETLW 0x00


    Initialise clrf count
    clrf PORTA
    clrf PORTB

    clrf PORTC


    SetPorts bsf STATUS, RP0 ;select bank 1
    movlw 0x00 ;make all pins outputs
    movwf LCD_TRIS

    MOVWF TRISC

    movlw 0x07
    movwf CMCON ;turn comparators off (make it like a 16F84)
    bcf STATUS, RP0 ;select bank 0

    call Delay100 ;wait for LCD to settle


    call LCD_Init ;setup LCD

    CALL LED
    CALL LED
    CALL LED
    CALL LED

    clrf count ;set counter register to zero
    Message movf count, w ;put counter value in W
    call Text ;get a character from the text table
    xorlw 0x00 ;is it a zero?
    btfsc STATUS, Z
    goto NextMessage
    call LCD_Char
    call Delay250
    incf count, f
    goto Message

    NextMessage call LCD_Line2 ;move to 2nd row, first column

    clrf count ;set counter register to zero
    Message2 movf count, w ;put counter value in W
    call Text2 ;get a character from the text table
    xorlw 0x00 ;is it a zero?
    btfsc STATUS, Z
    goto EndMessage
    call LCD_Char
    incf count, f
    goto Message2

    EndMessage

    Stop goto Stop ;endless loop




    ;Subroutines and text tables

    ;LCD routines

    ;Initialise LCD
    LCD_Init movlw 0x20 ;Set 4 bit mode
    call LCD_Cmd

    movlw 0x28 ;Set display shift
    call LCD_Cmd

    movlw 0x06 ;Set display character mode
    call LCD_Cmd

    movlw 0x0d ;Set display on/off and cursor command
    call LCD_Cmd

    call LCD_Clr ;clear display

    retlw 0x00

    ; command set routine
    LCD_Cmd movwf templcd
    swapf templcd, w ;send upper nibble
    andlw 0x0f ;clear upper 4 bits of W
    movwf LCD_PORT
    bcf PORTC, LCD_RS ;RS line to 0
    call Pulse_e ;Pulse the E line high

    movf templcd, w ;send lower nibble
    andlw 0x0f ;clear upper 4 bits of W
    movwf LCD_PORT
    bcf PORTC, LCD_RS ;RS line to 0
    call Pulse_e ;Pulse the E line high
    call Delay5
    retlw 0x00

    LCD_CharD addlw 0x30
    LCD_Char movwf templcd
    swapf templcd, w ;send upper nibble
    andlw 0x0f ;clear upper 4 bits of W
    movwf LCD_PORT
    bsf PORTC, LCD_RS ;RS line to 1
    call Pulse_e ;Pulse the E line high

    movf templcd, w ;send lower nibble
    andlw 0x0f ;clear upper 4 bits of W
    movwf LCD_PORT
    bsf PORTC, LCD_RS ;RS line to 1
    call Pulse_e ;Pulse the E line high
    call Delay5
    retlw 0x00

    LCD_Line1 movlw 0x80 ;move to 1st row, first column
    call LCD_Cmd
    retlw 0x00

    LCD_Line2 movlw 0xc0 ;move to 2nd row, first column
    call LCD_Cmd
    retlw 0x00

    LCD_Line1W addlw 0x80 ;move to 1st row, column W
    call LCD_Cmd
    retlw 0x00

    LCD_Line2W addlw 0xc0 ;move to 2nd row, column W
    call LCD_Cmd
    retlw 0x00

    LCD_CurOn movlw 0x0d ;Set display on/off and cursor command
    call LCD_Cmd
    retlw 0x00

    LCD_CurOff movlw 0x0c ;Set display on/off and cursor command
    call LCD_Cmd
    retlw 0x00

    LCD_Clr movlw 0x01 ;Clear display
    call LCD_Cmd
    retlw 0x00

    LCD_HEX movwf tmp1
    swapf tmp1, w
    andlw 0x0f
    call HEX_Table
    call LCD_Char
    movf tmp1, w
    andlw 0x0f
    call HEX_Table
    call LCD_Char
    retlw 0x00


    LED BSF PORTB,7
    CALL Delay250
    CALL Delay250
    CALL Delay250
    CALL Delay250
    BCF PORTB,7
    CALL Delay250
    CALL Delay250
    CALL Delay250
    CALL Delay250
    RETLW 0X00
    ;================================================= =====
    Delay250 ;250ms

    movlw 0x4E
    movwf d1
    movlw 0xC4
    movwf d2
    Delay_0
    decfsz d1, f
    goto $+2
    decfsz d2, f
    goto Delay_0

    ;3 cycles
    goto $+1
    nop

    ;4 cycles (including call)
    return



    Delay100
    ;100ms
    movlw 0x1E
    movwf d1
    movlw 0x4F
    movwf d2
    Delay_1
    decfsz d1, f
    goto $+2
    decfsz d2, f
    goto Delay_1

    ;3 cycles
    goto $+1
    nop

    ;4 cycles (including call)
    return


    Delay5
    ;5ms
    movlw 0xE6
    movwf d1
    movlw 0x04
    movwf d2
    Delay_2
    decfsz d1, f
    goto $+2
    decfsz d2, f
    goto Delay_2

    ;3 cycles
    goto $+1
    nop

    ;4 cycles (including call)
    return







    Pulse_e bsf PORTC, LCD_E
    call Delay5
    bcf PORTC, LCD_E
    retlw 0x00

    ;end of LCD routines

    HEX_Table ADDWF PCL , f
    RETLW 0x30
    RETLW 0x31
    RETLW 0x32
    RETLW 0x33
    RETLW 0x34
    RETLW 0x35
    RETLW 0x36
    RETLW 0x37
    RETLW 0x38
    RETLW 0x39
    RETLW 0x41
    RETLW 0x42
    RETLW 0x43
    RETLW 0x44
    RETLW 0x45
    RETLW 0x46




    end



     
  2. neonstrobe

    Member

    May 15, 2009
    13
    1
    Hi zeba
    I do not know the system you are having trouble with, but in general the numbers you highlight appear to be control commands for the LCD screen you have. Therefore, to specify what these should be you should have the data sheet for the LCD screen, since that is where they will come from. They aren't "to choose": they are for a particular purpose in setting the LCD up; they aren't "screen data".

    THe display data appears to be in a separate routine LCD_cmd. That is what I think you need to write to the display. Like all programming for actual hardware, you need to know the details of the chip you are programming, hardware and hardware operation.

    Hope this helps.
     
  3. zeeba

    Thread Starter New Member

    Sep 26, 2010
    22
    0
    hi.
    thanx 4 replying

    I have the data sheet for the LCD and the PIC, but I didn't understand why to write 20H I mean why is is 20 not 2 or any other number??
    I know it's from the data sheet but again I didn't get it I need some explain
     
Loading...