-extracredit
Dependencies: mbed
main.cpp@0:574e155464d5, 2015-01-28 (annotated)
- Committer:
- sheldonfernandes2404
- Date:
- Wed Jan 28 04:08:50 2015 +0000
- Revision:
- 0:574e155464d5
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sheldonfernandes2404 | 0:574e155464d5 | 1 | #include "mbed.h" |
sheldonfernandes2404 | 0:574e155464d5 | 2 | #include "MCP23S17.h" |
sheldonfernandes2404 | 0:574e155464d5 | 3 | |
sheldonfernandes2404 | 0:574e155464d5 | 4 | //------------------------------// |
sheldonfernandes2404 | 0:574e155464d5 | 5 | SPI spi(p5, p6, p7); |
sheldonfernandes2404 | 0:574e155464d5 | 6 | char Opcode1 = 0x40; |
sheldonfernandes2404 | 0:574e155464d5 | 7 | char Opcode2 = 0x42; |
sheldonfernandes2404 | 0:574e155464d5 | 8 | MCP23S17 chip1 = MCP23S17(spi, p20, Opcode1); |
sheldonfernandes2404 | 0:574e155464d5 | 9 | MCP23S17 chip2 = MCP23S17(spi, p20, Opcode2); |
sheldonfernandes2404 | 0:574e155464d5 | 10 | //-------------------------------// |
sheldonfernandes2404 | 0:574e155464d5 | 11 | |
sheldonfernandes2404 | 0:574e155464d5 | 12 | int main() |
sheldonfernandes2404 | 0:574e155464d5 | 13 | { |
sheldonfernandes2404 | 0:574e155464d5 | 14 | |
sheldonfernandes2404 | 0:574e155464d5 | 15 | chip1.direction(PORT_A, 0x00); //output |
sheldonfernandes2404 | 0:574e155464d5 | 16 | chip2.direction(PORT_B, 0xFF); //input |
sheldonfernandes2404 | 0:574e155464d5 | 17 | |
sheldonfernandes2404 | 0:574e155464d5 | 18 | while (1) { |
sheldonfernandes2404 | 0:574e155464d5 | 19 | |
sheldonfernandes2404 | 0:574e155464d5 | 20 | if(chip2.read(PORT_B)) { |
sheldonfernandes2404 | 0:574e155464d5 | 21 | chip1.write(PORT_A, 0x00); |
sheldonfernandes2404 | 0:574e155464d5 | 22 | } else { |
sheldonfernandes2404 | 0:574e155464d5 | 23 | chip1.write(PORT_A, 0xAA); |
sheldonfernandes2404 | 0:574e155464d5 | 24 | } |
sheldonfernandes2404 | 0:574e155464d5 | 25 | |
sheldonfernandes2404 | 0:574e155464d5 | 26 | |
sheldonfernandes2404 | 0:574e155464d5 | 27 | } |
sheldonfernandes2404 | 0:574e155464d5 | 28 | |
sheldonfernandes2404 | 0:574e155464d5 | 29 | } |