完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
//******************************************************************************
// RO_PINOSC_TA0_WDTp_Wheel_Buttons example // Touch the five wheel buttons to turn on/off the center button LED // RO method capactiance measurement using PinOsc IO, TimerA0, and WDT+ // // Schematic Description: // // MSP430G2452 // ----------------- // /|| XIN|- // | | | // --|RST XOUT|- // | | // SWITCH 3<--|P2.7 P1.3|<--Capacitive Touch 1 // | | // SWITCH 2<--|P1.7 P1.4|<--Capacitive Touch 2 // | | // SWITCH 1<--|P1.6 P1.5|<--Capacitive Touch 3 // | | // | | // // The WDT+ interval represents the measurement window. The number of // counts within the TA0R that have accumulated during the measurement // window represents the capacitance of the element. This is lowest // power option with either LPM3 (ACLK WDTp source) or LPM0 (SMCLK WDTp // source). // //****************************************************************************** #include "msp430g2452.h" #include "CTS_Layer.h" // Uncomment to have this compiler directive run characterization functions only // Comment to have this compiler directive run example application //#define ELEMENT_CHARACTERIZATION_MODE #define DELAY 5000 // Timer delay timeout count, 5000*0.1msec = 500 msec struct Element * keyPressed; // Pointer to the Element structure #ifdef ELEMENT_CHARACTERIZATION_MODE // Delta Counts returned from the API function for the sensor during characterization unsigned int wheelCnt[3]; // Becuase the Wheel is composed of five elements #endif // Sleep Function // Configures Timer A to run off ACLK, count in UP mode, places the CPU in LPM3 // and enables the interrupt vector to jump to ISR upon timeout void sleep(unsigned int time) { TA0CCR0 = time; TA0CTL = TASSEL_1+MC_1+TACLR; TA0CCTL0 &= ~CCIFG; TA0CCTL0 |= CCIE; __bis_SR_register(LPM3_bits+GIE); __no_operation(); } void delay() { unsigned char i,j; for(i=1;i>0;i--) for(j=100;j>0;j--); } // Main Function void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1, 8, 12 or 16MHz DCOCTL = CALDCO_1MHZ; BCSCTL1 |= DIVA_0; // ACLK/1 [ACLK/(0:1,1:2,2:4,3:8)] BCSCTL2 |= DIVS_3; // SMCLK/8 [SMCLK/(0:1,1:2,2:4,3:8)] BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO Clock Source P1OUT = 0x00; // Clear Port 1 bits P1DIR |= BIT6; // Set P1.6 as output pin P1DIR |= BIT7; // Set P1.6 as output pin P2SEL = 0x00; // No XTAL P2OUT = 0x00; // Drive all Port 2 pins low P2DIR = 0xFF; // Configure all Port 2 pins outputs // Initialize Baseline measurement TI_CAPT_Init_Baseline(&wheel_buttons); // Update baseline measurement (Average 5 measurements) TI_CAPT_Update_Baseline(&wheel_buttons,3); // Main loop starts here while (1) { #ifdef ELEMENT_CHARACTERIZATION_MODE // Get the raw delta counts for element characterization TI_CAPT_Custom(&wheel_buttons,wheelCnt); __no_operation(); // Set breakpoint here #endif #ifndef ELEMENT_CHARACTERIZATION_MODE // Return the pointer to the element which has been touched keyPressed = (struct Element *)TI_CAPT_Buttons(&wheel_buttons); // If a button has been touched, then take some action if(keyPressed) { // Left Element if(keyPressed == &left_element) { P1OUT ^= BIT6; // Turn on center LED } // Right Element if(keyPressed == &right_element) { P2OUT ^= BIT7; // Turn on center LED } // Middle Element if(keyPressed == &middle_element) { P1OUT ^= BIT7; // Turn on center LED } } // Put the MSP430 into LPM3 for a certain DELAY period sleep(DELAY); #endif } } // End Main /******************************************************************************/ // Timer0_A0 Interrupt Service Routine: Disables the timer and exists LPM3 /******************************************************************************/ #pragma vector=TIMER0_A0_VECTOR __interrupt void ISR_Timer0_A0(void) { TA0CTL &= ~(MC_1); TA0CCTL0 &= ~(CCIE); __bic_SR_register_on_exit(LPM3_bits+GIE); } 这是程序,按住触摸按键会不停闪烁,怎么能让它检测按住松开算一次动作,请教各位 |
|
相关推荐
1 个讨论
|
|
只有小组成员才能发言,加入小组>>
3030个成员聚集在这个小组
加入小组2921 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3591 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2340 浏览 1 评论
4799 浏览 1 评论
2572 浏览 1 评论
1321浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3591浏览 2评论
2921浏览 1评论
1505浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 09:16 , Processed in 1.122393 second(s), Total 44, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号