Adri67
Junior Member level 2
- Joined
- Aug 11, 2014
- Messages
- 24
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 267
#include <LiquidCrystal595.h> // the library
LiquidCrystal595 lcd(7,8,9); // datapin, latchpin, clockpin
void setup() {
lcd.begin(16,2); // LCD 1602
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LCD 3-wire");
lcd.setCursor(0,1);
lcd.print("communicator");
}
void loop() {
// not used.
#include <LiquidCrystal595.h> // the library
LiquidCrystal595 lcd1(7,8,9); // datapin, latchpin, clockpin
LiquidCrystal595 lcd2(4,5,6); // datapin, latchpin, clockpin
void setup() {
lcd1.begin(16,2); // LCD 1602
lcd2.begin(16,2); // LCD 1602
lcd1.clear();
lcd2.clear();
lcd1.setCursor(0,0);
lcd2.setCursor(0,0);
lcd1.print("LCD 3-wire");
lcd2.print("Second LCD");
lcd1.setCursor(0,1);
lcd2.setCursor(0,1);
lcd1.print("communicator");
lcd2.print("is here");
}
// for 2 x 74HC595 ... (20160924)
int SER_Pin = 8; // 14 / 595
int RCLK_Pin = 9; // 12 / 595
int SRCLK_Pin = 10; //11 / 595
boolean reg [16];
void setup() {
pinMode (SER_Pin, OUTPUT);
pinMode (RCLK_Pin, OUTPUT);
pinMode (SRCLK_Pin, OUTPUT);
//reset all register pins
clearReg ();
writeReg ();
}
void clearReg () {
for(int i = 15; i >= 0; i--) {
reg = LOW;
}
}
void writeReg () {
digitalWrite (RCLK_Pin, LOW);
for (int i = 15; i >= 0; i--) {
digitalWrite (SRCLK_Pin, LOW);
int val = reg ;
digitalWrite (SER_Pin, val);
digitalWrite (SRCLK_Pin, HIGH);
}
digitalWrite (RCLK_Pin, HIGH);
}
void K(int index, int value) {
reg [index] = value;
}
void loop() {
K (0, 0);
K (1, 1);
K (2, 0);
K (3, 0);
K (4, 0);
K (5, 0);
K (6, 0);
K (7, 1);
K (8, 0);
K (9, 0);
K (10, 0);
K (11, 0);
K (12, 1);
K (13, 0);
K (14, 0);
K (15, 1);
writeReg();
}
/* -----------------------------------------------------------------------------------
* Adaption of the LiquidCrystal library shipped with Arduino 22
* for use with 74HC595 shift register adapter board found on:
* http://www.stephenhobley.com
* Code adaption by Steve Hobley - February 2011
/*---Shift Register 74HC595---
* [SR Pin 14 (DS)] to Arduino pin - Yellow wire [datapin]
* [SR Pin 12 (ST_CP)] to Arduino pin - Green wire [latchpin]
* [SR Pin 11 (SH_CP)] to Arduino pin - White wire [clockpin]
* Black wire to Ground
* Red wire to +5v
-----Shift Reg to LCD--------
* SR Pin 15 - ENABLE 10000000
* SR Pin 1 - D4 00000010
* SR Pin 2 - D5 00000100
* SR Pin 3 - D6 00001000
* SR Pin 4 - D7 00010000
* SR Pin 5 - MOSFET / LED1 00100000
* SR Pin 6 - LED 2 01000000
* SR Pin 7 - RS 00000001
*
* -----------------------------------------------------------------------------------
*/
// 595 mappings - LED1 is also the backlight controller
#define ENABLE_PIN B00000001
#define RS_PIN B10000000
#define LED1_PIN B00100000
#define LED2_PIN B01000000
#define DATABITS B00011110
#define PIN_D4 B00000010
#define PIN_D5 B00000100
#define PIN_D6 B00001000
#define PIN_D7 B00010000
#include "LiquidCrystal595.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "WProgram.h"
// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set:
// DL = 1; 8-bit interface data
// N = 0; 1-line display
// F = 0; 5x8 dot character font
// 3. Display on/off control:
// D = 0; Display off
// C = 0; Cursor off
// B = 0; Blinking off
// 4. Entry mode set:
// I/D = 1; Increment by 1
// S = 0; No shift
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).
LiquidCrystal595::LiquidCrystal595(uint8_t datapin, uint8_t latchpin, uint8_t clockpin)
{
init(datapin, latchpin, clockpin);
}
// Performs the shift, MSB first
void LiquidCrystal595::shift595()
{
digitalWrite(_latchpin, LOW);
shiftOut(_datapin, _clockpin, MSBFIRST, _register);
digitalWrite(_latchpin, HIGH);
}
void LiquidCrystal595::init(uint8_t datapin, uint8_t latchpin, uint8_t clockpin)
{
_datapin = datapin;
_latchpin = latchpin;
_clockpin = clockpin;
pinMode(_datapin, OUTPUT);
pinMode(_latchpin, OUTPUT);
pinMode(_clockpin, OUTPUT);
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
begin(16, 1);
}
void LiquidCrystal595::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);
// Now we pull both RS and R/W low to begin commands
setRSPin(LOW);
setEPin(LOW);
shift595();
//digitalWrite(_rs_pin, LOW);
//digitalWrite(_enable_pin, LOW);
//if (_rw_pin != 255) {
// digitalWrite(_rw_pin, LOW);
//}
//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);
delayMicroseconds(4500); // wait min 4.1ms
// second try
write4bits(0x03);
delayMicroseconds(4500); // wait min 4.1ms
// third go!
write4bits(0x03);
delayMicroseconds(150);
// finally, set to 4-bit interface
write4bits(0x02);
} 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 LiquidCrystal595::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal595::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal595::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 LiquidCrystal595::noDisplay() {
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal595::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turns the underline cursor on/off
void LiquidCrystal595::noCursor() {
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal595::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turn on and off the blinking cursor
void LiquidCrystal595::noBlink() {
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal595::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// These commands scroll the display without changing the RAM
void LiquidCrystal595::scrollDisplayLeft(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void LiquidCrystal595::scrollDisplayRight(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
// This is for text that flows Left to Right
void LiquidCrystal595::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This is for text that flows Right to Left
void LiquidCrystal595::rightToLeft(void) {
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'right justify' text from the cursor
void LiquidCrystal595::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'left justify' text from the cursor
void LiquidCrystal595::noAutoscroll(void) {
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal595::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 LiquidCrystal595::command(uint8_t value) {
send(value, LOW);
}
inline void LiquidCrystal595::write(uint8_t value) {
send(value, HIGH);
}
/************ low level data pushing commands **********/
// write either command or data, with automatic 4/8-bit selection
void LiquidCrystal595::send(uint8_t value, uint8_t mode)
{
setRSPin(mode);
shift595();
//digitalWrite(_rs_pin, mode);
// if there is a RW pin indicated, set it low to Write
//if (_rw_pin != 255) {
// digitalWrite(_rw_pin, LOW);
//}
if (_displayfunction & LCD_8BITMODE)
{
write8bits(value);
}
else
{
write4bits(value>>4);
write4bits(value);
}
}
void LiquidCrystal595::pulseEnable(void)
{
// LOW / HIGH / LOW of ENABLE_PIN
setEPin(LOW); // LOW
shift595();
delayMicroseconds(1);
setEPin(HIGH); // HIGH
shift595();
delayMicroseconds(1); // enable pulse must be >450ns
setEPin(LOW); // LOW
shift595();
delayMicroseconds(100); // commands need > 37us to settle
}
void LiquidCrystal595::write4bits(uint8_t value)
{
int val_nibble= value & 0x0F; //clean the value. (unnecessary)
setD4Pin(val_nibble & 01);
val_nibble >>= 1;
setD5Pin(val_nibble & 01);
val_nibble >>= 1;
setD6Pin(val_nibble & 01);
val_nibble >>= 1;
setD7Pin(val_nibble & 01);
pulseEnable();
}
void LiquidCrystal595::write8bits(uint8_t value)
{
return;
// Should not be used
}
// Accessor functions --------------------------------------------------------
void LiquidCrystal595::setLED1Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= LED1_PIN; // HIGH
}
else
{
_register &= ~LED1_PIN; // LOW
}
}
void LiquidCrystal595::setLED2Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= LED2_PIN; // HIGH
}
else
{
_register &= ~LED2_PIN; // LOW
}
}
void LiquidCrystal595::setEPin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= ENABLE_PIN; // HIGH
}
else
{
_register &= ~ENABLE_PIN; // LOW
}
}
void LiquidCrystal595::setD4Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D4; // HIGH
}
else
{
_register &= ~PIN_D4; // LOW
}
}
void LiquidCrystal595::setD5Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D5; // HIGH
}
else
{
_register &= ~PIN_D5; // LOW
}
}
void LiquidCrystal595::setD6Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D6; // HIGH
}
else
{
_register &= ~PIN_D6; // LOW
}
}
void LiquidCrystal595::setD7Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D7; // HIGH
}
else
{
_register &= ~PIN_D7; // LOW
}
}
void LiquidCrystal595::setRSPin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= RS_PIN; // HIGH
}
else
{
_register &= ~RS_PIN; // LOW
}
}
// 595 mappings - LED1 is also the backlight controller
#define ENABLE_PIN B00000001
#define RS_PIN B10000000
#define LED1_PIN B00100000
#define LED2_PIN B01000000
#define DATABITS B00011110
#define PIN_D4 B00000010
#define PIN_D5 B00000100
#define PIN_D6 B00001000
#define PIN_D7 B00010000
// for 2 x 74HC595 (20160924)
int SER_Pin = 8; // 14 / 595
int RCLK_Pin = 9; // 12 / 595
int SRCLK_Pin = 10; //11 / 595
boolean reg [16];
void setup() {
pinMode (SER_Pin, OUTPUT);
pinMode (RCLK_Pin, OUTPUT);
pinMode (SRCLK_Pin, OUTPUT);
//reset all register pins
clearReg ();
writeReg ();
}
void clearReg () {
for(int i = 15; i >= 0; i--) {
reg [i] = LOW;
}
}
void writeReg () {
digitalWrite (RCLK_Pin, LOW);
for (int i = 15; i >= 0; i--) {
digitalWrite (SRCLK_Pin, LOW);
int val = reg [i];
digitalWrite (SER_Pin, val);
digitalWrite (SRCLK_Pin, HIGH);
}
digitalWrite (RCLK_Pin, HIGH);
}
void K(int index, int value) {
reg [index] = value;
}
void loop(){
K (0, 0);
K (1, 1);
K (2, 0);
K (3, 0);
K (4, 0);
K (5, 0);
K (6, 0);
K (7, 1);
K (8, 0);
K (9, 0);
K (10, 0);
K (11, 0);
K (12, 1);
K (13, 0);
K (14, 0);
K (15, 1);
writeReg();
}
/* -----------------------------------------------------------------------------------
* Adaption of the LiquidCrystal library shipped with Arduino 22
* for use with 74HC595 shift register adapter board found on:
* http://www.stephenhobley.com
* Code adaption by Steve Hobley - February 2011
/*---Shift Register 74HC595---
* [SR Pin 14 (DS)] to Arduino pin - Yellow wire [datapin]
* [SR Pin 12 (ST_CP)] to Arduino pin - Green wire [latchpin]
* [SR Pin 11 (SH_CP)] to Arduino pin - White wire [clockpin]
* Black wire to Ground
* Red wire to +5v
-----Shift Reg to LCD--------
* SR Pin 15 - ENABLE 10000000
* SR Pin 1 - D4 00000010
* SR Pin 2 - D5 00000100
* SR Pin 3 - D6 00001000
* SR Pin 4 - D7 00010000
* SR Pin 5 - MOSFET / LED1 00100000
* SR Pin 6 - LED 2 01000000
* SR Pin 7 - RS 00000001
*
* -----------------------------------------------------------------------------------
*/
// 595 mappings - LED1 is also the backlight controller
#define ENABLE_PIN B00000001
#define RS_PIN B10000000
#define LED1_PIN B00100000
#define LED2_PIN B01000000
#define DATABITS B00011110
#define PIN_D4 B00000010
#define PIN_D5 B00000100
#define PIN_D6 B00001000
#define PIN_D7 B00010000
#include "LiquidCrystal595.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "WProgram.h"
// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set:
// DL = 1; 8-bit interface data
// N = 0; 1-line display
// F = 0; 5x8 dot character font
// 3. Display on/off control:
// D = 0; Display off
// C = 0; Cursor off
// B = 0; Blinking off
// 4. Entry mode set:
// I/D = 1; Increment by 1
// S = 0; No shift
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).
LiquidCrystal595::LiquidCrystal595(uint8_t datapin, uint8_t latchpin, uint8_t clockpin)
{
init(datapin, latchpin, clockpin);
}
// Performs the shift, MSB first
void LiquidCrystal595::shift595()
{
digitalWrite(_latchpin, LOW);
shiftOut(_datapin, _clockpin, MSBFIRST, _register);
digitalWrite(_latchpin, HIGH);
}
void LiquidCrystal595::init(uint8_t datapin, uint8_t latchpin, uint8_t clockpin)
{
_datapin = datapin;
_latchpin = latchpin;
_clockpin = clockpin;
pinMode(_datapin, OUTPUT);
pinMode(_latchpin, OUTPUT);
pinMode(_clockpin, OUTPUT);
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
begin(16, 1);
}
void LiquidCrystal595::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);
// Now we pull both RS and R/W low to begin commands
setRSPin(LOW);
setEPin(LOW);
shift595();
//digitalWrite(_rs_pin, LOW);
//digitalWrite(_enable_pin, LOW);
//if (_rw_pin != 255) {
// digitalWrite(_rw_pin, LOW);
//}
//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);
delayMicroseconds(4500); // wait min 4.1ms
// second try
write4bits(0x03);
delayMicroseconds(4500); // wait min 4.1ms
// third go!
write4bits(0x03);
delayMicroseconds(150);
// finally, set to 4-bit interface
write4bits(0x02);
} 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 LiquidCrystal595::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal595::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal595::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 LiquidCrystal595::noDisplay() {
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal595::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turns the underline cursor on/off
void LiquidCrystal595::noCursor() {
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal595::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turn on and off the blinking cursor
void LiquidCrystal595::noBlink() {
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal595::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// These commands scroll the display without changing the RAM
void LiquidCrystal595::scrollDisplayLeft(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void LiquidCrystal595::scrollDisplayRight(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
// This is for text that flows Left to Right
void LiquidCrystal595::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This is for text that flows Right to Left
void LiquidCrystal595::rightToLeft(void) {
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'right justify' text from the cursor
void LiquidCrystal595::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'left justify' text from the cursor
void LiquidCrystal595::noAutoscroll(void) {
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal595::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 LiquidCrystal595::command(uint8_t value) {
send(value, LOW);
}
inline void LiquidCrystal595::write(uint8_t value) {
send(value, HIGH);
}
/************ low level data pushing commands **********/
// write either command or data, with automatic 4/8-bit selection
void LiquidCrystal595::send(uint8_t value, uint8_t mode)
{
setRSPin(mode);
shift595();
//digitalWrite(_rs_pin, mode);
// if there is a RW pin indicated, set it low to Write
//if (_rw_pin != 255) {
// digitalWrite(_rw_pin, LOW);
//}
if (_displayfunction & LCD_8BITMODE)
{
write8bits(value);
}
else
{
write4bits(value>>4);
write4bits(value);
}
}
void LiquidCrystal595::pulseEnable(void)
{
// LOW / HIGH / LOW of ENABLE_PIN
setEPin(LOW); // LOW
shift595();
delayMicroseconds(1);
setEPin(HIGH); // HIGH
shift595();
delayMicroseconds(1); // enable pulse must be >450ns
setEPin(LOW); // LOW
shift595();
delayMicroseconds(100); // commands need > 37us to settle
}
void LiquidCrystal595::write4bits(uint8_t value)
{
int val_nibble= value & 0x0F; //clean the value. (unnecessary)
setD4Pin(val_nibble & 01);
val_nibble >>= 1;
setD5Pin(val_nibble & 01);
val_nibble >>= 1;
setD6Pin(val_nibble & 01);
val_nibble >>= 1;
setD7Pin(val_nibble & 01);
pulseEnable();
}
void LiquidCrystal595::write8bits(uint8_t value)
{
return;
// Should not be used
}
// Accessor functions --------------------------------------------------------
void LiquidCrystal595::setLED1Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= LED1_PIN; // HIGH
}
else
{
_register &= ~LED1_PIN; // LOW
}
}
void LiquidCrystal595::setLED2Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= LED2_PIN; // HIGH
}
else
{
_register &= ~LED2_PIN; // LOW
}
}
void LiquidCrystal595::setEPin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= ENABLE_PIN; // HIGH
}
else
{
_register &= ~ENABLE_PIN; // LOW
}
}
void LiquidCrystal595::setD4Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D4; // HIGH
}
else
{
_register &= ~PIN_D4; // LOW
}
}
void LiquidCrystal595::setD5Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D5; // HIGH
}
else
{
_register &= ~PIN_D5; // LOW
}
}
void LiquidCrystal595::setD6Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D6; // HIGH
}
else
{
_register &= ~PIN_D6; // LOW
}
}
void LiquidCrystal595::setD7Pin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= PIN_D7; // HIGH
}
else
{
_register &= ~PIN_D7; // LOW
}
}
void LiquidCrystal595::setRSPin(uint8_t pinValue)
{
if (pinValue == HIGH)
{
_register |= RS_PIN; // HIGH
}
else
{
_register &= ~RS_PIN; // LOW
}
}
// 595 mappings - LED1 is also the backlight controller
#define ENABLE_PIN B00000001
#define RS_PIN B10000000
#define LED1_PIN B00100000
#define LED2_PIN B01000000
#define DATABITS B00011110
#define PIN_D4 B00000010
#define PIN_D5 B00000100
#define PIN_D6 B00001000
#define PIN_D7 B00010000
Should I alter/muddle with the original library and change its name (risking breaking it) ?
Or can changes be made in the new sketch leaving the original library intact?
If so, how?
Once you've got your shift registers daisy chained together writing out to the chain is super easy. All you have to do is call the shiftOut function once for every shift register you have connected. So in this code, which drives two 7 Segment LED displays, we have these two lines inside the nested for loops:
This outputs the numbers 00-99 on the shift registers. Not that the first call to shift out sends its byte to the shift register at the far end of the chain (i.e. the register that is furthest from the Arduino.Code:shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[onesColumn]); shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[tensColumn]);
Code:/* LucidTronix * Daisy Chained Shift Registers * 74HC595 connected to 7-Segment LED display * Tutorial at: * http://www.lucidtronix.com/tutorials/40 * April 2013 */ int dataPin = 2; int latchPin = 3; int clockPin = 4; byte dec_digits[] = {0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000011,0b11111000,0b10000000,0b10011000 }; void setup() { //set pins to output so you can control the shift register pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { for (int tensColumn = 0; tensColumn < 10; tensColumn++) { for (int onesColumn = 0; onesColumn < 10; onesColumn++) { // take the latchPin low so // the LEDs don't change while you're sending in bits: digitalWrite(latchPin, LOW); // shift out the bits: shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[onesColumn]); shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[tensColumn]); //take the latch pin high so the LEDs will light up: digitalWrite(latchPin, HIGH); // pause before next value: delay(300); } } }
Hi,
I hope I understand right:
* two 595 connected in series:
* MOSI --> 595A_SER (LCD)
* 595A_QH´--> 595B_SER
* (optionlal: 595B_QH´--> MISO)
* all other control lines in parallel to both 595
Software:
* activate chipselect
* write 8 bits for 595B
* write 8 bits for 595A
* deactivete chipselect
Klaus
Hi,
I hope I understand right:
* two 595 connected in series:
* MOSI --> 595A_SER (LCD)
* 595A_QH´--> 595B_SER
* (optionlal: 595B_QH´--> MISO)
* all other control lines in parallel to both 595
Software:
* activate chipselect
* write 8 bits for 595B
* write 8 bits for 595A
* deactivete chipselect
Klaus
Hi,
maybe you can look into the library.
The 595 acces is just simple SPI access.
If you can modify this acces to transmit 16 bit ...
But
Writing the SPI access on your own isn´t difficult, too.
I assume there are raw SPI libraries.
Klaus
Hi,
I can´t help you with code.
I´m more in hardware. I can read code, but don´t write code anymore.
There will be others to help you with code or libraries.
Klaus
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?