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 }
时间: 2024-10-29 19:09:57

MSP430F149学习之路——AD的相关文章

MSP430F149学习之路——时钟1

代码一: /************************** 功能:LED每隔1秒闪烁一次 ****************************/ #include <msp430x14x.h> void main() { P6DIR = 0XFF; P6OUT = 0X00; TACCR0 = 4095; TACCTL0 = CCIE; TACTL = TASSEL_1 + ID_3 + MC_1; _EINT(); LPM3; } #pragma vector=TIMERA0_VE

MSP430F149学习之路——LED

1 #include <msp430x14x.h> 2 3 void int_clk(); 4 void delay(int i); 5 void main() 6 { 7 WDTCTL = WDTPW + WDTHOLD; 8 int_clk(); 9 P6DIR = 0XFF; 10 P6OUT = 0Xff; 11 while(1) 12 { 13 P6OUT = 0XFF; 14 delay(20000); 15 P6OUT = 0x00; 16 delay(20000); 17 }

MSP430F149学习之路——PWM信号

代码一: 1 /******************************* 2 程序功能:ACLK=32768Hz 3 PWM波 T=512/32768 占空比75% 4 *********************************/ 5 6 #include <msp430x14x.h> 7 void main() 8 { 9 WDTCTL = WDTPW + WDTHOLD; 10 TACTL = TASSEL_1 + TACLR; 11 12 CCTL0 = 0X00; 13

MSP430F149学习之路——UART

代码一: 1 #include <msp430x14x.h> 2 void int_clk() 3 { 4 BCSCTL1 &= ~XT2OFF; 5 BCSCTL2 |= SELM_2 + SELS; 6 do 7 { 8 IFG1 &= ~OFIFG; 9 for(int i=0;i<100;i++) 10 _NOP(); 11 }while((IFG1 & OFIFG)!=0); 12 IFG1 &= ~OFIFG; 13 } 14 void int

MSP430F149学习之路——按键

代码一: 1 /********************************** 2 程序功能:用按键控制LED灯熄灭 3 ***********************************/ 4 #include <msp430x14x.h> 5 6 void int_clk(); 7 void main() 8 { 9 WDTCTL = WDTPW + WDTHOLD; 10 int_clk(); 11 P1DIR = 0Xf0; 12 P1OUT = 0Xff; 13 P6DIR

MSP430F149学习之路——SPI

代码一: 1 //****************************************************************************** 2 //Description:SPI slave talks to SPI master using 3-wire mode. Data is sent 3 //to the master starting at 0x00 and increments. Received data from the 4 //master

MSP430F149学习之路——捕获/比较模式

1.捕获模式 1 #include <msp430x14x.h> 2 unsigned int last0=0,last1=0; 3 unsigned int k=0,j=0; 4 void mian(void) 5 { 6 WDTCTL = WDTPW + WDTHOLD; 7 TACTL = TACLR + TASSEL_2 + ID_3 + MC_3; 8 9 TACCTL0 = CM_3 + CCIS_0 + SCS + CAP + CCIE; 10 TACCTL1 = CM_3 +

MSP430F149学习之路——按键与LED

代码 1 /*********************************** 2 程序功能:用按键控制LED状态 3 缺点:按键按下后无法改变LED灯的状态,可以利用板上的复位键^~^ 4 *************************************/ 5 #include <msp430x14x.h> 6 7 int k,i=0; 8 void int_clk(); 9 void led(int n); 10 void main() 11 { 12 WDTCTL = WD

MSP430F149学习之路——蓝牙模块

注意蓝牙模块的接法! 1 #include <msp430x14x.h> 2 char data[100]; 3 int k=0; 4 void int_clk() 5 { 6 BCSCTL1 &= ~XT2OFF; 7 BCSCTL2 |= SELM_2 + SELS; 8 do 9 { 10 IFG1 &= ~OFIFG; 11 for(int i=0;i<100;i++) 12 _NOP(); 13 }while((IFG1 & OFIFG)!=0); 14