📄 userexperience.c
字号:
//**********************************************************************//*****
// MSP-EXP430F5438 Experimenter's Board - User Experience Demo
//
// Main Project File: UserExprience.c
//
// D. Dang
// Texas Instruments Inc.
// Ver 1.00 - May 2008
// Built with Code Composer Essentials CCE v3.2
//*****************************************************************************
#include <msp430x54x.h>
#include "..\MSP-EXP430F5438 HAL\hal_MSP-EXP430F5438.h"
#include "UserExperienceGraphics.h"
#include "flashUtils.h"
//--Calibration constants and user configuration values stored in INFOB Flash--
#pragma DATA_SECTION(boardMode, ".infoB");
#pragma DATA_SECTION(lcdBackLightLevelSetting, ".infoB");
#pragma DATA_SECTION(lastAudioByteFlash, ".infoB");
#pragma DATA_SECTION(temperatureConversion, ".infoB");
#pragma DATA_SECTION(temperatureCalibrationC, ".infoB");
#pragma DATA_SECTION(wakeUpOnAcc, ".infoB");
#pragma DATA_SECTION(lcdContrastSetting, ".infoB");
#pragma DATA_SECTION(Acc_X_Calibrated_Offset, ".infoB");
#pragma DATA_SECTION(Acc_Y_Calibrated_Offset, ".infoB");
#pragma DATA_SECTION(Acc_Z_Calibrated_Offset, ".infoB");
#pragma DATA_ALIGN(boardMode, 8);
#pragma DATA_ALIGN(lcdBackLightLevelSetting, 8);
#pragma DATA_ALIGN(lastAudioByteFlash, 32);
#pragma DATA_ALIGN(lcdContrastSetting, 8);
#pragma DATA_ALIGN(temperatureConversion, 8);
#pragma DATA_ALIGN(temperatureCalibrationC, 32);
#pragma DATA_ALIGN(wakeUpOnAcc, 8);
#pragma DATA_ALIGN(Acc_X_Calibrated_Offset, 16);
#pragma DATA_ALIGN(Acc_Y_Calibrated_Offset, 16);
#pragma DATA_ALIGN(Acc_Z_Calibrated_Offset, 16);
#define TIME_OUT 10
#define TIME_OUT2 3
#define MENU_MAX 6
#define SETTING_MENU_MAX 6
#define MENU_ITEM_WIDTH 14
enum{ LPM4_MODE, LPM3_MODE, ACTIVE_MODE, APPLICATION_MODE } ;
enum{ APP_CLOCK, APP_BAL_BALL, APP_USB, APP_AUDIO, PMM_MCLK, MENU_SETTING};
enum{ SET_TIME, SET_CONTRAST, SET_BACKLIGHT, SET_TEMPERATURE_CONVERSION,
CONFIGURE_ACCELEROMETER, EXIT_SETTING};
unsigned char boardMode;
unsigned char lcdBackLightLevelSetting;
unsigned char lcdContrastSetting;
long temperatureCalibrationC;
unsigned char temperatureConversion;
unsigned long lastAudioByteFlash;
int Acc_X_Calibrated_Offset;
int Acc_Y_Calibrated_Offset;
int Acc_Z_Calibrated_Offset;
unsigned char wakeUpOnAcc;
unsigned char boardModeLOCAL;
int Acc_X_Calibrated_OffsetLOCAL;
int Acc_Y_Calibrated_OffsetLOCAL;
int Acc_Z_Calibrated_OffsetLOCAL;
unsigned char lcdBackLightLevelSettingLOCAL;
unsigned char lcdContrastSettingLOCAL;
unsigned char temperatureConversionLOCAL;
long temperatureCalibrationCLOCAL;
unsigned char wakeUpOnAccLOCAL;
static char menuText[]={
"MSP-EXP430F5438\0"
" 1. Clock \0"
" 2. UniBall \0"
" 3. USB-UART \0"
" 4. Voice Rec\0"
" 5. PMM-MCLK \0"
" 6. Settings \0"
};
unsigned char menuPos, settingMenuPos;
unsigned char timeOutCounter = 0;
unsigned char CpuMode, accWake=0, menuPos, settingMenuPos;
volatile unsigned char buttonsPressed;
volatile unsigned char buttonDebounce;
char TemperatureStr[]= "\0\0\0\0\0\0";
char VccStr[] = "0.0V";
unsigned char RTCAccHalfSec = 0, RTCExit64Hz= 0 , RTCExitSec= 0, RTCAccSec = 0;
#include "clock.c"
#include "balanceBall.c"
#include "usbTest.c"
#include "audio.c"
#include "menuSetting.c"
#include "PMM.c"
void setupRTC();
/**********************************************************************//**
* @brief Checks for the board revision and returns a value < 0 if wrong
* revision is specified in main.c
*
* @param none
*
* @return Whether or not the board revision matches the software
* - 0 - The board revision does not match the software
* - 1 - The board revision matches the software
*************************************************************************/
unsigned char assert_board_version( void )
{
P8DIR &= ~BIT7; // Set P8.7 input
P8OUT |= BIT7; // Set pullup resistor
P8REN |= BIT7; // Enable pull up resistors
#ifdef REV_02
if(!(P8IN & BIT7)) // Board rev = 0_02?
return 0;
#else
if((P8IN & BIT7)) // Board rev = 0_03?
return 0;
#endif
P8DIR |= BIT7; // Set P8.7 output
P8OUT &= ~BIT7; // Set P8.7 = 0
P8REN &= ~BIT7; // Disable pull up resistors
return 1;
}
/**********************************************************************//**
* @brief Enters LPM3 and waits for either accelerometer tilt or a button tilt
* to activate the board.
*
* @param none
*
* @return none
*************************************************************************/
void lowPowerMode3(void)
{
int accX, accY, accZ;
CpuMode = LPM3_MODE;
halLcdClearScreen();
halLcdImage(TI_BUG, 14, 106, 10, 0);
halLcdSetBackLight(0);
halLcdStandby();
accWake = 0;
if (wakeUpOnAcc)
{
RTCCTL0 |= RTCRDYIE; //Enable interrupt
RTCAccSec = 1;
halAccelerometerInit();
halAdcSetQuitFromISR( 1 );
}
halBoardSetSystemClock( SYSCLK_12MHZ );
/* Either a button press or an RTC interrupt will wake the CPU
* from LPM3 mode. The RTC interrupt will periodically enable and
* re-initialize the accelerometer to see if the user has registered
* a change in the tilt that is greater than the accelerometer thresholds.
* If so, accWake is set and the board is activated
*/
do
{
halAccelerometerShutDown();
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3
__no_operation(); // For debugger only
if (!buttonsPressed)
{
halAccelerometerRead( &accX, &accY, &accZ );
accWake = ( accX > ACC_X_THRESHOLD || accX < -ACC_X_THRESHOLD ||
accY > ACC_Y_THRESHOLD || accY < -ACC_Y_THRESHOLD) ;
}
}
while (accWake == 0 && buttonsPressed == 0);
halBoardSetSystemClock( SYSCLK_16MHZ );
RTCCTL0 |= RTCRDYIE; //Enable interrupt
RTCAccSec = 0;
halAccelerometerShutDown();
halLcdInit();
halLcdInit();
halLcdClearScreen();
halLcdSetBackLight(lcdBackLightLevelSettingLOCAL );
CpuMode = ACTIVE_MODE;
}
// -------------- Active Mode with Menu---------------------------------------
/**********************************************************************//**
* @brief Enters LPM3 and waits for either accelerometer tilt or a button tilt
* to activate the board.
*
* @param menuText The text that constitues the application menu.
*
* @param menuPos The line of the current menu option.
*
* @param change
*
* - 0 - Move menu selection up
* - 1 - Move menu selection down
*
* @param menuNum The enumerated value that represents the current
* menu selection.
*
* @return none
*************************************************************************/
void menuUpdate(char *menuText, unsigned char *menuPos, int change,
unsigned char menuNum)
{
halLcdPrintLine(&menuText[*menuPos*MENU_ITEM_WIDTH+16],
(*menuPos)+1, OVERWRITE_TEXT );
if (change == 0) //Subtract
{
if ( *menuPos > 0 )
(*menuPos)--;
else
*menuPos = (menuNum - 1);
}
else
{
if ( (*menuPos) < menuNum - 1 )
(*menuPos)++;
else
*menuPos = 0;
}
halLcdPrintLine(&menuText[*menuPos*MENU_ITEM_WIDTH+16],
(*menuPos)+1, INVERT_TEXT | OVERWRITE_TEXT );
}
/**********************************************************************//**
* @brief Draws and manages the selection of the menu options.
*
* @param menuText The text that constitues the application menu.
*
* @param menuNum The enumerated value that represents the current
* menu selection.
*
* @return The updated, or latest, menu selection.
*************************************************************************/
unsigned char activeMenuMode(char *menuText, unsigned char menuNum)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -