A83: Re: Contrast Settings Question


[Prev][Next][Index][Thread]

A83: Re: Contrast Settings Question




Hehe, I should release my tutorials quicker...here you go, here's the LCD
communcation tutorial.  The contrast part is a little way down.

Introduction.
This tutorial will probably be rather long and heavy-going, but stick with
me.  Also, this tutorial is heavily based on Ian Graf's tutorial that he
actually wrote for these tutorials.  You can look at his tutorial here.

The Ti-83 uses a LCD driver to communicate with the LCD screen, instead of
memory mapping like the Ti-85.  Direct communication is possible through
two ports, 10h and 11h.  These are equated to lcdinstport (command port)
and lcddataport (data port) respectively.  Writing to 10h sends the various
commands (discussed later) to the LCD driver, whereas the 11h port is for
actual data.  Before ever trying to communicate with the LCD driver, you
must disable interrupts, using the DI command, and using EI (Enable
Interrupts), when you are done.  Whenever you read/write from these ports
you must create a small delay.  The best way to do this is through this
routine:

lcd_busy:

push af
	inc  hl
	dec  hl
	pop  af
	ret

This provides a sufficient delay, and doesn’t screw any registers up
permanently.  With this in mind, perhaps you can look back on the Changing
Contrast tutorial, and understand the code a lot better.  Ian taught me
something new, and a lot more useful about the contrast — where the current
contrast is!

Current Contrast.

The current contrast is at 8008h in the RAM.  To use this number, you first
have to add 1Fh (31), then OR it with 0C0h (192) to get a number between
0D8h (216) and 0FFh (255).  So to get the current contrast and increment
it:

ld   a,(8008h)

add  a,18h

inc  a		
or   0C0h
call lcd_busy 	; See above.
out  (lcdinstport),a


Note:  There is no error checking!  This routine doesn't check whether
you've exceeded 63 (3Fh).  Ok, the simple stuff is over and done with…now
to the more complicated stuff!  Note:  Please let it be known that this
tutorial is nothing compared to Ian's…please read his too.  I'm writing
this for three reasons:  I want all tutorials to be written by me in the
main section, I learn by writing, and I can fit into and relate to other
parts better if I do it.  His tutorial has MUCH more code, and goes into
things more in-depth than I have the patience for (plus, I have 4 more
tutorials I want to write this evening)!!

Reading/Writing to the LCD.

Ok, this is complicated.  Not only is reading and writing using a different
coordinate system whereby the x and y are swapped, but the numbers also
start at 80h and 20h.  Now, on top of this there are two modes of
reading/writing.  X-increment, and Y-increment.  These modes are aptly
named, if the X-increment is set, the X-position is incremented after each
read/write.  Same with Y-increment on the Y-position.  Hopefully, you're
not completely confused yet!

Setting Increment Modes.

To set the X-increment mode:

ld   a,05h

call lcd_busy	; See above.
out  (lcdinstport),a


Note that the x position points to the row.

To set the Y-increment mode:

ld   a,07h

call lcd_busy	; See above.
out  (lcdinstport),a


Note that the y position points to the column.

Note:  The Ti expects everything to be in X-increment mode, so remember to
return it if you change it!

After the reading and writing modes are set, and a coordinate is specified
you are ready to read and write.  ONE more complication though, if you want
to read, you must make a dummy read.  Therefore, a code snippet to read the
first byte would look like:

out (lcdinstport),a

call lcd_busy		; Dummy read.
in a,(lcddataport)
call lcd_busy		; Read!

To write, it's a lot easier:

ld a,10101010b

call lcd_busy		; Write this.
out (lcddataport, a)


Conclusion.

For routines to read/write the entire screen, look at Ian's tutorial, since
reading/writing it all it a little more complicated. I have covered all the
important parts.

 Related Topics.

All tutorials Copyright (c) James Matthews 1998, unless specified.