Bertl 2014 Übung
Dependencies: mbed
Fork of _B14Test8 by
main.cpp@1:d1a664b263dc, 2015-01-25 (annotated)
- Committer:
- Enenkel
- Date:
- Sun Jan 25 17:30:27 2015 +0000
- Revision:
- 1:d1a664b263dc
- Parent:
- 0:951a35674581
I2C LED TEST
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Enenkel | 1:d1a664b263dc | 1 | /*********************************** |
Enenkel | 1:d1a664b263dc | 2 | name: BERTL_2014_LAMPENTEST |
Enenkel | 1:d1a664b263dc | 3 | modyfied by ENE@bulme.at |
Enenkel | 1:d1a664b263dc | 4 | description: |
Enenkel | 1:d1a664b263dc | 5 | Alle LED sind INVERS dh 0 = EIN; 1 = AUS; |
Enenkel | 1:d1a664b263dc | 6 | ***************************************/ |
Enenkel | 1:d1a664b263dc | 7 | #include "mbed.h" // Softwarestand: 19.1.2014 |
Enenkel | 0:951a35674581 | 8 | /*** Portkonfiguration ***/ |
Enenkel | 1:d1a664b263dc | 9 | Serial pc(USBTX, USBRX); // tx, rx |
Enenkel | 0:951a35674581 | 10 | I2C i2c(p28,p27); |
Enenkel | 0:951a35674581 | 11 | |
Enenkel | 0:951a35674581 | 12 | /*** Funktionsdefinitionen ***/ |
Enenkel | 1:d1a664b263dc | 13 | const int addr = 0x40; // I2C-Adresse des PCA9555 |
Enenkel | 1:d1a664b263dc | 14 | char cmd[3]; // Datenarray für I2C |
Enenkel | 0:951a35674581 | 15 | |
Enenkel | 0:951a35674581 | 16 | /*** Funktionen ***/ |
Enenkel | 0:951a35674581 | 17 | int main() |
Enenkel | 0:951a35674581 | 18 | { |
Enenkel | 1:d1a664b263dc | 19 | /*** I2C Konfigurationen ***/ |
Enenkel | 1:d1a664b263dc | 20 | i2c.frequency(40000); // I2C Frequenz 40kHz |
Enenkel | 1:d1a664b263dc | 21 | cmd[0] = 0x06; // Comman6 6 Portkonfiguration Port 0 |
Enenkel | 1:d1a664b263dc | 22 | cmd[1] = 0x00; // 00-> Port 0 = OUTPUT (all Pins 00) |
Enenkel | 1:d1a664b263dc | 23 | i2c.write(addr, cmd, 2); // Sende Adresse 0x40; cmd, s -> 0x06 0x00 |
Enenkel | 1:d1a664b263dc | 24 | // Defines Port0 as Output |
Enenkel | 1:d1a664b263dc | 25 | cmd[0] = 0x02; // OUTPUT Port 0 |
Enenkel | 1:d1a664b263dc | 26 | |
Enenkel | 0:951a35674581 | 27 | /*** Hauptprogramm - Endlosschleife ***/ |
Enenkel | 0:951a35674581 | 28 | while(1) |
Enenkel | 1:d1a664b263dc | 29 | { |
Enenkel | 1:d1a664b263dc | 30 | // 0x00 |
Enenkel | 1:d1a664b263dc | 31 | cmd[1] = 0x00; // Alle LED EIN 0000 0000 |
Enenkel | 1:d1a664b263dc | 32 | i2c.write(addr, cmd, 2); |
Enenkel | 1:d1a664b263dc | 33 | wait(2); |
Enenkel | 1:d1a664b263dc | 34 | // 0xF F |
Enenkel | 1:d1a664b263dc | 35 | cmd[1] = 0x00; // Alle LED AUS 1111 1111 |
Enenkel | 1:d1a664b263dc | 36 | i2c.write(addr, cmd, 2); |
Enenkel | 1:d1a664b263dc | 37 | wait(0.5); |
Enenkel | 1:d1a664b263dc | 38 | // F E |
Enenkel | 1:d1a664b263dc | 39 | cmd[1] = 0xFE; // D1 vorn links ws 1111 1110 |
Enenkel | 1:d1a664b263dc | 40 | i2c.write(addr, cmd, 2); |
Enenkel | 1:d1a664b263dc | 41 | wait(0.5); |
Enenkel | 1:d1a664b263dc | 42 | // F D |
Enenkel | 1:d1a664b263dc | 43 | cmd[1] = 0xFD; // D2 vorn links ge 1111 1101 |
Enenkel | 1:d1a664b263dc | 44 | i2c.write(addr, cmd, 2); |
Enenkel | 1:d1a664b263dc | 45 | wait(0.5); |
Enenkel | 1:d1a664b263dc | 46 | // F B |
Enenkel | 1:d1a664b263dc | 47 | cmd[1] = 0xFB; // D4 vorn rechts ws 1111 1011 |
Enenkel | 1:d1a664b263dc | 48 | i2c.write(addr, cmd, 2); |
Enenkel | 0:951a35674581 | 49 | wait(0.5); |
Enenkel | 0:951a35674581 | 50 | |
Enenkel | 1:d1a664b263dc | 51 | cmd[1] = 0xF7; // sieh ab hier in den Schaltplan |
Enenkel | 1:d1a664b263dc | 52 | i2c.write(addr, cmd, 2); |
Enenkel | 0:951a35674581 | 53 | wait(0.5); |
Enenkel | 0:951a35674581 | 54 | |
Enenkel | 1:d1a664b263dc | 55 | cmd[1] = 0xEF; // |
Enenkel | 1:d1a664b263dc | 56 | i2c.write(addr, cmd, 2); |
Enenkel | 0:951a35674581 | 57 | wait(0.5); |
Enenkel | 0:951a35674581 | 58 | |
Enenkel | 1:d1a664b263dc | 59 | cmd[1] = 0xDF; // |
Enenkel | 1:d1a664b263dc | 60 | i2c.write(addr, cmd, 2); |
Enenkel | 0:951a35674581 | 61 | wait(0.5); |
Enenkel | 0:951a35674581 | 62 | |
Enenkel | 1:d1a664b263dc | 63 | cmd[1] = 0xBF; |
Enenkel | 1:d1a664b263dc | 64 | i2c.write(addr, cmd, 2); |
Enenkel | 0:951a35674581 | 65 | wait(0.5); |
Enenkel | 0:951a35674581 | 66 | |
Enenkel | 1:d1a664b263dc | 67 | cmd[1] = 0x7F; |
Enenkel | 1:d1a664b263dc | 68 | i2c.write(addr, cmd, 2); |
Enenkel | 0:951a35674581 | 69 | wait(0.5); |
Enenkel | 1:d1a664b263dc | 70 | // F F |
Enenkel | 1:d1a664b263dc | 71 | cmd[1] = 0xFF; // Alle LED AUS 1111 1111 |
Enenkel | 1:d1a664b263dc | 72 | i2c.write(addr, cmd, 2); |
Enenkel | 1:d1a664b263dc | 73 | wait(1); |
Enenkel | 0:951a35674581 | 74 | } |
Enenkel | 0:951a35674581 | 75 | } |