asd

Committer:
hemmer_matthias
Date:
Mon Feb 29 12:06:30 2016 +0000
Revision:
0:d7de08989175
bla

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hemmer_matthias 0:d7de08989175 1 #include "mbed.h"
hemmer_matthias 0:d7de08989175 2 #include "I2C.h"
hemmer_matthias 0:d7de08989175 3
hemmer_matthias 0:d7de08989175 4 I2C pc9555 (p28, p27); //SDA,SCL
hemmer_matthias 0:d7de08989175 5
hemmer_matthias 0:d7de08989175 6 void bertl_PC9555_init()
hemmer_matthias 0:d7de08989175 7 {
hemmer_matthias 0:d7de08989175 8 char data[2];
hemmer_matthias 0:d7de08989175 9
hemmer_matthias 0:d7de08989175 10 // I2C Initialisierung
hemmer_matthias 0:d7de08989175 11 pc9555.frequency(PC9555_FREQUENCY);
hemmer_matthias 0:d7de08989175 12
hemmer_matthias 0:d7de08989175 13 // Port 0 = LEDs
hemmer_matthias 0:d7de08989175 14
hemmer_matthias 0:d7de08989175 15 // Adresse, RW# = 0, Config Port 0 (6) = 0x00 (=OutPut), Stop
hemmer_matthias 0:d7de08989175 16 data[0] = PC9555_Port0_DIR_IN;
hemmer_matthias 0:d7de08989175 17 data[1] = 0x00; // Output
hemmer_matthias 0:d7de08989175 18 pc9555.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:d7de08989175 19
hemmer_matthias 0:d7de08989175 20 // Adresse, RW# = 0, Config Port 1 (7) = 0x00 (=InPut), Stop
hemmer_matthias 0:d7de08989175 21 data[0] = PC9555_Port1_DIR_IN;
hemmer_matthias 0:d7de08989175 22 data[1] = 0xFF; // Input
hemmer_matthias 0:d7de08989175 23 pc9555.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:d7de08989175 24
hemmer_matthias 0:d7de08989175 25 // Adresse, RW# = 0, Polarity Inversion Port 0 (4) = 0xFF (= inverted) , Stop
hemmer_matthias 0:d7de08989175 26 data[0] = PC9555_Port0_INV;
hemmer_matthias 0:d7de08989175 27 data[1] = 0xFF;
hemmer_matthias 0:d7de08989175 28 pc9555.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:d7de08989175 29
hemmer_matthias 0:d7de08989175 30 // Adresse, RW# = 0, Polarity Inversion Port 1 (5) = 0x00 (=NonInverted) , Stop
hemmer_matthias 0:d7de08989175 31 data[0] = PC9555_Port1_INV;
hemmer_matthias 0:d7de08989175 32 data[1] = 0x00;
hemmer_matthias 0:d7de08989175 33 pc9555.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:d7de08989175 34 }
hemmer_matthias 0:d7de08989175 35
hemmer_matthias 0:d7de08989175 36 void bertl_PC9555_leds(unsigned char leds)
hemmer_matthias 0:d7de08989175 37 {
hemmer_matthias 0:d7de08989175 38 char data[2]; // Two Bytes for Transmitt via I2C
hemmer_matthias 0:d7de08989175 39
hemmer_matthias 0:d7de08989175 40 // Send leds to Port0 of PC9555 tp I2C:
hemmer_matthias 0:d7de08989175 41 // Start, Adress, RW# = 0, CMD I2C_Port0_OUT , leds, Stop
hemmer_matthias 0:d7de08989175 42 data[0] = PC9555_Port0_OUT;
hemmer_matthias 0:d7de08989175 43 data[1] = ~leds; //bitwise inversion since HW is switched on with 0 (invers logic)
hemmer_matthias 0:d7de08989175 44 pc9555.write(PC9555_ADDR, data, 2);
hemmer_matthias 0:d7de08989175 45 }
hemmer_matthias 0:d7de08989175 46
hemmer_matthias 0:d7de08989175 47 unsigned char bertl_PC9555_switches()
hemmer_matthias 0:d7de08989175 48 {
hemmer_matthias 0:d7de08989175 49 char data[1];
hemmer_matthias 0:d7de08989175 50 data[0] = PC9555_Port1_IN;
hemmer_matthias 0:d7de08989175 51 pc9555.write(PC9555_ADDR, data, 1, true); // tell him, we want to read Port1, no STOP
hemmer_matthias 0:d7de08989175 52 pc9555.read(PC9555_ADDR, data, 1, false); // read 1 byte, then send STOP
hemmer_matthias 0:d7de08989175 53 return((unsigned char) data[0]);
hemmer_matthias 0:d7de08989175 54 }