?? test44x_ca04.c
字號(hào):
#include "msp430x44x.h"
//******************************************************************************
// MSP430-TEST44X Demo - Comp_A Slope ADC to Detect Temp Level Set P5.1 > 25c
//
// Description: Comparator_A is used to detect a resistance threashold.
// Discharge times of a 0.1uf capacitor through a 10k-NTC (25c) and 10k ohm
// reference resistor are compared. If the NTC discharge time is is lower
// than the 10k referece, P5.1 is set. If the NTC discharge time is higher
// than refernce, P5.1 is reset. The LED is ON if the temperature is greater
// than 25c.
// ACLK = n/a, MCLK = SMCLK = default DCO ~ 800k
//
// MSP430F449
// -----------------
// /|\ | XIN|-
// | | |
// ---|RST XOUT|-
// | |
// +-10k-|P1.0 |
// | | |
// +-NTC-|P1.7 |
// | | |
// +-----|P1.6 P5.1|-->LED
// | | |
// ===.1uf| |
// | | |
// ------|VSS
//
// NTC = 10k @25c, (P/N 271-110A Radio Shack)
//
unsigned int sensor_time;
unsigned int ref_time;
unsigned int timer_count;
unsigned int measure(int); // measures the time to discharge the capacitor
#define Ref (0x01) // P1.0 = Reference
#define Sensor (0x80) // P1.7 = Sensor
//
// Yang Rui
// Lierda, Inc
// MAY 2004
// Built with IAR Embedded Workbench Version: 1.26B
//******************************************************************************
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P5OUT &= ~0x02; // P5.1 reset
P5DIR |= 0x02; // P5.1 output direction
P1OUT &= ~(Ref + Sensor); // Ref set
P1DIR |= Ref + Sensor; // Ref output
CACTL1 = CARSEL + CAREF0 + CAON; // -Comp = 0.25*Vcc - on
CACTL2 = P2CA0; // +Comp = 1.6
TACTL = TASSEL_2 + MC_2; // SMCLK, clear TAR
_EINT(); // Enable interrupts
while (1) // Mainloop
{
sensor_time = measure(Sensor); // Measure discharge time through sensor
ref_time = measure(Ref); // Measure discharge time through Ref
if (sensor_time < ref_time) // if sensor time < ref time ( >25c )
P5OUT |= 0x02; // LED on - Set P5.1
else P5OUT &= ~0x02; // LED off - Reset P5.1
}
}
unsigned int measure(int source) {
P1OUT |= Ref; // Ref Set
P1DIR |= Ref; // Ref output
CCR1 = TAR + 5000; // CCR1 ~ TAR+5ms
CCTL1 = CCIE; // Comp,interrupt
LPM0; // Wait for CCR1 interrupt
P1DIR &= ~Ref; // Ref = HiZ, Charge complete
P1OUT &= ~Ref; // Ref = Reset
CCTL1 = CM_2 + CCIS_1 + CAP + CCIE; // Neg, CCIB,Cap,interrupt
timer_count = TAR; // TAR at before discharge
P1DIR |= source; // Temp = Sensor or Ref
LPM0; // Wait for CCR1 interrupt
timer_count = CCR1 - timer_count; // timer_count = discharge time
P1DIR &= ~(Sensor + Ref); // Disable Sensor or Ref
CCTL1 = 0x00; // Disable CCTL1
return(timer_count);
}
// Timer A1 interrupt service routine
interrupt[TIMERA1_VECTOR] void Timer_A(void)
{
switch( TAIV )
{
case 2: LPM0_EXIT; // ccr1
break;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -