/* p7_5.c Use DAC to generate a saw tooth waveform * This program uses a for loop to generate a saw tooth * waveform output through a DAC. An 8-bit parallel input * DAC (TLC7524) is connected to P4. The DAC input latch * is put in transparent mode by grounding /CS and /WR. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0 * on XMS432P401R Rev C. */ #include "msp.h" void delayMs(int n); int main(void) { int i; /* Configure P4 as output */ P4->SEL0 &= ~0xFF; P4->SEL1 &= ~0xFF; P4->DIR |= 0xFF; while (1) { for (i = 0; i < 0xFF; i++) { /* write value of i to DAC0 */ P4->OUT = i; delayMs(1); /* delay 1ms */ } } } /* delay milliseconds when system clock is at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 750; i > 0; i--); /* Delay 1 ms */ }