Bertl 2014 Übung

Dependencies:   mbed

Fork of _B14Test8 by BULME_BERTL14

Committer:
Enenkel
Date:
Tue Nov 18 14:17:57 2014 +0000
Revision:
0:951a35674581
Child:
1:d1a664b263dc
Lampentest via I2C 9555

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Enenkel 0:951a35674581 1 #include "mbed.h" // Softwarestand: 19.1.2014
Enenkel 0:951a35674581 2 /*** Portkonfiguration ***/
Enenkel 0:951a35674581 3 Serial pc(USBTX, USBRX); // tx, rx
Enenkel 0:951a35674581 4 I2C i2c(p28,p27);
Enenkel 0:951a35674581 5
Enenkel 0:951a35674581 6 /*** Funktionsdefinitionen ***/
Enenkel 0:951a35674581 7 Ticker sekunden;
Enenkel 0:951a35674581 8 Ticker blink;
Enenkel 0:951a35674581 9
Enenkel 0:951a35674581 10 /*** Variablendefinitionen ***/
Enenkel 0:951a35674581 11 // int x = 1 ;
Enenkel 0:951a35674581 12 // int y = 0 ;
Enenkel 0:951a35674581 13 // bool var1 = false;
Enenkel 0:951a35674581 14
Enenkel 0:951a35674581 15 const int addr = 0x40; // I2C-Adresse PCA9555
Enenkel 0:951a35674581 16 char cmd[3]; // Datenarray für I2C
Enenkel 0:951a35674581 17
Enenkel 0:951a35674581 18 /*** Funktionen ***/
Enenkel 0:951a35674581 19
Enenkel 0:951a35674581 20 int main()
Enenkel 0:951a35674581 21 {
Enenkel 0:951a35674581 22 /*** I2C Konfigurationen ***/
Enenkel 0:951a35674581 23 i2c.frequency(40000); // I2C Frequenz 40kHz
Enenkel 0:951a35674581 24
Enenkel 0:951a35674581 25 cmd[0] = 0x06;
Enenkel 0:951a35674581 26 cmd[1] = 0x00;
Enenkel 0:951a35674581 27 i2c.write(addr, cmd, 2); // Define Port0 = Out
Enenkel 0:951a35674581 28 /*** Hauptprogramm - Endlosschleife ***/
Enenkel 0:951a35674581 29 while(1)
Enenkel 0:951a35674581 30 {
Enenkel 0:951a35674581 31 cmd[0] = 0x02;
Enenkel 0:951a35674581 32 cmd[1] = 0xFE; // Alle LED ON
Enenkel 0:951a35674581 33 i2c.write(addr, cmd, 2); // Def. Port0 = 0x00
Enenkel 0:951a35674581 34 wait(0.5);
Enenkel 0:951a35674581 35
Enenkel 0:951a35674581 36 cmd[0] = 0x02; //
Enenkel 0:951a35674581 37 cmd[1] = 0xFD; // Alle LED OFF
Enenkel 0:951a35674581 38 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 39 wait(0.5);
Enenkel 0:951a35674581 40
Enenkel 0:951a35674581 41 cmd[0] = 0x02; //
Enenkel 0:951a35674581 42 cmd[1] = 0xFB; // Alle LED OFF
Enenkel 0:951a35674581 43 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 44 wait(0.5);
Enenkel 0:951a35674581 45
Enenkel 0:951a35674581 46 cmd[0] = 0x02; //
Enenkel 0:951a35674581 47 cmd[1] = 0xF7; // Alle LED OFF
Enenkel 0:951a35674581 48 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 49 wait(0.5);
Enenkel 0:951a35674581 50
Enenkel 0:951a35674581 51 cmd[0] = 0x02; //
Enenkel 0:951a35674581 52 cmd[1] = 0xEF; // Alle LED OFF
Enenkel 0:951a35674581 53 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 54 wait(0.5);
Enenkel 0:951a35674581 55
Enenkel 0:951a35674581 56 cmd[0] = 0x02; //
Enenkel 0:951a35674581 57 cmd[1] = 0xDF; // Alle LED OFF
Enenkel 0:951a35674581 58 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 59 wait(0.5);
Enenkel 0:951a35674581 60
Enenkel 0:951a35674581 61 cmd[0] = 0x02; //
Enenkel 0:951a35674581 62 cmd[1] = 0xBF; // Alle LED OFF
Enenkel 0:951a35674581 63 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 64 wait(0.5);
Enenkel 0:951a35674581 65
Enenkel 0:951a35674581 66 cmd[0] = 0x02; //
Enenkel 0:951a35674581 67 cmd[1] = 0x7F; // Alle LED OFF
Enenkel 0:951a35674581 68 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 69 wait(0.5);
Enenkel 0:951a35674581 70
Enenkel 0:951a35674581 71 cmd[0] = 0x02; //
Enenkel 0:951a35674581 72 cmd[1] = 0x00; // Alle LED OFF
Enenkel 0:951a35674581 73 i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
Enenkel 0:951a35674581 74 wait(2);
Enenkel 0:951a35674581 75 }
Enenkel 0:951a35674581 76 }