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.
main.cpp
00001 /* Program Example 14.3: Uses digital input and output using control registers, and flashes an LED. LEDS connect to mbed pins 25 and 26. Switch input to pin 9. 00002 */ 00003 // function prototypes 00004 void delay(void); 00005 //Define Digital I/O registers 00006 #define FIO0DIR0 (*( volatile unsigned char *)(0x2009C000)) 00007 #define FIO0PIN0 (*( volatile unsigned char *)(0x2009C014)) 00008 #define FIO2DIR0 (*(volatile unsigned char *)(0x2009C040)) 00009 #define FIO2PIN0 (*(volatile unsigned char *)(0x2009C054)) 00010 //some variables 00011 char a; 00012 char b; 00013 char i; 00014 00015 int main() { 00016 FIO0DIR0=0x00; // set all bits of port 0 byte 0 to input 00017 FIO2DIR0=0xFF; // set port 2 byte 0 to output 00018 while(1) { 00019 if (FIO0PIN0&0x01==1){ // bit test port 0 pin 0 (mbed pin 9) 00020 a=0x01; // this reverses the order of LED flashing 00021 b=0x02; // based on the switch position 00022 } 00023 else { 00024 a=0x02; 00025 b=0x01; 00026 } 00027 FIO2PIN0 |= a; 00028 delay(); 00029 FIO2PIN0 &= ~a; 00030 delay(); 00031 00032 for (i=1;i<=3;i++){ 00033 FIO2PIN0 |= b; 00034 delay(); 00035 FIO2PIN0 &= ~b; 00036 delay(); 00037 } 00038 } //end while loop 00039 } 00040 00041 void delay(void){ //delay function. 00042 int j; //loop variable j 00043 for (j=0; j<1000000; j++) { 00044 j++; 00045 j--; //waste time 00046 } 00047 }
Generated on Wed Jul 27 2022 07:35:16 by
1.7.2