----- Original Message ----- From: "BENEDICIC SAMO" To: Sent: Tuesday, May 01, 2001 6:23 AM Subject: [PIC] yet another LCD problem > Hi! > > I have a bit of a problem with reading BUSY flag from LCD when it is in 4 > bit mode, The following routine works perfect in 8 bit mode, but fails in 4 > bit. If I replace BUSY_WAIT routine with fixed delay, it works fine. Are > there any diferences in reading BUSY flag when LCD is set for 4 bit mode? > > > ;* ************************************************************************** > *** > > LCD_BUSY > BANK1 > movlw h'FF' > movwf LCD_DATA_TRIS ;LCD_DATA all inputs > BANK0 > ; > bcf LCD_CTRL, RS ;we read BUSY flag > bsf LCD_CTRL, RW ;we will READ from LCD > bsf LCD_CTRL, E ;E high > movf LCD_DATA, W ;move data to W > bcf LCD_CTRL, E ;E low > andlw b'10000000' ;0=ready, 1=BUSY > btfss STATUS, Z ;=BUSY? > goto LCD_BUSY ;yes, wait > > NOT_BUSY ;no, go back > bcf LCD_CTRL, RW > BANK1 > clrf LCD_DATA_TRIS ;make PORTB outputs > BANK0 > return > At first glance, it looks like you are not reading both nibbles. You have to clock the enable line twice (once for each nibble in the reply). Here is some code that I use (I didn't write this, but it does seem to work). LCD_BF bcf LCD_RS ;This is a DATA operation. bsf LCD_RW ;This is a READ command. bsf STATUS, RP0 ;Select Bank 1. bsf TRISB & 0x07F, 4 ;Make ports input bsf TRISB & 0x07F, 5 bsf TRISB & 0x07F, 6 bsf TRISB & 0x07F, 7 bcf STATUS, RP0 ; Read in the upper nibble and save it bsf LCD_EN ;Clock out the RS and RW bits. movf LCD_PORT, w ;Get, andlw b'11110000' ; mask, and movwf TEMP0 ; store the upper nybble into a temp area bcf LCD_EN ;Bring enable pin low after getting data ;Read in the lower nibble and combine with upper nibble bsf LCD_EN ;Clock in the lower nybble movf LCD_PORT, w ;Get and andlw b'11110000' ; mask the lower nybble bcf LCD_EN swapf TEMP0, f ;Flip the temp area around backwards and iorwf TEMP0, f ; OR in the lower nybble to the upper half of temp swapf TEMP0, w ;Repair and load the byte into w. (w now contains the full byte) return ;Done -- return. Hope this helps. > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu