Thanks for this Jinx, I will try it out. Is there anything I need to change as far as timings are concerned, I am using a 4mhz oscillator. Cheers Stewart > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of Jinx > Sent: 28 June 2006 12:10 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] LCD Interface HD44780 > > Hi Stewart, nothing as sad as a blank screen is there ? > > I had some difficulty reading your style of code. You would > be better to use the bit definitions as in the .inc file. eg, without > looking it up, I have no idea what OPTION_REG,5 is > > Included here is code I use often for 4-bit LCDs. Bear in mind > this is an example for the 18F, so there are no bank changes, > and latd is what would be portd on a 16F > > Data is displayed by 'call write_d', a command by 'call write_c' > > Interface via macros (makes display code a lot simpler) > > clrscrn macro ;clear LCD > movlw 0x01 > call write_c > endm > > mov macro litval,file > movlw litval > movwf file > endm > > movfw macro litval > movf litval,w > endm > > lcd_pos macro litval ;set print address > movlw litval-1 > call address > endm > > disp macro litval ;display character > movlw litval > call write_d > endm > > eg > > lcd_pos ln1+d14 > disp "s" > > ========== > > #define rs porte,0 ;LCD RS > #define rw porte,1 ;LCD R/W > #define en porte,2 ;LCD Enable > > ;PortD 0-3 - LCD data > > #define busy portd,3 ;LCD Busy flag > > usec macro ;1us delay > movff temp,temp > movff temp,temp > movff temp,temp > movff temp,temp > movff temp,temp > endm > > ;================================================ > ; Initialise LCD screen > ;================================================ > > lcd_init bcf rw > usec > bcf rs > usec > > call write30 > call msdelay ;delay > 4.1ms > call msdelay > call msdelay > call msdelay > call msdelay > > call write30 > call msdelay ;delay > 100us > > call write30 > call msdelay ;delay > 100us > > ;LCD settings > > movlw b'00100000' ; > call write_c > movlw b'00001000' > call write_c > movlw b'00001100' > call write_c > movlw b'00000110' > call write_c > return > > write30 movfw portd > andlw b'00001111' > addlw b'00110000' > movwf latd > usec > bsf en > usec > bcf en > usec > return > > ;=============================================== > ; LCD commands > ;================================================ > > line1 movlw 0x00 ;line 1, column 0 > call address > return > > line2 movlw 0x40 ;line 2, column 0 > call address > return > > address addlw 0x80 ;set high bit of address command > call write_c > return > > write_c bcf rs ;write command > bra d_out > > write_d bsf rs ;write data > > ;send 2 x 4-bits > > d_out movwf temp ;save data in W, and split > swapf temp > movfw portd ;read port > andlw b'11110000' ;clear LSN > movwf shadowd > movfw temp ;add MSN to bshad > andlw b'00001111' > addwf shadowd,w > movwf latd ;write to port > usec > bcf rw > usec > bsf en > usec > bcf en > > movfw portd ;read port > andlw b'11110000' ;clear LSN > movwf shadowd > swapf temp,w ;add temp LSN to bshad > andlw b'00001111' > addwf shadowd,w > movwf latd ;write to port > usec > bcf rw > usec > bsf en > usec > bcf en > > usec > bsf rw ;set LCD RW for Read > usec > bcf rs > > mov b'00001000',trisd ;Busy as i/p > bsf en > rdbusy btfsc busy ;loop until Busy Flag clear > bra rdbusy > bcf en > usec > bcf rw > mov b'00000000',trisd > > return > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist