Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sun Jan 25 17:52:55 2015 +0000
Parent:
6:aaefa04f06be
Commit message:
Test of PCF8574 Bus interface to control HDSP253X Smart Alphanumeric LED matrix display.

Changed in this revision

BusDefines.h Show diff for this revision Revisions of this file
BusEnums.h Show diff for this revision Revisions of this file
PCF8574_AddressBus.cpp Show diff for this revision Revisions of this file
PCF8574_AddressBus.h Show diff for this revision Revisions of this file
PCF8574_Bus.lib Show annotated file Show diff for this revision Revisions of this file
PCF8574_DataBus.cpp Show diff for this revision Revisions of this file
PCF8574_DataBus.h Show diff for this revision Revisions of this file
PCF8574_EnableBus.cpp Show diff for this revision Revisions of this file
PCF8574_EnableBus.h Show diff for this revision Revisions of this file
main.cpp.orig Show annotated file Show diff for this revision Revisions of this file
mbed.bld.orig Show annotated file Show diff for this revision Revisions of this file
diff -r aaefa04f06be -r 8680b8b718c8 BusDefines.h
--- a/BusDefines.h	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/* BusDefines - Use the MBED Port pins and PCF8574s for controlling the Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#ifndef _BUS_DEFINES_H
-#define _BUS_DEFINES_H
-
-
-//Pin Defines for MBED Control Bus (inputs)
-#define D_CDINT                p20
-//Pin Defines for MBED Control Bus (outputs)
-#define D_DTR                  p21
-#define D_CDBUF                p22
-#define D_RD                   p23
-#define D_WR                   p24
-
-#define D_CTRL_MSK             0xFF
-
-//Pin Defines for I2C Bus
-//#define D_SDA                  p9
-//#define D_SCL                  p10
-#define D_SDA                  p28
-#define D_SCL                  p27
-
-//I2C Bus Address Defines for PCF8574 slaves
-#define D_I2C_DATA_BUS        0x40
-#define D_I2C_ADDR_BUS        0x42
-#define D_I2C_ENA_BUS         0x44
-
-
-//Host PC Baudrate (Virtual Com Port on USB)
-#define D_BAUDRATE            9600
-//#define D_BAUDRATE            57600
-
-#endif
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 BusEnums.h
--- a/BusEnums.h	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-/* BusEnums - Use the MBED Port pins and PCF8574s for controlling the Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#ifndef _BUS_ENUMS_H
-#define _BUS_ENUMS_H
-
-//Enums for Control Bus and Enable Bus
-enum Bit_Level { LOW, HIGH };
-enum Bus_Dir   { READ, WRITE };
-enum Bus_Ena   { ENABLE, DISABLE };
-
-
-#endif
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_AddressBus.cpp
--- a/PCF8574_AddressBus.cpp	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/* PCF8574_AddressBus - Use the PCF8574 I2C Port Extender for controlling the Address Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#include "mbed.h"
-#include "PCF8574_AddressBus.h"
-
-/** Create an PCF8574_AddressBus object connected to the specified I2C object and using the specified deviceAddress
- *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the PCF8574
-*/
-PCF8574_AddressBus::PCF8574_AddressBus(I2C &i2c, char deviceAddress) : _i2c(i2c) {
-   _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
-   _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read
-   _init();
-}
-
-/** Optimised AddressBus write operation.
- * @param address the addressvalue to output on the bus
-*/
-void PCF8574_AddressBus::write(char address) {
-    char data[1];
-    
-    data[0] = address;
-    _i2c.write(_writeOpcode, data, 1);    // Write addressvalue to bus   
-}
-
-
-/** Init PCF8574_AddressBus
- * @param
- * @returns 
- */
-void PCF8574_AddressBus::_init() {
- 
-    write(0x00);
-}
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_AddressBus.h
--- a/PCF8574_AddressBus.h	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/* PCF8574_AddressBus - Use the PCF8574 I2C Port Extender for controlling the Address Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#ifndef _PCF8574_ADDRESSBUS_H
-#define _PCF8574_ADDRESSBUS_H
-
-
-//Pin Defines for PCF8574 Address Bus
-#define D_A0                   0x01
-#define D_A1                   0x02
-#define D_A2                   0x04
-#define D_A3                   0x08
-#define D_A4                   0x10
-#define D_A5                   0x20
-#define D_A6                   0x40
-#define D_A7                   0x80
-
-#define D_ADDR_MSK             0x3F
-
-
-/** Create an PCF8574_AddressBus object connected to the specified I2C object and using the specified deviceAddress
- *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the PCF8574
-*/
-class PCF8574_AddressBus {
-public:
-    PCF8574_AddressBus(I2C &i2c, char deviceAddress);
-    void write(char address);
-protected:
-    I2C &_i2c;
-    char _readOpcode;
-    char _writeOpcode; 
-    void _init(); 
-};
-
-#endif
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_Bus.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCF8574_Bus.lib	Sun Jan 25 17:52:55 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/wim/code/PCF8574_Bus/#12207c70f4ea
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_DataBus.cpp
--- a/PCF8574_DataBus.cpp	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/* PCF8574_DataBus - Use the PCF8574 I2C Port Extender for controlling the Data Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#include "mbed.h"
-#include "PCF8574_DataBus.h"
-
-/** Create an PCF8574_DataBus object connected to the specified I2C object and using the specified deviceAddress
- *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the PCF8574
-*/
-PCF8574_DataBus::PCF8574_DataBus(I2C &i2c, char deviceAddress) : _i2c(i2c) {
-   _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
-   _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read
-   _init();
-}
-
-/** Optimised DataBus write operation.
- * @param byte the datavalue to output on the bus
-*/
-void PCF8574_DataBus::write(char byte) {
-    char data[1];
-    
-    data[0] = byte;
-    _i2c.write(_writeOpcode, data, 1);    // Write datavalue to bus   
-}
-
-/** Optimised DataBus read operation.
- *
- * @returns current data from Databus 
-*/
-char PCF8574_DataBus::read() {
-    char data[1];
-
-//Make sure that databus is enabled for Read
-//    data[0] = 0xFF;                       // Init Port for datainput by Writing 0xFF 
-//   _i2c.write(_writeOpcode, data, 1);    // Write to bus   
-    
-    _i2c.read(_readOpcode, data, 1);      // Read data from bus
-     
-   return data[0];
-}
-
-
-/** Enable databus for Write or Read
- *
- * @param Bus_Dir bus_dir
-*/
-void PCF8574_DataBus::busdir (Bus_Dir bus_dir) {
-
-    if (bus_dir == READ) {
-      // Make sure that databus is enabled for READ
-      write(0xFF);                          // Init Port as input by Writing 0xFF 
-            
-    }                
-    else {
-      // Make sure that databus is enabled for WRITE   
-      write(0xFF);                          // Not really needed, just Init Port to safe settings
-    }      
-}
-
-
-
-/** Init PCF8574_DataBus
- * @param
- * @returns 
- */
-void PCF8574_DataBus::_init() {
- 
-    busdir(WRITE);                          // Init Port as output 
-}
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_DataBus.h
--- a/PCF8574_DataBus.h	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/* PCF8574_DataBus - Use the PCF8574 I2C Port Extender for controlling the Data Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#ifndef _PCF8574_DATABUS_H
-#define _PCF8574_DATABUS_H
-
-//Pin Defines for PCF8574 Data Bus
-#define D_D0                   0x01
-#define D_D1                   0x02
-#define D_D2                   0x04
-#define D_D3                   0x08
-#define D_D4                   0x10
-#define D_D5                   0x20
-#define D_D6                   0x40
-#define D_D7                   0x80
-
-#define D_DATA_MSK             0xFF
-
-//Enums for Data Bus
-#include "BusEnums.h"
-
-
-/** Create an PCF8574_DataBus object connected to the specified I2C object and using the specified deviceAddress
- *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the PCF8574
-*/
-class PCF8574_DataBus {
-public:
-    PCF8574_DataBus(I2C &i2c, char deviceAddress);
-    char read();
-    void write(char byte);
-    void busdir (Bus_Dir bus_dir);    
-protected:
-    I2C &_i2c;
-    char _readOpcode;
-    char _writeOpcode; 
-    void _init(); 
-};
-
-#endif
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_EnableBus.cpp
--- a/PCF8574_EnableBus.cpp	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-/* PCF8574_EnableBus - Use the PCF8574 I2C Port Extender for controlling the Chip Enable Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#include "mbed.h"
-#include "PCF8574_EnableBus.h"
-
-
-/** Create an PCF8574_EnableBus object connected to the specified I2C object and using the specified deviceAddress
- *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the PCF8574
-*/
-PCF8574_EnableBus::PCF8574_EnableBus(I2C &i2c, char deviceAddress) : _i2c(i2c) {
-   _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
-   _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read
-   _init();
-}
-
-
-/** Set or Reset Chip Select pins on Enable Bus
- *
- * @param CS_Pin cs_pin 
- * @param Bit_Level cs_level
-*/
-void PCF8574_EnableBus::chipselect (CS_Pin cs_pin, Bit_Level cs_level) {
-    int result = 1;
-      
-    switch (cs_pin) {
-     case CS_SWITCH : if (cs_level == LOW)
-                         _enable_bus = ~D_CS_SWITCH; // CS Pin Low, make sure that only one CS is active
-                      else
-                         _enable_bus |= D_CS_SWITCH; // CS Pin High
-                      break;
-     case LATCHEN_1 : if (cs_level == LOW)
-                         _enable_bus = ~D_LATCHEN_1; // CS Pin Low, make sure that only one CS is active
-                      else
-                         _enable_bus |= D_LATCHEN_1; // CS Pin High
-                      break;
-     case LATCHEN_2 : if (cs_level == LOW)
-                         _enable_bus = ~D_LATCHEN_2; // CS Pin Low, make sure that only one CS is active
-                      else
-                         _enable_bus |= D_LATCHEN_2; // CS Pin High
-                      break;
-     case CS_BRIGHT : if (cs_level == LOW)
-                         _enable_bus = ~D_CS_BRIGHT; // CS Pin Low, make sure that only one CS is active
-                      else
-                         _enable_bus |= D_CS_BRIGHT; // CS Pin High
-                      break;
-     case CS_DISP : if (cs_level == LOW)
-                         _enable_bus = ~D_CS_DISP;   // CS Pin Low, make sure that only one CS is active
-                      else
-                         _enable_bus |= D_CS_DISP;   // CS Pin High
-                      break;
-     
-     default:          // Oops, we should never end up here....
-                      result = -1;
-    }
-
-    _write();                              // Write chip enable bits to bus
-}
-
-/** Set or Clear the Reset pin on Enable Bus
- *
- * @param Bit_Level rst_level
-*/
-void PCF8574_EnableBus::reset (Bit_Level rst_level) {
-
-    if (rst_level == LOW) {
-        _reset_pin = 0x00;                 // Reset Pin Low
-      }               
-    else {
-        _reset_pin = D_RESET;              // Reset Pin High
-    }     
-    
-    _write();                              // Write RST bit to bus
-}
- 
-               
-/** Set or Clear the NoGo pin on Enable Bus
- *
- * @param Bit_Level nogo_level
-*/
-void PCF8574_EnableBus::nogo (Bit_Level nogo_level) {
-
-    if (nogo_level == LOW) {
-        _nogo_pin = 0x00;                  // NOGO Pin Low
-      }               
-    else {
-        _nogo_pin = D_NOGO;                // NOGO Pin High
-    }     
-    
-    _write();                              // Write NoGo bit to bus
-}
- 
-
-/** Optimised EnableBus write operation.
- * @param byte the value to output on the bus
-*/
-void PCF8574_EnableBus::_write(char byte) {
-    char data[1];
-    
-    data[0] = byte;
-    _i2c.write(_writeOpcode, data, 1);    // Write value to bus   
-}
-
-/** Optimised EnableBus write operation.
- * @param 
-*/
-void PCF8574_EnableBus::_write() {
-    char data[1];
-    
-    data[0] = (_enable_bus & D_ENABLE_MSK) | _reset_pin | _nogo_pin;      // Combine enable bits and control bits
-    _i2c.write(_writeOpcode, data, 1);    // Write value to bus   
-}
-
-
-/** Init PCF8574_EnableBus
- * @param
- * @returns 
- */
-void PCF8574_EnableBus::_init() {
-    _enable_bus = 0xFF;                    // Make sure that all CS pins are disabled
-    _reset_pin  = D_RESET;                 // Make sure that Reset pin is disabled
-    _nogo_pin   = D_NOGO;                  // Make sure that NoGo pin is disabled    
-    _write();                              // Write value to bus    
-}
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 PCF8574_EnableBus.h
--- a/PCF8574_EnableBus.h	Sun Jan 25 17:30:47 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-/* PCF8574_EnableBus - Use the PCF8574 I2C Port Extender for controlling the Chip Enable Bus
- * Copyright (c) 2011 Wim Huiskamp
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * version 0.2 Initial Release
-*/
-#ifndef _PCF8574_ENABLEBUS_H
-#define _PCF8574_ENABLEBUS_H
-
-//Pin Defines for PCF8574 Enable Bus
-//Note: 'Reset' causes all devices on the 'Control & Display Unit' to be reset!
-#define D_CS_SWITCH            0x01
-#define D_LATCHEN_1            0x02
-#define D_LATCHEN_2            0x04
-#define D_CS_BRIGHT            0x08
-#define D_CS_DISP              0x10
-#define D_CS_SPARE             0x20
-#define D_RESET                0x40
-#define D_NOGO                 0x80
-
-#define D_ENABLE_MSK           0x3F
-
-//Enums for Enable Bus
-#include "BusEnums.h"
-enum CS_Pin { CS_SWITCH, LATCHEN_1, LATCHEN_2, CS_BRIGHT, CS_DISP, CS_SPARE };
-
-
-/** Create an PCF8574_EnableBus object connected to the specified I2C object and using the specified deviceAddress
- *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the PCF8574
-*/
-class PCF8574_EnableBus {
-public:
-    PCF8574_EnableBus(I2C &i2c, char deviceAddress);
-    void chipselect (CS_Pin cs_pin, Bit_Level cs_level);
-    void reset (Bit_Level rst_level);
-    void nogo (Bit_Level nogo_level);
-protected:
-    I2C &_i2c;
-    char _readOpcode;
-    char _writeOpcode; 
-    char _enable_bus;   
-    char _reset_pin;   
-    char _nogo_pin;   
-//    char _read();
-    void _write();  
-    void _write(char byte);      
-    void _init(); 
-};
-
-#endif
\ No newline at end of file
diff -r aaefa04f06be -r 8680b8b718c8 main.cpp.orig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp.orig	Sun Jan 25 17:52:55 2015 +0000
@@ -0,0 +1,363 @@
+/* mbed bus - Main
+ * Copyright (c) 2011 Wim Huiskamp
+ *
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * version 0.2 Initial Release
+*/
+#include "mbed.h"
+#include "BusDefines.h"
+#include "PCF8574_DataBus.h"
+#include "PCF8574_AddressBus.h"
+#include "PCF8574_EnableBus.h"
+#include "MBED_ControlBus.h"
+#include "HDSP253X.h"
+  
+// Debug stuff
+#define __DEBUG  
+#include "Dbg.h"
+
+// mbed Interface Hardware definitions
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut heartbeatLED(LED4);
+
+// Host PC Communication channels
+Serial pc(USBTX, USBRX);
+
+//I2C Bus
+I2C i2c(D_SDA, D_SCL);
+
+// Bus Interface Hardware definitions
+PCF8574_DataBus    databus = PCF8574_DataBus(i2c, D_I2C_DATA_BUS);  //Copy constructors..
+PCF8574_AddressBus addressbus = PCF8574_AddressBus(i2c, D_I2C_ADDR_BUS);
+PCF8574_EnableBus  enablebus = PCF8574_EnableBus(i2c, D_I2C_ENA_BUS);
+MBED_ControlBus  controlbus = MBED_ControlBus(D_WR, D_RD, D_DTR, D_CDBUF, D_CDINT);
+
+// Display Hardware definitions
+HDSP253X_Display LED_display = HDSP253X_Display(databus, addressbus, enablebus, controlbus);
+
+// Dummy delay
+#define DEVICE_WAIT_MS   0
+
+
+// Variables for Heartbeat and Status monitoring
+Ticker heartbeat;
+bool heartbeatflag=false;
+
+// Cycle Timer
+Timer cycletimer;
+int cyclecount = 0;
+const int maxcount = 10;
+
+// Local functions
+void clear_screen() {
+//ANSI Terminal Commands
+    pc.printf("\x1B[2J");
+    pc.printf("\x1B[H");
+}
+
+
+void init_interfaces() {
+// Init Host PC communication, default is 9600
+    pc.baud(D_BAUDRATE);
+      
+// Init I/F hardware
+    i2c.frequency(100000);  
+  
+    //Done, Tell me about it
+    myled1 = 1;
+//    DBG("Init Interfaces Done\r");    
+}
+      
+
+// Heartbeat monitor
+void pulse() {
+  heartbeatLED = !heartbeatLED;
+}
+
+void heartbeat_start() {
+  heartbeat.attach(&pulse, 0.5);
+  heartbeatflag = true;
+}
+
+void heartbeat_stop() {
+  heartbeat.detach();
+  heartbeatflag = false;
+}
+
+void show_LEDS () {
+  static int state = 0;
+ 
+  switch (state) {
+   case 0: 
+        myled1 = 1;
+        myled2 = 0;
+        myled3 = 0;
+        state = 1;
+        break;
+   case 1: 
+        myled1 = 0;
+        myled2 = 1;
+        myled3 = 0;
+        state = 2;
+        break;
+   case 2:     
+        myled1 = 0;
+        myled2 = 0;
+        myled3 = 1;
+        state = 0;
+        break;
+   }
+}
+
+
+// The next two functions are examples of low-level reading and writing to a device that is connected on the mbed bus.
+// In your own application you can develop a Class for each specific slave device and include modified versions of the 
+// functions below as 'private' functions. This allows you to hardcode the device CS_pin signals, define specific delays
+// when needed, change the sequence of CS, WR etc or mask out certain address or databits when they are not used in a certain case.
+//
+
+/*---------------------------------------------------------------------------*\
+ |
+ |  Function:       write
+ |
+ |  Description:    Low level data write routine for device. Takes in data
+ |                  and address and CS pin to identify the device and writes
+ |                  data to the display. For simplicity, entire address byte
+ |                  is written, even though top two bits are unused inputs.
+ |                  After performing the operation, address lines are set
+ |                  all high, in order to eliminate current drain through
+ |                  pullup resistors (0.5mA per pin with 10K pullups)
+ |
+ |  Parameters:     address - full address in bits 0-5
+ |                  device  - enum CS_Pin for Chip Select pin
+ |                  data - data byte to write out
+ |
+ |  Returns:        Nothing.
+ |
+\*---------------------------------------------------------------------------*/
+
+void write(uint8_t address, CS_Pin device, uint8_t data)
+{
+//    // Switch databus buffer to outputs (note: this is the default state)
+//    controlbus.busdir(WRITE);        
+//    // Switch databus to outputs
+//    databus.busdir(WRITE);   
+
+    
+    // Write out the address on to the addressbus and wait
+    addressbus.write(address);
+    wait_ms(DEVICE_WAIT_MS);
+
+    // Set CE low and wait
+    enablebus.chipselect(device, LOW);  
+    wait_ms(DEVICE_WAIT_MS);
+
+    // Write data to the databus
+    databus.write(data);        
+    wait_ms(DEVICE_WAIT_MS);
+     
+    // Set WR low, wait, then set high and wait
+    controlbus.WR(LOW);
+    wait_ms(DEVICE_WAIT_MS);
+    controlbus.WR(HIGH);
+    wait_ms(DEVICE_WAIT_MS);
+
+    // Set CE high and wait
+    enablebus.chipselect(device, HIGH);  
+    wait_ms(DEVICE_WAIT_MS);
+    
+//    // Switch databus back to inputs
+//    databus.busdir(READ);        
+//    // Switch databus buffer back to inputs
+//    controlbus.busdir(READ);  
+
+//    // Set address lines all high to minimise power through pullups
+//    addressbus.write(0xFF);
+}
+
+/*---------------------------------------------------------------------------*\
+ |
+ |  Function:       read
+ |
+ |  Description:    Low level data read routine for a Device. Takes in 
+ |                  address and CS pin to identify the device and then 
+ |                  reads data from the device.
+ |                  After performing the operation, address lines are set
+ |                  all high, in order to eliminate current drain through
+ |                  pullup resistors (0.5mA per pin with 10K pullups)
+ |
+ |  Parameters:     address - 8 bit address
+ |                  device  - enum CS_Pin for Chip Select pin
+ |  Returns:        data - data byte read
+ |
+\*---------------------------------------------------------------------------*/
+
+uint8_t read(uint8_t address, CS_Pin device)
+{
+    uint8_t data = 0;
+
+    // Switch databus to inputs (default state is output)
+    databus.busdir(READ);        
+    // Switch databus buffer to inputs
+    controlbus.busdir(READ);      
+       
+    // Write out the address on to the addressbus and wait
+    addressbus.write(address);
+    wait_ms(DEVICE_WAIT_MS);
+
+    // Set CE low and wait
+    enablebus.chipselect(device, LOW);
+    wait_ms(DEVICE_WAIT_MS);
+
+    // Set RD low and wait
+    controlbus.RD(LOW);
+    wait_ms(DEVICE_WAIT_MS);
+    
+    // Read the data byte from databus
+    data = databus.read();
+
+    // set RD high and wait
+    controlbus.RD(HIGH);
+    wait_ms(DEVICE_WAIT_MS);
+
+    // Set CE high and wait
+    enablebus.chipselect(device, HIGH);
+    wait_ms(DEVICE_WAIT_MS);
+
+//    // Set address lines all high to minimise power through pullups
+//    addressbus.write(0xFF);
+
+    // Switch databus buffer back to outputs
+    controlbus.busdir(WRITE);        
+    // Switch databus to outputs
+    databus.busdir(WRITE);   
+    
+    // Return read data to caller
+    return data;
+}
+
+
+void HDSP_BITE() {
+  int count;
+    
+    for (count=0; count<5; count++) {
+      LED_display.locate(0);
+      LED_display.printf("BITE  - ");
+      wait(0.05);                    
+      LED_display.locate(0);         
+      LED_display.printf("BITE  \\ ");
+      wait(0.05);                              
+      LED_display.locate(0);        
+      LED_display.printf("BITE  | ");
+      wait(0.05);              
+      LED_display.locate(0);    
+      LED_display.printf("BITE  / ");    
+      wait(0.05);      
+      LED_display.locate(0);    
+      LED_display.printf("BITE  - ");                
+      wait(0.05);      
+    };
+
+    LED_display.locate(0);    
+    LED_display.printf("BITE  OK"); 
+
+    LED_display.set_blink_mode(true);            
+    wait(2.0);          
+    LED_display.set_blink_mode(false);
+                    
+    LED_display.cls();  
+
+    //Done, Tell me about it                        
+//    DBG("BITE Done, Main, Step = %d\r", 30);    
+}
+
+void HDSP_Init_UDC() {
+
+// batt empty
+  LED_display.define_user_char(0, 0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F);
+// batt full  
+  LED_display.define_user_char(1, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F);  
+}  
+  
+
+void HDSP_Show_UDC() {
+ 
+  LED_display.locate(0);    
+  LED_display.printf("Batt "); 
+//  LED_display.putc(HDSP253X_ASCII_UDC_CHARS + 0); 
+//  LED_display.putc(HDSP253X_ASCII_UDC_CHARS + 1); 
+  LED_display.putudc(0); 
+  LED_display.putudc(1); 
+    
+  wait(2.0);          
+}
+
+int main() {
+    int address;
+    uint8_t dummy;
+
+    init_interfaces();
+    
+    heartbeat_start();
+          
+    clear_screen(); 
+    
+    HDSP_Init_UDC();
+            
+//    DBG("Start Main Loop\r");    
+
+//Testing stuff
+        
+    //Test cycletime
+    cycletimer.start();      
+    cycletimer.reset();
+
+
+#if (1)
+// Bus test
+    while (1) {
+      for (address=0; address<256; address++) {
+        //data = read(address, CS_SWITCH);
+        
+        dummy = ~address;
+        write(address, LATCHEN_1, dummy); 
+//        wait(0.05);       
+      }    
+    
+      // Just for Info, lets see how fast this cycle is...
+      cyclecount++;
+      if (cyclecount == maxcount) {
+        pc.printf("Freq = %d Hz\r", (cyclecount * 256 * 1000) / cycletimer.read_ms());
+        cyclecount = 0;          
+        cycletimer.reset();      
+      }
+      
+      show_LEDS ();      
+    }
+#else
+// LED Display test
+    while (1) {
+      HDSP_BITE();   
+
+      cyclecount++;
+      if (cyclecount == 10) {
+        cyclecount = 0;
+//        LED_display.printf ("Restart ");
+        HDSP_Show_UDC();         
+      }       
+      else {
+        LED_display.printf ("Cnt=  %2d", cyclecount);      
+      }
+      wait(2.0);
+      pc.printf ("."); 
+                     
+      show_LEDS ();      
+    }
+
+#endif
+      
+    //DBG("I'll be back...\r\r");
+}
diff -r aaefa04f06be -r 8680b8b718c8 mbed.bld.orig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld.orig	Sun Jan 25 17:52:55 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
\ No newline at end of file