📄 bsp.c
字号:
/*********************************************************************
*
* IAR PowerPac
*
* (c) Copyright IAR Systems 2008. All rights reserved.
*
**********************************************************************
----------------------------------------------------------------------
File : BSP.c
Purpose : LED interface for MSP430 Evalboard
-------- END-OF-HEADER ---------------------------------------------
*/
#define BSP_C
#include "BSP.h"
#include <msp430.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
/****** Target specific configuration *******************************/
/****** Assign LEDs to Ports ****************************************/
#define _LED0_BIT (0) // LED1 on EXP430 Eval board
#define _LED1_BIT (1) // LED2 on EXP430 Eval board
#define _LED_PORT_DIR (P1DIR) // LEDS are connected to Port A
#define _LED_PORT_OUT (P1OUT)
#define _LED_MASK_ALL (_LED_MASK_LED0 | _LED_MASK_LED1)
#define _LED_MASK_LED0 (1 << _LED0_BIT)
#define _LED_MASK_LED1 (1 << _LED1_BIT)
/*********************************************************************
*
* Global functions
*
**********************************************************************
*/
/*********************************************************************
*
* BSP_Init()
*/
void BSP_Init(void) {
_LED_PORT_DIR = _LED_MASK_ALL; // Switch Port to output
_LED_PORT_OUT = _LED_MASK_ALL; // Switch LEDs on initially
P1DIR &= ~BIT2;
P1IE |= BIT2; // P1.3 interrupt enabled
P1IES |= BIT2; // P1.3 Hi/lo edge
P1IFG &= ~BIT2; // P1.3 IFG cleared
P1REN |= BIT2;
P1OUT |= BIT2;
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
P3DIR = 0xFF; // All P3.x outputs
P3OUT = 0; // All P3.x reset
UCA0CTL1 |= UCSSEL_2; // SMCLK
// UCA0BR0 = 104; // 1MHz 9600
// UCA0BR1 = 0; // 1MHz 9600
UCA0BR0 = 64; // 1MHz 1200
UCA0BR1 = 3; // 1MHz 1200
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
// IE2 |= ( UCA0RXIE | UCA0TXIE ); // Enable USCI_A0 RX interrupt
}
/*********************************************************************
*
* LED switching routines
* LEDs are switched on with low level on port lines
*/
void BSP_SetLED(int Index) {
if (Index == 0) {
_LED_PORT_OUT |= _LED_MASK_LED0; // Switch on LED 0
}
if (Index == 1) {
_LED_PORT_OUT |= _LED_MASK_LED1; // Switch on LED 1
}
}
void BSP_ClrLED(int Index) {
if (Index == 0) {
_LED_PORT_OUT &= ~_LED_MASK_LED0; // Switch off LED 0
}
if (Index == 1) {
_LED_PORT_OUT &= ~_LED_MASK_LED1; // Switch off LED 0
}
}
void BSP_ToggleLED(int Index) {
if (Index == 0) {
_LED_PORT_OUT ^= _LED_MASK_LED0;
}
if (Index == 1) {
_LED_PORT_OUT ^= _LED_MASK_LED1;
}
}
/****** EOF *********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -