Shop OBEX P1 Docs P2 Docs Learn Events
LCD - Ampire 162AC java class — Parallax Forums

LCD - Ampire 162AC java class

HasanHasan Posts: 10
edited 2004-10-13 17:26 in General Discussion
Hi,
I am using the Ampire 162AC 2x16 LCD display in a project. I am going to have to write a Java class for it. My starting starting point is the abstract classes designed by Peter Verkaik found on yahoo groups site. So my questions are mainly for Peter, I guess.

Peter, what is the difference (in terms of functionality) between the two abstract classes AbstractLCD.java and LcdDevice.java? Why have two classes instead of one? Why not merge the two classes?

Please let me know if someone has already implemented this peripheral and is willing to share the code. Otherwise I'll be happy to implement the class.

Thanks.

- Hasan.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-09-12 15:30
    Hasan,

    They both do the same and are experiment classes. You may consider

    the Display class located here:

    http://groups.yahoo.com/group/javelinstamp/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/display/

    which is more useful as it also defines areas within a display. Those areas

    are of type Display also. I asked myself the following questons:

    What is a LCD? Obviously it is a display.

    What are the basic properties of a display? It has width (i.e. columns) and

    height (i.e rows) and there is a cursor that can be placed anywhere inside

    the display area. There need to be methods for placing the cursor and

    displaying characters.

    I defined an abstract display with properties:

    size is width x height characters

    displaying a character moves the cursor one position right, wrapping to

    next line if necessary. Moving the cursor manually is limited by display

    boundaries. A clearScreen method is defined that writes spaces to all display

    positions.

    The display class has an UartVt100 class that can be used with hyperterminal

    and that serves as an example how to define an extended class.

    Let me know what you think about this setup.



    regards peter
  • HasanHasan Posts: 10
    edited 2004-09-20 09:18
    Hi,
    I looked at the Display class and I like it. It is pretty comprehensive and It does more than what I need so I will simply implement it for AC162. There is one issue I will have to deal with though. This particular lcd has 8 bit parallel interface and it eats up 11 lines of i/o. I didn't have that many lines available so I am using 74hc595 serial to parallel converter. I am still working on an OO class design that will allow both parallel interface and syncronous serial interface.

    It will be a few weeks before I'll have a working display done since I get to work on the project only part time. Thanks for the help. I'll let you know when it is ready.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-09-20 12:19
    Here is a tip:

    define your lcd class as an abstract class that implements the cursorDisplay()

    method using the writeByte() method. See class Vt100 as an example.
    Then write 2 classes that extend your lcd class and that implement the
    writeByte() method. One class for your lcd with a uart interface,
    the other class for your lcd with a spi interfsce (because the 595 is
    a spi chip). You could write a 3rd for the parallel interface.
    In your application you would still use your lcd class (or Display if your
    class does not provide extra functions) as a parameter in a parameterlist.
    For example (uart version):

    UartAC162 myAC162 = new UartAC162(txUart,columns,rows);
    UartVt100 myVt100 = new UartVt100(tx2Uart,columns2,rows2);

    public void testDisplay(Display dp,String text,int x, int y) {
    · dp.cursorSet(x,y);
    · dp.writeString(text);
    }

    static void main() {
    · textDisplay(myAC162,"test line",0,0);
    }

    The above example method works with any display of type Display.
    If you write your application classes to use Display, your application
    can use any display while just changing the display definition, not the
    application code.

    regards peter



    Post Edited (Peter Verkaik) : 9/20/2004 2:05:51 PM GMT
  • HasanHasan Posts: 10
    edited 2004-10-13 14:34
    Hi,
    I finally got back to the project again to finish it. Thanks for the useful suggestions. I am not adding any new functionality so the Display class will do just fine. I have a couple of questions for you.

    Why would I need a Uart interface? Uart is an asyncronous protocol while SPI is a syncronous protocol. This is a fundamental difference. I would have my classes such that I would end up with:

    Spi txSpi = new Spi(...);
    SpiAC162 myAC162 = new SpiAC162(txSpi, columns, rows);
    or
    ParallelLcd txParallel = new ParallelLcd(...);
    ParallelAC162 myAC162 = new ParallelAC162(txParallel, columns, rows);

    My second question is hardware related. How would you connect 74xx595 as an spi device? The datasheet didn't help me there. SPI defines four wires ie, MOSI, MISO, SCK and SS. As I understood it, this is how I would connect 595 with SPI wires.

    MOSI connects to SDI, pin 14 of 595
    SCK would connect to shift clock, pin 11
    Which wire of SPI would connect the latch clock (pin 12)?

    Latch pin of 595 has different timing requirement than SPI timing.

    Thanks

    -Hasan
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-10-13 17:21
    Hasan,
    The javelin uses 2 wires for SPI, clock and data.
    You use the methods shiftIn and shiftOut for that.
    Some devices require additional pins, like flash memory
    that also requires a chip select pin. The data input
    (MOSI) and the data output (MISO) are normally
    tied together (via resistor) and connected to the javelin
    datapin.

    ·· javelin cs_out·· ··
    spi cs_in
    ·· javelin data_io·····+
    spi MOSI
    ······················ ··· +--[noparse][[/noparse] 1k ]---- spi MISO
    ·· javelin clock_out·
    spi clock_in

    You do not need a uart if your interface is spi.
    I defined the abstract Display class with methods
    as the programmer thinks, for cursor movement and
    display characters. I defined an abstract Vt100 class
    because Vt100 is a standard. This Vt100 class extends
    the Display class. Then I defined the UartVt100·which
    extends the Vt100 class for a serial connection
    which is normally used with a PC (hyperterminal).

    However, if you would have a Vt100 compatible
    display that uses a spi interface you would
    create a SpiVt100 class.
    Something like

    package stamp.peripheral.display;
    import stamp.core.*;

    public class SpiVt100 extends Vt100 {

    · private int clockPin; //clock pin
    · private int dataPin; //data pin

    · public SpiVt100(int clockPin, int dataPin, int columns, int rows) {
    ··· super(columns,rows);
    ··· this.clockPin = clockPin;
    ··· this.dataPin = dataPin;
    · }

    · protected void writeByte(int data) {
    ··· shiftOut(dataPin,clockPin,8,CPU.SHIFT_MSB,data);
    · }
    }

    Now you can use your SpiVt100 everywhere a
    Display type is required.
    You would create somewhat identical classes
    for Vt100 compatible displays that are connected
    using a 4bit or 8bit bus HD44780 interface.

    regards peter



    Post Edited (Peter Verkaik) : 10/13/2004 5:34:05 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-10-13 17:26
    Hasan,

    To connect a hc595:

    javelin clock_out
    595 clock_in

    javelin data_out
    ·595 data_in

    Use shiftOut method to write byte to 595:

    shiftOut(dataPin,clockPin,8,CPU.SHIFT_MSB,value)

    You will find a 595 class here:
    http://www.parallax.com/javelin/underdev.asp

    regards peter


    Post Edited (Peter Verkaik) : 10/13/2004 5:32:37 PM GMT
Sign In or Register to comment.