by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

main.cpp

Committer:
robt
Date:
2013-06-16
Revision:
0:62e4724eaaaf

File content as of revision 0:62e4724eaaaf:

/*Program Example 14.1: Sets up a digital output pin using control registers, and flashes an led.                                      
                                                                         */
// function prototypes                                   
void delay(void);

//Define addresses of digital i/o control registers, as pointers to volatile data
#define FIO2DIR0       (*(volatile unsigned char *)(0x2009C040)) 
#define FIO2PIN0       (*(volatile unsigned char *)(0x2009C054))

int main() {
  FIO2DIR0=0xFF;     // set port 2, lowest byte to output
  while(1) {
    FIO2PIN0 |= 0x01;     // OR bit 0 with 1 to set pin high
    delay();
    FIO2PIN0 &= ~0x01;   // AND bit 0 with 0 to set pin low
    delay();
  }
}
//delay function
void delay(void){                                         
  int j;                      //loop variable j
  for (j=0;j<1000000;j++) {     
    j++;
    j--;                      //waste time
  }
}