Adding shift register LCD

This commit is contained in:
Will Bradley 2011-11-28 01:37:35 -07:00
parent ba8dd63974
commit e91a8a0f3a
15 changed files with 1448 additions and 1 deletions

View File

@ -28,9 +28,10 @@
* input device.
* Outputs go to relays for door hardware/etc control.
*
* Relay outputs on digital pins 6,7,8,9
* Relay outputs on digital pins 6,7,8,9 //TODO: fix this conflict -WB
* Reader 1: pins 2,3
* Ethernet: pins 10,11,12,13 (reserved for the Ethernet shield)
* LCD: pins 7, 6, 5, 4, 3, 2
*
* Quickstart tips:
* Compile and upload the code, then log in via serial console at 57600,8,N,1
@ -51,6 +52,7 @@
#include <WIEGAND26.h> // Wiegand 26 reader format libary
#include <PCATTACH.h> // Pcint.h implementation, allows for >2 software interupts.
#include <LiquidCrystal.h>
// Create an instance of the various C++ libraries we are using.
WIEGAND26 wiegand26; // Wiegand26 (RFID reader serial protocol) library
@ -85,6 +87,10 @@ byte server[] = { 10,1,1,1 }; // hsl-access
// that you want to connect to (port 80 is default for HTTP):
Client client(server, 80);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// strings for storing results from web server
String httpresponse = "";
String username = "";
@ -119,10 +125,20 @@ void setup(){ // Runs once at Arduino boot-up
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// set up the LCD's number of columns and rows:
lcd.begin(10, 2);
// Print a message to the LCD.
lcd.print("hI");
}
void loop() // Main branch, runs over and over again
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
//////////////////////////
// Reader input/authentication section
//////////////////////////

View File

