📄 f4270_altimeter_sb_iar.c
字号:
// Advance RTC counter variables
//
// TickMins == 0 --> advance seconds
// TickMins == 1 --> advance minutes
//------------------------------------------------------------------------------
void RTC_Tick(unsigned int TickMins)
{
Secs = __bcd_add_short(Secs, 1);
if ((Secs == 0x60) || TickMins)
{
Secs = 0x00;
Mins = __bcd_add_short(Mins, 1);
if (Mins == 0x60)
{
Mins = 0x00;
Hrs = __bcd_add_short(Hrs, 1);
if (Hrs == 0x13)
Hrs = 0x01;
}
}
}
//------------------------------------------------------------------------------
// Decrement RTC counter variables
//
// TickMins == 0 --> decrement seconds
// TickMins == 1 --> decrement minutes
//------------------------------------------------------------------------------
void RTC_Dec(unsigned int TickMins)
{
Secs = __bcd_add_short(Secs, 0x9999);
if ((Secs == 0x99) || TickMins)
{
Secs = TickMins ? 0x00 : 0x59;
Mins = __bcd_add_short(Mins, 0x9999);
if (Mins == 0x99)
{
Mins = 0x59;
Hrs = __bcd_add_short(Hrs, 0x9999);
if (Hrs == 0x00)
Hrs = 0x12;
}
}
}
//------------------------------------------------------------------------------
// Programs the calibration constants into Flash info memory segment A
// using in-system self programming techniques. LED1 will be lit to
// indicate the programming process.
//------------------------------------------------------------------------------
void StoreCalInFlash(void)
{
FCTL2 = FWKEY + FSSEL1 + FN1; // SMCLK/3 = ~333kHz
FCTL3 = FWKEY; // Clear LOCK
FCTL1 = FWKEY + ERASE; // Enable segment erase
*(unsigned int *)0x1080 = 0; // Dummy write, erase info A
FCTL1 = FWKEY + WRT; // Enable write
CalConstA_Flash = CalConstA; // Program calibration constants
CalConstP_Flash = CalConstP;
CalConstT_Flash = CalConstT;
DispContr_Flash = DispContr;
AppFlags_Flash = AppFlags;
FCTL1 = FWKEY; // Done. Clear WRT
FCTL3 = FWKEY + LOCK; // Done. Set LOCK
LCDM1 = 0x00; // Clear display and output
LCDM2 = DIG_D; // 'done'
LCDM3 = DIG_O;
LCDM4 = DIG_N;
LCDM5 = DIG_E;
LCDM6 = 0x00;
LCDM7 = 0x00;
StatusFlags |= SF_HOLD_DISPL; // Hold display contents
}
//------------------------------------------------------------------------------
// Converts the 16-Bit integer number 'Value' to BCD and outputs it
// on the LCD display. The position of the the leftmost digit is used
// to indicate sign information.
//------------------------------------------------------------------------------
void Disp_Value(unsigned int ShiftLeft, int Value)
{
unsigned int i;
unsigned int Output;
char fNeg = 0;
char *pLCD = (char *)&LCDM7 - ShiftLeft;
if (Value < 0) // Test for negative value
{
Value = -Value; // Negate value
fNeg = 1; // Set negative flag
}
if (Value > 9999) // Perform range check
{
if (fNeg)
{
*pLCD-- = DIG_O; // Number too small
*pLCD = DIG_L;
}
else
{
*pLCD-- = DIG_I; // Number too large
*pLCD = DIG_H;
}
return; // Stop processing here
}
for (i = 16, Output = 0; i; i--) // BCD Conversion, 16-Bit
{
Output = __bcd_add_short(Output, Output);
if (Value & 0x8000)
Output = __bcd_add_short(Output, 1);
Value <<= 1;
}
for (i = 4; i; i--) // Process 4 digits
{
*pLCD-- = LCD_Tab[Output & 0x0f]; // Segments to LCD
Output >>= 4; // Process next digit
if (Output == 0 || i == 1) // Leading zeros or last dig.?
{
if (fNeg) // Append sign info
*pLCD = DIG_MINUS;
break; // Stop processing
}
}
}
//------------------------------------------------------------------------------
// Displays the BCD number 'Value' on the LCD display
// 7 digits are output
//------------------------------------------------------------------------------
void Disp_BCD(unsigned long Value)
{
char *pLCD = (char *)&LCDM7;
int i;
for (i = 0; i < 7; i++) // Process 7 digits
{
*pLCD-- = LCD_Tab[Value & 0x0f]; // Segments to LCD
Value >>= 4; // Process next digit
}
}
//------------------------------------------------------------------------------
void InitConversion(void)
{
switch (ProgramMode) // Prepare SD16 conversion
{
case PM_MEASURE_A :
case PM_MEASURE_P :
case PM_CAL_A :
case PM_CAL_P :
P6OUT |= BRIDGE_SUPPLY; // Power-up bridge sensor
SD16CTL = SD16SSEL_2; // Use ACLK for SD16
SD16INCTL0 = SD16GAIN_32 + SD16INCH_0; // 32x gain, channel pair A0
SD16CCTL0 = SD16BUF_1 + SD16OSR_1024 + SD16DF + SD16IE;
// Continuous conv., 2s compl.
break;
case PM_MEASURE_TEMP :
case PM_CAL_TEMP :
SD16CTL = SD16SSEL_2; // Use ACLK
SD16INCTL0 = SD16GAIN_1 + SD16INCH_6; // 1x gain, channel pair A6
SD16CCTL0 = SD16OSR_1024 + SD16DF + SD16IE; // Continuous conv., 2s compl.
break;
}
}
//------------------------------------------------------------------------------
void StartNextConversion(void)
{
SD16Temp = 0;
SD16TempCtr = 0;
switch (ProgramMode) // Start SD16 conversion
{
case PM_MEASURE_A :
case PM_MEASURE_P :
case PM_CAL_A :
case PM_CAL_P :
SD16NrConversions = 64; // Average 64 results
break;
case PM_MEASURE_TEMP :
case PM_CAL_TEMP :
SD16NrConversions = 1; // Don't use averaging
SD16CTL |= SD16VMIDON + SD16REFON; // Enable Vref
// Now use Timer_A to allow a defined time for voltages to settle
TAR = 65535 - 163; // Delay 164 ACLK cycles (~5ms)
TACTL = TASSEL_1 + MC_2; // ACLK, start continuous mode
while (!(TACTL & TAIFG)); // Wait for TAR overflow
TACTL = 0x00; // Stop Timer_A
break;
}
SD16CCTL0 |= SD16SC; // Start conversion
}
//------------------------------------------------------------------------------
void StopConversion(void)
{
SD16CCTL0 &= ~SD16SC; // Disable conversions
switch (ProgramMode)
{
case PM_MEASURE_A :
case PM_MEASURE_P :
case PM_CAL_A :
case PM_CAL_P :
P6OUT &= ~BRIDGE_SUPPLY; // Power-down bridge sensor
break;
case PM_MEASURE_TEMP :
case PM_CAL_TEMP :
SD16CTL = 0x00; // Disable SD16 reference
break;
}
}
//------------------------------------------------------------------------------
// The SD16 ISR is executed upon SD16 conversion completion.
//------------------------------------------------------------------------------
#pragma vector = SD16_VECTOR
__interrupt void SD16_ISR(void)
{
SD16Temp += (long)(int)SD16MEM0; // Read 15+1 bits
if (++SD16TempCtr >= SD16NrConversions) // Enough samples taken?
{
SD16CCTL0 &= ~SD16SC; // Disable conversions
SD16CTL &= ~(SD16VMIDON + SD16REFON); // Disable SD16 reference
StatusFlags |= SF_SD16_READY; // Conversion result ready
__bic_SR_register_on_exit(LPM3_bits); // Exit LPM3 on ISR exit
}
}
//------------------------------------------------------------------------------
// The Basic Timer ISR is executed every 1s and used to wake up the
// main program from low-power mode.
//------------------------------------------------------------------------------
#pragma vector = BASICTIMER_VECTOR
__interrupt void BT_ISR(void)
{
StatusFlags |= SF_BT_TICK; // Indicate Basic Timer tick
__bic_SR_register_on_exit(LPM3_bits); // Exit LPM3 on ISR exit
}
//------------------------------------------------------------------------------
// The Port 1 ISR is executed on detection of a push-button press.
//------------------------------------------------------------------------------
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1IE &= ~(PUSH_BUTTON1 + PUSH_BUTTON2); // Disable button interrupts
WDTCTL = WDT_ADLY_16; // WDT as 16ms interval timer
IFG1 &= WDTIFG;
IE1 |= WDTIE; // Enable WDT interrupt
}
//------------------------------------------------------------------------------
// The WDT ISR is executed periodically after a push-button press was detected
// to poll the port pins and update various push-button status variables.
//------------------------------------------------------------------------------
#pragma vector = WDT_VECTOR
__interrupt void WDT_ISR(void)
{
if (P1IFG & PUSH_BUTTON1) // Was button 1 pressed?
{
if (!(StatusFlags & SF_PB1_DOWN)) // Press detected?
{
PB1DownCtr = 0; // Reset 'down' counter
StatusFlags |= SF_PB1_DOWN;
StatusFlags |= SF_PB1_PRESSED; // Button got pressed
StatusFlags &= ~SF_PB1_RELEASED;
}
if (P1IN & PUSH_BUTTON1) // Button released?
{
P1IFG &= ~PUSH_BUTTON1; // Clear int flag
StatusFlags &= ~SF_PB1_DOWN;
StatusFlags &= ~SF_PB1_PRESSED; // Button got released
StatusFlags |= SF_PB1_RELEASED;
}
if (PB1DownCtr != 0xff) PB1DownCtr++; // Increment button counter
__bic_SR_register_on_exit(LPM3_bits); // Exit LPM3 on ISR exit
}
if (P1IFG & PUSH_BUTTON2) // Was button 2 pressed?
{
if (!(StatusFlags & SF_PB2_DOWN)) // Press detected?
{
PB2DownCtr = 0; // Reset 'down' counter
StatusFlags |= SF_PB2_DOWN;
StatusFlags |= SF_PB2_PRESSED; // Button got pressed
StatusFlags &= ~SF_PB2_RELEASED;
}
if (P1IN & PUSH_BUTTON2) // Button released?
{
P1IFG &= ~PUSH_BUTTON2; // Clear int flag
StatusFlags &= ~SF_PB2_DOWN;
StatusFlags &= ~SF_PB2_PRESSED; // Button got released
StatusFlags |= SF_PB2_RELEASED;
}
if (PB2DownCtr != 0xff) PB2DownCtr++; // Increment button counter
__bic_SR_register_on_exit(LPM3_bits); // Exit LPM3 on ISR exit
}
if (!(P1IFG & (PUSH_BUTTON1 + PUSH_BUTTON2))) // Buttons clear?
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1IE |= PUSH_BUTTON1 + PUSH_BUTTON2; // Enable button interrupts
}
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -