by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
Revision 0:ee400a44f6f3, committed 2013-06-16
- Comitter:
- robt
- Date:
- Sun Jun 16 15:41:50 2013 +0000
- Commit message:
- by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /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
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jun 16 15:41:50 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file