Used to hold all my \"snippets\" I create in forum support.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
AjK
Date:
Thu Feb 10 11:20:12 2011 +0000
Commit message:
1.0 Initial release

Changed in this revision

forum1828/forum1828.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/forum1828/forum1828.cpp	Thu Feb 10 11:20:12 2011 +0000
@@ -0,0 +1,106 @@
+/**
+ * @file forum1828.cpp
+ * @see http://mbed.org/forum/mbed/topic/1828
+ * @code
+#include "mbed.h"
+
+#define P0_22_SEL_MASK    ~(3UL << 12)
+#define P0_22_SET_MASK    (1UL << 22)
+#define P0_22_CLR_MASK    ~(p15_SET_MASK)
+#define P0_22_AS_OUTPUT   LPC_PINCON->PINSEL1&=P0_22_SEL_MASK;LPC_GPIO0->FIODIR|=P0_22_SET_MASK
+#define P0_22_AS_INPUT    LPC_GPIO0->FIOMASK &= P0_22_CLR_MASK; 
+#define P0_22_SET         LPC_GPIO0->FIOSET = P0_22_SET_MASK
+#define P0_22_CLR         LPC_GPIO0->FIOCLR = P0_22_SET_MASK
+#define P0_22_IS_SET      (bool)(LPC_GPIO0->FIOPIN & P0_22_SET_MASK)
+#define P0_22_IS_CLR      !(P0_22_IS_SET)
+#define P0_22_MODE(x)     LPC_PINCON->PINMODE1&=P0_22_SEL_MASK;LPC_PINCON->PINMODE1|=((x&0x3)<<12)
+
+DigitalOut myled(LED1);
+DigitalOut led2(LED2);
+InterruptIn mybool(P0_22);
+
+void led2on(void) {
+    led2 = 1;
+}
+ 
+void led2off(void) {
+    led2 = 0;
+}   
+
+int main() {
+
+    // Setup InterruptIn as normal.
+    mybool.mode(PullUp);
+    mybool.rise(&led2on);
+    mybool.fall(&led2off);
+    
+    // Now cheat, manually switch it to an output.
+    P0_22_AS_OUTPUT;
+
+    while(1) {
+        myled = 1;
+        P0_22_SET; // Set the bool and led2on() is called.
+        wait(0.2);
+        
+        myled = 0;
+        P0_22_CLR; // Clear the bool and led2off() is called.
+        wait(0.2);
+    }
+}
+ 
+ * @endcode
+ */
+
+#ifdef FORUM_1828
+
+/**
+ * @see http://mbed.org/forum/mbed/topic/1828 
+ */
+
+#include "mbed.h"
+
+#define P0_22_SEL_MASK    ~(3UL << 12)
+#define P0_22_SET_MASK    (1UL << 22)
+#define P0_22_CLR_MASK    ~(p15_SET_MASK)
+#define P0_22_AS_OUTPUT   LPC_PINCON->PINSEL1&=P0_22_SEL_MASK;LPC_GPIO0->FIODIR|=P0_22_SET_MASK
+#define P0_22_AS_INPUT    LPC_GPIO0->FIOMASK &= P0_22_CLR_MASK; 
+#define P0_22_SET         LPC_GPIO0->FIOSET = P0_22_SET_MASK
+#define P0_22_CLR         LPC_GPIO0->FIOCLR = P0_22_SET_MASK
+#define P0_22_IS_SET      (bool)(LPC_GPIO0->FIOPIN & P0_22_SET_MASK)
+#define P0_22_IS_CLR      !(P0_22_IS_SET)
+#define P0_22_MODE(x)     LPC_PINCON->PINMODE1&=P0_22_SEL_MASK;LPC_PINCON->PINMODE1|=((x&0x3)<<12)
+
+DigitalOut myled(LED1);
+DigitalOut led2(LED2);
+InterruptIn mybool(P0_22);
+
+void led2on(void) {
+    led2 = 1;
+}
+ 
+void led2off(void) {
+    led2 = 0;
+}   
+
+int main() {
+
+    // Setup InterruptIn as normal.
+    mybool.mode(PullUp);
+    mybool.rise(&led2on);
+    mybool.fall(&led2off);
+    
+    // Now cheat, manually switch it to an output.
+    P0_22_AS_OUTPUT;
+
+    while(1) {
+        myled = 1;
+        P0_22_SET; // Set the bool and led2on() is called.
+        wait(0.2);
+        
+        myled = 0;
+        P0_22_CLR; // Clear the bool and led2off() is called.
+        wait(0.2);
+    }
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 10 11:20:12 2011 +0000
@@ -0,0 +1,48 @@
+/*
+    Copyright (c) 2011 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+/*
+ * I tend to do a lot of forum help and write sample code to demo how some
+ * things can be done. So I dedcided to wrap up all teh demo code I do into
+ * a project that people can look at.
+ *
+ * To use, uncomment the "forum post number" and compile.
+ */
+
+/**
+ * @file main.cpp
+ * A project to show demo code supporting forum posts.
+ */
+
+/** 
+ * To compile the code for Forum post 1828 
+ * uncomment the #define and the #include.
+ * Ensure all other #defines and #includes
+ * are commentted out. You can only compile
+ * one sample at a time.
+ *
+ * @see http://mbed.org/forum/mbed/topic/1828 
+ * @see forum1828.cpp
+ */
+#define FORUM_1828
+#include "forum1828/forum1828.cpp"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Feb 10 11:20:12 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1