Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:d7fe22a24841
- Parent:
- 0:d58b942de71e
- Child:
- 2:2e8fca65efaf
diff -r d58b942de71e -r d7fe22a24841 main.cpp
--- a/main.cpp Sat Aug 21 14:49:00 2010 +0000
+++ b/main.cpp Sat Aug 21 16:51:33 2010 +0000
@@ -10,17 +10,19 @@
char writeOpcode = 0x40; // A0, A1, A2 are tied to ground on the breadboard.
MCP23S17 chip = MCP23S17(spi, p20, 0x40);
-DigitalOut chipA0(p12);
-DigitalIn chipB0(p10);
+DigitalInOut chipA0(p12);
+DigitalInOut chipB0(p10);
void checkEqual(int expected, int actual, char * text) {
if (expected != actual) {
- printf("%s **TEST FAILED** - expected %i but get %i", text, expected, actual);
+ printf("%s **TEST FAILED** - expected %i but get %i\r\n", text, expected, actual);
exit(-1);
}
}
int main() {
+ chipA0.output(); // output from the mbed
+ chipB0.input(); // input to the mbed
for (int i = 0; i < 100; i++) {
chip.directionA(0xFF); // all 8 bits set to input
chip.directionB(0xFE); // bit 0 set to output
@@ -29,7 +31,24 @@
chip.outputB(chip.inputA() && 1);
checkEqual(1, int(chipB0),"copying 1 from A0 to B0");
// copy input bit 0 from A to output bit 0 on B
+ chipA0 = 0;
chip.outputB(chip.inputA() && 1);
- checkEqual(1, int(chipB0), "copying 0 from A0 to B0");
+ checkEqual(0, int(chipB0), "copying 0 from A0 to B0");
}
+
+ chipB0.output(); // output from the mbed
+ chipA0.input(); // input to the mbed
+ for (int i = 0; i < 100; i++) {
+ chip.directionB(0xFF); // all 8 bits set to input
+ chip.directionA(0xFE); // bit 0 set to output
+ chipB0 = 1;
+ // copy input bit 0 from B to output bit 0 on A
+ chip.outputA(chip.inputB() && 1);
+ checkEqual(1, int(chipB0),"copying 1 from B0 to A0");
+ // copy input bit 0 from B to output bit 0 on A
+ chipB0 = 0;
+ chip.outputA(chip.inputB() && 1);
+ checkEqual(0, int(chipB0), "copying 0 from B0 to A0");
+ }
+
}