MSP430F149学习之路——AD

代码一:Timer_A触发转换

 1 #include <msp430x14x.h>
 2 void main()
 3 {
 4   WDTCTL = WDTPW + WDTHOLD;
 5   P6SEL |= BIT0;
 6   TACTL |= TASSEL_2 + MC_2;
 7   TACCTL1 = OUTMOD_3;
 8   TACCR1 = 0X0FFF;
 9   ADC12CTL0 = ADC12ON + SHT0_2;
10   ADC12CTL1 = SHS_1 + SHP;
11   while(1)
12   {
13     ADC12CTL0 |= ENC;
14     ADC12CTL0 |= ADC12SC;
15     while((ADC12IFG & ADC12BUSY) == 0);
16     ADC12CTL0 &= ~ENC;
17   }
18 }

 

代码二:ADC12序列通道多次转换

 1 #include <msp430x14x.h>
 2 #define uint unsigned int
 3 #define uchar unsigned char
 4 
 5 uint results0;
 6 uint results1;
 7 uint results2;
 8 uint results3;
 9 
10 void int_clk()
11 {
12   BCSCTL1 &= ~XT2OFF;
13   BCSCTL2 |= SELS + SELM1;
14   do
15   {
16     IFG1 &= ~OFIFG;
17     for(int i=0;i<100;i++)
18       _NOP();
19   }while((IFG1 & OFIFG)==1);
20   IFG1 &= ~OFIFG;
21 }
22 
23 void int_adc()
24 {
25   P6SEL |= 0X0F;
26   ADC12CTL0 = ADC12ON + MSC + SHT0_2 + REFON + REF2_5V;
27   ADC12CTL1 = SHP + CONSEQ_3;
28   ADC12MCTL0 = INCH_0;
29   ADC12MCTL1 = INCH_1;
30   ADC12MCTL2 = INCH_2;
31   ADC12MCTL3 = INCH_3;
32   ADC12IE = 0X08;
33   ADC12CTL0 |= ENC;
34 }
35 #pragma vector=ADC_VECTOR
36 __interrupt void ADC12_ISR()
37 {
38   results0 = ADC12MEM0;
39   results1 = ADC12MEM1;
40   results2 = ADC12MEM2;
41   results3 = ADC12MEM3;
42 }
43 void main()
44 {
45   WDTCTL = WDTPW + WDTHOLD;
46   int_clk();
47   int_adc();
48   _EINT();
49   ADC12CTL0 |= ADC12SC;
50 }

 

转载于:https://www.cnblogs.com/boyiliushui/p/4670039.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值