mig29fulcrum
Junior Member level 1
Hi...
I've written following code to drive an LCD in 4-bit mode using busy flag.When i simulate my hex on Proteus,i should see "xxxxxxx"but i have " xwxwxw(A'x'=0x78 and A'w'=0x77).I also tested my code for "4444444" but i got " 434343"(A'4'=0x34 and A'3'=0x33).As you see higher nibble latches twice alternately and then cursor shifts right and latching lower nibble does not affects on the LCD.On the other hand when i increase clock frequency i get "4 4 4"or "x x x"(one shift to left alternately).
I also got "[HD44780]Attempted to write after reading a single nibble" warning.
I'll appreciate if you help me with this problem.
tnx...
I've corrected my code as you mentioned (change PORT to LAT and attached my LCD to PORTD)but result is the same.:sad:
I also got "[HD44780]Attempted to write after reading a single nibble" warning again.:sad:
I'm completely confused.
I've written following code to drive an LCD in 4-bit mode using busy flag.When i simulate my hex on Proteus,i should see "xxxxxxx"but i have " xwxwxw(A'x'=0x78 and A'w'=0x77).I also tested my code for "4444444" but i got " 434343"(A'4'=0x34 and A'3'=0x33).As you see higher nibble latches twice alternately and then cursor shifts right and latching lower nibble does not affects on the LCD.On the other hand when i increase clock frequency i get "4 4 4"or "x x x"(one shift to left alternately).
I also got "[HD44780]Attempted to write after reading a single nibble" warning.
I'll appreciate if you help me with this problem.
tnx...
Code:
LIST P=PIC18F4550
#INCLUDE P18F4550.INC
CONFIG FOSC=INTOSC_EC
CONFIG WDT=OFF
LCD EQU LATD
RS EQU RD0
RW EQU RD1
EN EQU RD2
BUFFER EQU 0XAA
;-------------main program------------
ORG 0H
MOVLW 0X42
MOVWF OSCCON
RCALL LCD_INIT
RCALL MYDATA
BRA $
;------------LCD initialization-------
LCD_INIT
CLRF TRISD
BCF LCD,EN
BCF LCD,RS
BCF LCD,RW
RCALL LONG_DELAY ;Power-up delay
MOVLW 0X28 ;4-bit/5*7
RCALL COMMAND_ISSUE ;command send
RCALL BUSY ;check for busy flag
MOVLW 0X0F ;LCD on/cursor blinking
RCALL COMMAND_ISSUE ;send command
RCALL BUSY ;check for busy flag
MOVLW 0X06 ;increment cursor
RCALL COMMAND_ISSUE
RCALL BUSY
MOVLW 0X84 ;1st line/loc=4
RCALL COMMAND_ISSUE
RCALL BUSY ;check for busy flag
RETURN
;-----------command issue--------------
COMMAND_ISSUE
MOVWF BUFFER ;store command into a file reg
ANDLW 0XF0 ;mask lower nibble of command
MOVWF LCD ;move higher nibble into LATB
BCF LCD,RS ;select command reg
BCF LCD,RW ;select write mode
BSF LCD,EN
NOP
BCF LCD,EN ;H-to-L for latch
MOVF BUFFER,W
ANDLW 0X0F ;mask lower nibble of command
SWAPF WREG
MOVWF LCD ;move lower nibble into LATB
BSF LCD,EN
NOP
BCF LCD,EN ;H-to-L enable pulse
RETURN
;------------idata-----------
MYDATA
MOVLW A'z' ;move A'x' into working register
RCALL DATA_ISSUE ;send data
RCALL BUSY ;check for busy flag
MOVLW A'x'
RCALL DATA_ISSUE
RCALL BUSY
MOVLW A'x'
RCALL DATA_ISSUE
RCALL BUSY
MOVLW A'x'
RCALL DATA_ISSUE
RCALL BUSY
MOVLW A'x'
RCALL DATA_ISSUE
RCALL BUSY
MOVLW A'x'
RCALL DATA_ISSUE
RCALL BUSY
MOVLW A'x'
RCALL DATA_ISSUE
RETURN
;------------data issue-----------
DATA_ISSUE
MOVWF BUFFER ;store data into a file reg
ANDLW 0XF0 ;mask lower nibble
MOVWF LCD ;move higher nibble into LATB
BSF LCD,RS ;select data reg
BCF LCD,RW ;select write mode
BSF LCD,EN
NOP
BCF LCD,EN ;H-to-L enable pulse(in this line first character send as A' ')
MOVF BUFFER,W
ANDLW 0X0F ;mask higher nibble
SWAPF WREG
MOVWF LCD
BSF LCD,RS
BCF LCD,RW
BSF LCD,EN
NOP
BCF LCD,EN ;H-to-L enable pulse
RETURN
;-------------busy flag checking----------
BUSY
BCF LCD,RS ;select command reg
BSF LCD,RW ;select read mode
MOVLW 0XF0 ;make higher nibble of PORTB input
MOVWF TRISD
CHECK ;busy flag checking
BSF LCD,EN
NOP
BCF LCD,EN ;enable LCD
BTFSC PORTD,7 ;test for RB,7(busy flag)skip if clean
BRA CHECK
CLRF TRISD ;make PORTB output
RETURN
;------------------(50msec)---------
LONG_DELAY
MOVLW 0X3D
MOVWF TMR0L
RCALL GENERAL_DELAY
RETURN
;------------------(1msec)------------
JIFFY
MOVLW 0XFC
MOVWF TMR0L
RCALL GENERAL_DELAY
RETURN
;------------general delay--------
GENERAL_DELAY
MOVLW B'01000111'
MOVWF T0CON
BCF INTCON,TMR0IF
BSF T0CON,TMR0ON
COUNT
BTFSS INTCON,TMR0IF
BRA COUNT
BCF T0CON,TMR0ON
RETURN
END
I also got "[HD44780]Attempted to write after reading a single nibble" warning again.:sad:
I'm completely confused.
Last edited: