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.
forum1828.cpp
00001 /** 00002 * @file forum1828.cpp 00003 * @see http://mbed.org/forum/mbed/topic/1828 00004 * @code 00005 #include "mbed.h" 00006 00007 #define P0_22_SEL_MASK ~(3UL << 12) 00008 #define P0_22_SET_MASK (1UL << 22) 00009 #define P0_22_CLR_MASK ~(p15_SET_MASK) 00010 #define P0_22_AS_OUTPUT LPC_PINCON->PINSEL1&=P0_22_SEL_MASK;LPC_GPIO0->FIODIR|=P0_22_SET_MASK 00011 #define P0_22_AS_INPUT LPC_GPIO0->FIOMASK &= P0_22_CLR_MASK; 00012 #define P0_22_SET LPC_GPIO0->FIOSET = P0_22_SET_MASK 00013 #define P0_22_CLR LPC_GPIO0->FIOCLR = P0_22_SET_MASK 00014 #define P0_22_IS_SET (bool)(LPC_GPIO0->FIOPIN & P0_22_SET_MASK) 00015 #define P0_22_IS_CLR !(P0_22_IS_SET) 00016 #define P0_22_MODE(x) LPC_PINCON->PINMODE1&=P0_22_SEL_MASK;LPC_PINCON->PINMODE1|=((x&0x3)<<12) 00017 00018 DigitalOut myled(LED1); 00019 DigitalOut led2(LED2); 00020 InterruptIn mybool(P0_22); 00021 00022 void led2on(void) { 00023 led2 = 1; 00024 } 00025 00026 void led2off(void) { 00027 led2 = 0; 00028 } 00029 00030 int main() { 00031 00032 // Setup InterruptIn as normal. 00033 mybool.mode(PullUp); 00034 mybool.rise(&led2on); 00035 mybool.fall(&led2off); 00036 00037 // Now cheat, manually switch it to an output. 00038 P0_22_AS_OUTPUT; 00039 00040 while(1) { 00041 myled = 1; 00042 P0_22_SET; // Set the bool and led2on() is called. 00043 wait(0.2); 00044 00045 myled = 0; 00046 P0_22_CLR; // Clear the bool and led2off() is called. 00047 wait(0.2); 00048 } 00049 } 00050 00051 * @endcode 00052 */ 00053 00054 #ifdef FORUM_1828 00055 00056 /** 00057 * @see http://mbed.org/forum/mbed/topic/1828 00058 */ 00059 00060 #include "mbed.h" 00061 00062 #define P0_22_SEL_MASK ~(3UL << 12) 00063 #define P0_22_SET_MASK (1UL << 22) 00064 #define P0_22_CLR_MASK ~(p15_SET_MASK) 00065 #define P0_22_AS_OUTPUT LPC_PINCON->PINSEL1&=P0_22_SEL_MASK;LPC_GPIO0->FIODIR|=P0_22_SET_MASK 00066 #define P0_22_AS_INPUT LPC_GPIO0->FIOMASK &= P0_22_CLR_MASK; 00067 #define P0_22_SET LPC_GPIO0->FIOSET = P0_22_SET_MASK 00068 #define P0_22_CLR LPC_GPIO0->FIOCLR = P0_22_SET_MASK 00069 #define P0_22_IS_SET (bool)(LPC_GPIO0->FIOPIN & P0_22_SET_MASK) 00070 #define P0_22_IS_CLR !(P0_22_IS_SET) 00071 #define P0_22_MODE(x) LPC_PINCON->PINMODE1&=P0_22_SEL_MASK;LPC_PINCON->PINMODE1|=((x&0x3)<<12) 00072 00073 DigitalOut myled(LED1); 00074 DigitalOut led2(LED2); 00075 InterruptIn mybool(P0_22); 00076 00077 void led2on(void) { 00078 led2 = 1; 00079 } 00080 00081 void led2off(void) { 00082 led2 = 0; 00083 } 00084 00085 int main() { 00086 00087 // Setup InterruptIn as normal. 00088 mybool.mode(PullUp); 00089 mybool.rise(&led2on); 00090 mybool.fall(&led2off); 00091 00092 // Now cheat, manually switch it to an output. 00093 P0_22_AS_OUTPUT; 00094 00095 while(1) { 00096 myled = 1; 00097 P0_22_SET; // Set the bool and led2on() is called. 00098 wait(0.2); 00099 00100 myled = 0; 00101 P0_22_CLR; // Clear the bool and led2off() is called. 00102 wait(0.2); 00103 } 00104 } 00105 00106 #endif
Generated on Thu Jul 14 2022 06:02:30 by
1.7.2