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

Dependencies:   mbed

Revision:
0:ee400a44f6f3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jun 16 15:41:50 2013 +0000
@@ -0,0 +1,28 @@
+/* Program Example 14.4: Sawtooth waveform on DAC output. View on oscilloscope. Port 0.26 is used for DAC output, i.e. mbed Pin 18
+                                                */
+// function prototype                                              
+void delay(void);
+// variable declarations                                              
+int dac_value;             //the value to be output
+//define addresses of control registers, as pointers to volatile data 
+#define DACR (*(volatile unsigned long *)(0x4008C000))
+#define PINSEL1 (*(volatile unsigned long *)(0x4002C004))
+
+int main(){
+  PINSEL1=0x00200000; //set bits 21-20 to 10 to enable analog out on P0.26
+  while(1){
+    for (dac_value=0;dac_value<1023;dac_value=dac_value+1){
+      DACR=(dac_value<<6); 
+      delay();
+    }
+  }
+ }
+
+void delay(void){            //delay function.
+    int j;                      //loop variable j
+    for (j=0; j<1000000; j++) {
+        j++;
+        j--;                      //waste time
+    }
+}
+