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

msp430g2xx2 pinosc 02

4 110 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 4
Dung lượng 7,72 KB

Nội dung

//****************************************************************************** // MSP430G2xx2 Demo - Capacitive Touch, Pin Oscillator Method, 4-buttons // // Description: Basic 4-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 // LEDs flash if input is touched // // Input 1: LED1 (LED2 off) // Input 2: LED2 (LED1 off) // Input 3: Both LEDs on // Input 4: Both LEDs flash on/off // // ACLK = VLO = 12kHz, MCLK = SMCLK = 1MHz DCO // // MSP430G2xx2 // // /|\| XIN|// | | | // |RST XOUT|// | | // | P1.1|< Capacitive Touch Input // | | // LED < |P1.6 P1.2|< Capacitive Touch Input // | | // LED < |P1.0 P1.4|< Capacitive Touch Input // | | // | P1.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 220 /*Set to ~ half the max delta expected*/ // Defines 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) // #define LED_1 (0x01) ACLK/32768 ACLK/8192 ACLK/512 ACLK/64 SMCLK/32768 SMCLK/8192 SMCLK/512 SMCLK/64 // P1.0 LED output #define LED_2 (0x40) // P1.6 LED output // 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[NUM_SEN]={BIT1, BIT2, BIT4, BIT5}; /* System Routines*/ void measure_count(void); // Measures each capacitive sensor void pulse_LED(void); // LED gradient routine /* Main Function*/ void main(void) { unsigned int i,j; WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; BCSCTL3 |= LFXT1S_2; IE1 |= WDTIE; P2SEL = 0x00; P1DIR = LED_1 + LED_2; P1OUT = 0x00; 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 quickly delta_cnt[i] = 0; // Zero out for pos determination } 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) { 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) + DIVA_0; // ACLK/(0:1,1:2,2:4,3:8) + DIVA_3; // ACLK/(0:1,1:2,2:4,3:8) // WDT, ACLK, interval timer /* Handle baseline measurment for a base C increase*/ if (!key_pressed) // Only adjust baseline down { // if no keys are touched for (i = 0; i

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

TỪ KHÓA LIÊN QUAN

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

TÀI LIỆU LIÊN QUAN

w