by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp
00001 /*Program Example 14.1: Sets up a digital output pin using control registers, and flashes an led. 00002 */ 00003 // function prototypes 00004 void delay(void); 00005 00006 //Define addresses of digital i/o control registers, as pointers to volatile data 00007 #define FIO2DIR0 (*(volatile unsigned char *)(0x2009C040)) 00008 #define FIO2PIN0 (*(volatile unsigned char *)(0x2009C054)) 00009 #define FIO0PIN0 (*( volatile unsigned char *)(0x2009C014)) 00010 00011 int main() 00012 { 00013 FIO2DIR0=0xFF; // set port 2, lowest byte to output 00014 while(1) { 00015 for (int i=1; i<=3; i++) { 00016 FIO0PIN0 |= 0x02; // set port 2 pin 1 high (mbed pin 25) 00017 delay(); 00018 FIO0PIN0 &= ~0x02; // set port 2 pin 1 low 00019 delay(); 00020 } 00021 00022 } 00023 } 00024 //delay function 00025 void delay(void) 00026 { 00027 int j; //loop variable j 00028 for (j=0; j<1000000; j++) { 00029 j++; 00030 j--; //waste time 00031 } 00032 } 00033 00034
Generated on Thu Jul 28 2022 01:17:38 by
1.7.2