#include "dac.h" //#include "api.h" #include void dac_init() { // setup the related pin to DAC output LPC_PINCON->PINSEL1 = 0x00200000; // set p0.26 to DAC output // Clock tick pr. sample delay (DAC clock) LPC_DAC->DACCNTVAL = 2267; // 44111Hz LPC_DAC->DACCTRL = (0x1<<1)|(0x1<<2); LPC_SC->PCLKSEL0 |= (0x1 << 22); // Use full 100MHz clock } #define VOL 1 void dac_play_samples(const short int *samples, int size) { for(int i = 0; i < size; i++) { LPC_DAC->DACR = ((unsigned short)(samples[i] * VOL)<< 6);// | DAC_BIAS; for(int j = 0; j < 100; j++) { if(!LPC_DAC->DACR) LPC_DAC->DACR = 0; } } }