#include #include "lcd.h" #include "delay.h" double sample, CDEG, FDEG, XIN,Y,SIGK; float XIN7 = 24.5, XIN6 = 24.5, XIN5 = 24.5; float XIN4 = 24.5, XIN3 = 24.5, XIN2 = 24.5, XIN1 = 24.5; const float A = .05699, A1 = 25, B = 2.8; 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) { // ****************************************** // ****************************************** // The following code combines code writen by // Mat Mahin of UNF to get display output for the // AD590 Analog Device temperature sensor. // This code will work for deg F up to 199. For // deg F of 200 and greater, modifications need to // be made on handling the display. A separate lcd // file is developed for this case: lcdHigh.c // Prepared by W. L. Green ECE Department, University // of Tennessee; March, 2006 sample = ADC12MEM6; if(sample < 150){ lcd_scroll("Connect Sensor"); wait_ms(2000); }else{ //AD22103 Code // lcd_scroll("AD22103"); // XIN = ((sample*A) - A1)/B; // AD590 Code // lcd_scroll("AD590"); XIN = ((sample * .613*0.2)-273.2); // Filter the signal with an 8th order moving average // filter. SIGK = (XIN + XIN4 + XIN5 + XIN6 + XIN7 + XIN1 + XIN2 + XIN3)*0.125; if(XIN7 == 0 ){ XIN7 = XIN;}else{ XIN7 = XIN6;} if(XIN6 == 0 ){ XIN6 = XIN;}else{ XIN6 = XIN5;} if(XIN5 == 0 ){ XIN5 = XIN;}else{ XIN5 = XIN4;} if(XIN4 == 0 ){ XIN4 = XIN;}else{ XIN4 = XIN3;} if(XIN3 == 0 ){ XIN3 = XIN;}else{ XIN3 = XIN2;} if(XIN2 == 0 ){ XIN2 = XIN;}else{ 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 // wait_ms(2000); // Output the sample rate (useful for debugging) // lcd_word(sample,0); // wait_ms(2000); 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 } }