Permalink
Browse files

Merged in changes/fixes from jpbot (fixes to recv method;

jpbot commit 0f006f5)
  • Loading branch information...
1 parent 0ee9004 commit 6878cde73918c78e9d7d08e5905a782858cae1bd @smpaine committed Aug 25, 2011
Showing with 30 additions and 26 deletions.
  1. +17 −14 SPI_VFD.cpp
  2. +13 −12 SPI_VFD.h
View
@@ -187,8 +187,6 @@ void SPI_VFD::command(uint8_t value) {
// Wait for display to be ready
do {
- //Serial.print("Checking BF... ");
-
// check if display is ready (checking for BF=0)
ready=read_addr();
@@ -213,8 +211,6 @@ void SPI_VFD::write(uint8_t value) {
// Wait for display to be ready
do {
- //Serial.print("Checking BF... ");
-
// check if display is ready (checking for BF=0)
ready=read_addr();
@@ -223,12 +219,12 @@ void SPI_VFD::write(uint8_t value) {
} while (ready);
digitalWrite(_strobe, LOW);
- send(VFD_SPIWRITE);
+ send(VFD_SPIDATAWRITE);
send(value);
digitalWrite(_strobe, HIGH);
/*
- Serial.print(VFD_SPIWRITE, HEX);
+ Serial.print(VFD_SPIDATAWRITE, HEX);
Serial.print('\t');
Serial.println(value, HEX);
*/
@@ -239,15 +235,14 @@ uint8_t SPI_VFD::read_addr() {
digitalWrite(_strobe, LOW);
send(VFD_SPIADDREAD);
- delayMicroseconds(1);
value=recv();
digitalWrite(_strobe, HIGH);
/*
Serial.print(VFD_SPIADDREAD, HEX);
Serial.print('\t');
Serial.println(value, HEX);
- */
+ */
return value;
}
@@ -275,20 +270,28 @@ inline void SPI_VFD::send(uint8_t c) {
// read spi data
inline uint8_t SPI_VFD::recv() {
- int8_t i,c;
+ int8_t i, c;
+ pinMode(_data, INPUT);
digitalWrite(_clock, HIGH);
+ c = 0;
+
for (i=7; i>=0; i--) {
// pull clock low
digitalWrite(_clock, LOW);
- // read next value from display
- c|=digitalRead(_data);
+
// make room for next value
- if (i) {
- c<<=1;
- }
+ c <<= 1;
+
+ // read next value from display
+ c |= digitalRead(_data);
+
// pull clock high to prepare for next read
digitalWrite(_clock, HIGH);
}
+
+ pinMode(_data, OUTPUT);
+
+ return c;
}
View
@@ -43,7 +43,8 @@
#define VFD_BRIGHTNESS100 0x00
#define VFD_SPICOMMAND 0xF8
-#define VFD_SPIWRITE 0xFA
+#define VFD_SPIDATAWRITE 0xFA
+#define VFD_SPIDATAREAD 0xFE
#define VFD_SPIADDREAD 0xFC
class SPI_VFD : public Print {
@@ -75,20 +76,20 @@ class SPI_VFD : public Print {
void setCursor(uint8_t, uint8_t);
virtual void write(uint8_t);
virtual uint8_t read_addr();
- void command(uint8_t);
- private:
- inline void send(uint8_t data);
- inline uint8_t recv();
+ void command(uint8_t);
+private:
+ inline void send(uint8_t data);
+ inline uint8_t recv();
- uint8_t _clock, _data, _strobe; // SPI interface
+ uint8_t _clock, _data, _strobe; // SPI interface
- uint8_t _displayfunction;
- uint8_t _displaycontrol;
- uint8_t _displaymode;
+ uint8_t _displayfunction;
+ uint8_t _displaycontrol;
+ uint8_t _displaymode;
- uint8_t _initialized;
+ uint8_t _initialized;
- uint8_t _numlines, _currline;
- };
+ uint8_t _numlines, _currline;
+};
#endif

0 comments on commit 6878cde

Please sign in to comment.