Пример #1
0
/**************************************************************************************************
 * @fn          BSP_InitBoard
 *
 * @brief       Initialize the board.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
void BSP_InitBoard(void)
{
  /* configure internal digitally controlled oscillator */
  DCOCTL  = BSP_CONFIG_MSP430_DCOCTL;
  BCSCTL1 = BSP_CONFIG_MSP430_BCSCTL1;

  /* Configure TimerA for use by the delay function */

  /* Reset the timer */
  TACTL |= TACLR; /* Set the TACLR */

  /* Clear all settings */
  TACTL = 0x0;

  /* Select the clk source to be - SMCLK (Sub-Main CLK)*/
  TACTL |= TASSEL_2;

  /* Initialize SPI for multiple devices */
  bspSpiInit();

#if defined(SW_TIMER)
#define MHZ_CLOCKS_PER_USEC      BSP_CLOCK_MHZ
#define MHZ_CLOCKS_PER_ITERATION 10

  sIterationsPerUsec = (uint8_t)(((MHZ_CLOCKS_PER_USEC)/(MHZ_CLOCKS_PER_ITERATION))+.5);

  if (!sIterationsPerUsec)
  {
    sIterationsPerUsec = 1;
  }
#endif   /* SW_TIMER */
}
Пример #2
0
/**************************************************************************************************
 * @fn      HalLcdInit
 *
 * @brief   Initilize LCD Service
 *
 * @param   init - pointer to void that contains the initialized value
 *
 * @return  None
 **************************************************************************************************/
void HalLcdInit(void)
{
#if (HAL_LCD == TRUE)
  bspSpiInit(SPI_CLOCK);
  lcdInit();
#if defined LCD_NO_DEFAULT_BUFFER && (defined HAL_IMG_AREA && (HAL_IMG_AREA == 2))
  (void)memset(HAL_LCD_DEF_BUF, 0, LCD_BYTES);
#endif
#endif
}
Пример #3
0
/**************************************************************************//**
* @brief    Main function of example.
******************************************************************************/
void main(void)
{
    uint8_t ui8KeyBm = 0;
    uint_fast16_t ui16Cnt = 0;
    uint8_t ui8Byte = APP_TX_BYTE;

    //
    // Initialize clocks and board I/O
    //
    bspInit(BSP_SYS_CLK_SPD);

    //
    // Set LED1 to indicate life
    //
    bspLedSet(BSP_LED_1);

    //
    // Initialize key driver
    //
    bspKeyInit(BSP_KEY_MODE_ISR);
    bspKeyIntEnable(BSP_KEY_SELECT|BSP_KEY_UP);

    //
    // Initialize UART to USB MCU
    //
    bspUartBufInit(pui8TxBuf, sizeof(pui8TxBuf), pui8RxBuf, sizeof(pui8RxBuf));

    //
    // Application must register the UART interrupt handler
    //
    UARTIntRegister(BSP_UART_BASE, &appUartIsr);

    //
    // Open UART connection
    //
    if(bspUartOpen(eBaudRate115200) != BSP_UART_SUCCESS)
    {
        //
        // Failed to initialize UART handler
        //
        bspAssert();
    }

    //
    // Initialize SPI interface to LCD, configure LCD, and display information.
    //
    bspSpiInit(BSP_SPI_CLK_SPD);
    lcdInit();
    lcdBufferPrintStringAligned(0, "UART example", eLcdAlignCenter, eLcdPage0);
    lcdBufferInvertPage(0, 0,127, eLcdPage0);
    lcdBufferPrintString(0, "Baud rate   :", 6, eLcdPage2);
    lcdBufferPrintIntAligned(0, bspUartBaudRateGet(), eLcdAlignRight, eLcdPage2);
    lcdBufferPrintString(0, "Format      :", 6, eLcdPage3);
    lcdBufferPrintStringAligned(0, "8-N-1", eLcdAlignRight, eLcdPage3);
    lcdBufferPrintString(0, "Flow control:", 6, eLcdPage4);
    lcdBufferPrintStringAligned(0, "No", eLcdAlignRight, eLcdPage4);
    lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignRight, eLcdPage6);
    lcdBufferPrintStringAligned(0, "SELECT to toggle mode", eLcdAlignCenter, eLcdPage7);
    lcdBufferInvertPage(0, 0,127, eLcdPage7);
    lcdSendBuffer(0);

    //
    // Enable global interrupts
    //
    IntMasterEnable();

    while(1)
    {
        ui8KeyBm = bspKeyPushed(BSP_KEY_ALL);

        if(BSP_KEY_SELECT & ui8KeyBm)
        {
            //
            // Change mode
            //
            bRepeaterMode ^= 1;
            bspLedToggle(BSP_LED_3);

            //
            // Update LCD for the new mode
            //
            lcdBufferClearPart(0, 0,127, eLcdPage6, eLcdPage6);
            if(bRepeaterMode)
            {
                lcdBufferPrintStringAligned(0, "Repeater mode",
                                            eLcdAlignCenter, eLcdPage6);
            }
            else
            {
                lcdBufferPrintStringAligned(0, "Transmit: UP key",
                                            eLcdAlignCenter, eLcdPage6);
            }
            lcdSendBufferPart(0, 0,127, eLcdPage6, eLcdPage6);
        }

        //
        // Read data from UART RX buffer to application buffer
        //
        ui16Cnt = bspUartDataGet(pui8AppBuf, bspUartRxCharsAvail());

        if(bRepeaterMode)
        {
            //
            // Repeater mode
            //

            if(ui16Cnt)
            {
                //
                // Send data from application buffer to UART TX buffer
                //
                bspUartDataPut(pui8AppBuf, ui16Cnt);
            }
        }
        else
        {
            //
            // Transmit mode
            //

            if(BSP_KEY_UP & ui8KeyBm)
            {
                //
                // Transmit a single character
                //
                bspUartDataPut(&ui8Byte, 1);
            }
        }
    }
}