-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdac.c
43 lines (36 loc) · 996 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
33
34
35
36
37
38
39
40
41
42
43
/*
* dac.c
* Created on: 17/10/2017
* Author: Evandro Teixeira
*/
#include "dac.h"
/****************************************************************************************
*
*****************************************************************************************/
void dac_Init(void)
{
// DAC0 clock enabled
SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK;
// Clear status register
DAC0_SR = 0x00;
// The DAC system is enabled
DAC0_C0 = DAC_C0_DACEN_MASK ;
}
/****************************************************************************************
*
*****************************************************************************************/
bool dac_Output(uint16_t value)
{
uint8_t msb = 0;
uint8_t lsb = 0;
if(value < 4096)
{
msb = (uint8_t)(value >> 8);
lsb = (uint8_t)(value);
DAC0_DAT0L = lsb;
DAC0_DAT0H = msb;
return true;
}
else return false;
}
/********************************************************************************