MSP430F149学习之路——比较器Comparaor_A

代码一:

 1 #include <msp430x14x.h>
 2 int flag = 0;
 3 void int_clk()
 4 {
 5   BCSCTL1 &= ~XT2OFF;
 6   BCSCTL2 |= SELM_2 + SELS;
 7   do
 8   {
 9     IFG1 &= ~OFIFG;
10     for(int i=0;i<100;i++)
11       _NOP();
12   }while((IFG1 & OFIFG)!=0);
13   IFG1 &= ~OFIFG;
14 }
15
16 void int_COMPARATORA()
17 {
18   P2SEL |= BIT3 + BIT4;               //P2.3,P2.4分别作为比较器的输出和输入
19   P2DIR |= BIT3;                      //P2.3作为输出
20
21   CACTL1 &= ~CAEX;
22   CACTL1 |= CARSEL + CAREF_2 + CAON + CAIES + CAIE;
23   CACTL2 |= CAF + P2CA1;              //使能输出滤波器,CA1作为比较器的输入功能
24 }
25 #pragma vector=COMPARATORA_VECTOR
26 __interrupt void COMPARATORA(void)
27 {
28   flag = 1;
29 }
30
31 void main()
32 {
33   WDTCTL = WDTPW + WDTHOLD;
34   P6DIR = 0XFF;
35   P6OUT = 0X00;
36   int_clk();
37   int_COMPARATORA();
38   _EINT();
39   while(1)
40   {
41     while(flag)
42     {
43       P6OUT ^= 0XFF;
44       flag = 0;
45     }
46   }
47 }

代码二:

 1 #include <msp430x14x.h>
 2 void main()
 3 {
 4   WDTCTL = WDTPW + WDTHOLD;
 5   P2SEL |= BIT3;
 6   P1DIR |= BIT2;
 7   P1OUT &= ~BIT2;
 8
 9   CACTL1 = CAEX + CARSEL + CAREF_2 + CAON;
10   CACTL2 = CAF + P2CA1;
11
12   while(1)
13   {
14     if(CAOUT==0)
15       P6OUT = BIT0;
16     else
17       P6OUT = BIT7;
18   }
19 }
时间: 2024-10-05 05:50:33

MSP430F149学习之路——比较器Comparaor_A的相关文章

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学习之路——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