//****************************************************************************** //MSP430-TEST44X Demo Timer_B worked at capture mode ,LCD display the key value // // Description;P1.1 connect P3.6; P1.2 connect P3.5; P1.3 connect P3.4; // Timer_B worked at the capture mode ,when the key put down,bring a negl . // Timer_B capture the signal and intrrupt to get the key value.LCD dispaly // the key vaule.There are have eight key weave. // only key_1;only key_2,only key_3;put key_1>5s;put key_3>5s;first key_2, // then key_3;first key_3 then key_2; // // // msp430f449 // --------------- // | P3.4 |<----KEY_1(INC) // | P3.5 |<----KEY_2(DEC) // | P3.6 |<----KEY_3(FUN) // | | // | | // Yang Rui // Lierda, Inc // MAY 2004 // Built with IAR Embedded Workbench Version: 1.26B //******************************************************************************* #include unsigned int key_count=0x00; unsigned char key_value=0xff; unsigned char kinput=0x00; unsigned char ktemp=0x00; unsigned char kstore=0x00; unsigned char kready=0x00; unsigned char koutput=0x00; unsigned char getkey=0x00; unsigned char key_flag=0x00; const unsigned kconst=0x70; #define ten_ms 0x028e; #define key_1_5s 0x1f; #define key_error 0xee; #define key_3_5s 0x3f; #define key_2_3 0x23; #define key_3_2 0x32; const unsigned char lcd_table[16]={ 0x7B, /* "0" */ 0x12, /* "1" */ 0x4F, /* "2" */ 0x1F, /* "3" */ //0-F display table 0x36, /* "4" */ 0x3D, /* "5" */ 0x7D, /* "6" */ 0x13, /* "7" */ 0x7F, /* "8" */ 0x3F, /* "9" */ 0x77, /* "A" */ 0x7C, /* "B" */ 0x69, /* "c" */ 0x5E, /* "D" */ 0x6D, /* "E" */ 0x65, /* "F" */ }; void main(void) { int i; WDTCTL = WDTPW + WDTHOLD; TBCTL = TBSSEL0+TBCLR; TBCCTL3 = CM_2+SCS+CAP+CCIE+CCIS_1; //下降沿捕获,CCI3B 为信号源 TBCCTL4 = CM_2+SCS+CAP+CCIE+CCIS_1; //下降沿捕获,CCI4B 为信号源 TBCCTL5 = CM_2+SCS+CAP+CCIE+CCIS_1; //下降沿捕获,CCI5B 为信号源 P3SEL |= BIT4+BIT5+BIT6; BTCTL=BTSSEL+BT_ADLY_250+BTFRFQ1; //BT 0.25 S interrupt IE2|=BTIE; P5SEL=0xfc; //enable lcd display LCDCTL=LCDON+LCD4MUX+LCDP2; for (i=0; i<8; ++i) // clear lcd LCDMEM[i] = 0x00; _EINT(); //允许中断 //*mainloop*// for(;;) { _BIS_SR(LPM3_bits); //进入低功耗模式3 _NOP(); } } #if __VER__ < 200 interrupt[TIMERB1_VECTOR] void Timer_B1(void) #else #pragma vector=TIMERB1_VECTOR __interrupt void Timer_B1 (void) #endif { switch (TBIV) { case 6: goto key; case 8:goto key; case 10:goto key; key: if (TBCTL&MC_1) { kinput= ~P3IN; kready = ktemp & kinput | kready &(ktemp ^ kinput); ktemp = kinput; koutput = kready & ( ~kstore | kconst); kstore = kready; if (koutput!=0) key_count++; if (koutput==0x10) getkey=0x10; else if (koutput==0x20) getkey=0x20; else if (koutput==0x40) getkey=0x40; } else { TBCTL |= MC_1+TBIE; TBCCTL3 = CCIE; TBCCR3 = ten_ms; TBCCR0 = TBCCR3; break; } switch (koutput) { case 0x00: goto key_00; case 0x10: goto key_10; // case 0x20: goto key_20; case 0x30: goto key_30; case 0x40: goto key_40; case 0x50: goto key_50; case 0x60: goto key_60; key_00: if((P3IN&0x70)!=0x70) break; else if(getkey==0x10) key_value=0x10; else if((getkey==0x20)&(key_flag==0)) key_value=0x20; else if((getkey==0x40)&(key_flag==0)) key_value=0x40; goto tb_init; key_10: if(key_count>250) { key_value=key_1_5s; goto tb_init;} break; key_30: key_value=0x30; goto tb_init; key_40: if(key_count>250) { key_value=key_3_5s; goto tb_init;} break; key_50: key_value=key_error; goto tb_init; key_60: key_flag++; if(getkey==0x20) {key_value=key_2_3; break;} else if(getkey==0x40) {key_value=key_3_2; break;} tb_init: TBCTL = TBSSEL_1+TBCLR; TBCCTL3 = CM_2+SCS+CAP+CCIE+CCIS_1; //下降沿捕获,CCI3B 为信号源 TBCCTL4 = CM_2+SCS+CAP+CCIE+CCIS_1; //下降沿捕获,CCI4B 为信号源 TBCCTL5 = CM_2+SCS+CAP+CCIE+CCIS_1; //下降沿捕获,CCI5B 为信号源 key_count=00; kinput=00; ktemp=00; kstore=00; kready=00; koutput=00; getkey=00; key_flag=00; } break; } } #pragma vector=BASICTIMER_VECTOR __interrupt void basic_timer(void) { LCDMEM[1]=lcd_table[key_value&0x0f]; LCDMEM[2]=lcd_table[key_value>>4]; }