This is a multi-part message in MIME format. ------=_NextPart_000_00AF_01C41707.9693E020 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > I never fully implemented all the functions and never really > documented my old code. It is harder to go back to it than > it would be to start over That's so true so often. A prototype I'm working on came back from the customer at the w/e for some minor alterations. Even though I thought the code was fairly well commented at the time, it could have been a lot fuller and I took longer than expected to get up to speed, yet the programme is barely a month old Attached is some 4-bit LCD code from that prototype Note that - It's for the 18F452, so there are no banking instructions and WREG is accessed directly. 877 code is very similar, just needs those things added Busy Flag routine is called before proceeding with any writing. This is probably the most efficient way, time-wise - no waiting The status of Porta.4 needs to be preserved. The nybble writing section would be a lot simpler otherwise Be aware that Enable may be high outside the LCD routine. This may or may not be important depending on what is going on with Porta lines. You could re-write the busy routine to clear Enable on exit, whatever the status of Busy I did some tidying up and re-arranging on-the-fly before attaching it. It looks OK, but if there are errors hopefully you'll work those out and see the methodology -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body ------=_NextPart_000_00AF_01C41707.9693E020 Content-Type: text/plain; name="4bit_lcd.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="4bit_lcd.txt" ;=============================================== ; 16x2 LCD, 4-bit PIC18F452 ;================================================ ; Variables ; bits - bflag rw rs en busy ; bytes - temp bshad #define rs porte,0 ;LCD RS - 0=command, 1=data #define rw porte,1 ;LCD R/W #define en porte,2 ;LCD Enable clrf porta movlw b'00010000' ; 1 toggle switch (input) ; 0000 LCD 4-bit data (output) movwf trisa clrf porte movlw b'00000000' ; 0 RS ; 0 R/W ; 0 Enable movwf trise readbusy bsf rw ;set LCD RW for Read nop nop bcf rs movlw b'00011000' ;make d7 (porta.3) an input movwf trisa bsf en bsf bflag ;Busy status btfsc busy ;skip if Busy Flag clear return ;still busy, exit with Busy status=1 bcf bflag ;not busy, previous command finished bcf en nop nop bcf rw movlw b'00010000' ;d7 as output again movwf trisa return ;exit with Busy status=0 ;================================================ line1 addlw b'10000000' ;line 1, column W call write_c return line2 addlw b'11000000' ;line 2, column W call write_c return write_c bcf rs ;write command in W bra d_out write_d bsf rs ;write data in W ;write two nybbles to porta, hold status of porta.4 d_out bcf rw movwf temp ;store 8-bit value movf porta,w ;read port andlw 0xf0 ;clear LSN movwf bshad ;0000 xxxx movf temp,w ;add temp MSN to bshad andlw 0xf0 swapf wreg,w ;add into low nybble addwf bshad,w movwf porta ;write to port bsf en nop nop bcf en movf porta,w ;read port andlw 0xf0 ;clear LSN movwf bshad ;0000 xxxx swapf temp,w ;add LSN to bshad andlw 0xf0 swapf wreg,w ;add into low nybble addwf bshad,w movwf porta ;write to port bsf en nop nop bcf en return -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body ------=_NextPart_000_00AF_01C41707.9693E020--