by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp
00001 /* 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 00002 */ 00003 // function prototype 00004 void delay(void); 00005 // variable declarations 00006 int dac_value; //the value to be output 00007 //define addresses of control registers, as pointers to volatile data 00008 #define DACR (*(volatile unsigned long *)(0x4008C000)) 00009 #define PINSEL1 (*(volatile unsigned long *)(0x4002C004)) 00010 00011 int main(){ 00012 PINSEL1=0x00200000; //set bits 21-20 to 10 to enable analog out on P0.26 00013 while(1){ 00014 for (dac_value=0;dac_value<1023;dac_value=dac_value+1){ 00015 DACR=(dac_value<<6); 00016 delay(); 00017 } 00018 } 00019 } 00020 00021 void delay(void){ //delay function. 00022 int j; //loop variable j 00023 for (j=0; j<1000000; j++) { 00024 j++; 00025 j--; //waste time 00026 } 00027 } 00028
Generated on Sat Sep 10 2022 14:44:31 by
1.7.2