1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

msp430g2xx2 pinosc 04

5 133 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 9,54 KB

Nội dung

//****************************************************************************** // MSP430G2xx2 Demo - Capacitive Touch, Pin Oscillator Method, buttons, UART // // Description: Basic 8-button input using the built-in pin oscillation feature // on GPIO input structure PinOsc signal feed into TA0CLK WDT interval is used // to gate the measurements Difference in measurements indicate button touch // Pins used for inputs listed in the diagram below // After each scan, one UART byte identifying the key# being pressed is // transmitted via TimerA UART at port pin P1.1 // // // ACLK = VLO = 12kHz, MCLK = SMCLK = 1MHz DCO // // MSP430G2xx2 // // /|\| | // | | | // |RST | // | | // input >|P2.0 P1.1| > TA UART output TXD // | | // input >|P2.1 | // | | // input >|P2.2 P2.7|< Capacitive Touch Input // | | // input >|P2.3 P2.6|< Capacitive Touch Input // | | // input >|P2.4 P2.5|< Capacitive Touch Input // | | // // // Brandon Elliott/D Dang // Texas Instruments Inc // November 2010 // Built with IAR Embedded Workbench Version: 5.10 //****************************************************************************** #include "msp430g2452.h" /* Define User Configuration values */ /* */ /* Defines WDT SMCLK interval for sensor measurements*/ #define WDT_meas_setting (DIV_SMCLK_512) /* Defines WDT ACLK interval for delay between measurement cycles*/ #define WDT_delay_setting (DIV_ACLK_512) /* Sensor settings*/ #define NUM_SEN #define KEY_LVL 190 /* Set to ~ half the max delta expected*/ // Total number of sensors // Defines threshold for a key press /* Definitions for use with the WDT settings*/ #define DIV_ACLK_32768 (WDT_ADLY_1000) // #define DIV_ACLK_8192 (WDT_ADLY_250) // #define DIV_ACLK_512 (WDT_ADLY_16) // #define DIV_ACLK_64 (WDT_ADLY_1_9) // #define DIV_SMCLK_32768 (WDT_MDLY_32) // #define DIV_SMCLK_8192 (WDT_MDLY_8) // #define DIV_SMCLK_512 (WDT_MDLY_0_5) // #define DIV_SMCLK_64 (WDT_MDLY_0_064) // ACLK/32768 ACLK/8192 ACLK/512 ACLK/64 SMCLK/32768 SMCLK/8192 SMCLK/512 SMCLK/64 /* Global variables for sensing*/ unsigned int base_cnt[NUM_SEN]; unsigned int meas_cnt[NUM_SEN]; int delta_cnt[NUM_SEN]; unsigned char key_press[NUM_SEN]; char key_pressed; int cycles; const unsigned char electrode_bit_P2[NUM_SEN]={BIT0, BIT1, BIT2, BIT3, BIT4}; /* System Routines*/ void measure_count(void); // Measures each capacitive sensor void TX_Byte (char); // Transmits key pressed via UART /* Main Function*/ void main(void) { unsigned int i,j; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO IE1 |= WDTIE; // enable WDT interrupt P2SEL = 0x00; // No XTAL bis_SR_register(GIE); measure_count(); for (i = 0; i0; i ) // Repeat and avg base measurement { measure_count(); for (j = 0; j 1; // Re-average up quickly delta_cnt[i] = 0; // Zero out for position determination } else { delta_cnt[i] = base_cnt[i] - meas_cnt[i]; // Calculate delta: c_change } if (delta_cnt[i] > j) // Determine if each key is pressed { // per a preset threshold key_press[i] = 1; // Specific key pressed j = delta_cnt[i]; key_pressed = i+1; // key pressed } } else key_press[i] = 0; /* Delay to next sample, sample if (key_pressed) { TX_Byte(key_pressed); BCSCTL1 = (BCSCTL1 & 0x0CF) + cycles = 20; } else { cycles ; if (cycles > 0) BCSCTL1 = (BCSCTL1 & 0x0CF) else { BCSCTL1 = (BCSCTL1 & 0x0CF) cycles = 0; } } WDTCTL = WDT_delay_setting; more slowly if no keys are pressed*/ DIVA_0; // ACLK/(0:1,1:2,2:4,3:8) // ACLK/(0:1,1:2,2:4,3:8) + DIVA_0; // ACLK/(0:1,1:2,2:4,3:8) + DIVA_3; // WDT, ACLK, interval timer /* Handle baseline measurment for a base C increase*/ if (!key_pressed) // adjust down if no keys touched { for (i = 0; i

Ngày đăng: 25/12/2017, 12:24

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w