I2C Steuerung by Matthias Hemmer
Revision 0:266ede55f588, committed 2016-02-05
- Comitter:
- hemmer_matthias
- Date:
- Fri Feb 05 18:13:27 2016 +0000
- Commit message:
- Projekt Bulme Drohne;
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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2C.cpp Fri Feb 05 18:13:27 2016 +0000 @@ -0,0 +1,79 @@ +#include "mbed.h" +#include "I2C.h" + +I2C i2c(p28, p27); + +void PC9555_init(){ + + char data[2]; // Initialisierung der Befehle/Zustände + +//------------------------Port 0---------------------------------------------------------------- + // Definieren der Befehle/Zustände + data[0] = Port0_InPut; // Zuerst die gewünschte Adresse + data[1] = 0x00; // Wird als Ausgang definiert (Zustand definieren) + + i2c.write(PC9555_ADDR, data, 2); // Schreiben auf die Adresse des I2C's +//------------------------Port 1---------------------------------------------------------------- + data[0] = Port1_InPut; + data[1] = 0x00; + + i2c.write(PC9555_ADDR, data, 2); + //------------------------Port 2---------------------------------------------------------------- + data[0] = Port2_OutPut; + data[1] = 0x00; + + i2c.write(PC9555_ADDR, data, 2); +//------------------------Port 3---------------------------------------------------------------- + data[0] = Port3_OutPut; + data[1] = 0x00; + + i2c.write(PC9555_ADDR, data, 2); +//------------------------Port 4---------------------------------------------------------------- + data[0] = Port4_PolarityInvert; + data[1] = 0xFF; // Würde dies als Eingang setzten, aber diese eingänge sind Invertiert + + i2c.write(PC9555_ADDR, data, 2); +//------------------------Port 5---------------------------------------------------------------- + data[0] = Port5_PolarityInvert; + data[1] = 0xFF; + + i2c.write(PC9555_ADDR, data, 2); +//------------------------Port 6---------------------------------------------------------------- + data[0] = Port6_Config; + data[1] = 0x00; + + i2c.write(PC9555_ADDR, data, 2); +//------------------------Port 7---------------------------------------------------------------- + data[0] = Port7_Config; + data[1] = 0x00; + + i2c.write(PC9555_ADDR, data, 2); +//------------------------Ende------------------------------------------------------------------ +}// Ende bertl_PC9555_init + +void LEDs(unsigned char led){ + char data[2]; + + data[0] = Port2_OutPut; + data[1] = ~led; + + i2c.write(PC9555_ADDR, data, 2); +}// Ende LEDs + +unsigned char Switch(){ + + char data[1]; + + data[0] = Port1_InPut; + i2c.write(PC9555_ADDR, data, 1, true); // Schreiben eines Bits, nicht STOPEN + i2c.read(PC9555_ADDR, data, 1, false); // Lesen eines Bits und dann STOPEN + + return((unsigned char) data[0]); +}// Ende Switch + + + + + + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2C.h Fri Feb 05 18:13:27 2016 +0000 @@ -0,0 +1,40 @@ + + +// Definieren der Input port registers +#define Port0_InPut (0) +#define Port1_InPut (1) + +// Definieren der Outout port registers +#define Port2_OutPut (2) +#define Port3_OutPut (3) + +// Definieren der Polaroty Inversion registers +#define Port4_PolarityInvert (4) +#define Port5_PolarityInvert (5) + +// Definieren der Configuration registers +#define Port6_Config (6) +#define Port7_Config (7) + +// PC9555-defines +#define PC9555_ADDR 0x40 // A2 = A1 = A0 = 0 +#define PC9555_FREQUENCY 100000 // f in Hz + +// 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 + +void PC9555_init(); +void LEDs(unsigned char led); +unsigned char Switch(); \ No newline at end of file