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

Dependencies:   mbed

Committer:
robt
Date:
Sun Jun 16 15:40:24 2013 +0000
Revision:
0:62e4724eaaaf
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:62e4724eaaaf 1 /*Program Example 14.1: Sets up a digital output pin using control registers, and flashes an led.
robt 0:62e4724eaaaf 2 */
robt 0:62e4724eaaaf 3 // function prototypes
robt 0:62e4724eaaaf 4 void delay(void);
robt 0:62e4724eaaaf 5
robt 0:62e4724eaaaf 6 //Define addresses of digital i/o control registers, as pointers to volatile data
robt 0:62e4724eaaaf 7 #define FIO2DIR0 (*(volatile unsigned char *)(0x2009C040))
robt 0:62e4724eaaaf 8 #define FIO2PIN0 (*(volatile unsigned char *)(0x2009C054))
robt 0:62e4724eaaaf 9
robt 0:62e4724eaaaf 10 int main() {
robt 0:62e4724eaaaf 11 FIO2DIR0=0xFF; // set port 2, lowest byte to output
robt 0:62e4724eaaaf 12 while(1) {
robt 0:62e4724eaaaf 13 FIO2PIN0 |= 0x01; // OR bit 0 with 1 to set pin high
robt 0:62e4724eaaaf 14 delay();
robt 0:62e4724eaaaf 15 FIO2PIN0 &= ~0x01; // AND bit 0 with 0 to set pin low
robt 0:62e4724eaaaf 16 delay();
robt 0:62e4724eaaaf 17 }
robt 0:62e4724eaaaf 18 }
robt 0:62e4724eaaaf 19 //delay function
robt 0:62e4724eaaaf 20 void delay(void){
robt 0:62e4724eaaaf 21 int j; //loop variable j
robt 0:62e4724eaaaf 22 for (j=0;j<1000000;j++) {
robt 0:62e4724eaaaf 23 j++;
robt 0:62e4724eaaaf 24 j--; //waste time
robt 0:62e4724eaaaf 25 }
robt 0:62e4724eaaaf 26 }
robt 0:62e4724eaaaf 27