Code One:
1#include <msp430x14x.h>2 intFlag =0;3 voidINT_CLK ()4 {5BCSCTL1 &= ~Xt2off;6BCSCTL2 |= selm_2 +SELS;7 Do8 {9IFG1 &= ~OFIFG;Ten for(intI=0;i< -; i++) One _nop (); A} while((IFG1 & OFIFG)! =0); -IFG1 &= ~OFIFG; - } the - voidInt_comparatora () - { -P2sel |= BIT3 + BIT4;//p2.3,p2.4 as output and input of comparator respectively +P2dir |= BIT3;//P2.3 as Output - +CACTL1 &= ~Caex; ACACTL1 |= Carsel + caref_2 + Caon + caies +Caie; atCACTL2 |= CAF + p2ca1;//Enable output filter, CA1 as input function of comparator - } - #pragmaVector=comparatora_vector -__interruptvoidComparatora (void) - { -Flag =1; in } - to voidMain () + { -Wdtctl = Wdtpw +Wdthold; theP6dir =0XFF; *P6out =0x00; $ int_clk ();Panax Notoginseng Int_comparatora (); - _eint (); the while(1) + { A while(flag) the { +P6out ^=0XFF; -Flag =0; $ } $ } -}
Code two:
1#include <msp430x14x.h>2 voidMain ()3 {4Wdtctl = Wdtpw +Wdthold;5P2sel |=BIT3;6P1dir |=BIT2;7P1out &= ~BIT2;8 9CACTL1 = Caex + Carsel + caref_2 +Caon;TenCACTL2 = CAF +P2CA1; One A while(1) - { - if(caout==0) theP6out =BIT0; - Else -P6out =BIT7; - } +}
msp430f149 Learning Path-Comparator comparaor_a