I2C Steuerung by Matthias Hemmer

Committer:
hemmer_matthias
Date:
Fri Feb 05 18:13:27 2016 +0000
Revision:
0:266ede55f588
Projekt Bulme Drohne;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hemmer_matthias 0:266ede55f588 1 #include "mbed.h"
hemmer_matthias 0:266ede55f588 2 #include "I2C.h"
hemmer_matthias 0:266ede55f588 3
hemmer_matthias 0:266ede55f588 4 I2C i2c(p28, p27);
hemmer_matthias 0:266ede55f588 5
hemmer_matthias 0:266ede55f588 6 void PC9555_init(){
hemmer_matthias 0:266ede55f588 7
hemmer_matthias 0:266ede55f588 8 char data[2]; // Initialisierung der Befehle/Zustände
hemmer_matthias 0:266ede55f588 9
hemmer_matthias 0:266ede55f588 10 //------------------------Port 0----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 11 // Definieren der Befehle/Zustände
hemmer_matthias 0:266ede55f588 12 data[0] = Port0_InPut; // Zuerst die gewünschte Adresse
hemmer_matthias 0:266ede55f588 13 data[1] = 0x00; // Wird als Ausgang definiert (Zustand definieren)
hemmer_matthias 0:266ede55f588 14
hemmer_matthias 0:266ede55f588 15 i2c.write(PC9555_ADDR, data, 2); // Schreiben auf die Adresse des I2C's
hemmer_matthias 0:266ede55f588 16 //------------------------Port 1----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 17 data[0] = Port1_InPut;
hemmer_matthias 0:266ede55f588 18 data[1] = 0x00;
hemmer_matthias 0:266ede55f588 19
hemmer_matthias 0:266ede55f588 20 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 21 //------------------------Port 2----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 22 data[0] = Port2_OutPut;
hemmer_matthias 0:266ede55f588 23 data[1] = 0x00;
hemmer_matthias 0:266ede55f588 24
hemmer_matthias 0:266ede55f588 25 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 26 //------------------------Port 3----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 27 data[0] = Port3_OutPut;
hemmer_matthias 0:266ede55f588 28 data[1] = 0x00;
hemmer_matthias 0:266ede55f588 29
hemmer_matthias 0:266ede55f588 30 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 31 //------------------------Port 4----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 32 data[0] = Port4_PolarityInvert;
hemmer_matthias 0:266ede55f588 33 data[1] = 0xFF; // Würde dies als Eingang setzten, aber diese eingänge sind Invertiert
hemmer_matthias 0:266ede55f588 34
hemmer_matthias 0:266ede55f588 35 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 36 //------------------------Port 5----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 37 data[0] = Port5_PolarityInvert;
hemmer_matthias 0:266ede55f588 38 data[1] = 0xFF;
hemmer_matthias 0:266ede55f588 39
hemmer_matthias 0:266ede55f588 40 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 41 //------------------------Port 6----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 42 data[0] = Port6_Config;
hemmer_matthias 0:266ede55f588 43 data[1] = 0x00;
hemmer_matthias 0:266ede55f588 44
hemmer_matthias 0:266ede55f588 45 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 46 //------------------------Port 7----------------------------------------------------------------
hemmer_matthias 0:266ede55f588 47 data[0] = Port7_Config;
hemmer_matthias 0:266ede55f588 48 data[1] = 0x00;
hemmer_matthias 0:266ede55f588 49
hemmer_matthias 0:266ede55f588 50 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 51 //------------------------Ende------------------------------------------------------------------
hemmer_matthias 0:266ede55f588 52 }// Ende bertl_PC9555_init
hemmer_matthias 0:266ede55f588 53
hemmer_matthias 0:266ede55f588 54 void LEDs(unsigned char led){
hemmer_matthias 0:266ede55f588 55 char data[2];
hemmer_matthias 0:266ede55f588 56
hemmer_matthias 0:266ede55f588 57 data[0] = Port2_OutPut;
hemmer_matthias 0:266ede55f588 58 data[1] = ~led;
hemmer_matthias 0:266ede55f588 59
hemmer_matthias 0:266ede55f588 60 i2c.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:266ede55f588 61 }// Ende LEDs
hemmer_matthias 0:266ede55f588 62
hemmer_matthias 0:266ede55f588 63 unsigned char Switch(){
hemmer_matthias 0:266ede55f588 64
hemmer_matthias 0:266ede55f588 65 char data[1];
hemmer_matthias 0:266ede55f588 66
hemmer_matthias 0:266ede55f588 67 data[0] = Port1_InPut;
hemmer_matthias 0:266ede55f588 68 i2c.write(PC9555_ADDR, data, 1, true); // Schreiben eines Bits, nicht STOPEN
hemmer_matthias 0:266ede55f588 69 i2c.read(PC9555_ADDR, data, 1, false); // Lesen eines Bits und dann STOPEN
hemmer_matthias 0:266ede55f588 70
hemmer_matthias 0:266ede55f588 71 return((unsigned char) data[0]);
hemmer_matthias 0:266ede55f588 72 }// Ende Switch
hemmer_matthias 0:266ede55f588 73
hemmer_matthias 0:266ede55f588 74
hemmer_matthias 0:266ede55f588 75
hemmer_matthias 0:266ede55f588 76
hemmer_matthias 0:266ede55f588 77
hemmer_matthias 0:266ede55f588 78
hemmer_matthias 0:266ede55f588 79