by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp
- Committer:
- robt
- Date:
- 2013-06-16
- Revision:
- 0:ee400a44f6f3
File content as of revision 0:ee400a44f6f3:
/* 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 } }