forked from Jia-xinSu/MSP430F149DriverLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsp430f149_adc12.c
115 lines (101 loc) · 2.85 KB
/
msp430f149_adc12.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "msp430f149_adc12.h"
#include "assert.h"
void ADC12_init(ADC12_initTypedef ADC12_initParam)
{
ADC12CTL0&=~ENC;
ADC12CTL0&=~(ADC12ON+ADC12OVIE+ENC+ADC12SC);
ADC12IE=0x0000;
ADC12IFG=0x0000;
uint16_t newADC12CTL1=(ADC12CTL1&0xf307)+\
ADC12_initParam.clockSourceDivider+\
ADC12_initParam.clockSourceSelect+\
ADC12_initParam.sampleHoldSignalSourceSelect;
ADC12CTL1=newADC12CTL1;
}
void ADC12_enable(void)
{
ADC12CTL0|=ADC12ON;
}
void ADC12_disable(void)
{
ADC12CTL0&=~ADC12ON;
}
void ADC12_setupSamplingTimer(uint16_t clockCycleHoldCountLowMem, \
uint16_t clockCycleHoldCountHighMem, \
uint16_t multipleSamplesEnabled)
{
ADC12CTL1|=SHP;
ADC12CTL0=ADC12CTL0&(0x007f)+\
clockCycleHoldCountLowMem+
(uint16_t)((clockCycleHoldCountHighMem<<4)&0xf000)+\
multipleSamplesEnabled;
}
void ADC12_disableSamplingTimer(void)
{
ADC12CTL1&=~SHP;
}
void ADC12_configureMemory(ADC12_configureMemoryTypeDef ADC12_configureMemoryParam)
{
assert(!(ADC12CTL0&ENC));
if(!(ADC12CTL0&ENC))
{
HWREG8(0x0080+ADC12_configureMemoryParam.memoryBufferControlIndex)= \
ADC12_configureMemoryParam.endOfSequence+ \
ADC12_configureMemoryParam.inputSourceSelect+ \
ADC12_configureMemoryParam.negativeRefVoltageSourceSelect+ \
ADC12_configureMemoryParam.positiveRefVoltageSourceSelect;
}
}
void ADC12_enableInterrupt(uint16_t ADC12_interruptEnable,uint16_t ADC12_overflowInterruptEnable)
{
ADC12IE|=ADC12_interruptEnable;
ADC12CTL0=ADC12CTL0&(0xfff3)+ADC12_overflowInterruptEnable;
}
void ADC12_disableInterrupt(uint16_t ADC12_interruptEnable,uint16_t ADC12_overflowInterruptEnable)
{
ADC12IE&=~ADC12_interruptEnable;
ADC12CTL0&=ADC12_overflowInterruptEnable;
}
void ADC12_clearInterrupt(uint16_t ADC12_interruptFlag)
{
ADC12IFG&=~ADC12_interruptFlag;
}
uint16_t ADC12_getInerruptStatus(uint16_t ADC12_interruptFlag)
{
return(ADC12IFG&ADC12_interruptFlag);
}
void ADC12_startConversion(uint16_t startMemoryBufferIndex,uint16_t conversionSequenceModeSelect)
{
ADC12CTL0&=~ENC;
ADC12CTL1=(ADC12CTL1&0x0ff9)+ \
(uint16_t)((startMemoryBufferIndex<<12)&0xf000)+ \
conversionSequenceModeSelect;
ADC12CTL0|=ENC+ADC12SC;
}
void ADC12_disableConversion(preemptTypedef ADC12_xCONVERSION)
{
if(ADC12_xCONVERSION==ADC12_PREEMPTCONVERSION)
{
ADC12CTL1&=~CONSEQ_3;
}
else if(~ADC12CTL1&CONSEQ_3)
{
while(ADC12_isBusy())
{
__no_operation();
}
}
}
uint16_t ADC12_isBusy(void)
{
return (ADC12CTL1&ADC12BUSY);
}
uint16_t ADC12_getResults(uint16_t memoryBufferControlIndex)
{
return(HWREG16(0x0140+2*memoryBufferControlIndex));
}
void ADC12_setSampleHoldSignalInversion(uint16_t invertedSignal)
{
ADC12CTL1&=~ISSH;
ADC12CTL1|=invertedSignal;
}