Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.

Dependents:   Mbell

Files at this revision

API Documentation at this revision

Comitter:
hlipka
Date:
Tue Jan 04 22:10:41 2011 +0000
Parent:
5:3ff30ca33efc
Child:
7:b472970bd8f6
Commit message:
added initial driver for SED1335 based displays (text mode only, no fancy stuff, 320x240 pixels)

Changed in this revision

sed1335text.cpp Show annotated file Show diff for this revision Revisions of this file
sed1335text.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sed1335text.cpp	Tue Jan 04 22:10:41 2011 +0000
@@ -0,0 +1,197 @@
+/*
+ * mbed LCDWindow library
+* Copyright (c) 2010 Hendrik Lipka
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
+#include "sed1335text.h"
+
+#include "BusOut.h"
+#include "DigitalOut.h"
+#include "wait_api.h"
+
+void SED1335TextLCD::writeText(const unsigned int column, const unsigned int row, const char text[]) {
+    int i=0;
+    
+    int pos=row*getColumns()+column;
+    
+    sendCmd(0x46); // set cursor addr
+    sendData(pos&0xff); 
+    sendData((pos&0xff00)>>8);
+    
+    sendCmd(0x42);
+    while (text[i]!=0) {
+        sendData(text[i]);
+        i++;
+    }
+}
+
+void SED1335TextLCD::clear() {
+    _guard->take();
+    
+    ::printf("start clear\n");
+    // first block    
+    sendCmd(0x46); // set cursor addr
+    sendData(0x00); // start of RAM
+    sendData(0x00);
+    wait_ms(1);
+    
+    sendCmd(0x42); // write to memory
+    for (int i=0;i<40*30;i++)
+        sendData(0x20);    // send space
+    wait_ms(1);
+    
+    // second block
+    sendCmd(0x46); // set cursor addr
+    sendData(0x00); // start of RAM
+    sendData(0x10);
+    wait_ms(1);
+    
+    sendCmd(0x42); // write to memory
+    for (int i=0;i<40*30*8;i++)
+        sendData(0x00);    // send space
+    wait_ms(1);
+
+    // third block
+    sendCmd(0x46); // set cursor addr
+    sendData(0x00); // start of RAM
+    sendData(0x08);
+    wait_ms(1);
+    
+    sendCmd(0x42); // write to memory
+    for (int i=0;i<40*30;i++)
+        sendData(0x00);    // send space
+    wait_ms(1);
+
+    sendCmd(0x46); // set cursor addr
+    sendData(0x00); // start of RAM
+    sendData(0x00);
+    
+    ::printf("end clear\n");
+    _guard->release();
+}
+
+
+void SED1335TextLCD::character(int column, int row, int c){
+    _guard->take();
+    _guard->release();
+}
+
+SED1335TextLCD::SED1335TextLCD
+(const unsigned int columns, const unsigned int rows, BusOut *data, const PinName read, const PinName write, const PinName cs, const PinName a0, const PinName reset)
+        :TextLCDBase(columns, rows) {
+    _data=data;
+    _rd=new DigitalOut(read);
+    _wr=new DigitalOut(write);
+    _a0=new DigitalOut(a0);
+    _cs=new DigitalOut(cs);
+    _reset=new DigitalOut(reset);
+    wait_ms(10);
+}
+
+void SED1335TextLCD::init() {
+    ::printf("reset");
+    _reset->write(0);
+    wait_ms(2);
+    _reset->write(1);
+    wait_ms(10);
+    ::printf(" finished\n");
+    
+    sendCmd(0x40); // SYSTEM SET
+    sendData(0x30); // p1 set cg rom
+    sendData(0x87); // p2 
+    sendData(0x7);  // p3 
+    sendData(0x27); // p4 
+    sendData(0x2f); // p5 
+    sendData(0xef); // p6 
+    sendData(0x28); // p7 
+    sendData(0x0);  // p8 
+    wait_ms(1);
+
+    sendCmd(0x44); // SCROLL
+    sendData(0x00); // first block at 0
+    sendData(0x00);
+    sendData(0xf0); // 240 lines
+    sendData(0x00); // second block at 0x1000
+    sendData(0x10);
+    sendData(0xf0); // 240 lines
+    sendData(0x00); // third block at 0x800
+    sendData(0x08);
+    wait_ms(1);
+    
+    sendCmd(0x5a); // HDOT SCR
+    sendData(0x0);
+        
+
+    sendCmd(0x5b); // OVLAY
+    sendData(0x01); // 2 layers, text, x-or
+    wait_ms(1);
+
+    sendCmd(0x59); // DISP on
+    sendData(0x54); // all layers on, cursor off
+//    sendData(0x56); // all layers on, cursor flashing
+    wait_ms(1);
+    
+    clear();
+    
+    sendCmd(0x5d); // CSR FORM
+    sendData(0x04); // 8 pixels wide
+    sendData(0x86); // 2 pixel high, block cursor
+    wait_ms(1);
+    
+    sendCmd(0x4c); // CSR DIR right
+    wait_ms(1);
+    
+}
+
+void SED1335TextLCD::sendCmd(const unsigned char cmd) {
+    ::printf("c->%x\n",cmd);
+    _rd->write(1);
+    _wr->write(1);
+    _a0->write(1);
+    _cs->write(0);
+    // address setup time is 0
+    sendByte(cmd);
+    wait_us(10);
+}
+
+void SED1335TextLCD::sendData(const unsigned char cmd) {
+//    ::printf("d");
+    _rd->write(1);
+    _wr->write(1);
+    _a0->write(0);
+    _cs->write(0);
+    // address setup time is 0
+    sendByte(cmd);
+    wait_us(10);
+}
+
+void SED1335TextLCD::sendByte(const unsigned char byte) {
+//    ::printf("->%x\n",byte);
+    // display reads with rising flank of /wr
+    // first, set data, then set /wr low (no timing needed)
+    _data->write(byte);
+    _wr->write(0);
+    // wait for setup
+    wait_us(1);
+    // set /wr back to high
+    _wr->write(1);
+    // address / data hold time is 10 / 5 ns, so its handled by executing normal code :)
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sed1335text.h	Tue Jan 04 22:10:41 2011 +0000
@@ -0,0 +1,65 @@
+/*
+ * mbed LCDWindow library
+* Copyright (c) 2010 Hendrik Lipka
+* 
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+* 
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+* 
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
+#ifndef SED1335_8BIT_H_
+#define SED1335_8BIT_H_
+
+#include "lcd.h"
+
+#include "BusOut.h"
+#include "DigitalOut.h"
+
+using namespace mbed; 
+
+/**
+ * class for connecting graphical SED1335-based LCD-Display (or using similiar controllers)
+ * displays are connected in 8bit-mode, and are using the internal 8x8 font
+*/
+class SED1335TextLCD: public TextLCDBase
+{
+    public:
+        /**
+         * @param columns number of chars per line (using an 8x8 font)
+         * @param rows number of lines (using an 8x8 font)
+         * @param data the bus object used for sending data (must be 8bit)
+         * @param enable the pin name for the enable line (1=active)
+         * @param rs the pin name for the register select line (0=cmd, 1=data)
+         * @param leftCS the pin name for the left display half (1=active)
+         * @param rightCS the pin name for the right display half (1=active, use NC for smaller displays)
+        */
+        SED1335TextLCD(const unsigned int columns, const unsigned int rows, BusOut *data, const PinName read, const PinName write, const PinName cs, const PinName a0, const PinName reset); 
+        virtual void init();
+        virtual void writeText(const unsigned int column, const unsigned int row, const char text[]);
+        virtual void clear();
+        virtual void character(int column, int row, int c);
+
+    protected:
+        void sendCmd(const unsigned char byte);
+        void sendData(const unsigned char byte);
+        
+        void sendByte(const unsigned char byte);
+        
+        BusOut* _data;
+        DigitalOut *_rd, *_wr, *_cs, *_a0, *_reset;
+};
+#endif
\ No newline at end of file