Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/24/02 05:21
Read: times


 
#21115 - RE: help lcd initialisation code
there are a few things that concern me.

let's start with the code:

First of all, we'll assume, for now, and since the oscillator frequency is not known, that your timing code is correct. That's not really critical anyway, so long as the minimum is met in each case.

org 0000h
ajmp 0100h

org 0100h
mov b,#14h
again1: mov a,#0ffh; 15ms delay
again: nop
nop
dec a
jnz again
djnz b,again1

setb p3.0 ;enable
clr p3.1 ; write
clr p3.2; command register
mov a,#30h ;command word
mov p1,a
clr p3.0

IF I WERE YOU, I'd use direct-bytewide (or nibble-wide) output to the control port, and only use the bitwise I/O to pulse the 'E' signal. RS and nWR can be set directly with a specific nibble code and that can be written to the port. In the default, and, in general when the LCD interface is inactive, your control bits (E, RS, nWR) should all be at zero.

Use a mode nibble that you write to the port prior to each data or command transfer. Then raise and subsequently lower 'E' and then AND the negative of your all-zero control nibble to the port. That should be done as a complete operation, not piecewise.

mov b,#05h ;4.1 ms delay
again3: mov a,#0ffh
again2: nop
nop
dec a
jnz again2
djnz b,again3

setb p3.0
clr p3.1
clr p3.2
mov a,#30h; command word
mov p1,a
clr p3.0
mov a,#2fh ; 100microseconds delay

The delay here should be 15 ms. and the command should be 38, IIRC.

again4: nop
dec a
jnz again4
setb p3.0
clr p3.1
clr p3.2
mov a,#30h ; command word
mov p1,a
clr p3.0
mov a,#2fh ; 100microseconds delay

the delay here should be 15 ms again, and the command should be 0x38,IIRC

again5: nop
dec a
jnz again5

setb p3.0
clr p3.1
clr p3.2
mov a,#30h ; 8 data lines & 1 line & character font 5x7 dots

That's not the correct command for this step.

mov p1,a
clr p3.0
lcall wait_lcd

and you can't, yet, wait for the LCD status yet either. You must first set the correct input parameters. Try a 6 ...

setb p3.0
clr p3.2
mov a,#08h ;
mov p1,a
clr p3.0
lcall wait_lcd

I'm not going to comment on this code, since I'm confused about which signal is which.

remember always to set nWR and RS BEFORE you toggle 'E' and you'll be fine.

setb p3.0
clr p3.2
mov a,#01h
mov p1,a
clr p3.0

lcall wait_lcd

setb p3.0
clr p3.2
mov a,#06h
mov p1,a
clr p3.0
lcall wait_lcd

setb p3.0
clr p3.2
mov a,#0fh
mov p1,a
clr p3.0
lcall wait_lcd

There's some question in my mind about whether it makes any difference in which order you send these commands, but I use

38 followed by a 20 ms delay
38 followed by a 20 ms delay
06 followed by a 20 ms delay

01 and wait for ready status
0F and wait for ready status
80 and wait for ready status

that should leave the cursor at the begining of the top line. The lengthy delays save on effort and, since they're only used at power-on, the time isn't missed. I use 20 ms because I have a regular interrupt at that rate.

dis: setb p3.0
setb p3.2
mov a ,#'7'
mov p1,a
clr p3.0
lcall wait_lcd
ajmp dis



wait_lcd:
mov a,#2fh ; 100microseconds delay
again7:
nop
dec a
jnz again7
ret
end



List of 7 messages in thread
TopicAuthorDate
help lcd initialisation code            01/01/70 00:00      
RE: help lcd initialisation code            01/01/70 00:00      
RE: help lcd initialisation code            01/01/70 00:00      
RE: help lcd initialisation code            01/01/70 00:00      
RE: help lcd initialisation code            01/01/70 00:00      
RE: help lcd initialisation code            01/01/70 00:00      
RE: help lcd initialisation code            01/01/70 00:00      

Back to Subject List