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:85d249817f55
- Parent:
- 0:c862449fe089
--- a/main.cpp Mon Apr 04 20:59:46 2016 +0000
+++ b/main.cpp Tue Apr 05 12:55:58 2016 +0000
@@ -3,14 +3,10 @@
*
* Omschrijving:
* I2C testprogramma:
- * -Configureer PCF8574 4x OUT, 4x IN.
- * -Zet alle PCF8574-Leds aan en geef terminal echo.
- * -Zet alle PCF8574-Leds uit en geef terminal echo.
- * -Zet led 2 aan ten teken 'Initialisatie Klaar' en geef terminal echo.
* -Als PCF8574-Knop# ingedrukt: PCF8574-Led# aan
* -Als PCF8574-Knop# losgelaten: PCF8574-Led# uit.
*
- * Aanmaakdatum: 04 april 2016
+ * Aanmaakdatum: 05 april 2016
*
* Geschreven door: Marout Yasuo Sluijter-Borms
*
@@ -24,9 +20,8 @@
/* Definieer seriële poorten */
Serial pc(USBTX, USBRX); // tx, rx communicatie met PC terminal via USB.
-I2C i2c_bus( p9, p10); // I2C bus.
-PCF8574 pcf0( p9, p10, 0x70); // Eerste PCF8574 chip
-PCF8574 pcf1( p9, p10, 0x72); // Tweede PCF8574 chip
+PCF8574 pcf0( p9, p10, 0x72); // Eerste PCF8574 chip
+//PCF8574 pcf1( p28, p37, 0x74); // Tweede PCF8574 chip
/* Definieer digitale IO */
@@ -39,37 +34,21 @@
char DataOut; // Data te schrijven naar PCF8574
/* Definieer globale constanten */
-// const int chipaddress = 0x40; // Adres van de PCF8574
-const int i2c_speed = 400000; // Bussnelheid 400kHz
-const int baudrate = 38400; // Baudrate communicatie met terminal
+
+/* Definieer functie */
/* Start hoofprogramma */
int main()
{
-// pc.baud(baudrate); // stel baudrate in van usb serial
- pc.printf("\x1B\x48\x1B\x4A\r"); // scherm schoon en cursor linksboven
- pc.printf("PCF8574A als bidirectionele IO\n\r");
-
- i2c_bus.frequency( i2c_speed); // Zet de I2C bus op 400kHz
-
- pc.printf("Zet I2C speed op %d Hz.\n\r", i2c_speed); // echo naar de terminal
-
while (1)
{
- DataOut = 0xF0;
-// pcf0.write(DataOut);
- DataIn = pcf0.read(); // lees eerste chip uit
- pc.printf("Waaarde van inputs: %d.\r\n", DataIn); // echo gelezen data naar terminal
- wait ( 0.2);
- DataOut = DataIn >> 4; // Shift DataIn 4 plaatsen rechts
- pc.printf("Waaarde van outputs: %d.\r\n", DataOut); // echo gemodificeerde data naar terminal
- wait ( 0.2);
+ DataIn = pcf0.read(); // lees inputs uit
+ DataOut = DataIn >> 4; // schuif knoppen naar leds
+ DataOut = DataOut + 0xf0; // zet leds uit en knoppen uitleesbaar (out = high)
pcf0.write(DataOut);
} // endwhile
-
} // endmain
-
/*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal