#include #include "lcd.h" #include "delay.h" float sample, CDEG, FDEG, XIN,Y,SIGK; float XIN7 = 25, XIN6 = 25, XIN5 = 25; float XIN4 = 25, XIN3 = 25, XIN2 = 25, XIN1 = 25; const float A = 0.0612, A1 = 21.5927, B = 2.41799; void main(void) { // clock config WDTCTL = WDTPW + WDTHOLD; // Stop WDT // set up Basic Timer IE2 |= BTIE; // Enable BT interrupt BTCTL = BT_ADLY_2000 | BT_fLCD_DIV256; // 128 Hz LCD, 2s Interrupt // set up ADC ADC12IE |= 0x0040; // Enable ADC6 interrupt ADC12CTL0 = ADC12ON + REF2_5V + REFON; // Aref = 2.5V, Aref on ADC12CTL1 = CSTARTADD_6 + ADC12SSEL_1 + SHP; // ADCCLK = ACLK, pulse mode; ADC12MCTL6 = SREF_1 + INCH_6; // Select sixth reg, Aref on, Aref = Vref+,Avss ADC12CTL0 |= ENC ; //set port pins //set P6.6/A6 as input P6SEL |= BIT6; //select adc function //call lcd func setupLCD(); // Enable interrupts and go to sleep forever _EINT(); // Enable interrupts // _BIS_SR(LPM3_bits); // Enter LPM4 while(1); // NOP } // Basic Timer interrupt service routine interrupt[BASICTIMER_VECTOR] void basic_timer(void) { ADC12CTL0 |= ADC12SC; // start conversion } // ADC interrupt service routine interrupt[ADC_VECTOR] void adc(void) { sample = ADC12MEM6; // The sensor signal is brought in on the A to D // converter at ADC12MEM6; XIN = ((sample*A) - A1)/B; // Filter the signal with a 4th order moving average // filter. SIGK = (XIN + XIN4 + XIN5 + XIN6 + XIN7 + XIN1 + XIN2 + XIN3)*0.125; XIN7 = XIN6; XIN6 = XIN5; XIN5 = XIN4; XIN4 = XIN3; XIN3 = XIN2; XIN2 = XIN1; XIN1 = XIN; CDEG = (SIGK); //converting from Kelvin to deg C FDEG = 1.8*CDEG + 32.0; // converting from deg C to deg F lcd_word(100*CDEG, 2); // the l00 moves the position of CDEG // on the display 2 positions to the left //lcd_char(1,' '); // The 1 corresponds to the second position from // the right on thedisplay. The ' ' places a // space in this position. Take out if you want // a decimal with the temperature display. lcd_char(0,'C'); // The 0 corresponds to the first positin on the // right side of the display. The 'C' causes a C // to be displayed in this position wait_ms(2000); // Waits 200 milliseconds then displays deg F lcd_word(100*FDEG, 2); // The l00 moves the position of FDEG on // the display, 2 positions to the left //lcd_char(1,' '); // See the above statement lcd_char(0, 'F'); // See the above statement wait_ms(2000); // Wait 2000 milliseconds. The program then moves // back to lcd_word(100*CDEG, 0) and continues as // a loop } ÿÿ