@ -0,0 +1,347 @@
#include "ShiftLCD.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "WProgram.h"
/**
* This is a modified version of the standard LiquidCrystal class that
* ships with the Arduino software.
*
* It has been modified to work with either one or two eight bit shift registers
* in 4 and 8 bit mode respectivly
*
* The original file was released under the LGPL licence which I have to confess
* I found more than a little confusing. I belive that I am obligated to release
* this software under the GPL licence, as it is a derivitive work:
* (if not, I am very sorry and please tell me what I should hve done)
*
*******************************************************************************
ShiftLCD, allows the HD44780 LCD to be opertaed via a shift register
Copyright (C) 2010 Chris Parish
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************
* Please see the example files for usage information
*/
ShiftLCD::ShiftLCD(uint8_t dp, uint8_t cp, uint8_t lp, uint8_t mode)
{
init (dp, cp, lp, mode);
}
void ShiftLCD::init(uint8_t dp, uint8_t cp, uint8_t lp, uint8_t mode)
{
_data_pin = dp;
_clock_pin = cp;
_latch_pin = lp;
_backlight = LCD_BL_PIN;
pinMode(_data_pin, OUTPUT);
pinMode(_clock_pin, OUTPUT);
pinMode(_latch_pin, OUTPUT);
if (mode <= 4)
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
else
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
begin(16, 1);
}
void ShiftLCD::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_currline = 0;
// for some 1 line displays you can select a 10 pixel high font
if ((dotsize != 0) && (lines == 1)) {
_displayfunction |= LCD_5x10DOTS;
}
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
delayMicroseconds(50000);
// clear the shift register by sending 16 0's to it
shiftOut(_data_pin, _clock_pin, LSBFIRST, B00000000);
shiftOut(_data_pin, _clock_pin, LSBFIRST, B00000000);
//put the LCD into 4 bit or 8 bit mode
if (! (_displayfunction & LCD_8BITMODE)) {
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
write4bits(0x03, LOW);
delayMicroseconds(4500); // wait min 4.1ms
// second try
write4bits(0x03, LOW);
delayMicroseconds(4500); // wait min 4.1ms
// third go!
write4bits(0x03, LOW);
delayMicroseconds(150);
// finally, set to 8-bit interface
write4bits(0x02, LOW);
} else {
// this is according to the hitachi HD44780 datasheet
// page 45 figure 23
// Send function set command sequence
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(4500); // wait more than 4.1ms
// second try
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(150);
// third go
command(LCD_FUNCTIONSET | _displayfunction);
}
// finally, set # lines, font size, etc.
command(LCD_FUNCTIONSET | _displayfunction);
// turn the display on with no cursor or blinking default
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
display();
// clear it off
clear();
// Initialize to default text direction (for romance languages)
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
command(LCD_ENTRYMODESET | _displaymode);
}
/********** high level commands, for the user! */
void ShiftLCD::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void ShiftLCD::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void ShiftLCD::setCursor(uint8_t col, uint8_t row)
{
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row > _numlines ) {
row = _numlines-1; // we count rows starting w/0
}
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
// Turn the display on/off (quickly)
void ShiftLCD::noDisplay() {
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void ShiftLCD::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turns the underline cursor on/off
void ShiftLCD::noCursor() {
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void ShiftLCD::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turn on and off the blinking cursor
void ShiftLCD::noBlink() {
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void ShiftLCD::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// These commands scroll the display without changing the RAM
void ShiftLCD::scrollDisplayLeft(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void ShiftLCD::scrollDisplayRight(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
// This is for text that flows Left to Right
void ShiftLCD::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This is for text that flows Right to Left
void ShiftLCD::rightToLeft(void) {
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'right justify' text from the cursor
void ShiftLCD::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'left justify' text from the cursor
void ShiftLCD::noAutoscroll(void) {
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will turn the backlight on
void ShiftLCD::backlightOn(void) {
_backlight = LCD_BL_PIN;
updateBacklight();
}
// This will turn the backlight off
void ShiftLCD::backlightOff(void) {
_backlight &= ~LCD_BL_PIN;
updateBacklight();
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void ShiftLCD::createChar(uint8_t location, uint8_t charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
command(LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++) {
write(charmap[i]);
}
}
/*********** mid level commands, for sending data/cmds */
inline void ShiftLCD::command(uint8_t value) {
send(value, false);
}
inline void ShiftLCD::write(uint8_t value) {
send(value, true);
}
/************ low level data pushing commands **********/
void ShiftLCD::updateBacklight(void) {
if (_displayfunction & LCD_8BITMODE) {
digitalWrite(_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, _backlight);
shiftOut(_data_pin, _clock_pin, LSBFIRST, B00000000);
digitalWrite(_latch_pin, LOW);
} else {
digitalWrite(_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, _backlight);
digitalWrite(_latch_pin, LOW);
}
}
// write either command or data, with automatic 4/8-bit selection
void ShiftLCD::send(uint8_t value, uint8_t mode) {
if (_displayfunction & LCD_8BITMODE) {
write8bits(value, mode);
} else {
write4bits(value>>4, mode);
write4bits(value, mode);
}
}
void ShiftLCD::write4bits(uint8_t value, uint8_t mode) {
int EN_SWITCH = B00000010;
int RS_SWITCH = B00000001;
int cmd = 0;
int data = 0;
if (!mode) {
cmd = 0 | _backlight;
} else {
cmd = LCD_RS_PIN | _backlight;
}
data = value<<4 & B11110000;
cmd |= EN_SWITCH;
digitalWrite(_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, data | cmd);
digitalWrite(_latch_pin, LOW);
delayMicroseconds(1);
cmd &= ~EN_SWITCH;
digitalWrite(_latch_pin, HIGH);
shiftOut (_data_pin, _clock_pin, LSBFIRST, data | cmd);
digitalWrite(_latch_pin, LOW);
delayMicroseconds(1);
cmd |= EN_SWITCH;
digitalWrite(_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, data | cmd);
digitalWrite(_latch_pin, LOW);
delayMicroseconds(100);
}
void ShiftLCD::write8bits(uint8_t value, uint8_t mode) {
int EN_SWITCH = B00000010;
int RS_SWITCH = B00000001;
int cmd = 0;
if (!mode) {
cmd = 0;
} else {
cmd = RS_SWITCH;
}
//set enable low
cmd |= EN_SWITCH;
digitalWrite (_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, cmd);
shiftOut(_data_pin, _clock_pin, LSBFIRST, value);
digitalWrite (_latch_pin, LOW);
//delay (500);
//set enable high;
cmd &= ~EN_SWITCH;
digitalWrite (_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, cmd);
shiftOut(_data_pin, _clock_pin, LSBFIRST, value);
digitalWrite (_latch_pin, LOW);
delayMicroseconds (1);
//delay (500);
//set enable low
cmd |= EN_SWITCH;
digitalWrite (_latch_pin, HIGH);
shiftOut(_data_pin, _clock_pin, LSBFIRST, cmd);
shiftOut(_data_pin, _clock_pin, LSBFIRST, value);
digitalWrite (_latch_pin, LOW);
delayMicroseconds (100);
}

View File

@ -0,0 +1,140 @@
#ifndef ShiftLCD_h
#define ShiftLCD_h
/**
* This is a modified version of the standard LiquidCrystal class that
* ships with the Arduino software.
*
* It has been modified to work with either one or two eight bit shift registers
* in 4 and 8 bit mode respectivly
*
* The original file was released under the LGPL licence which I have to confess
* I found more than a little confusing. I belive that I am obligated to release
* this software under the GPL licence, as it is a derivitive work:
* (if not, I am very sorry and please tell me what I should hve done)
*
*******************************************************************************
ShiftLCD, allows the HD44780 LCD to be opertaed via a shift register
Copyright (C) 2010 Chris Parish
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************
* Please see the example files for usage information
*/
#include <inttypes.h>
#include "Print.h"
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
// pins for functional output
#define LCD_RS_PIN 0x01
#define LCD_EN_PIN 0x02
#define LCD_BL_PIN 0x04
/*
ShiftLCD Class
*/
class ShiftLCD: public Print {
public:
ShiftLCD(uint8_t dp, uint8_t cp, uint8_t lp, uint8_t mode = 4);
void init(uint8_t dp, uint8_t cp, uint8_t lp, uint8_t mode);
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
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 backlightOn();
void backlightOff();
void createChar(uint8_t, uint8_t[]);
void setCursor(uint8_t, uint8_t);
virtual void write(uint8_t);
void command(uint8_t);
private:
void updateBacklight();
void send(uint8_t, uint8_t);
void write4bits(uint8_t, uint8_t);
void write8bits(uint8_t, uint8_t);
uint8_t _clock_pin; //shift register clock pin
uint8_t _data_pin; //shift register data pin
uint8_t _latch_pin; //shift register latch pin
uint8_t _smart_enable;
uint8_t _displayfunction;
uint8_t _displaycontrol;
uint8_t _displaymode;
uint8_t _backlight;
uint8_t _initialized;
uint8_t _numlines,_currline;
};
#endif

View File

@ -0,0 +1,89 @@
/*
ShiftLCD Library - Autoscroll
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch demonstrates the use of the autoscroll()
and noAutoscroll() functions.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
}
void loop() {
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// set the cursor to (16,1):
lcd.setCursor(16,1);
// set the display to automatically scroll:
lcd.autoscroll();
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();
// clear screen for the next loop:
lcd.clear();
}

View File

@ -0,0 +1,75 @@
/*
ShiftLCD Library - Backlight
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch displays "Hello, World!" and then flashes the display
on and off once a second
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
Example by
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initalise the library with the numbers of the interface pins
ShiftLCD lcd(2,4,3);
void setup()
{
// set up the LCD's number of rows and columns:
lcd.begin(16,2);
// Output Hello, World!
lcd.print("Hello, World!");
}
void loop()
{
// Turn the backlight on
lcd.backlightOn();
delay(1000);
// Turn the backlight off
lcd.backlightOff();
delay(1000);
}

View File

@ -0,0 +1,75 @@
/*
ShiftLCD Library - Blink
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints "Hello World!" and makes the cursor blink
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2,4,3);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// Turn off the blinking cursor:
lcd.noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink();
delay(3000);
}

View File

@ -0,0 +1,84 @@
/*
ShiftLCD Library - CreateChar
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints "Hello, World!" and then adds a smiley after it
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
Example based on the code from the arduino.cc reference library for LiquidCrystal
Chris Parish, January 17th 2010
*/
//include the library code:
#include <ShiftLCD.h>
// initalise the library with the numbers of the interface pins
ShiftLCD lcd(2,4,3);
//define the smiley
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
void setup()
{
// create the character. This must be done before calling lcd.begin
lcd.createChar(0, smiley);
// initalise the display with the number of row and colums:
lcd.begin(16,2);
// output Hello World to the display:
lcd.print("Hello, World!");
// output the custom character:
lcd.write(0);
}
void loop()
{
}

View File

@ -0,0 +1,76 @@
/*
ShiftLCD Library - Cursor
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints "Hello World!" to the LCD and
uses the cursor() and noCursor() methods to turn
on and off the cursor.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// Turn off the cursor:
lcd.noCursor();
delay(500);
// Turn on the cursor:
lcd.cursor();
delay(500);
}

View File

@ -0,0 +1,76 @@
/*
ShiftLCD Library - Display
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints "Hello World!" to the LCD and uses the
display() and noDisplay() functions to turn on and off
the display.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// Turn off the display:
lcd.noDisplay();
delay(500);
// Turn on the display:
lcd.display();
delay(500);
}

View File

@ -0,0 +1,74 @@
/*
ShiftLCD Library - Hello World
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hello, World!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

View File

@ -0,0 +1,86 @@
/*
ShiftLCD Library - Scroll
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints "Hello World!" to the LCD and uses the
scrollDisplayLeft() and scrollDisplayRight() methods to scroll
the text.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
lcd.setCursor(0,7);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// scroll 27 positions (display length + string length) to the left:
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(200);
}
// scroll 27 positions (display length + string length) to the right:
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(200);
}
}

View File

@ -0,0 +1,81 @@
/*
ShiftLCD Library - SerialDisplay
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch displays text sent over the serial port
(e.g. from the Serial Monitor) on an attached LCD.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup(){
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}

View File

@ -0,0 +1,102 @@
/*
ShiftLCD Library - TextDirection
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch demonstrates how to use leftToRight() and rightToLeft()
to move the cursor.
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
int thisChar = 'a';
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// turn on the cursor:
lcd.cursor();
Serial.begin(9600);
}
void loop() {
// reverse directions at 'm':
if (thisChar == 'm') {
// go right for the next letter
lcd.rightToLeft();
}
// reverse again at 's':
if (thisChar == 's') {
// go left for the next letter
lcd.leftToRight();
}
// reset at 'z':
if (thisChar > 'z') {
// go to (0,0):
lcd.home();
// start again at 0
thisChar = 'a';
}
// print the character
lcd.print(thisChar, BYTE);
// wait a second:
delay(1000);
// increment the letter:
thisChar++;
}

View File

@ -0,0 +1,87 @@
/*
ShiftLCD Library - setCursor
Demonstrates the use a 16x2 LCD display. The ShiftLCD library works with
all LCD displays that are compatible with the Hitachi HD44780 driver.
There are many of them out there, and you can usually tell them by the
16-pin interface.
This sketch prints to all the positions of the LCD using the
setCursor method:
The circuit:
---Shift Register 74HC595---
* SR Pin 14 to Arduino pin 2
* SR Pin 12 to Arduino pin 3
* SR Pin 11 to Arduino pin 4
* SR Pin 8 to Ground
* SR Pin 16 to +5v
* SR Pin 13 to Ground
* SR Pin 10 to +5v
-----Shift Reg to LCD--------
* SR Pin 15 to D7
* SR Pin 1 to D6
* SR Pin 2 to D5
* SR Pin 3 to D4
* SR Pin 5 to MOSFET gate
* SR Pin 6 to Enable
* SR Pin 7 to RS
-----LCD HD44780-------------
* Vss to Ground
* Vdd to +5V
* Vo to 10k Wiper
* R/W to Ground
* 5v to +5v
* Gnd to MOSFET Drain
------N Chanel MOSFET--------
* Source to Ground
* Gate to SP Pin 5
* Drain to LCD Gnd
* 1k Resistor Between gate and source
For a more detailed schematic, please see my blog:
http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html
Library modified from the original LiquidCrystal Library
This example originaly by Tom Igoe, Jul 2009
Example modified for use with ShiftLCD
Chris Parish, January 12th 2010
*/
// include the library code:
#include <ShiftLCD.h>
// these constants won't change. But you can change the size of
// your LCD using them:
const int numRows = 2;
const int numCols = 16;
// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(numRows, numCols);
}
void loop() {
// loop from ASCII 'a' to ASCII 'z':
for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) {
// loop over the columns:
for (int thisCol = 0; thisCol < numRows; thisCol++) {
// loop over the rows:
for (int thisRow = 0; thisRow < numCols; thisRow++) {
// set the cursor position:
lcd.setCursor(thisRow,thisCol);
// print the letter:
lcd.print(thisLetter, BYTE);
delay(200);
}
}
}
}

View File

@ -0,0 +1,39 @@
#######################################
# Syntax Coloring Map For LiquidCrystal
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
ShiftLCD KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
clear KEYWORD2
home KEYWORD2
print KEYWORD2
setCursor KEYWORD2
cursor KEYWORD2
noCursor KEYWORD2
blink KEYWORD2
noBlink KEYWORD2
display KEYWORD2
noDisplay KEYWORD2
autoscroll KEYWORD2
noAutoscroll KEYWORD2
leftToRight KEYWORD2
rightToLeft KEYWORD2
scrollDisplayLeft KEYWORD2
scrollDisplayRight KEYWORD2
createChar KEYWORD2
backlightOn KEYWORD2
backlightOff KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################