Continuation:
Here is the LCD Shield library code. For now, the setSegments(), setIcons(), and setDigits() functions seem to work 100%. From the read side, I am working on the ::test() function and the ::analogRead() function. The functions other than these may or may not have been tested.
I hit the 9000 character limit again, so I deleted omitted the body of some unused functions from the .CPP file.
#include "DigitLCD.h"
#ifndef Arduino_h
#include "arduino.h"
#endif
#include <SPI.h>
static const int SPI_PACING= 50;
//
// These are the commands from the Arduino to the VMShield device
//
#define VMS_WAIT_FOR_RESPONSE 0x00
#define VMS_TEST_INTERFACE 0x03
#define VMS_SET_SEGMENTS 0x10
#define VMS_SET_DIGIT 0x11
#define VMS_SET_ICONS 0x12
#define VMS_DISPLAY_NUMBER 0x13
#define VMS_DIGITAL_READ 0x14
#define VMS_DIGITAL_WRITE 0x15
#define VMS_SET_OUTPUT_PIN 0x16
#define VMS_ANALOG_READ 0x17
#define VMS_BYTE_WRITE 0x18
#define VMS_SET_DECIMALS 0x1D
#define VMS_SET_LEDS 0x20
#define VMS_SET_BACKLIGHT 0x21
#define VMS_BEEP 0x30
#define VMS_HANDLE_BUTTONS 0x40
// constructor used by spi driver
DigitLCD::DigitLCD(byte pin) {
configSpi() ;
SPI.begin();
if (pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin,HIGH);
}
_pin= pin;
SPI.end() ;
}
void DigitLCD::waitForResponse(void) {
int cnt= 0;
while(cnt < 1000) {
delayMicroseconds(SPI_PACING);
if(SPI.transfer(VMS_WAIT_FOR_RESPONSE) == 0x55) return;
cnt++;
}
Serial.println("SPI TIMEOUT");
}
void DigitLCD::SendAByte(unsigned char SomeNum) {
configSpi() ;
SPI.begin() ;
digitalWrite(_pin, LOW);
delayMicroseconds(SPI_PACING) ;
SPI.transfer(SomeNum) ;
delayMicroseconds(SPI_PACING) ;
digitalWrite(_pin, HIGH) ;
delayMicroseconds(SPI_PACING) ;
SPI.end() ;
}
void DigitLCD::configSpi(void) {
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV16);
}
void DigitLCD::setDecimals(byte position) {
configSpi() ;
SPI.begin() ;
if (_pin) digitalWrite(_pin,LOW);
delayMicroseconds(SPI_PACING) ;
SPI.transfer(VMS_SET_DECIMALS) ;
delayMicroseconds(SPI_PACING) ;
SPI.transfer(position) ;
delayMicroseconds(SPI_PACING) ;
digitalWrite(_pin,HIGH);
SPI.end() ;
}
void DigitLCD::setBacklight(byte level) {
configSpi() ;
SPI.begin() ;
digitalWrite(_pin,LOW);
delayMicroseconds(SPI_PACING) ;
SPI.transfer(VMS_SET_BACKLIGHT) ;
delayMicroseconds(SPI_PACING) ;
SPI.transfer(level) ;
digitalWrite(_pin,HIGH);
SPI.end() ;
}
void DigitLCD::setSegments(byte position, byte segments) {
configSpi() ;
SPI.begin() ;
if (_pin) digitalWrite(_pin,LOW);
delayMicroseconds(SPI_PACING);
SPI.transfer(VMS_SET_SEGMENTS);
delayMicroseconds(SPI_PACING);
SPI.transfer(position);
delayMicroseconds(SPI_PACING);
SPI.transfer(segments);
delayMicroseconds(SPI_PACING) ;
if (_pin) digitalWrite(_pin,HIGH);
delayMicroseconds(SPI_PACING);
SPI.end() ;
}
void DigitLCD::setDigit(byte position, byte value) {
configSpi() ;
SPI.begin() ;
if (_pin) digitalWrite(_pin,LOW);
delayMicroseconds(SPI_PACING);
SPI.transfer(VMS_SET_DIGIT);
delayMicroseconds(SPI_PACING);
SPI.transfer(position);
delayMicroseconds(SPI_PACING);
SPI.transfer(value);
delayMicroseconds(SPI_PACING) ;
if (_pin) digitalWrite(_pin,HIGH);
delayMicroseconds(SPI_PACING);
SPI.end() ;
}
// this routine both clears and sets icons based on the two integers sent
void DigitLCD::setIcons(unsigned int set) {
configSpi() ;
SPI.begin() ;
if (_pin) digitalWrite(_pin,LOW);
delayMicroseconds(SPI_PACING);
SPI.transfer(VMS_SET_ICONS);
delayMicroseconds(SPI_PACING);
SPI.transfer(set >> 8);
delayMicroseconds(SPI_PACING);
SPI.transfer(set & 0xFF);
delayMicroseconds(SPI_PACING);
if (_pin) digitalWrite(_pin,HIGH);
SPI.end() ;
}
void DigitLCD::setRGB(byte red, byte green, byte blue) {
}
void DigitLCD::beep(byte pitch, byte duration) {
}
byte DigitLCD::buttons(byte *currentPtr) {
return events;
}
byte DigitLCD::test(void) {
byte value;
configSpi() ;
SPI.begin() ;
digitalWrite(_pin,LOW); // Assert CS To ST Micro
delayMicroseconds(SPI_PACING);
SPI.transfer(VMS_TEST_INTERFACE); // Send Test Command
delayMicroseconds(SPI_PACING);
value= SPI.transfer(0x00); // Read Response
delayMicroseconds(SPI_PACING);
digitalWrite(_pin,HIGH);
SPI.end() ;
return value;
}
byte DigitLCD::JEMdigitalRead(byte pin) {
}
void DigitLCD::JEMdigitalWrite(byte pin, byte onoff) {
}
void DigitLCD::JEMpinMode(byte pin, byte hilow) {
}
//
// DigitLCD::JEMwrite(byte data) ;
//
// General purpose byte write from Arduino to VMS device
//
void DigitLCD::JEMwrite(byte data) {
}
unsigned int DigitLCD::JEManalogRead(byte ADCpin) {
}
byte DigitLCD::JEMread(void) {
}
byte DigitLCD::JEMavailable(void) {
}
void DigitLCD::SetBitRate(unsigned long bitrate) {
}
void DigitLCD::JEM_init(void) {
}
Here is the #include file for the .CPP library code
/*
*/
#ifndef DIGIT_LCD_H
#define DIGIT_LCD_H
#ifndef Arduino_h
#include "arduino.h"
#endif
//
// The following are the icons available on the VMShield
// Not including the typical 7 segment alphanumerics.
//
#define SET_ICON 0x0001
#define ALARM_ICON 0x0002
#define AMPS_ICON 0x0004
#define VOLTS_ICON 0x0008
#define LOW_ICON 0x0010
#define BATTERY_ICON 0x0020
#define START_ICON 0x0040
#define STOP_ICON 0x0080
#define DEGREE_ICON 0x0100
#define COLON_ICON 0x0200
class DigitLCD {
public:
DigitLCD(byte pin);
void setSegments(byte position, byte segments);
void setDigit(byte position, byte value);
void setIcons(unsigned int set);
void setDecimals(byte position) ;
void display(int value, byte field= 0, byte format= 0);
void setRGB(byte red, byte green, byte blue);
void beep(byte pitch, byte duration);
void setBacklight(byte level);
byte JEMdigitalRead(byte pin);
void JEMdigitalWrite(byte pin, byte onoff);
void JEMpinMode(byte pin, byte onoff);
void JEMwrite(byte data);
byte JEMread(void);
byte JEMavailable(void);
void SetBitRate(unsigned long bitrate);
void JEM_init(void);
void SendAByte(unsigned char SomeNum) ;
byte buttons(byte *currentPtr = NULL);
unsigned int JEManalogRead(byte ADCpin);
byte test(void);
private:
void waitForResponse(void);
void configSpi(void);
int _pin;
};
#endif