// Main Function void main(void) { uint8_t i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO TI_CAPT_Init_Baseline(&keypad); TI_CAPT_Update_Baseline(&keypad,5); // Main loop starts here while (1) { keypressed = (struct Element *)TI_CAPT_Buttons(&keypad); if(keypressed) { for(i=0; i<NUM_SEN; i++) { if (keypressed == address_list[i]) { __no_operation(); } } } } } // End Main
// Main Function void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer // establish baseline TI_CAPT_Init_Baseline(&slider); TI_CAPT_Update_Baseline(&slider,5); TI_CAPT_Init_Baseline(&menu); TI_CAPT_Update_Baseline(&menu,5); // Main loop starts here while (1) { // TI_CAPT_Raw(&slider,dCNT); // TI_CAPT_Custom(&slider,dCNT); position = TI_CAPT_Slider(&slider); direction = (struct Element*)TI_CAPT_Buttons(&menu); if(direction == (struct Element*)&right) { __no_operation(); } if(direction == (struct Element*)&left); { __no_operation(); } if(position != ILLEGAL_SLIDER_WHEEL_POSITION) { __no_operation(); } __delay_cycles(100); } } // End Main
/** * Read the capacitive buttons once. Returns a bit vector with one bit representing * each available button--a button is pressed when the bit is set (1), and unset (0) * otherwise. * * Which bit corresponds to which button? */ CAP_BUTTON CapButtonRead(void) { int i; CAP_BUTTON ret = BUTTON_NONE; // Check cap touch keys // This function returns an element in address_list matching the pressed key. struct Element *keypressed = (struct Element *)TI_CAPT_Buttons(&keypad); __no_operation(); // one instruction delay as a precaution if (keypressed) // If some key was pressed { // Loop over all the key and find the one in address_list that matches for(i=0; i<NUM_KEYS; i++) { if (keypressed == address_list[i]) { ret = (CAP_BUTTON)(0x1 << i); } } } return ret; }
/* * ======== main() ======== */ uint16_t main(void) { volatile uint8_t i; WDTCTL = WDTPW + WDTHOLD; /* Stop watchdog timer */ /* Initialize IO */ P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF; PJDIR = 0xFF; P1OUT = 0; P2OUT = 0; P3OUT = 0; P4OUT = 0; PJOUT = 0; /* XT1 Setup taken from msp430fr59xx_CS_03.c code example. */ PJSEL0 |= BIT4 + BIT5; CSCTL0 = CSKEY; CSCTL1 = DCOFSEL_6; /* Set DCO = 8MHz */ CSCTL2 = SELA__LFXTCLK + SELS__DCOCLK + SELM__DCOCLK; CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0; /* ACLK/1, SMCLK/1, MCLK/1 */ CSCTL4 |= LFXTDRIVE_0; CSCTL4 &= ~LFXTOFF; do { CSCTL5 &= ~LFXTOFFG; /* Clear XT1 fault flag */ SFRIFG1 &= ~OFIFG; }while (SFRIFG1&OFIFG); /* Test oscillator fault flag */ /* establish baseline */ TI_CAPT_Init_Baseline(&keyPad); TI_CAPT_Update_Baseline(&keyPad,5); /* Main loop starts here */ while (1) { activeKey = (struct Element *)TI_CAPT_Buttons(&keyPad); for(i=0;i<6;i++) { //if(activeKey == keyAddress[i]) if(activeKey == keyPad.arrayPtr[i]) { *(uint8_t *)ledPort[i] |= ledBit[i]; } } // TI_CAPT_Custom(&keyPad,dCnt); /* * 32ms delay. This delay can be replaced with other application tasks. */ sleep(1000); /* Turn off all LEDs before next measurement */ for(i=0;i<6;i++) { *(uint8_t *)ledPort[i] &= ~ledBit[i]; } } } /* End Main */
// Main Function void main(void) { uint8_t last = 0; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_16MHZ; // Set DCO to 1, 8, 12 or 16MHz DCOCTL = CALDCO_16MHZ; 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 |= BIT0; // P1.0 out P1DIR |= BIT0; // P1.0 high P2DIR |= BIT0 | BIT1 | BIT4 | BIT5; // Configure Port 2 pins outputs // Initialize Baseline measurement TI_CAPT_Init_Baseline(&button_bar); // Update baseline measurement (Average 5 measurements) TI_CAPT_Update_Baseline(&button_bar,5); SPISetup(); // Initialize SPI Display //drawBitmap(blackbird_96_64, 96, 8, 0, 0); clear(); //setcharmode(1); //largechars //writeString(2,1,"Press button!"); // Main loop starts here while (1) { #ifdef ELEMENT_CHARACTERIZATION_MODE // Get the raw delta counts for element characterization TI_CAPT_Custom(&button_bar,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(&button_bar); // If a button has been touched, then take some action if(keyPressed) { // Up Element if(keyPressed == &a_element) { P1OUT |= BIT0; // Turn on center LED if (last != 2) { clear(); last = 2; drawBitmap(big_1, 32, 6, 32, 1); //writeString(4,3,"A Pressed"); } } if(keyPressed == &b_element) { P1OUT |= BIT0; // Turn on center LED if (last != 3) { clear(); last = 3; drawBitmap(big_2, 32, 6, 32, 1); //writeString(4,3,"B Pressed"); } } if(keyPressed == &c_element) { P1OUT |= BIT0; // Turn on center LED if (last != 1) { clear(); last = 1; drawBitmap(big_3, 32, 6, 32, 1); //writeString(4,3,"C Pressed"); } } if(keyPressed == &d_element) { P1OUT |= BIT0; // Turn on center LED if (last != 4) { clear(); last = 4; drawBitmap(big_4, 32, 6, 32, 1); //writeString(4,3,"D Pressed"); } } } else { P1OUT &= ~(BIT0); // Turn off center LED if (last != 0) { drawBitmap(blackbird_96_64, 96, 8, 0, 0); //writeString(4,4,"Press a button"); last = 0; } } // Put the MSP430 into LPM3 for a certain DELAY period sleep(DELAY); #endif } } // End Main