asd

Files at this revision

API Documentation at this revision

Comitter:
hemmer_matthias
Date:
Mon Feb 29 12:06:30 2016 +0000
Commit message:
bla

Changed in this revision

I2C.cpp Show annotated file Show diff for this revision Revisions of this file
I2C.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d7de08989175 I2C.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2C.cpp	Mon Feb 29 12:06:30 2016 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#include "I2C.h"
+
+I2C pc9555 (p28, p27);    //SDA,SCL
+
+void bertl_PC9555_init()
+{
+    char data[2];
+    
+    // I2C Initialisierung
+    pc9555.frequency(PC9555_FREQUENCY);
+    
+    // Port 0 = LEDs
+    
+    // Adresse, RW# = 0, Config Port 0 (6) = 0x00 (=OutPut), Stop
+    data[0] = PC9555_Port0_DIR_IN;
+    data[1] = 0x00;     // Output    
+    pc9555.write(PC9555_ADDR, data, 2);  
+    
+    // Adresse, RW# = 0, Config Port 1 (7) = 0x00 (=InPut), Stop
+    data[0] = PC9555_Port1_DIR_IN;
+    data[1] = 0xFF;     // Input
+    pc9555.write(PC9555_ADDR, data, 2);  
+    
+    // Adresse, RW# = 0, Polarity Inversion Port 0 (4) = 0xFF (= inverted) , Stop  
+    data[0] = PC9555_Port0_INV;
+    data[1] = 0xFF;
+    pc9555.write(PC9555_ADDR, data, 2); 
+    
+     // Adresse, RW# = 0, Polarity Inversion Port 1 (5) = 0x00 (=NonInverted) , Stop
+    data[0] = PC9555_Port1_INV;
+    data[1] = 0x00;
+    pc9555.write(PC9555_ADDR, data, 2);      
+}
+
+void bertl_PC9555_leds(unsigned char leds)
+{
+    char data[2];   // Two Bytes for Transmitt via I2C
+    
+    // Send leds to Port0 of PC9555 tp I2C: 
+    // Start, Adress, RW# = 0, CMD I2C_Port0_OUT , leds, Stop
+    data[0] = PC9555_Port0_OUT;
+    data[1] = ~leds;        //bitwise inversion since HW is switched on with 0 (invers logic)
+    pc9555.write(PC9555_ADDR, data, 2);
+}
+
+unsigned char bertl_PC9555_switches()
+{
+    char data[1];
+    data[0] = PC9555_Port1_IN;
+    pc9555.write(PC9555_ADDR, data, 1, true); // tell him, we want to read Port1, no STOP
+    pc9555.read(PC9555_ADDR, data, 1, false); // read 1 byte, then send STOP
+    return((unsigned char) data[0]);
+}
\ No newline at end of file
diff -r 000000000000 -r d7de08989175 I2C.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2C.h	Mon Feb 29 12:06:30 2016 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+
+// LED-Defines
+#define LED_FL_WHITE    0x01 // 0b0000 0001
+#define LED_FR_WHITE    0x04 // 0b0000 0100
+#define LED_FL_ORANGE   0x02 // 0b0000 0010
+#define LED_FR_ORANGE   0x08 // 0b0000 1000
+#define LED_BL_ORANGE   0x20 // 0b0010 0000
+#define LED_BR_ORANGE   0x80 // 0b1000 0000
+#define LED_BL_RED      0x10 // 0b0001 0000
+#define LED_BR_RED      0x40 // 0b0100 0000
+
+#define LED_L_ORANGE (LED_FL_ORANGE | LED_BL_ORANGE) // 0b0000 0010 | 0b0010 0000 = 0b0010 0010
+#define LED_R_ORANGE (LED_FR_ORANGE | LED_BR_ORANGE) // right blinkers    
+#define LED_WHITE    (LED_FL_WHITE  | LED_FR_WHITE)  // front light
+#define LED_RED      (LED_BL_RED    | LED_BR_RED)    //back light
+
+#define SW_FM 0x04
+#define SW_FL
+#define SW_FR
+#define SW_F (SW_FM|SW_FL|SW_FR)
+
+// PC9555-defines
+#define PC9555_ADDR 0x40 // A2 = A1 = A0 = 0
+#define PC9555_FREQUENCY 100000 // f in Hz
+
+//PC9555 Commands
+#define PC9555_Port0_IN (0)
+#define PC9555_Port1_IN (1)
+#define PC9555_Port0_OUT (2)
+#define PC9555_Port1_OUT (3)
+#define PC9555_Port0_INV (4)
+#define PC9555_Port1_INV (5)
+#define PC9555_Port0_DIR_IN (6)
+#define PC9555_Port1_DIR_IN (7)
+
+void bertl_PC9555_init();
+void bertl_PC9555_leds(unsigned char leds);
+unsigned char bertl_PC9555_switches();
\ No newline at end of file