You are on page 1of 10

I HC NNG TRNG I HC BCH KHOA KHOA IN T VIN THNG ---o0o--BO CO TH NGHIM K THUT VI X !

" VI I#U KHI$N

Gio vin hng dn % &'() X*+, T-*,. Danh Sch SVTH %NGU/N V0N %TR1NG CNG T! Nhm % 234 56A

Nng Thng 11-2012 M7C TI8U CHUNG -s dng KIT MSP-EXP430FG4618 thc h !n c"c #$ %&# c' #(n) - S dng #* +,#-g MSP-FET430.IF n/0 ch1'ng t23nh cho ch 0 MSP430 t24n KIT MSPEXP430FG4618 )- S dng 0h5n 676 I89 %:0 t23nh 6*t ch1'ng t23nh 'n g (n) - Thc h !n c"c #$ % 4n ;-&n <n =->t?nh:0@ ngAt@ t 6,2) BI 9% G&IO 9: B;< 9:9 /=* >?*% B <t ch1'ng t23nh cho CE+1 B$ CE+D tAt s"ng %-En 0h 4n@ thF g &n g G& D %5n tAt s"ng %$ 1s

& !" h#i 1$ H"c CE+ 1Ic J<t nK BL MH. nh1 h3nh t24nM N CE+1 nK B$o chOn n$o cP& MH.Q RHSng RPo2tT n$oQT T2( %F MUU&5:5UUUUUUUUUUUUUUU N CE+D nK B$o chOn n$o cP& MH.Q RHSng RPo2tT n$oQT T2( %F MUU&5:9UUUUUUUUUUUUUU N V 7- Jh n CE+@ c"c chOn 0o2t 0h( %$ n0-t h&W o-t0-tQ T2( %F MUU@*AB*AUUUUUUUUUUUUUUU N V CE+ s"ng@ 0h( =->t g " t2X g3 2& chOn 0o2tQ T2( %F MUUU9UUUUUUUUUUUUUU !" h#i 2$ Yo$n chZnh ch1'ng t23nh #[ng c"ch 7n B$o c"c ch\ t2KngM
#include <msp430xG46x.h> void main (void) {

volatile unsigned int i; WDTCTL = WDTPW | WDTHOLD; //Stop Watchdog Timer P2DIR |= BIT1+BIT2; //Configure P2.1 and P2.2 as Output P2OUT &= ~(BIT1+BIT2); // Turn off LED1, LED2 P2OUT |= BIT2; // Turn on LED 1, turn off LED 2 while(1) //Infinite loop { i= 30000; //Delay do (i--); while (i !=0); //Toggle Port P2.1 and P2.2 using an exclusive-OR P2OUT ^= BIT1+BIT2; } }

5: B;< 9:5 /=* >?*% s nh B 4n B <t ch1'ng t23nh (o t2/ng th" CE+1 6\ Jh s] tch 1 1Ic nh>n

!" h#i 1$ H"c S^Rs] tchT 1Ic J<t nK BL MH. nh1 h3nh t24n) V 7n B$o ch\ t2Kng t2( %F c"c cO- h_ d1L OW) N S^1 nK B$o chOn n$o cP& MH.Q RHSng RPo2tT n$oQT T2( %F MUU&9:2UUUUUUUUUUUUUUU N S^D nK B$o chOn n$o cP& MH.Q RHSng RPo2tT n$oQT T2( %F MUU&9:9UUUUUUUUUUUUUUU N V `c t2/ng th" s] tch@ c"c chOn 0o2t 0h( %$ n0-t h&W o-t0-tQ

T2( %F MUU<,B*AUUUUUUUUUUUUUUU !" h#i 2$ Yo$n chZnh ch1'ng t23nh #[ng c"ch 7n B$o c"c ch\ t2KngM
#include <msp430xG46x.h> void main (void) { volatile unsigned int i; WDTCTL = 0x5A00|0x0080; //Stop Watchdog Timer P2DIR |= BIT2; //Configure P2.2 as Output (LED1) P1DIR &= BIT0; //Configure P1.0 as Input (S1) while (1) { while ((P1IN & 0x01));//Wait for the press of the button P2OUT ^= BIT2; //Toggle Port P2.2 for(i=1;i<3000;i++); //Delay, button debounce while((P1IN&0x01)==0);//Wait for the release of the button for(i=1;i<3000;i++); //Delay, button debounce } }

BI 5: G&IO " INTCRRU&T /=* >?*% S nh B 4n B <t ch1'ng t23nh (o t2/ng th" CE+1 Jh S] tch 1 1Ic nh>n) T2ong ch1'ng t23nh s dng ngAt t24n chOn 0o2t g &o t <0 S] tch

!" h#i 1$ H"c

