Advertisement
Guest User

Untitled

a guest
Oct 10th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.55 KB | None | 0 0
  1. /* --COPYRIGHT--,BSD
  2.  * Copyright (c) 2012, Texas Instruments Incorporated
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * *  Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  *
  12.  * *  Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  *
  16.  * *  Neither the name of Texas Instruments Incorporated nor the names of
  17.  *    its contributors may be used to endorse or promote products derived
  18.  *    from this software without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30.  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  * --/COPYRIGHT--*/
  32. /*
  33.  *  main.c
  34.  *  RO_COMPB_TB0_WDTA example with the MSP430F5529.
  35.  *
  36.  *     c-+------------------R--+--<PortMap/TB0CLK/CBOUT
  37.  *       |                     |
  38.  *       |  c-+-------------R--+
  39.  *       |    |                |
  40.  *       |    | c-+---------R--+
  41.  *       |    |   |            |
  42.  *       |    |   | c-+-----R--+
  43.  *       |    |   |   |        |
  44.  *       |    |   |   | c-+-R--+
  45.  *       |    |   |   |   |
  46.  *       |    |   |   |   +------->CB0
  47.  *       |    |   |   +----------->CB1
  48.  *       |    |   +--------------->CB2
  49.  *       |    +------------------->CB3
  50.  *       +------------------------>CB4
  51.  *
  52.  *  In order to access the TimerB0 clock input the port mapping value must be
  53.  *  set to 1 (see Table 9 of the MSP430F551x,MSP430F552x datasheet).  In this
  54.  *  example the TB0CLK/CBOUT function is ported to pin 4.7.
  55.  *
  56.  *  Some MSP430 devices allow the digital IO to be driven from a different
  57.  *  voltage rail (DVIO) than the voltage rail (VCC) that the Comp_B peripheral
  58.  *  uses.  If the comparator output, CBOUT, uses DVIO and DVIO is different
  59.  *  from VCC, then the input high and input low values set within the library
  60.  *  need to be updated.  These values are set in the Comp_B control register 2,
  61.  *  CBCTL2, found in the CTS_HAL.c file.
  62.  *
  63.  *  The element and sensor definitions found in the configuration file
  64.  *  structure.c use designated initializer lists. This allows members to be
  65.  *  initialized in any order and also enhances the readability of the element
  66.  *  being initialized.  
  67.  *  This feature requires the GCC language extension found in Code Composer
  68.  *  Studio (CCS).  C99 is the default dialect found in IAR and therefore the
  69.  *  default settings can be used.
  70.  */
  71. #include "CTS_Layer.h"
  72.  
  73. #define NUM_KEYS    5
  74. #define LED4        BIT5
  75. #define LED5        BIT4
  76. #define LED6        BIT3
  77. #define LED7        BIT3
  78. #define LED8        BIT1
  79.  
  80. uint16_t dCnt[NUM_KEYS];
  81. struct Element* keypressed;
  82.  
  83. const struct Element* address_list[NUM_KEYS] =
  84. {
  85.     &element0,
  86.     &element1,
  87.     &element2,
  88.     &element3,
  89.     &element4
  90. };                     
  91. /*
  92.  *  Invert order of LEDs so that when pad1 is touched the LED with pad5 is
  93.  *  illuminated.
  94.  */
  95. const uint8_t ledMask[NUM_KEYS] = {
  96.         LED4,
  97.         LED5,
  98.         LED6,
  99.         LED7,
  100.         LED8
  101. };
  102. /*
  103.  *  ======== main() ========
  104.  */
  105. uint16_t main(void)
  106. {
  107.     uint8_t i;
  108.     WDTCTL = WDTPW + WDTHOLD;     // Stop watchdog timer
  109.     /* Default DCO frequency, ACLK = REFO */
  110.     UCSCTL4 |= SELA_2;
  111.     /* Port Map P4.7 to TB0CLK/CBOUT */
  112.     PMAPKEYID = 0x2D52;  // Unlock
  113.     P4MAP7 = 1;          // Port Px.y map
  114.     PMAPKEYID = 0xFFFF;  // Illegal write to lock
  115.     /* Initialize IO */
  116.     P1DIR = 0xFF;
  117.     P2DIR = 0xFF;
  118.     P3DIR = 0xFF;
  119.     P4DIR = 0xFF;
  120.     P5DIR = 0xFF;
  121.     P6DIR = 0xFF;
  122.     P7DIR = 0xFF;
  123.     P8DIR = 0xFF;
  124.     P1OUT = 0;
  125.     P2OUT = 0;
  126.     P3OUT = 0;
  127.     P4OUT = 0;
  128.     P5OUT = 0;
  129.     P6OUT = 0;
  130.     P7OUT = 0;
  131.     P8OUT = 0;
  132.     /*
  133.      *  establish baseline
  134.      */
  135.     TI_CAPT_Init_Baseline(&keypad);
  136.     TI_CAPT_Update_Baseline(&keypad,5);
  137.     while (1)
  138.     {
  139.         P1OUT &= ~(LED4+LED5+LED6+LED7+LED8);
  140.         keypressed = (struct Element *)TI_CAPT_Buttons(&keypad);
  141.         TI_CAPT_Custom(&keypad,dCnt);
  142.         __no_operation();
  143.         if(keypressed)
  144.         {
  145.             for(i=0; i<NUM_KEYS; i++)
  146.             {
  147.                 if (keypressed == address_list[i])
  148.                 {
  149.                     P1OUT |= ledMask[i];
  150.                 }
  151.             }
  152.         }
  153.         __delay_cycles(10000);
  154.     } // while loop
  155. } // End Main
  156. /*
  157.  *  Initialize all unused interrupt vectors
  158.  */
  159. #pragma vector=RTC_VECTOR,PORT2_VECTOR,TIMER0_A0_VECTOR,                    \
  160.   USCI_B1_VECTOR,USCI_A1_VECTOR,PORT1_VECTOR,TIMER1_A1_VECTOR,DMA_VECTOR,   \
  161.   TIMER0_A1_VECTOR,TIMER1_A0_VECTOR,TIMER2_A0_VECTOR,TIMER2_A1_VECTOR,      \
  162.   USCI_B0_VECTOR,USCI_A0_VECTOR,TIMER0_B1_VECTOR,TIMER0_B0_VECTOR,          \
  163.   ADC12_VECTOR,COMP_B_VECTOR,UNMI_VECTOR,SYSNMI_VECTOR,USB_UBM_VECTOR
  164. __interrupt void ISR_trap(void)
  165. {
  166.     /* The following will cause a software BOR */
  167.     PMMCTL0 = PMMPW | PMMSWBOR;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement