- // *************************************************************************************************
- // @fn test_mode
- // @brief Manual test mode. Activated by holding buttons STAR and UP simultaneously.
- // Cancelled by any other button press.
- // @param none
- // @return none
- // *************************************************************************************************
- void test_mode(void)
- {
- u8 test_step, start_next_test;
- u8 *str;
- u8 i;
- // Disable timer - no need for a clock tick
- //关闭定时器
- Timer0_Stop();
- // Disable LCD charge pump while in standby mode
- // This reduces current consumption by ca. 5礎 to ca. 10礎
- LCDBVCTL = 0;
- // Show welcome screen
- //显示LCD的所有字段
- display_chars(LCD_SEG_L1_3_0, (u8 *) "0430", SEG_ON);
- display_chars(LCD_SEG_L2_4_0, (u8 *) "CC430", SEG_ON);
- display_symbol(LCD_SEG_L1_COL, SEG_ON);
- display_symbol(LCD_ICON_HEART, SEG_ON);
- display_symbol(LCD_ICON_STOPWATCH, SEG_ON);
- display_symbol(LCD_ICON_RECORD, SEG_ON);
- display_symbol(LCD_ICON_ALARM, SEG_ON);
- display_symbol(LCD_ICON_BEEPER1, SEG_ON);
- display_symbol(LCD_ICON_BEEPER2, SEG_ON);
- display_symbol(LCD_ICON_BEEPER3, SEG_ON);
- display_symbol(LCD_SYMB_ARROW_UP, SEG_ON);
- display_symbol(LCD_SYMB_ARROW_DOWN, SEG_ON);
- display_symbol(LCD_SYMB_AM, SEG_ON);
- // Hold watchdog
- //关闭看门狗
- WDTCTL = WDTPW + WDTHOLD;
- // Wait for button press
- //等待按键
- _BIS_SR(LPM3_bits + GIE);
- __no_operation();
- // Clear display
- //清除LCD显示
- display_all_off();
- #ifdef USE_LCD_CHARGE_PUMP
- // Charge pump voltage generated internally, internal bias (V2-V4) generation
- // This ensures that the contrast and LCD control is constant for the whole battery lifetime
- LCDBVCTL = LCDCPEN | VLCD_2_72;
- #endif
- // Renenable timer
- //使能Timer0
- Timer0_Start();
- // Debounce button press
- //按键去抖,延时100ms
- Timer0_A4_Delay(CONV_MS_TO_TICKS(100));
- //
- //按键定义见上原理图,P2口,0,1,2,3,4
#define BUTTON_STAR_PIN (BIT2)
- #define BUTTON_NUM_PIN (BIT1)
- #define BUTTON_UP_PIN (BIT4)
- #define BUTTON_DOWN_PIN (BIT0)
- #define BUTTON_BACKLIGHT_PIN (BIT3)
- #define ALL_BUTTONS (BUTTON_STAR_PIN + BUTTON_NUM_PIN + BUTTON_UP_PIN + \
- BUTTON_DOWN_PIN + BUTTON_BACKLIGHT_PIN)
复制代码
while (1)
{
// Check button event
//针对不同的按键做出不同的响应
//如果"*"和向上键同时按下
if (BUTTON_STAR_IS_PRESSED && BUTTON_UP_IS_PRESSED)
{
// Start with test #0
test_step = 0;
start_next_test = 1;
while (1)
{
if (start_next_test)
{
// Clean up previous test display
display_all_off();
start_next_test = 0;
switch (test_step)
{
case 0: // All LCD segments on
display_all_on();
// Wait until buttons are off
while (BUTTON_STAR_IS_PRESSED && BUTTON_UP_IS_PRESSED) ;
break;
case 1: // Altitude measurement
display_altitude(LINE1, DISPLAY_LINE_UPDATE_FULL);
for (i = 0; i < 2; i++)
{
while ((PS_INT_IN & PS_INT_PIN) == 0) ;
do_altitude_measurement(FILTER_OFF);
display_altitude(LINE1, DISPLAY_LINE_UPDATE_PARTIAL);
}
stop_altitude_measurement();
break;
//温度测量
case 2: // Temperature measurement
display_temperature(LINE1, DISPLAY_LINE_UPDATE_FULL);
for (i = 0; i < 4; i++)
{
Timer0_A4_Delay(CONV_MS_TO_TICKS(250));
temperature_measurement(FILTER_OFF);
display_temperature(LINE1, DISPLAY_LINE_UPDATE_PARTIAL);
}
break;
//加速度测量,在初始化的时候已经根据硬件不同,置不同的标志位,这里根据标志位选择BOSCH或者VTI的加速度传感器。
//以兼容不同的硬件版本
case 3: // Acceleration measurement
if (bmp_used)
{
bmp_as_start();
}
else
{
cma_as_start();
}
for (i = 0; i < 4; i++)
{
Timer0_A4_Delay(CONV_MS_TO_TICKS(250));
if (bmp_used)
{
bmp_as_get_data(sAccel.xyz);
}
else
{
cma_as_get_data(sAccel.xyz);
}
str = int_to_array(sAccel.xyz[0], 3, 0);
display_chars(LCD_SEG_L1_2_0, str, SEG_ON);
str = int_to_array(sAccel.xyz[2], 3, 0);
display_chars(LCD_SEG_L2_2_0, str, SEG_ON);
}
if (bmp_used)
{
bmp_as_stop();
}
else
{
cma_as_stop();
}
break;
case 4: // BlueRobin test
button.flag.up = 1;
sx_bluerobin(LINE1);
//按键去抖,延时100ms
Timer0_A4_Delay(CONV_MS_TO_TICKS(100));
get_bluerobin_data();
display_heartrate(LINE1, DISPLAY_LINE_UPDATE_FULL);
stop_bluerobin();
break;
}
// Debounce button
//按键去抖,延时200ms
Timer0_A4_Delay(CONV_MS_TO_TICKS(200));
}
// Check button event
if (BUTTON_STAR_IS_PRESSED)
{
test_step = 1;
start_next_test = 1;
}
else if (BUTTON_NUM_IS_PRESSED)
{
test_step = 2;
start_next_test = 1;
}
else if (BUTTON_UP_IS_PRESSED)
{
test_step = 3;
start_next_test = 1;
}
else if (BUTTON_DOWN_IS_PRESSED)
{
test_step = 4;
start_next_test = 1;
}
else if (BUTTON_BACKLIGHT_IS_PRESSED)
{
// Wait until button has been released (avoid restart)
while (BUTTON_BACKLIGHT_IS_PRESSED) ;
// Disable LCD and LCD charge pump
LCDBCTL0 &= ~BIT0;
LCDBVCTL = 0;
// Debounce button press
//按键去抖,延时500ms
Timer0_A4_Delay(CONV_MS_TO_TICKS(500));
// Disable timer - no need for a clock tick
Timer0_Stop();
// Hold watchdog
WDTCTL = WDTPW + WDTHOLD;
// Sleep until button is pressed (ca. 4礎 current consumption)
_BIS_SR(LPM4_bits + GIE);
__no_operation();
// Force watchdog reset for a clean restart
//看门狗标志位置位,是系统复位
WDTCTL = 1;
}
#ifdef USE_WATCHDOG
// Service watchdog
WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK + WDTCNTCL;
#endif
// To LPM3
//进入LPM3功耗模式
_BIS_SR(LPM3_bits + GIE);
__no_operation();
}
}
else
{
// Debounce button
//按键去抖
Timer0_A4_Delay(CONV_MS_TO_TICKS(100));
button.all_flags = 0;
// Turn off backlight
//关闭背光
P2OUT &= ~BUTTON_BACKLIGHT_PIN;
P2DIR &= ~BUTTON_BACKLIGHT_PIN;
break;
}
}
}