S^Rs] tchT 1Ic J<t nK BL MH. nh1 h3nh t24n) V 7n B$o ch\ t2Kng t2( %F c"c cO- h_ d1L OW) N S^1 nK B$o chOn Po2t g3 cP& HP.Q T2( %F MUUU&9:2UUUUUUUUUUUUUU

N Kh S] tch 1Ic nh>n@ sa cb ch-Wn t2/ng th" nh1 th< n$o t24n chOn Pc9TQ '<.' A@ D@E N V cho 0hd0 ngAt t24n chOn P1)0@ t& 0h( gh U9U B$o # tU2U)cP& th&nh gh UU&9ICUUU)Q N V ch`n c/nh =-Kng cho ngAt t24n chOn P1)0@ t& 0h( gh U9UB$o # tU 2U)cP& th&nh gh U&9ICFUUQ !" h#i 2$ Yo$n chZnh ch1'ng t23nh #[ng c"ch 7n B$o c"c ch\ t2KngM
#include <msp430xG46x.h> #pragma vector=ISR_VECTOR __interrupt void Port_1 (void) { //define an interrupt service routine at 0xFFE8 volatile unsigned int i; P2OUT ^= 0x04; //Toggle Port P2.2 for(i=1;i<3000;i++); //Delay, button debounce while (P1IN & 0x01); //Wait for the release of the button for(i=1;i<3000;i++); //Delay, button debounce P1IFG &= ~0x01;//CleanP1.0 Interrupt Flag } void main (void) { WDTCTL = WDTPW | WDTHOLD //Stop Watchdog Timer P2DIR |= BIT2; //Configure P2.2 as Output (LED1) P1DIR &= ~BIT0; //Configure P1.0 as Input (S1) P1IE |= BIT0; //Interrupt Enable in P1.0 P1IES |= BIT0; //P1.0 Interrupt flag high-to-low transition //Low Power Mode with interrupts enabled _BIS_SR (SCG1+SCG0+CPUOFF); }

BI G% TIMCR 9: B;< G:9 /=* >?*% S nh B 4n B <t ch1'ng t23nh (o t2/ng th" CE+1 B$ CE+D s&- thF g &n 1s@ s dng ngAt e&s c T 6,2 1 Int,22-0t)

!" h#i 1$ V BE h !- hb& ^&tchdog T 6,2@ t& 0h( gh B$o th&nh gh ^+THTC 6*t g " t2X #[ng #&o nh 4-Q ^+THTC f UUUU2HIA22 J 2H22K2UUUUUUUUUUUUU))g !" h#i 2$ H>- h3nh FCCN M*t th/ch &nh t5n sK 3Dh68 Yi -Ic nK B$o #* d&o *ng CFXT1) T& 0h( gh B$o th&nh gh FCCjHTC0 g " t2X g3 ch`n t #4n t2ong cb g " t2X 8PFQ FCCjHTC0 kf UU2H52UUUUUUUUUUUUUU)))g lL c"c th&nh gh Jh"c m g " t2X 6nc Xnh@ t5n sK cP& c"c ton h !- =-ng nhX0 sa #[ng #&o nh 4-Q 8HCK f UUG5LMK HNUUUUUUUg MHCK f U )926KILM HNUUUUUUUg SMHCK f U926KILM HNUU))g !" h#i %$ H>- h3nh GPIc CE+1 B$ CE+D 1Ic nK B$o chOn PD)D B$ PD)1) T& 0h( gh B$o th&nh gh n$o BL g " t2X g3 c>- h3nh cho D chOn Pc9T n$W th$nh o-t0-t@ cpn %/ %$ n0-tQ UU&5OIRUUUUU) f UU2H2MUUUUUUUUUU)g T& 0h( gh B$o th&nh gh n$o BL g " t2X g3 %$6 cho CE+1 s"ng@ CE+D tAtQ UUU&5OUTUUUU) f UU2H26UUUUUUUUUU)g !" h#i &$ H>- h3nh cho e&s c T 6,2 1M T& dqng e&s c T 6,2 1 t/o ngAt) e&s c t 6,2 gr6 D #* <6 6Ac nK t <0@ t2ong b ngs B$o cP& eTHtTD %$ ngs 2& cP& eTHtT1 ch & cho Du6) RTh&6 Jh(o h3nh D)1T) tgs B$o cP& eTHtT1 %$ ton h !- 8HCK cb t5n sK 3Dh68 Yi) tgs 2& cP& eTHtTD 0h( 1Ic ch & cho #&o nh 4- cb ngAt e&s c T 6,2 1 cb ch- Jv %$ 1sQ U95KUUUU)) G " t2X 0h( gh B$o c"c th&nh gh s&- %$ #&o nh 4- cb sK ch & cho eTHtTD nh1 t24n B$ cho 0hd0 ngAt eTHTC f UUUU2H5MUUUUUUUUg IED f UUBITLUUUUUUUUUUU)))g !" h#i '$ Hh< * cEng s->t th>0M Hh1'ng t23nh 'n g (n (o t2/ng th" CE+1 B$ CE+D t2ong ngAt) Hh< * cEng s->t th>0 n$o n4n 1Ic s dngQ UU &MGUUUUUUU) Kh b@ ng-rn =-ng nhX0 n$o sa 1Ic toch cc t2ong s-Kt ;-" t23nh ho/t *ngQ ))))))))))))))AC K)))))))))))))))))))))))

