7 //static int prevDDR;
\r
8 //static int prevPORT;
\r
13 * @purpose driver for DAC (efmini mcp4922)
\r
17 * Initialise the DAC
\r
22 //prevDDR = DAC_DDR;
\r
23 //prevPORT = DAC_PORT;
\r
25 DAC_DDR = 0xFF & ~(1<<PORTB6);
\r
26 DAC_PORT = 0xFF | (1<<PORTB6);
\r
28 DAC_PORT = (1<<CS) | (1<<LDAC) | (1<<SHDN) | (1<<PORTB6);
\r
29 //runningDAC = TRUE;
\r
32 void DAC_Set(int output)
\r
38 DAC_PORT |= (1<<CS) | (1<<LDAC);
\r
43 //Wait for clock off
\r
46 DAC_PORT &= ~(1<<CS);
\r
48 //Configuration bits:
\r
51 DAC_PORT &= ~(1<<SDI); //Select DAC A
\r
57 DAC_PORT |= (1<<SDI); //Select buffered reference voltage
\r
65 DAC_PORT &= ~(1<<SDI); //Select 2x gain
\r
66 output = output / 2;
\r
69 DAC_PORT |= (1<<SDI); //Select 1x gain
\r
75 DAC_PORT |= (1<<SDI); //DAC is turned on!
\r
80 //Now send the 12 data bits
\r
81 for (int i=1; i <= 12; ++i)
\r
83 if ((output & (1<<(12-i))) == 0x00)
\r
84 DAC_PORT &= ~(1<<SDI);
\r
86 DAC_PORT |= (1<<SDI);
\r
94 DAC_PORT |= (1<<CS);
\r
100 DAC_PORT &= ~(1<<LDAC);
\r
105 DAC_PORT |= (1<<LDAC);
\r