Removed example code and keep only the library.
Dependents: Arch_GroveSerialLCD_Ex1 Arch_GroveSerialLCD_Ex2
Fork of Grove_Serial_LCD by
Revision 1:83ce5e2a368a, committed 2013-10-23
- Comitter:
- viswesr
- Date:
- Wed Oct 23 02:19:38 2013 +0000
- Parent:
- 0:289aecd28ddc
- Child:
- 2:a166e203e4cf
- Commit message:
- 1. License updated.; 2. Removed few print functions.; 3. Document added.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialLCD.cpp Wed Oct 23 02:19:38 2013 +0000 @@ -0,0 +1,197 @@ +/* + SerialLCD.h - Serial LCD driver Library + + 2010-2013 Copyright (c) Seeed Technology Inc (www.seeedstudio.com) + Authors: Jimbo.We, Visweswara R and Frankie.Chu (Orignially written for Seeeduino) + + This library can be used under Apache License 2.0 or MIT License. + */ + +#include "SerialLCD.h" + +//Initialization Commands or Responses + +#define SLCD_INIT 0xA3 +#define SLCD_INIT_ACK 0xA5 +#define SLCD_INIT_DONE 0xAA + +//WorkingMode Commands or Responses +#define SLCD_CONTROL_HEADER 0x9F +#define SLCD_CHAR_HEADER 0xFE +#define SLCD_CURSOR_HEADER 0xFF +#define SLCD_CURSOR_ACK 0x5A + +#define SLCD_RETURN_HOME 0x61 +#define SLCD_DISPLAY_OFF 0x63 +#define SLCD_DISPLAY_ON 0x64 +#define SLCD_CLEAR_DISPLAY 0x65 +#define SLCD_CURSOR_OFF 0x66 +#define SLCD_CURSOR_ON 0x67 +#define SLCD_BLINK_OFF 0x68 +#define SLCD_BLINK_ON 0x69 +#define SLCD_SCROLL_LEFT 0x6C +#define SLCD_SCROLL_RIGHT 0x72 +#define SLCD_NO_AUTO_SCROLL 0x6A +#define SLCD_AUTO_SCROLL 0x6D +#define SLCD_LEFT_TO_RIGHT 0x70 +#define SLCD_RIGHT_TO_LEFT 0x71 +#define SLCD_POWER_ON 0x83 +#define SLCD_POWER_OFF 0x82 +#define SLCD_INVALIDCOMMAND 0x46 +#define SLCD_BACKLIGHT_ON 0x81 +#define SLCD_BACKLIGHT_OFF 0x80 + +SerialLCD::SerialLCD(PinName rx, PinName tx) : Serial(rx,tx) +{ + Serial::baud(9600); +} + +/********** High level commands, for the user! **********/ + +/// Initialize the Serial LCD Driver. SerialLCD Module initiates the communication. +void SerialLCD::begin() +{ + wait_ms(2); + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_POWER_OFF); + wait_ms(1); + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_POWER_ON); + wait_ms(1); + Serial::putc(SLCD_INIT_ACK); + while(1) { + if (Serial::readable() > 0 &&Serial::getc()==SLCD_INIT_DONE) + break; + } + wait_ms(2); +} +/// Clear the display +void SerialLCD::clear() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_CLEAR_DISPLAY); +} +/// Return to home(top-left corner of LCD) +void SerialLCD::home() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_RETURN_HOME); + wait_ms(2); //this command needs more time; +} +/// Set Cursor to (Column,Row) Position +void SerialLCD::setCursor(uint8_t column, uint8_t row) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_CURSOR_HEADER); //cursor header command + Serial::putc(column); + Serial::putc(row); +} +/// Switch the display off without clearing RAM +void SerialLCD::noDisplay() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_DISPLAY_OFF); +} +/// Switch the display on +void SerialLCD::display() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_DISPLAY_ON); +} +/// Switch the underline cursor off +void SerialLCD::noCursor() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_CURSOR_OFF); +} +/// Switch the underline cursor on +void SerialLCD::cursor() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_CURSOR_ON); +} + +/// Switch off the blinking cursor +void SerialLCD::noBlink() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_BLINK_OFF); +} +/// Switch on the blinking cursor +void SerialLCD::blink() +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_BLINK_ON); +} +/// Scroll the display left without changing the RAM +void SerialLCD::scrollDisplayLeft(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_SCROLL_LEFT); +} +/// Scroll the display right without changing the RAM +void SerialLCD::scrollDisplayRight(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_SCROLL_RIGHT); +} +/// Set the text flow "Left to Right" +void SerialLCD::leftToRight(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_LEFT_TO_RIGHT); +} +/// Set the text flow "Right to Left" +void SerialLCD::rightToLeft(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_RIGHT_TO_LEFT); +} +/// This will 'right justify' text from the cursor +void SerialLCD::autoscroll(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_AUTO_SCROLL); +} +/// This will 'left justify' text from the cursor +void SerialLCD::noAutoscroll(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_NO_AUTO_SCROLL); +} +/// Switch on the LCD power +void SerialLCD::Power(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_POWER_ON); +} +/// Switch off the LCD power +void SerialLCD::noPower(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_POWER_OFF); +} +/// Switch off the back light +void SerialLCD::noBacklight(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_BACKLIGHT_OFF); +} +/// Switch on the back light +void SerialLCD::backlight(void) +{ + Serial::putc(SLCD_CONTROL_HEADER); + Serial::putc(SLCD_BACKLIGHT_ON); +} +/// Print char +void SerialLCD::print(uint8_t b) +{ + Serial::putc(SLCD_CHAR_HEADER); + Serial::putc(b); +} +/// Print char +void SerialLCD::print(const char b[]) +{ + Serial::putc(SLCD_CHAR_HEADER); + Serial::puts(b); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialLCD.h Wed Oct 23 02:19:38 2013 +0000 @@ -0,0 +1,46 @@ +/* + SerialLCD.h - Serial LCD driver Library + + 2010-2013 Copyright (c) Seeed Technology Inc (www.seeedstudio.com) + Authors: Jimbo.We, Visweswara R and Frankie.Chu (Orignially written for Seeeduino) + + This library can be used under Apache License 2.0 or MIT License. +*/ + +#ifndef __SERIAL_LCD_H__ +#define __SERIAL_LCD_H__ + +#include "mbed.h" + +class SerialLCD : public Serial { +public: + + SerialLCD(PinName, PinName); + void begin(); + void clear(); + void home(); + + void noDisplay(); + void display(); + void noBlink(); + void blink(); + void noCursor(); + void cursor(); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + + void setCursor(uint8_t, uint8_t); + void noPower(void); + void Power(void); + void noBacklight(void); + void backlight(void); + void print(uint8_t b); + void print(const char[]); + +}; + +#endif
--- a/SerialLCD/SerialLCD.cpp Mon Sep 23 02:15:27 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,249 +0,0 @@ -/* - SerialLCD.h - Serial LCD driver Library - 2010 Copyright (c) Seeed Technology Inc. All right reserved. - - Original Author: Jimbo.We - Contribution: Visweswara R - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "SerialLCD.h" - -//Initialization Commands or Responses - -#define SLCD_INIT 0xA3 -#define SLCD_INIT_ACK 0xA5 -#define SLCD_INIT_DONE 0xAA - -//WorkingMode Commands or Responses -#define SLCD_CONTROL_HEADER 0x9F -#define SLCD_CHAR_HEADER 0xFE -#define SLCD_CURSOR_HEADER 0xFF -#define SLCD_CURSOR_ACK 0x5A - -#define SLCD_RETURN_HOME 0x61 -#define SLCD_DISPLAY_OFF 0x63 -#define SLCD_DISPLAY_ON 0x64 -#define SLCD_CLEAR_DISPLAY 0x65 -#define SLCD_CURSOR_OFF 0x66 -#define SLCD_CURSOR_ON 0x67 -#define SLCD_BLINK_OFF 0x68 -#define SLCD_BLINK_ON 0x69 -#define SLCD_SCROLL_LEFT 0x6C -#define SLCD_SCROLL_RIGHT 0x72 -#define SLCD_NO_AUTO_SCROLL 0x6A -#define SLCD_AUTO_SCROLL 0x6D -#define SLCD_LEFT_TO_RIGHT 0x70 -#define SLCD_RIGHT_TO_LEFT 0x71 -#define SLCD_POWER_ON 0x83 -#define SLCD_POWER_OFF 0x82 -#define SLCD_INVALIDCOMMAND 0x46 -#define SLCD_BACKLIGHT_ON 0x81 -#define SLCD_BACKLIGHT_OFF 0x80 - -SerialLCD::SerialLCD(PinName rx, PinName tx) : Serial(rx,tx) -{ - Serial::baud(9600); -} - -/********** High level commands, for the user! **********/ - -// Initialize the Serial LCD Driver. SerialLCD Module initiates the communication. -void SerialLCD::begin() -{ - wait_ms(2); - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_POWER_OFF); - wait_ms(1); - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_POWER_ON); - wait_ms(1); - Serial::putc(SLCD_INIT_ACK); - while(1) - { - if (Serial::readable() > 0 &&Serial::getc()==SLCD_INIT_DONE) - break; - } - wait_ms(2); -} - -// Clear the display -void SerialLCD::clear() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_CLEAR_DISPLAY); -} - -// Return to home(top-left corner of LCD) -void SerialLCD::home() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_RETURN_HOME); - wait_ms(2);//this command needs more time; -} - -// Set Cursor to (Column,Row) Position -void SerialLCD::setCursor(uint8_t column, uint8_t row) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_CURSOR_HEADER); //cursor header command - Serial::putc(column); - Serial::putc(row); -} - -// Switch the display off without clearing RAM -void SerialLCD::noDisplay() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_DISPLAY_OFF); -} - -// Switch the display on -void SerialLCD::display() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_DISPLAY_ON); -} - -// Switch the underline cursor off -void SerialLCD::noCursor() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_CURSOR_OFF); -} - -// Switch the underline cursor on -void SerialLCD::cursor() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_CURSOR_ON); -} - -// Switch off the blinking cursor -void SerialLCD::noBlink() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_BLINK_OFF); -} - -// Switch on the blinking cursor -void SerialLCD::blink() -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_BLINK_ON); -} - -// Scroll the display left without changing the RAM -void SerialLCD::scrollDisplayLeft(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_SCROLL_LEFT); -} - -// Scroll the display right without changing the RAM -void SerialLCD::scrollDisplayRight(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_SCROLL_RIGHT); -} - -// Set the text flow "Left to Right" -void SerialLCD::leftToRight(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_LEFT_TO_RIGHT); -} - -// Set the text flow "Right to Left" -void SerialLCD::rightToLeft(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_RIGHT_TO_LEFT); -} - -// This will 'right justify' text from the cursor -void SerialLCD::autoscroll(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_AUTO_SCROLL); -} - -// This will 'left justify' text from the cursor -void SerialLCD::noAutoscroll(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_NO_AUTO_SCROLL); -} -void SerialLCD::Power(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_POWER_ON); -} -void SerialLCD::noPower(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_POWER_OFF); -} -//Turn off the backlight -void SerialLCD::noBacklight(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_BACKLIGHT_OFF); -} -//Turn on the back light -void SerialLCD::backlight(void) -{ - Serial::putc(SLCD_CONTROL_HEADER); - Serial::putc(SLCD_BACKLIGHT_ON); -} -// Print Commands - -void SerialLCD::print(uint8_t b) -{ - Serial::putc(SLCD_CHAR_HEADER); - Serial::putc(b); -} -void SerialLCD::print(const char b[]) -{ - Serial::putc(SLCD_CHAR_HEADER); - Serial::puts(b); -} - -void SerialLCD::print(unsigned long n, uint8_t base) -{ - unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. - unsigned long i = 0; - - if (base == 0) print(n); - - else if(base!=0) - { - if (n == 0) { - print('0'); - return; - } - - while (n > 0) { - buf[i++] = n % base; - n /= base; - } - - for (; i > 0; i--) - print((char) (buf[i - 1] < 10 ? - '0' + buf[i - 1] : - 'A' + buf[i - 1] - 10)); - } -}
--- a/SerialLCD/SerialLCD.h Mon Sep 23 02:15:27 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - SerialLCD.h - Serial LCD driver Library - 2010 Copyright (c) Seeed Technology Inc. All right reserved. - - Original Author: Jimbo.We - Contribution: Visweswara R - - Modified 15 March,2012 for Arduino 1.0 IDE - by Frankie.Chu - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef __SERIAL_LCD_H__ -#define __SERIAL_LCD_H__ - -#include "mbed.h" - - - -class SerialLCD : public Serial { -public: - - SerialLCD(PinName, PinName); - void begin(); - void clear(); - void home(); - - void noDisplay(); - void display(); - void noBlink(); - void blink(); - void noCursor(); - void cursor(); - void scrollDisplayLeft(); - void scrollDisplayRight(); - void leftToRight(); - void rightToLeft(); - void autoscroll(); - void noAutoscroll(); - - void setCursor(uint8_t, uint8_t); - void noPower(void); - void Power(void); - void noBacklight(void); - void backlight(void); - void print(uint8_t b); - void print(const char[]); - void print(unsigned long n, uint8_t base); - -}; - -#endif
--- a/main.cpp Mon Sep 23 02:15:27 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#include "mbed.h" -#include "SerialLCD.h" - -SerialLCD lcd(P1_13, P1_14); - -int main() { - lcd.begin(); - - lcd.print("hello, world"); - - while (1) { - lcd.setCursor(0, 1); - lcd.print('a'); - - wait(1); - } -}
--- a/mbed.bld Mon Sep 23 02:15:27 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file