-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdac.c
32 lines (29 loc) · 955 Bytes
/
dac.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <xc.h>
#include "dac.h"
#include "pmd.h"
#include "fvr.h"
#include <stdint.h>
#include <stdbool.h>
// init dac to use specified positive reference, set value
// also use to set dac value (pmd_on and setting con0 again harmless)
// not real fast, but fast not needed
//=============================================================================
void
dac_init (dac_pss_t pss, uint8_t v)
{
pmd_on( pmd_DAC1 );
if(pss >= dac_FVR1V){
fvr_dac( (fvr_compdac_t)(pss & 3) ); //bits0,1 hold fvr lvl
pss = 8;//bit3=fvr
}
DAC1CON1 = v;
DAC1CON0 = pss | 0xA0; //pss|DAC1EN|DAC1OE1
}
//=============================================================================
void
dac_deinit (void)
{
DAC1CON0 = 0;
pmd_off( pmd_DAC1 );
fvr_dac( fvr_DACOFF );
}