Writing to 2nd line on LCD for PIC18F4620

Code given in textbook is something like this:

WR_INS
bcf RS ;clear Register Status bit
movwf temp_lcd ;store instruction
andlw 0xF0 ;mask 4 MSB
movwf LATD ;send 4 MSB
bsf E ;pulse enable high
call delay5ms
swapf temp_lcd, 0 ;swap nibbles (result into WREG)
andlw 0xF0 ;mask 4 LSB
bcf E
movwf LATD ;send 4 LSB
bsf E ;pulse enable high
nop
bcf E
call delay5ms ;allow time for change
return

But this does not allow for lines to be switched.
After some investigation, the following working code was written.

WR_INS
bcf RS ;clear Register Status bit
movwf temp_lcd ;store instruction
andlw 0xF0 ;mask 4 MSB
movwf LATD ;send 4 MSB
bsf E ;pulse enable high
nop
bcf E
call delay5ms
swapf temp_lcd, 0 ;swap nibbles (result into WREG)
andlw 0xF0 ;mask 4 LSB
bcf E
movwf LATD ;send 4 LSB
bsf E ;pulse enable high
nop
bcf E
call delay5ms ;allow time for change
return

tl;dr: adding a nop and bcf fixes after sending the MSB fixes the problem.

EDIT: note that I also added a delay after the nop and bcf.

Views: 243

Comment

You need to be a member of Personal Mechatronics Lab to add comments!

Join Personal Mechatronics Lab

© 2024   Created by PML.   Powered by

Badges  |  Report an Issue  |  Terms of Service