Philip, many 16x1 LCDs works as 8x2, even there are only one line. As you say, you see only 8 black square it's sure you have to change the cursor position after 8 writtings to line2. But "hello" should appear... See the example f84lcd1.jal ( in jal) from the: http://www.geocities.com/vsurducan/pic84lcd.htm Cheers, Vasile On Sat, 16 Jun 2001, Philip Pemberton wrote: > Hi PICLISTers, > I've just found a Samsung KS0066-based (HD44780-compatible) 16x1 LCD in > my junk box and I've been trying all afternoon to make my code work. What am > I doing wrong? I've attached my code to the end of this message (after the > snips). Compile with MPASM. > When the LCD and PIC are powered up, the LCD displays 8 black squares on the > left-hand side of the display. After about half a second, the LCD goes > completely blank. The text that is sent to the LCD ("Hello") never appears. > Any ideas? > > BTW, this code is for a 4-bit interface. See the pin definitions at the top > of LCD-4BIT.INC > > Thanks in advance. > > --8<--- LCD-4BIT.INC > ; LCD routines > ; pin assignment for the 4-bit (6 PIC I/O pins) interface: > ; > ; PIC HD44870 > ; ------------------ > ;PIN FUNCTION PIN FUNCTION > ; 5 Gnd 1 Gnd > ; 14 Vcc 2 Vcc > ; 5 Gnd 3 Contrast > ; 6 B0 11 D4 > ; 7 B1 12 D5 > ; 8 B2 13 D6 > ; 9 B3 14 D7 > ; 10 B4 4 RS D/I_ > ; 5 Gnd 5 R/W_ > ; 11 B5 6 E > > ; Data lines from D0 to D3 > #DEFINE LCD_RS PORTB, 4 > #DEFINE LCD_EN PORTB, 5 > #DEFINE LCD_LINE2 0x40 > > SENDCMD: > BCF LCD_RS ; RS=0 (command) > CALL SEND ; Send the command > CALL SHORTDELAY ; A short delay > RETURN ; Return > > PUTLCD: > BSF LCD_RS ; RS=1 (data) > CALL SEND ; Send the data > CALL SHORTDELAY ; A short delay > RETURN ; Return > > SEND: > MOVWF LCDTEMP2 ; Temporarily store command/data > SWAPF LCDTEMP2 ; Swap nibbles > MOVFW LCDTEMP2 ; Load back into W > ANDLW 0x0F ; Mask off > IORWF PORTB, F ; OR with PORTB > CALL PULSE_E ; Pulse the EN line > > SWAPF LCDTEMP2 ; Second run - lower eight bits > MOVFW LCDTEMP2 ; Load back into W > ANDLW 0x0F ; Mask off > IORWF PORTB, F ; OR with PORTB > CALL PULSE_E > RETURN ; Return > > INITLCD: > MOVLW 0x00 ; W=0 > TRIS PORTB ; PORTB=all outputs > CLRF PORTB ; Clear PORTB > CLRF LCDTEMP0 ; Clear delay counters > CLRF LCDTEMP1 > > CALL LONGDELAY ; Long delay while LCD starts up > > MOVLW 0x33 > CALL SENDCMD ; Send it to the LCD > MOVLW 0x33 > CALL SENDCMD ; Send it to the LCD > MOVLW 0x32 > CALL SENDCMD ; Send it to the LCD > MOVLW 0x44 > CALL SENDCMD ; Send it to the LCD > MOVLW 0x06 > CALL SENDCMD ; Send it to the LCD > MOVLW 0x0C > CALL SENDCMD ; Send it to the LCD > MOVLW 0x01 > CALL SENDCMD ; Send it to the LCD > MOVLW 0x02 > CALL SENDCMD ; Send it to the LCD > > CLRF LCDTEMP0 ; Clear delay counters > CLRF LCDTEMP1 > CALL LONGDELAY > RETURN > > LONGDELAY: > CALL SHORTDELAY ; Long delay for LCD to initialise > DECFSZ LCDTEMP0, F ; Decrement count > GOTO LONGDELAY ; Keep going > RETURN ; Return. > > SHORTDELAY: > DECFSZ LCDTEMP1, F ; Short delay (LCD BUSY) > GOTO SHORTDELAY ; Keep going > RETLW 0 ; Return. > > PULSE_E: > BSF LCD_EN ; EN high > NOP ; 1uS delay > BCF LCD_EN ; EN low > RETLW 0 > > MOVECRSR: ; Move cursor, W=address > ADDLW 0x80 ; Add command to W > CALL SENDCMD ; Send the command > CALL SHORTDELAY ; Short delay (LCD BUSY) > RETURN > --8<--- END OF LCD-4BIT.INC > > --8<--- LCDTEST.ASM > LIST P=16C84 > INCLUDE "P16C84.INC" > __CONFIG _XT_OSC & _PWRTE_OFF & _CP_OFF & _WDT_OFF > > ; Variables > TEMP EQU 0x16 > LCDTEMP0 EQU 0x17 > LCDTEMP1 EQU 0x18 > LCDTEMP2 EQU 0x19 > > ; Code > > ORG 0 ; Reset vector > GOTO INIT > ORG 4 ; Interrupt vector > GOTO INIT > ORG 5 ; Start of code area > > ; Includes > ERRORLEVEL -305 > ERRORLEVEL -302 > INCLUDE "LCD-4BIT.INC" > > ; Main code > > INIT: > MOVLW 0 ; W=0 > TRIS PORTB ; PORTB=all outputs > MAIN: > CALL INITLCD ; Initialise the LCD > MOVLW 'H' > CALL PUTLCD ; Send to LCD > MOVLW 'e' > CALL PUTLCD ; Send to LCD > MOVLW 'l' > CALL PUTLCD ; Send to LCD > MOVLW 'l' > CALL PUTLCD ; Send to LCD > MOVLW 'o' > CALL PUTLCD ; Send to LCD > CRASH: > GOTO CRASH > END > --8<--- END OF LCDTEST.ASM > > -- > Phil. > http://www.philpem.f9.co.uk/ > philpem@bigfoot.com > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.