LCD 4-Bit communication using PIC16F84A

Discussion in 'Programmer's Corner' started by VaCrow, Mar 11, 2011.

  1. VaCrow

    Thread Starter New Member

    Mar 11, 2011
    1
    0
    I am currently working on a small project using a PIC16F84A. I need to set up the 4-bit communication with the LCD but have not been able to get it to function. I was able to set up the 8-bit communication but the 4-bit still eludes me. At this point I am only trying to get the LCD to display a "T".

    I have the following code, could someone tell me what I am doing wrong.

    BCF STATUS,RP0
    CLRF PORTA
    CLRF PORTB
    BSF STATUS,RP0
    MOVLW 0X00
    MOVWF TRISA
    MOVLW 0X0F
    MOVWF TRISB
    BCF STATUS,RP0

    CALL DELAY_20M
    CALL DELAY_20M
    CALL DELAY_20M
    CALL DELAY_20M
    CALL DELAY_20M

    ORG 0X0200

    BCF PORTA,RA0
    CALL LCD_INIT_4_BIT
    BSF PORTA,RA0
    CLRW
    MOVWF TEMP
    DISPLAY
    MOVF TEMP,W
    INCF TEMP,F
    CALL TEST
    CALL LCD_4BIT_CONV
    IORLW 0X00
    BTFSC STATUS,Z
    GOTO STOP
    CALL TOGGLE_E
    CALL DELAY_20M
    GOTO DISPLAY
    STOP GOTO $

    ;SUBROUTINES

    LCD_INIT_4_BIT
    BCF PORTA,RA0
    MOVLW 0X20
    CALL LCD_4BIT_CONV
    MOVLW 0X20
    CALL LCD_4BIT_CONV
    MOVLW 0X20
    CALL LCD_4BIT_CONV
    MOVLW 0X28
    CALL LCD_4BIT_CONV
    MOVLW 0X0C
    CALL LCD_4BIT_CONV
    MOVLW 0X01
    CALL LCD_4BIT_CONV
    MOVLW 0X06
    CALL LCD_4BIT_CONV
    MOVLW 0X02
    CALL LCD_4BIT_CONV
    RETURN

    LCD_4BIT_CONV

    MOVWF TEMP2
    SWAPF TEMP2,W
    ANDLW 0X0F
    MOVWF PORTB
    BCF PORTA,RA0
    CALL TOGGLE_E
    CALL DELAY_20M
    MOVF TEMP2,W
    ANDLW 0X0F
    MOVWF PORTB
    BCF PORTA,RA0
    CALL TOGGLE_E
    CALL DELAY_20M
    BSF PORTA,RA0
    RETURN

    TOGGLE_E
    BSF PORTA,RA1
    NOP
    NOP
    NOP
    BCF PORTA,RA1
    RETURN

    DELAY_20M
    MOVLW 0X03
    MOVF DVAR
    P151
    MOVLW 0XF3
    MOVWF DVAR1
    P152
    MOVLW 0X01
    MOVWF DVAR2
    P153
    DECF DVAR2,F
    BTFSS STATUS,Z
    GOTO P153
    DECF DVAR1,F
    BTFSS STATUS,Z
    GOTO P152
    DECF DVAR,F
    BTFSS STATUS,Z
    GOTO P151
    RETURN

    TEST
    ADDWF PCL,F
    RETLW "T"
    RETLW 0X00

    END

    I probably do not need to say this but I am kind of new to microcontrollers.

    Thanks
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Have you tried debugging in MPLAB SIM? Also your code is free for comments. Very hard for other people to help. Commenting will also help you in the coding process.
     
Loading...