!" h#i ($ Yo$n t>t ch1'ng t23nhM


#include <msp430xG46x.h> //********************************************************** //BasicTimer interrupt service routine:refresh LCD with 0.5s //********************************************************** #pragma vector=BASICTIMER_VECTOR __interrupt void basic_timer_ISR(void) { P2OUT ^=0x06; // LED2 toogle } //********************************************************** // Main routine //********************************************************** void main(void) { WDTCTL = 0x5A00|0x0080; // Stop WDT FLL_CTL0 |= 0x20; // Set load cap for 32k xtal // Basic Timer 1 Configuration BTCTL = 0x25; // (ACLK/256)/64 IE2 |= BIT7; // Enable BT interrupt with 0.5 period // LED1 & LED2 configuration P2DIR = 0x06; // P2.2 and P2.1 as digital output P2OUT = 0x04; // LED1 on and LED2 off __bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupt }

5: B;< G:5 w4- c5- B <t ch1'ng t23nh h n thX g " t2X %5n %1It tx 0 -y z %4n %,d h o/n P1 cP& CH+) G " t2X h n thX t{ng %4n 1 s&- 1 s) t<- >n S^D@ ch1'ng t23nh ngxng <6 Rg " t2X ngxng t{ng %4nT) t<- >n S^1@ ch1'ng t23nh ho/t *ng #3nh th1Fng) Hh1'ng t23nh s dng ngAt t 6,2 h n thX CH+@ ngAt ngo$ t24n chOn PD)1 B$ PD)D cho 0hd0 ch1'ng t23nh dxng <6 h&W t <0 tc ho/t *ng) CH+ s dng t24n #o&2d cb c"c 0h5n t h n thX nh1 s&-M

S dng | %, %dc)h J}6 th,o Hh1'ng t23nh 1Ic B <t nh1 s&-M
#include "msp430FG4618.h" #include"lcd.h" char i=0; #pragma vector=BASICTIMER_VECTOR __interrupt void basic_timer_ISR(void) { lcda_display_number(0,i, 0); i++; if(i>9)i=0; } #pragma vector = PORT1_VECTOR __interrupt void port1_isr(void) { if(P1IFG & BIT0) IE2&=~BIT7; if(P1IFG & BIT1) IE2|=BIT7; int i; for(i=0;i<3000;i++); P1IFG &=~(BIT0+BIT1); } main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD;

FLL_CTL0 |= OSCCAP1; //8 pF lcda_init(); lcda_clear(); BTCTL = BTDIV + BTIP2 +BTIP1; //(ACLK/256)/128 =1Hz P1IE|=BIT0+BIT1; //SW1 SW2 P1IES |=BIT0+BIT1;// suon xuong IE2 = BIT7; __bis_SR_register(LPM3_bits +GIE); }

T=1s

G: B;< G:G /=* >?*M Th <t J< 6*t rng hr sK 'n g (n Rcho 0hd0 %& ch`n g G& 2,&% t 6, honc s dng #* Xnh thF T T& s dng 2,&% t 6,)
#include <msp430xG46x.h> //----------------------------------------------------------------------------void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer FLL_CTL0 = XCAP14PF; // Configure load caps // RTC enable, BCD mode, RTCCTL = RTCBCD+RTCHOLD+RTCMODE_3; // Init time RTCSEC = 0x11; // Set Seconds RTCMIN = 0x59; // Set Minutes RTCHOUR = 0x59; // Set Hours RTCCTL &= ~RTCHOLD; // Enable RTC // Basic Timer interrupt service routine __bis_SR_register(LPM3_bits + GIE); // Basic Timer interrupt service routine #pragma vector=BASICTIMER_VECTOR __interrupt void basic_timer(void) { lcda_display_number(1,RTCSEC & 0x0F,0); lcda_display_number(2,RTCSEC & 0xF0>>4,1);

lcda_display_number(3,RTCMIN & 0x0F,0); lcda_display_number(4,RTCMIN & 0xF0>>4,1); lcda_display_number(5,RTCHOUR & 0x0F,0); lcda_display_number(6,RTCHOUR & 0xF0>>4,0); }